Skip to content

Transcoder: can add a stream with a custum profile #11

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 5 commits into from
Jun 30, 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
3 changes: 2 additions & 1 deletion app/avTranscoder/avTranscoder.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ void transcodeVideo( const char* inputfilename, const char* outputFilename )

// av_log_set_level( AV_LOG_DEBUG );

Profile profile( true );
ProgressListener p;

InputFile input( inputfilename );
Expand All @@ -29,7 +30,7 @@ void transcodeVideo( const char* inputfilename, const char* outputFilename )

// init video encoder
OutputVideo outputVideo;
outputVideo.setProfile( "xdcamhd422" );
outputVideo.setProfile( profile.getProfile( "xdcamhd422" ) );
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.find( avtranscoder::Profile::avProfileIdentificator )->second );
outputVideo.setProfile( profile );
}

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

}
Expand Down
10 changes: 3 additions & 7 deletions src/AvTranscoder/EssenceStream/OutputAudio.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -166,14 +166,10 @@ bool OutputAudio::encodeFrame( DataStream& codedFrame )
#endif
}

void OutputAudio::setProfile( const std::string& profile )
void OutputAudio::setProfile( Profile::ProfileDesc& desc )
{
Profile p;
p.loadProfiles();
Profile::ProfileDesc profDesc = p.getProfile( profile );

_audioDesc.setAudioCodec( profDesc["codec"] );
_audioDesc.setAudioParameters( 48000, 2, av_get_sample_fmt( profDesc["sample_fmt"].c_str() ) );
_audioDesc.setAudioCodec( desc["codec"] );
_audioDesc.setAudioParameters( 48000, 2, av_get_sample_fmt( desc["sample_fmt"].c_str() ) );

setup();
}
Expand Down
5 changes: 4 additions & 1 deletion src/AvTranscoder/EssenceStream/OutputAudio.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,12 @@
#define _AV_TRANSCODER_ESSENCE_STREAM_OUTPUT_AUDIO_HPP_

#include "OutputEssence.hpp"

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

#include <AvTranscoder/Profile.hpp>

