Skip to content

OutputAudio: completely set audio profile #23

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 6 commits into from
Jul 17, 2014
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
44 changes: 43 additions & 1 deletion src/AvTranscoder/EssenceStream/OutputAudio.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -191,12 +191,54 @@ void OutputAudio::setProfile( Profile::ProfileDesc& desc, const AudioFrameDesc&
throw std::runtime_error( "Profile " + desc[ Profile::avProfileIdentificatorHuman ] + ": bad audio channel layout." );

_audioDesc.setAudioCodec( desc[ Profile::avProfileCodec ] );

size_t sample_rate = std::strtoul( desc[ Profile::avProfileSampleRate ].c_str(), NULL, 0 );
size_t channels = std::strtoul( desc[ Profile::avProfileChannel ].c_str(), NULL, 0 );

_audioDesc.setAudioParameters( sample_rate, channels, av_get_sample_fmt( desc[ Profile::avProfileSampleFormat ].c_str() ) );

for( Profile::ProfileDesc::iterator it = desc.begin(); it != desc.end(); ++it )
{
if( (*it).first == Profile::avProfileIdentificator ||
(*it).first == Profile::avProfileIdentificatorHuman ||
(*it).first == Profile::avProfileType ||
(*it).first == Profile::avProfileCodec ||
(*it).first == Profile::avProfileSampleFormat ||
(*it).first == Profile::avProfileSampleRate ||
(*it).first == Profile::avProfileChannel )
continue;

try
{
_audioDesc.set( (*it).first, (*it).second );
}
catch( std::exception& e )
{
std::cout << "warning: " << e.what() << std::endl;
}
}

setup();

for( Profile::ProfileDesc::iterator it = desc.begin(); it != desc.end(); ++it )
{
if( (*it).first == Profile::avProfileIdentificator ||
(*it).first == Profile::avProfileIdentificatorHuman ||
(*it).first == Profile::avProfileType ||
(*it).first == Profile::avProfileCodec ||
(*it).first == Profile::avProfileSampleFormat ||
(*it).first == Profile::avProfileSampleRate ||
(*it).first == Profile::avProfileChannel )
continue;

try
{
_audioDesc.set( (*it).first, (*it).second );
}
catch( std::exception& e )
{
std::cout << "2.warning: " << e.what() << std::endl;
}
}
}

}
Expand Down
46 changes: 16 additions & 30 deletions src/AvTranscoder/EssenceStream/OutputVideo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -201,21 +201,14 @@ void OutputVideo::setProfile( Profile::ProfileDesc& desc, const avtranscoder::Im

for( Profile::ProfileDesc::iterator it = desc.begin(); it != desc.end(); ++it )
{
if( (*it).first == Profile::avProfileIdentificator )
continue;
if( (*it).first == Profile::avProfileIdentificatorHuman )
continue;
if( (*it).first == Profile::avProfileType )
continue;
if( (*it).first == Profile::avProfileCodec )
continue;
if( (*it).first == Profile::avProfilePixelFormat )
continue;
if( (*it).first == Profile::avProfileWidth )
continue;
if( (*it).first == Profile::avProfileHeight )
continue;
if( (*it).first == Profile::avProfileFrameRate )
if( (*it).first == Profile::avProfileIdentificator ||
(*it).first == Profile::avProfileIdentificatorHuman ||
(*it).first == Profile::avProfileType ||
(*it).first == Profile::avProfileCodec ||
(*it).first == Profile::avProfilePixelFormat ||
(*it).first == Profile::avProfileWidth ||
(*it).first == Profile::avProfileHeight||
(*it).first == Profile::avProfileFrameRate)
continue;

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

for( Profile::ProfileDesc::iterator it = desc.begin(); it != desc.end(); ++it )
{
if( (*it).first == Profile::avProfileIdentificator )
continue;
if( (*it).first == Profile::avProfileIdentificatorHuman )
continue;
if( (*it).first == Profile::avProfileType )
continue;
if( (*it).first == Profile::avProfileCodec )
continue;
if( (*it).first == Profile::avProfilePixelFormat )
continue;
if( (*it).first == Profile::avProfileWidth )
continue;
if( (*it).first == Profile::avProfileHeight )
continue;
if( (*it).first == Profile::avProfileFrameRate )
if( (*it).first == Profile::avProfileIdentificator ||
(*it).first == Profile::avProfileIdentificatorHuman ||
(*it).first == Profile::avProfileType ||
(*it).first == Profile::avProfileCodec ||
(*it).first == Profile::avProfilePixelFormat ||
(*it).first == Profile::avProfileWidth ||
(*it).first == Profile::avProfileHeight||
(*it).first == Profile::avProfileFrameRate)
continue;

try
Expand Down
35 changes: 33 additions & 2 deletions src/AvTranscoder/OptionLoader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ extern "C" {
#include <libavutil/opt.h>
#include <libavutil/pixfmt.h>
#include <libavutil/pixdesc.h>
#include <libavutil/samplefmt.h>
}

#ifndef AV_OPT_FLAG_FILTERING_PARAM
Expand Down Expand Up @@ -300,9 +301,9 @@ std::vector<std::string> OptionLoader::getPixelFormats( const std::string& video
// specific video codec
else
{
AVCodec* videoCodec = avcodec_find_encoder_by_name( videoCodecName.c_str() );
const AVCodec* videoCodec = avcodec_find_encoder_by_name( videoCodecName.c_str() );

if( videoCodec->pix_fmts != NULL )
if( videoCodec && videoCodec->pix_fmts != NULL )
{
size_t pix_fmt = 0;
while( videoCodec->pix_fmts[pix_fmt] != -1 )
Expand All @@ -322,4 +323,34 @@ std::vector<std::string> OptionLoader::getPixelFormats( const std::string& video
return pixelFormats;
}

std::vector<std::string> OptionLoader::getSampleFormats( const std::string& audioCodecName ) const
{
std::vector<std::string> sampleFormats;

if( audioCodecName.empty() )
{
for( size_t sampleFormat = 0; sampleFormat < AV_SAMPLE_FMT_NB; ++sampleFormat)
{
sampleFormats.push_back( av_get_sample_fmt_name( static_cast<AVSampleFormat>( sampleFormat ) ) );
}
}
else
{
const AVCodec* audioCodec = avcodec_find_encoder_by_name( audioCodecName.c_str() );
if( audioCodec && audioCodec->sample_fmts != NULL )
{
size_t sample_fmt = 0;
while( audioCodec->sample_fmts[sample_fmt] != -1 )
{
const char* sampleFormatName = av_get_sample_fmt_name( audioCodec->sample_fmts[sample_fmt] );
if( sampleFormatName )
sampleFormats.push_back( std::string( sampleFormatName ) );
sample_fmt++;
}
}
}

return sampleFormats;
}

}
8 changes: 7 additions & 1 deletion src/AvTranscoder/OptionLoader.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -62,11 +62,17 @@ class OptionLoader
std::vector<std::string>& getAudioCodecsShortNames() { return _audioCodecsShortNames; }

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

/**
* Get array of sample format supported by an audio codec.
* @param audioCodecName: the audio codec name (empty if not indicated, and so get all sample formats supported by all audio codecs).
*/
std::vector<std::string> getSampleFormats( const std::string& audioCodecName = "" ) const;

private:
/**
* @brief: load array of Option depending on the flags.
Expand Down