Skip to content

Commit 8ea9d8e

Browse files
Merge pull request #23 from cchampet/getSampleFormats
OutputAudio: completely set audio profile
2 parents 7a6b02d + 90b5113 commit 8ea9d8e

File tree

4 files changed

+99
-34
lines changed

4 files changed

+99
-34
lines changed

src/AvTranscoder/EssenceStream/OutputAudio.cpp

Lines changed: 43 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -191,12 +191,54 @@ void OutputAudio::setProfile( Profile::ProfileDesc& desc, const AudioFrameDesc&
191191
throw std::runtime_error( "Profile " + desc[ Profile::avProfileIdentificatorHuman ] + ": bad audio channel layout." );
192192

193193
_audioDesc.setAudioCodec( desc[ Profile::avProfileCodec ] );
194+
194195
size_t sample_rate = std::strtoul( desc[ Profile::avProfileSampleRate ].c_str(), NULL, 0 );
195196
size_t channels = std::strtoul( desc[ Profile::avProfileChannel ].c_str(), NULL, 0 );
196-
197197
_audioDesc.setAudioParameters( sample_rate, channels, av_get_sample_fmt( desc[ Profile::avProfileSampleFormat ].c_str() ) );
198+
199+
for( Profile::ProfileDesc::iterator it = desc.begin(); it != desc.end(); ++it )
200+
{
201+
if( (*it).first == Profile::avProfileIdentificator ||
202+
(*it).first == Profile::avProfileIdentificatorHuman ||
203+
(*it).first == Profile::avProfileType ||
204+
(*it).first == Profile::avProfileCodec ||
205+
(*it).first == Profile::avProfileSampleFormat ||
206+
(*it).first == Profile::avProfileSampleRate ||
207+
(*it).first == Profile::avProfileChannel )
208+
continue;
209+
210+
try
211+
{
212+
_audioDesc.set( (*it).first, (*it).second );
213+
}
214+
catch( std::exception& e )
215+
{
216+
std::cout << "warning: " << e.what() << std::endl;
217+
}
218+
}
198219

199220
setup();
221+
222+
for( Profile::ProfileDesc::iterator it = desc.begin(); it != desc.end(); ++it )
223+
{
224+
if( (*it).first == Profile::avProfileIdentificator ||
225+
(*it).first == Profile::avProfileIdentificatorHuman ||
226+
(*it).first == Profile::avProfileType ||
227+
(*it).first == Profile::avProfileCodec ||
228+
(*it).first == Profile::avProfileSampleFormat ||
229+
(*it).first == Profile::avProfileSampleRate ||
230+
(*it).first == Profile::avProfileChannel )
231+
continue;
232+
233+
try
234+
{
235+
_audioDesc.set( (*it).first, (*it).second );
236+
}
237+
catch( std::exception& e )
238+
{
239+
std::cout << "2.warning: " << e.what() << std::endl;
240+
}
241+
}
200242
}
201243

202244
}

src/AvTranscoder/EssenceStream/OutputVideo.cpp