namespace avtranscoder
{

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

void setProfile( const std::string& profile );
void setProfile( Profile::ProfileDesc& desc );

AudioDesc& getAudioDesc() { return _audioDesc; }

Expand Down
6 changes: 4 additions & 2 deletions src/AvTranscoder/EssenceStream/OutputEssence.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ extern "C" {
#include <AvTranscoder/DatasStructures/Frame.hpp>
#include <AvTranscoder/DatasStructures/DataStreamDesc.hpp>

#include <AvTranscoder/Profile.hpp>

namespace avtranscoder
{

Expand Down Expand Up @@ -50,9 +52,9 @@ class AvExport OutputEssence
/**
* @brief Set the profile for the encoder
* @note see Profile to get list of supported profiles
* @param profile selected profile name
* @param desc description of the selected profile
*/
virtual void setProfile( const std::string& profile ) = 0;
virtual void setProfile( Profile::ProfileDesc& desc ) = 0;

};

Expand Down
16 changes: 5 additions & 11 deletions src/AvTranscoder/EssenceStream/OutputVideo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -176,19 +176,13 @@ bool OutputVideo::encodeFrame( DataStream& codedFrame )
#endif
}

void OutputVideo::setProfile( const std::string& profile )
void OutputVideo::setProfile( Profile::ProfileDesc& desc )
{
Profile p;

p.loadProfiles();

Profile::ProfileDesc prof = p.getProfile( profile );

_videoDesc.setVideoCodec( prof[ "codec" ] );
_videoDesc.setVideoCodec( desc[ "codec" ] );
_videoDesc.setTimeBase( 1, 25 ); // 25 fps
_videoDesc.setImageParameters( 1920, 1080, av_get_pix_fmt( prof[ "pix_fmt" ].c_str() ) );
_videoDesc.setImageParameters( 1920, 1080, av_get_pix_fmt( desc[ "pix_fmt" ].c_str() ) );

for( Profile::ProfileDesc::iterator it = prof.begin(); it != prof.end(); ++it )
for( Profile::ProfileDesc::iterator it = desc.begin(); it != desc.end(); ++it )
{
if( (*it).first == Profile::avProfileIdentificator )
continue;
Expand Down Expand Up @@ -217,7 +211,7 @@ void OutputVideo::setProfile( const std::string& profile )

setup();

for( Profile::ProfileDesc::iterator it = prof.begin(); it != prof.end(); ++it )
for( Profile::ProfileDesc::iterator it = desc.begin(); it != desc.end(); ++it )
{
if( (*it).first == Profile::avProfileIdentificator )
continue;
Expand Down
6 changes: 4 additions & 2 deletions src/AvTranscoder/EssenceStream/OutputVideo.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ extern "C" {
#include <AvTranscoder/DatasStructures/VideoDesc.hpp>
#include <AvTranscoder/DatasStructures/DataStreamDesc.hpp>

#include <AvTranscoder/Profile.hpp>

#include <string>
#include <vector>

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

void setProfile( Profile::ProfileDesc& desc );

VideoDesc& getVideoDesc() { return _videoDesc; }

void setProfile( const std::string& profile );

private:
VideoDesc _videoDesc;
};
Expand Down
28 changes: 26 additions & 2 deletions src/AvTranscoder/Profile.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,10 @@ const std::string Profile::avProfileTypeVideo( "avProfileTypeVideo" );
const std::string Profile::avProfileTypeAudio( "avProfileTypeAudio" );


Profile::Profile()
Profile::Profile( bool autoload )
{

if( autoload )
loadProfiles();
}

void Profile::loadProfiles()
Expand Down Expand Up @@ -78,6 +79,23 @@ void Profile::loadProfiles()
}
}

void Profile::update( const ProfileDesc& profile )
{
std::string profileId( profile.find( avProfileIdentificator )->second );
size_t profileIndex = 0;
for( ProfilesDesc::iterator it = _profiles.begin(); it != _profiles.end(); ++it )
{
if( (*it).find( avProfileIdentificator )->second == profileId )
{
_profiles.at( profileIndex ) = profile;
return;
}
++profileIndex;
}
// profile not found: add the new profile
_profiles.push_back( profile );
}

const Profile::ProfilesDesc& Profile::getProfiles()
{
return _profiles;
Expand All @@ -100,6 +118,12 @@ Profile::ProfilesDesc Profile::getAudioProfiles()
{
ProfilesDesc profiles;

for( ProfilesDesc::iterator it = _profiles.begin(); it != _profiles.end(); ++it )
{
if( (*it).find( avProfileType )->second == avProfileTypeAudio )
profiles.push_back( *it );
}

return profiles;
}

Expand Down
4 changes: 3 additions & 1 deletion src/AvTranscoder/Profile.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,12 @@ class Profile
typedef std::map< std::string, std::string > ProfileDesc;
typedef std::vector< ProfileDesc > ProfilesDesc;

Profile();
Profile( bool autoload = false );

void loadProfiles();

void update( const ProfileDesc& profile );

const ProfilesDesc& getProfiles();

ProfilesDesc getVideoProfiles();
Expand Down
15 changes: 9 additions & 6 deletions src/AvTranscoder/Transcoder/StreamTranscoder.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,10 @@ StreamTranscoder::~StreamTranscoder()
delete _outputEssence;
}

void StreamTranscoder::init( const std::string& profile )
void StreamTranscoder::init( const Profile::ProfileDesc& profileDesc )
{
_transcodeStream = profile.size();
const std::string profileName = profileDesc.find( Profile::avProfileIdentificator )->second;
_transcodeStream = profileName.size();

switch( _stream->getStreamType() )
{
Expand All @@ -39,7 +40,7 @@ void StreamTranscoder::init( const std::string& profile )
_inputEssence->setup();

// re-wrap only, get output descriptor from input
if( profile.empty() )
if( profileName.empty() )
{
_outputFile->addVideoStream( _stream->getVideoDesc() );
break;
Expand All @@ -48,7 +49,8 @@ void StreamTranscoder::init( const std::string& profile )
OutputVideo* outputVideo = new OutputVideo();
_outputEssence = outputVideo;

_outputEssence->setProfile( profile );
Profile::ProfileDesc prof = profileDesc;
_outputEssence->setProfile( prof );
_outputFile->addVideoStream( outputVideo->getVideoDesc() );
_videoFrameBuffer = new Image( outputVideo->getVideoDesc().getImageDesc() );
_frameBuffer = _videoFrameBuffer;
Expand All @@ -61,7 +63,7 @@ void StreamTranscoder::init( const std::string& profile )
_inputEssence->setup();

// re-wrap only, get output descriptor from input
if( profile.empty() )
if( profileName.empty() )
{
_outputFile->addAudioStream( _stream->getAudioDesc() );
break;
Expand All @@ -70,7 +72,8 @@ void StreamTranscoder::init( const std::string& profile )
OutputAudio* outputAudio = new OutputAudio();
_outputEssence = outputAudio;

_outputEssence->setProfile( profile );
Profile::ProfileDesc prof = profileDesc;
_outputEssence->setProfile( prof );
_outputFile->addAudioStream( outputAudio->getAudioDesc() );
_audioFrameBuffer = new AudioFrame( outputAudio->getAudioDesc().getFrameDesc() );
_frameBuffer = _audioFrameBuffer;
Expand Down
3 changes: 2 additions & 1 deletion src/AvTranscoder/Transcoder/StreamTranscoder.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@

#include <AvTranscoder/File/OutputFile.hpp>

#include <AvTranscoder/Profile.hpp>

namespace avtranscoder
{
Expand All @@ -21,7 +22,7 @@ class StreamTranscoder
StreamTranscoder( InputStream& stream, OutputFile& outputFile, const size_t& streamId );
~StreamTranscoder();

void init( const std::string& profile );
void init( const Profile::ProfileDesc& profileDesc );

bool processFrame();

Expand Down
47 changes: 32 additions & 15 deletions src/AvTranscoder/Transcoder/Transcoder.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ namespace avtranscoder

Transcoder::Transcoder( OutputFile& outputFile )
: _outputFile( outputFile )
, _profile( true )
{
_outputFile.setup();
}
Expand All @@ -31,8 +32,36 @@ Transcoder::~Transcoder()
}
}

void Transcoder::add( const std::string& filename, const size_t streamIndex, const std::string& profile )
void Transcoder::add( const std::string& filename, const size_t streamIndex, const std::string& profileName )
{
InputStreamDesc streamDesc( streamIndex, filename, profileName );
add( streamDesc );
}

void Transcoder::add( const std::string& filename, const size_t streamIndex, const Profile::ProfileDesc& profileDesc )
{
_profile.update( profileDesc );

InputStreamDesc streamDesc( streamIndex, filename, profileDesc );
add( streamDesc );
}

void Transcoder::add( const InputStreamsDesc& streamDefs )
{
for( size_t streamDest = 0; streamDest < streamDefs.size(); ++streamDest )
{
add( streamDefs.at( streamDest ) );
}
if( _inputStreams.size() != _streamTranscoders.size() )
throw std::runtime_error( "_inputStreams and _streamTranscoders must have the same number of streams" );
}

void Transcoder::add( const InputStreamDesc& streamDefinition )
{
const std::string filename( streamDefinition.filename );
const size_t streamIndex = streamDefinition.streamId;
const Profile::ProfileDesc profileDesc = streamDefinition.transcodeProfile;

if( ! filename.length() )
{
try
Expand Down Expand Up @@ -82,15 +111,15 @@ void Transcoder::add( const std::string& filename, const size_t streamIndex, con
case AVMEDIA_TYPE_VIDEO:
{
StreamTranscoder* streamTranscoder = new StreamTranscoder( referenceFile->getStream( streamIndex ), _outputFile, _streamTranscoders.size() );
streamTranscoder->init( profile );
streamTranscoder->init( profileDesc );
_streamTranscoders.push_back( streamTranscoder );
_inputStreams.push_back( & referenceFile->getStream( streamIndex ) );
break;
}
case AVMEDIA_TYPE_AUDIO:
{
StreamTranscoder* streamTranscoder = new StreamTranscoder( referenceFile->getStream( streamIndex ), _outputFile, _streamTranscoders.size() );
streamTranscoder->init( profile );
streamTranscoder->init( profileDesc );
_streamTranscoders.push_back( streamTranscoder );
_inputStreams.push_back( & referenceFile->getStream( streamIndex ) );
break;
Expand All @@ -106,18 +135,6 @@ void Transcoder::add( const std::string& filename, const size_t streamIndex, con
return;
}

void Transcoder::add( const InputStreamsDesc& streamDefs )
{
for( size_t streamDest = 0; streamDest < streamDefs.size(); ++streamDest )
{
add( streamDefs.at( streamDest ).filename,
streamDefs.at( streamDest ).streamId,
streamDefs.at( streamDest ).transcodeProfile );
}
if( _inputStreams.size() != _streamTranscoders.size() )
throw std::runtime_error( "error during settings streams and transcoders" );
}


bool Transcoder::processFrame()
{
Expand Down
Loading