Skip to content

OutputVideo: update setProfile #15

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 13 commits into from
Jul 3, 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
5 changes: 3 additions & 2 deletions app/avTranscoder/avTranscoder.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,11 +26,12 @@ void transcodeVideo( const char* inputfilename, const char* outputFilename )

// init video decoders
InputVideo inputVideo( input.getStream( 0 ) );
Image sourceImage( input.getStream( 0 ).getVideoDesc().getImageDesc() );
ImageDesc imageDesc = input.getStream( 0 ).getVideoDesc().getImageDesc();
Image sourceImage( imageDesc );

// init video encoder
OutputVideo outputVideo;
outputVideo.setProfile( profile.getProfile( "xdcamhd422" ) );
outputVideo.setProfile( profile.getProfile( "xdcamhd422" ), imageDesc );
Image imageToEncode( outputVideo.getVideoDesc().getImageDesc() );

DataStream codedImage;
Expand Down
4 changes: 2 additions & 2 deletions app/presetChecker/presetChecker.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,13 +25,13 @@ int main( int argc, char** argv )
if( profile.find( avtranscoder::Profile::avProfileType )->second == avtranscoder::Profile::avProfileTypeVideo )
{
avtranscoder::OutputVideo outputVideo;
outputVideo.setProfile( profile );
outputVideo.setProfile( profile, outputVideo.getVideoDesc().getImageDesc() );
}

if( profile.find( avtranscoder::Profile::avProfileType )->second == avtranscoder::Profile::avProfileTypeAudio )
{
avtranscoder::OutputAudio outputAudio;
outputAudio.setProfile( profile );
outputAudio.setProfile( profile, outputAudio.getAudioDesc().getFrameDesc() );
}

}
Expand Down
22 changes: 17 additions & 5 deletions src/AvTranscoder/EssenceStream/OutputAudio.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,9 @@ extern "C" {
#include <AvTranscoder/DatasStructures/AudioFrame.hpp>
#include <AvTranscoder/Profile.hpp>

#include <stdexcept>
#include <cstdlib>

namespace avtranscoder
{

Expand Down Expand Up @@ -166,12 +169,21 @@ bool OutputAudio::encodeFrame( DataStream& codedFrame )
#endif
}

void OutputAudio::setProfile( Profile::ProfileDesc& desc )
void OutputAudio::setProfile( Profile::ProfileDesc& desc, const AudioFrameDesc& frameDesc )
{
_audioDesc.setAudioCodec( desc["codec"] );
size_t sample_rate = atoi( desc["sample_rate"].c_str() );
size_t channels = atoi( desc["channels"].c_str() );
_audioDesc.setAudioParameters( sample_rate, channels, av_get_sample_fmt( desc["sample_fmt"].c_str() ) );
if( ! desc.count( Profile::avProfileCodec ) ||
! desc.count( Profile::avProfileSampleFormat ) ||
! desc.count( Profile::avProfileSampleRate ) ||
! desc.count( Profile::avProfileChannel ) )
{
throw std::runtime_error( "The profile " + desc[ Profile::avProfileIdentificatorHuman ] + " is invalid." );
}

_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() ) );

setup();
}
Expand Down
3 changes: 2 additions & 1 deletion src/AvTranscoder/EssenceStream/OutputAudio.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@

#include <AvTranscoder/DatasStructures/AudioDesc.hpp>
#include <AvTranscoder/DatasStructures/DataStreamDesc.hpp>
#include <AvTranscoder/DatasStructures/AudioFrame.hpp>

#include <AvTranscoder/Profile.hpp>

Expand All @@ -28,7 +29,7 @@ class OutputAudio : public OutputEssence
*/
bool encodeFrame( DataStream& codedFrame );

void setProfile( Profile::ProfileDesc& desc );
void setProfile( Profile::ProfileDesc& desc, const AudioFrameDesc& frameDesc );

AudioDesc& getAudioDesc() { return _audioDesc; }