Lines changed: 16 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -201,21 +201,14 @@ void OutputVideo::setProfile( Profile::ProfileDesc& desc, const avtranscoder::Im
201201

202202
for( Profile::ProfileDesc::iterator it = desc.begin(); it != desc.end(); ++it )
203203
{
204-
if( (*it).first == Profile::avProfileIdentificator )
205-
continue;
206-
if( (*it).first == Profile::avProfileIdentificatorHuman )
207-
continue;
208-
if( (*it).first == Profile::avProfileType )
209-
continue;
210-
if( (*it).first == Profile::avProfileCodec )
211-
continue;
212-
if( (*it).first == Profile::avProfilePixelFormat )
213-
continue;
214-
if( (*it).first == Profile::avProfileWidth )
215-
continue;
216-
if( (*it).first == Profile::avProfileHeight )
217-
continue;
218-
if( (*it).first == Profile::avProfileFrameRate )
204+
if( (*it).first == Profile::avProfileIdentificator ||
205+
(*it).first == Profile::avProfileIdentificatorHuman ||
206+
(*it).first == Profile::avProfileType ||
207+
(*it).first == Profile::avProfileCodec ||
208+
(*it).first == Profile::avProfilePixelFormat ||
209+
(*it).first == Profile::avProfileWidth ||
210+
(*it).first == Profile::avProfileHeight||
211+
(*it).first == Profile::avProfileFrameRate)
219212
continue;
220213

221214
try
@@ -232,21 +225,14 @@ void OutputVideo::setProfile( Profile::ProfileDesc& desc, const avtranscoder::Im
232225

233226
for( Profile::ProfileDesc::iterator it = desc.begin(); it != desc.end(); ++it )
234227
{
235-
if( (*it).first == Profile::avProfileIdentificator )
236-
continue;
237-
if( (*it).first == Profile::avProfileIdentificatorHuman )
238-
continue;
239-
if( (*it).first == Profile::avProfileType )
240-
continue;
241-
if( (*it).first == Profile::avProfileCodec )
242-
continue;
243-
if( (*it).first == Profile::avProfilePixelFormat )
244-
continue;
245-
if( (*it).first == Profile::avProfileWidth )
246-
continue;
247-
if( (*it).first == Profile::avProfileHeight )
248-
continue;
249-
if( (*it).first == Profile::avProfileFrameRate )
228+
if( (*it).first == Profile::avProfileIdentificator ||
229+
(*it).first == Profile::avProfileIdentificatorHuman ||
230+
(*it).first == Profile::avProfileType ||
231+
(*it).first == Profile::avProfileCodec ||
232+
(*it).first == Profile::avProfilePixelFormat ||
233+
(*it).first == Profile::avProfileWidth ||
234+
(*it).first == Profile::avProfileHeight||
235+
(*it).first == Profile::avProfileFrameRate)
250236
continue;
251237

252238
try

src/AvTranscoder/OptionLoader.cpp

Lines changed: 33 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ extern "C" {
77
#include <libavutil/opt.h>
88
#include <libavutil/pixfmt.h>
99
#include <libavutil/pixdesc.h>
10+
#include <libavutil/samplefmt.h>
1011
}
1112

1213
#ifndef AV_OPT_FLAG_FILTERING_PARAM
@@ -300,9 +301,9 @@ std::vector<std::string> OptionLoader::getPixelFormats( const std::string& video
300301
// specific video codec
301302
else
302303
{
303-
AVCodec* videoCodec = avcodec_find_encoder_by_name( videoCodecName.c_str() );
304+
const AVCodec* videoCodec = avcodec_find_encoder_by_name( videoCodecName.c_str() );
304305

305-
if( videoCodec->pix_fmts != NULL )
306+
if( videoCodec && videoCodec->pix_fmts != NULL )
306307
{
307308
size_t pix_fmt = 0;
308309
while( videoCodec->pix_fmts[pix_fmt] != -1 )
@@ -322,4 +323,34 @@ std::vector<std::string> OptionLoader::getPixelFormats( const std::string& video
322323
return pixelFormats;
323324
}
324325

326+
std::vector<std::string> OptionLoader::getSampleFormats( const std::string& audioCodecName ) const
327+
{
328+
std::vector<std::string> sampleFormats;
329+
330+
if( audioCodecName.empty() )
331+
{
332+
for( size_t sampleFormat = 0; sampleFormat < AV_SAMPLE_FMT_NB; ++sampleFormat)
333+
{
334+
sampleFormats.push_back( av_get_sample_fmt_name( static_cast<AVSampleFormat>( sampleFormat ) ) );
335+
}
336+
}
337+
else
338+
{
339+
const AVCodec* audioCodec = avcodec_find_encoder_by_name( audioCodecName.c_str() );
340+
if( audioCodec && audioCodec->sample_fmts != NULL )
341+
{
342+
size_t sample_fmt = 0;
343+
while( audioCodec->sample_fmts[sample_fmt] != -1 )
344+
{
345+
const char* sampleFormatName = av_get_sample_fmt_name( audioCodec->sample_fmts[sample_fmt] );
346+
if( sampleFormatName )
347+
sampleFormats.push_back( std::string( sampleFormatName ) );
348+
sample_fmt++;
349+
}
350+
}
351+
}
352+
353+
return sampleFormats;
354+
}
355+
325356
}

src/AvTranscoder/OptionLoader.hpp

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,11 +62,17 @@ class OptionLoader
6262
std::vector<std::string>& getAudioCodecsShortNames() { return _audioCodecsShortNames; }
6363

6464
/**
65-
* Get array of pixel format supported by video codec.
65+
* Get array of pixel format supported by a video codec.
6666
* @param videoCodecName: the video codec name (empty if not indicated, and so get all pixel formats supported by all video codecs).
6767
*/
6868
std::vector<std::string> getPixelFormats( const std::string& videoCodecName = "" ) const;
6969

70+
/**
71+
* Get array of sample format supported by an audio codec.
72+
* @param audioCodecName: the audio codec name (empty if not indicated, and so get all sample formats supported by all audio codecs).
73+
*/
74+
std::vector<std::string> getSampleFormats( const std::string& audioCodecName = "" ) const;
75+
7076
private:
7177
/**
7278
* @brief: load array of Option depending on the flags.

0 commit comments

Comments
 (0)