Expand Down
7 changes: 0 additions & 7 deletions src/AvTranscoder/EssenceStream/OutputEssence.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -49,13 +49,6 @@ class AvExport OutputEssence
*/
virtual bool encodeFrame( DataStream& codedFrame ) = 0;

/**
* @brief Set the profile for the encoder
* @note see Profile to get list of supported profiles
* @param desc description of the selected profile
*/
virtual void setProfile( Profile::ProfileDesc& desc ) = 0;

};

}
Expand Down
45 changes: 33 additions & 12 deletions src/AvTranscoder/EssenceStream/OutputVideo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,9 @@ extern "C" {
#include <AvTranscoder/DatasStructures/Image.hpp>
#include <AvTranscoder/Profile.hpp>

#include <stdexcept>
#include <cstdlib>

namespace avtranscoder
{

Expand Down Expand Up @@ -176,11 +179,25 @@ bool OutputVideo::encodeFrame( DataStream& codedFrame )
#endif
}

void OutputVideo::setProfile( Profile::ProfileDesc& desc )
void OutputVideo::setProfile( Profile::ProfileDesc& desc, const avtranscoder::ImageDesc& imageDesc )
{
_videoDesc.setVideoCodec( desc[ "codec" ] );
_videoDesc.setTimeBase( 1, 25 ); // 25 fps
_videoDesc.setImageParameters( 1920, 1080, av_get_pix_fmt( desc[ "pix_fmt" ].c_str() ) );
if( ! desc.count( Profile::avProfileCodec ) ||
! desc.count( Profile::avProfilePixelFormat ) ||
! desc.count( Profile::avProfileFrameRate ) )
{
throw std::runtime_error( "The profile " + desc[ Profile::avProfileIdentificatorHuman ] + " is invalid." );
}

if( ( desc.count( Profile::avProfileWidth ) && std::strtoul( desc[ Profile::avProfileWidth ].c_str(), NULL, 0 ) != imageDesc.getWidth() ) ||
( desc.count( Profile::avProfileHeight ) && std::strtoul( desc[ Profile::avProfileHeight ].c_str(), NULL, 0 ) != imageDesc.getHeight() ) )
{
throw std::runtime_error( "Invalid imageDesc with the profile " + desc[ Profile::avProfileIdentificatorHuman ] + "." );
}

_videoDesc.setVideoCodec( desc[ Profile::avProfileCodec ] );
const size_t frameRate = std::strtoul( desc[ Profile::avProfileFrameRate ].c_str(), NULL, 0 );
_videoDesc.setTimeBase( 1, frameRate );
_videoDesc.setImageParameters( imageDesc );

for( Profile::ProfileDesc::iterator it = desc.begin(); it != desc.end(); ++it )
{
Expand All @@ -190,13 +207,15 @@ void OutputVideo::setProfile( Profile::ProfileDesc& desc )
continue;
if( (*it).first == Profile::avProfileType )
continue;
if( (*it).first == "codec" )
if( (*it).first == Profile::avProfileCodec )
continue;
if( (*it).first == Profile::avProfilePixelFormat )
continue;
if( (*it).first == "pix_fmt" )
if( (*it).first == Profile::avProfileWidth )
continue;
if( (*it).first == "width" )
if( (*it).first == Profile::avProfileHeight )
continue;
if( (*it).first == "height" )
if( (*it).first == Profile::avProfileFrameRate )
continue;

try
Expand All @@ -219,13 +238,15 @@ void OutputVideo::setProfile( Profile::ProfileDesc& desc )
continue;
if( (*it).first == Profile::avProfileType )
continue;
if( (*it).first == "codec" )
if( (*it).first == Profile::avProfileCodec )
continue;
if( (*it).first == Profile::avProfilePixelFormat )
continue;
if( (*it).first == "pix_fmt" )
if( (*it).first == Profile::avProfileWidth )
continue;
if( (*it).first == "width" )
if( (*it).first == Profile::avProfileHeight )
continue;
if( (*it).first == "height" )
if( (*it).first == Profile::avProfileFrameRate )
continue;

try
Expand Down
3 changes: 2 additions & 1 deletion src/AvTranscoder/EssenceStream/OutputVideo.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ extern "C" {

#include <AvTranscoder/DatasStructures/VideoDesc.hpp>
#include <AvTranscoder/DatasStructures/DataStreamDesc.hpp>
#include <AvTranscoder/DatasStructures/Image.hpp>

#include <AvTranscoder/Profile.hpp>

Expand Down Expand Up @@ -43,7 +44,7 @@ class AvExport OutputVideo : public OutputEssence
*/
bool encodeFrame( DataStream& codedFrame );

void setProfile( Profile::ProfileDesc& desc );
void setProfile( Profile::ProfileDesc& desc, const avtranscoder::ImageDesc& imageDesc );

VideoDesc& getVideoDesc() { return _videoDesc; }

Expand Down
30 changes: 20 additions & 10 deletions src/AvTranscoder/OptionLoader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -65,11 +65,11 @@ OptionLoader::OptionLoader()
AVCodec* c = NULL;
while( ( c = av_codec_next( c ) ) != NULL )
{
#if LIBAVCODEC_VERSION_INT >= AV_VERSION_INT( 53, 34, 0 )
if( ! c->encode2 )
#if LIBAVCODEC_VERSION_INT < AV_VERSION_INT( 53, 34, 0 )
if( ! c->encode )
continue;
#else
if( ! c->encode )
if( ! c->encode2 )
continue;
#endif
switch( c->type )
Expand Down Expand Up @@ -153,10 +153,10 @@ OptionLoader::OptionMap OptionLoader::loadVideoCodecOptions()
// iterate on codecs
while( _codec )
{
#if LIBAVCODEC_VERSION_INT >= AV_VERSION_INT( 53, 34, 0 )
if( _codec->encode2 )
#else
#if LIBAVCODEC_VERSION_INT < AV_VERSION_INT( 53, 34, 0 )
if( _codec->encode )
#else
if( _codec->encode2 )
#endif
{
// add only video codec
Expand Down Expand Up @@ -189,10 +189,10 @@ OptionLoader::OptionMap OptionLoader::loadAudioCodecOptions()
// iterate on codecs
while( _codec )
{
#if LIBAVCODEC_VERSION_INT >= AV_VERSION_INT( 53, 34, 0 )
if( _codec->encode2 )
#else
#if LIBAVCODEC_VERSION_INT < AV_VERSION_INT( 53, 34, 0 )
if( _codec->encode )
#else
if( _codec->encode2 )
#endif
{
// add only audio codec
Expand Down Expand Up @@ -276,15 +276,21 @@ OptionLoader::OptionArray OptionLoader::loadOptions( void* av_class, int req_fla
return options;
}

std::vector<std::string> OptionLoader::getPixelFormats ( const std::string& videoCodecName ) const
std::vector<std::string> OptionLoader::getPixelFormats( const std::string& videoCodecName ) const
{
std::vector<std::string> pixelFormats;

// all video codec concerned
if( videoCodecName == "" )
{
const AVPixFmtDescriptor* pixFmtDesc = NULL;

#if LIBAVUTIL_VERSION_INT < AV_VERSION_INT( 51, 44, 0 )
for( int pix_fmt = 0; pix_fmt < PIX_FMT_NB; ++pix_fmt )
pixFmtDesc = &av_pix_fmt_descriptors[pix_fmt];
#else
while( ( pixFmtDesc = av_pix_fmt_desc_next( pixFmtDesc ) ) != NULL )
#endif
{
if( ! pixFmtDesc->name )
continue;
Expand All @@ -301,7 +307,11 @@ std::vector<std::string> OptionLoader::getPixelFormats ( const std::string& vide
size_t pix_fmt = 0;
while( videoCodec->pix_fmts[pix_fmt] != -1 )
{
#if LIBAVUTIL_VERSION_INT < AV_VERSION_INT( 51, 44, 0 )
const AVPixFmtDescriptor* pix_desc = &av_pix_fmt_descriptors[ videoCodec->pix_fmts[pix_fmt] ];
#else
const AVPixFmtDescriptor* pix_desc = av_pix_fmt_desc_get( videoCodec->pix_fmts[pix_fmt] );
#endif
if( ! pix_desc->name )
continue;
pixelFormats.push_back( std::string( pix_desc->name ) );
Expand Down
9 changes: 8 additions & 1 deletion src/AvTranscoder/Profile.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,14 @@ const std::string Profile::avProfileIdentificatorHuman( "avProfileLong" );
const std::string Profile::avProfileType( "avProfileType" );
const std::string Profile::avProfileTypeVideo( "avProfileTypeVideo" );
const std::string Profile::avProfileTypeAudio( "avProfileTypeAudio" );

const std::string Profile::avProfileCodec( "codec" );
const std::string Profile::avProfilePixelFormat( "pix_fmt" );
const std::string Profile::avProfileSampleFormat( "sample_fmt" );
const std::string Profile::avProfileFrameRate( "r" );
const std::string Profile::avProfileSampleRate( "ar" );
const std::string Profile::avProfileChannel( "channel" );
const std::string Profile::avProfileWidth( "width" );
const std::string Profile::avProfileHeight( "height" );

Profile::Profile( bool autoload )
{
Expand Down
10 changes: 10 additions & 0 deletions src/AvTranscoder/Profile.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,16 @@ class Profile

static const std::string avProfileTypeVideo;
static const std::string avProfileTypeAudio;

static const std::string avProfileCodec;
static const std::string avProfilePixelFormat;
static const std::string avProfileSampleFormat;
static const std::string avProfileFrameRate;
static const std::string avProfileSampleRate;
static const std::string avProfileChannel;

static const std::string avProfileWidth;
static const std::string avProfileHeight;

// typedef std::pair< std::string, std::string > KeyDesc;
typedef std::map< std::string, std::string > ProfileDesc;
Expand Down
15 changes: 9 additions & 6 deletions src/AvTranscoder/Profiles/DNxHD.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,28 +10,31 @@ void loadDNxHD( Profile::ProfilesDesc& profiles )
dnxhd120[ Profile::avProfileIdentificator ] = "dnxhd120";
dnxhd120[ Profile::avProfileIdentificatorHuman ] = "DNxHD 120";
dnxhd120[ Profile::avProfileType ] = Profile::avProfileTypeVideo;
dnxhd120[ "codec" ] = "dnxhd";
dnxhd120[ Profile::avProfileCodec ] = "dnxhd";
dnxhd120[ "b" ] = "120000000";
dnxhd120[ "pix_fmt" ] = "yuv422p";
dnxhd120[ Profile::avProfilePixelFormat ] = "yuv422p";
dnxhd120[ "g" ] = "1";
dnxhd120[ Profile::avProfileFrameRate ] = "25";

Profile::ProfileDesc dnxhd185;
dnxhd185[ Profile::avProfileIdentificator ] = "dnxhd185";
dnxhd185[ Profile::avProfileIdentificatorHuman ] = "DNxHD 185";
dnxhd185[ Profile::avProfileType ] = Profile::avProfileTypeVideo;
dnxhd185[ "codec" ] = "dnxhd";
dnxhd185[ Profile::avProfileCodec ] = "dnxhd";
dnxhd185[ "b" ] = "185000000";
dnxhd185[ "pix_fmt" ] = "yuv422p";
dnxhd185[ Profile::avProfilePixelFormat ] = "yuv422p";
dnxhd185[ "g" ] = "1";
dnxhd185[ Profile::avProfileFrameRate ] = "25";

Profile::ProfileDesc dnxhd185x;
dnxhd185x[ Profile::avProfileIdentificator ] = "dnxhd185x";
dnxhd185x[ Profile::avProfileIdentificatorHuman ] = "DNxHD 185 X";
dnxhd185x[ Profile::avProfileType ] = Profile::avProfileTypeVideo;
dnxhd185x[ "codec" ] = "dnxhd";
dnxhd185x[ Profile::avProfileCodec ] = "dnxhd";
dnxhd185x[ "b" ] = "185000000";
dnxhd185x[ "pix_fmt" ] = "yuv422p10";
dnxhd185x[ Profile::avProfilePixelFormat ] = "yuv422p10";
dnxhd185x[ "g" ] = "1";
dnxhd185x[ Profile::avProfileFrameRate ] = "25";

profiles.push_back( dnxhd120 );
profiles.push_back( dnxhd185 );
Expand Down
16 changes: 8 additions & 8 deletions src/AvTranscoder/Profiles/Wave.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,21 +12,21 @@ void loadWave( Profile::ProfilesDesc& profiles )
wave24b48kMono[ Profile::avProfileIdentificatorHuman ] = "Wave 24bits 48kHz mono";
wave24b48kMono[ Profile::avProfileType ] = Profile::avProfileTypeAudio;

wave24b48kMono[ "codec" ] = "pcm_s24le";
wave24b48kMono[ "sample_fmt" ] = "s32";
wave24b48kMono[ "sample_rate" ] = "48000";
wave24b48kMono[ "channels" ] = "1";
wave24b48kMono[ Profile::avProfileCodec ] = "pcm_s24le";
wave24b48kMono[ Profile::avProfileSampleFormat ] = "s32";
wave24b48kMono[ Profile::avProfileSampleRate ] = "48000";
wave24b48kMono[ Profile::avProfileChannel ] = "1";

Profile::ProfileDesc wave16b48kMono;

wave16b48kMono[ Profile::avProfileIdentificator ] = "wave16b48kMono";
wave16b48kMono[ Profile::avProfileIdentificatorHuman ] = "Wave 16bits 48kHz mono";
wave16b48kMono[ Profile::avProfileType ] = Profile::avProfileTypeAudio;

wave16b48kMono[ "codec" ] = "pcm_s16le";
wave16b48kMono[ "sample_fmt" ] = "s16";
wave16b48kMono[ "sample_rate" ] = "48000";
wave16b48kMono[ "channels" ] = "1";
wave16b48kMono[ Profile::avProfileCodec ] = "pcm_s16le";
wave16b48kMono[ Profile::avProfileSampleFormat ] = "s16";
wave16b48kMono[ Profile::avProfileSampleRate ] = "48000";
wave16b48kMono[ Profile::avProfileChannel ] = "1";

profiles.push_back( wave24b48kMono );
profiles.push_back( wave16b48kMono );
Expand Down
5 changes: 3 additions & 2 deletions src/AvTranscoder/Profiles/XdCamHd422.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ void loadXdCamHD422( Profile::ProfilesDesc& profiles )
xdCamHd422[ Profile::avProfileType ] = Profile::avProfileTypeVideo;


xdCamHd422[ "codec" ] = "mpeg2video";
xdCamHd422[ Profile::avProfileCodec ] = "mpeg2video";
xdCamHd422[ "profile" ] = "0"; // FF_PROFILE_MPEG2_422
xdCamHd422[ "level" ] = "2";

Expand All @@ -23,8 +23,9 @@ void loadXdCamHD422( Profile::ProfilesDesc& profiles )
xdCamHd422[ "qmin" ] = "2";
xdCamHd422[ "qmax" ] = "12";
xdCamHd422[ "dc" ] = "2"; // 10 - 8 = 2
xdCamHd422[ Profile::avProfileFrameRate ] = "25";

xdCamHd422[ "pix_fmt" ] = "yuv422p";
xdCamHd422[ Profile::avProfilePixelFormat ] = "yuv422p";

// color informations are not used in FFmpeg/LibAV for Mpeg2
xdCamHd422[ "colorspace" ] = "1"; // AVCOL_SPC_BT709
Expand Down
Loading