Skip to content

Commit 8ea50c6

Browse files
author
Clement Champetier
committed
Transcoder: can add a stream with a custum profile
* Transcoder: 3 ways to add a stream, which call the private function add( const InputStreamDesc& streamDefinition ). * This impacts: * StreamTranscoder: init with a ProfileDesc instead of a profileName. * OutputEssence (and the subclasses OutputVideo and OutputAudio): set profile with a ProfileDesc instead of a profileName. * swig avTranscoder.i: include Profile because of includes in output essence source files. * avTranscoder app.: can't update the profile with only the profileName. * optionChecker app.: set the profile with the profileDesc.
1 parent 00d1694 commit 8ea50c6

File tree

12 files changed

+111
-51
lines changed

12 files changed

+111
-51
lines changed

app/avTranscoder/avTranscoder.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ void transcodeVideo( const char* inputfilename, const char* outputFilename )
1616

1717
// av_log_set_level( AV_LOG_DEBUG );
1818

19+
Profile profile( true );
1920
ProgressListener p;
2021

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

3031
// init video encoder
3132
OutputVideo outputVideo;
32-
outputVideo.setProfile( "xdcamhd422" );
33+
outputVideo.setProfile( profile.getProfile( "xdcamhd422" ) );
3334
Image imageToEncode( outputVideo.getVideoDesc().getImageDesc() );
3435

3536
DataStream codedImage;

app/presetChecker/presetChecker.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,13 +25,13 @@ int main( int argc, char** argv )
2525
if( profile.find( avtranscoder::Profile::avProfileType )->second == avtranscoder::Profile::avProfileTypeVideo )
2626
{
2727
avtranscoder::OutputVideo outputVideo;
28-
outputVideo.setProfile( profile.find( avtranscoder::Profile::avProfileIdentificator )->second );
28+
outputVideo.setProfile( profile );
2929
}
3030

3131
if( profile.find( avtranscoder::Profile::avProfileType )->second == avtranscoder::Profile::avProfileTypeAudio )
3232
{
3333
avtranscoder::OutputAudio outputAudio;
34-
outputAudio.setProfile( profile.find( avtranscoder::Profile::avProfileIdentificator )->second );
34+
outputAudio.setProfile( profile );
3535
}
3636

3737
}

src/AvTranscoder/EssenceStream/OutputAudio.cpp

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -166,14 +166,10 @@ bool OutputAudio::encodeFrame( DataStream& codedFrame )
166166
#endif
167167
}
168168

169-
void OutputAudio::setProfile( const std::string& profile )
169+
void OutputAudio::setProfile( Profile::ProfileDesc& desc )
170170
{
171-
Profile p;
172-
p.loadProfiles();
173-
Profile::ProfileDesc profDesc = p.getProfile( profile );
174-
175-
_audioDesc.setAudioCodec( profDesc["codec"] );
176-
_audioDesc.setAudioParameters( 48000, 2, av_get_sample_fmt( profDesc["sample_fmt"].c_str() ) );
171+
_audioDesc.setAudioCodec( desc["codec"] );
172+
_audioDesc.setAudioParameters( 48000, 2, av_get_sample_fmt( desc["sample_fmt"].c_str() ) );
177173

178174
setup();
179175
}

src/AvTranscoder/EssenceStream/OutputAudio.hpp

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,12 @@
22
#define _AV_TRANSCODER_ESSENCE_STREAM_OUTPUT_AUDIO_HPP_
33

44
#include "OutputEssence.hpp"
5+
56
#include <AvTranscoder/DatasStructures/AudioDesc.hpp>
67
#include <AvTranscoder/DatasStructures/DataStreamDesc.hpp>
78

9+
#include <AvTranscoder/Profile.hpp>
10+
811
namespace avtranscoder
912
{
1013

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

28-
void setProfile( const std::string& profile );
31+
void setProfile( Profile::ProfileDesc& desc );
2932

3033
AudioDesc& getAudioDesc() { return _audioDesc; }
3134

src/AvTranscoder/EssenceStream/OutputEssence.hpp

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@ extern "C" {
1414
#include <AvTranscoder/DatasStructures/Frame.hpp>
1515
#include <AvTranscoder/DatasStructures/DataStreamDesc.hpp>
1616

17+
#include <AvTranscoder/Profile.hpp>
18+
1719
namespace avtranscoder
1820
{
1921

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

5759
};
5860

src/AvTranscoder/EssenceStream/OutputVideo.cpp

Lines changed: 5 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -176,19 +176,13 @@ bool OutputVideo::encodeFrame( DataStream& codedFrame )
176176
#endif
177177
}
178178

179-
void OutputVideo::setProfile( const std::string& profile )
179+
void OutputVideo::setProfile( Profile::ProfileDesc& desc )
180180
{
181-
Profile p;
182-
183-
p.loadProfiles();
184-
185-
Profile::ProfileDesc prof = p.getProfile( profile );
186-
187-
_videoDesc.setVideoCodec( prof[ "codec" ] );
181+
_videoDesc.setVideoCodec( desc[ "codec" ] );
188182
_videoDesc.setTimeBase( 1, 25 ); // 25 fps
189-
_videoDesc.setImageParameters( 1920, 1080, av_get_pix_fmt( prof[ "pix_fmt" ].c_str() ) );
183+
_videoDesc.setImageParameters( 1920, 1080, av_get_pix_fmt( desc[ "pix_fmt" ].c_str() ) );
190184

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

218212
setup();
219213

220-
for( Profile::ProfileDesc::iterator it = prof.begin(); it != prof.end(); ++it )
214+
for( Profile::ProfileDesc::iterator it = desc.begin(); it != desc.end(); ++it )
221215
{
222216
if( (*it).first == Profile::avProfileIdentificator )
223217
continue;

src/AvTranscoder/EssenceStream/OutputVideo.hpp

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@ extern "C" {
1313
#include <AvTranscoder/DatasStructures/VideoDesc.hpp>
1414
#include <AvTranscoder/DatasStructures/DataStreamDesc.hpp>
1515

16+
#include <AvTranscoder/Profile.hpp>
17+
1618
#include <string>
1719
#include <vector>
1820

@@ -41,10 +43,10 @@ class AvExport OutputVideo : public OutputEssence
4143
*/
4244
bool encodeFrame( DataStream& codedFrame );
4345

46+
void setProfile( Profile::ProfileDesc& desc );
47+
4448
VideoDesc& getVideoDesc() { return _videoDesc; }
4549

46-
void setProfile( const std::string& profile );
47-
4850
private:
4951
VideoDesc _videoDesc;
5052
};

src/AvTranscoder/Transcoder/StreamTranscoder.cpp

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -27,9 +27,10 @@ StreamTranscoder::~StreamTranscoder()
2727
delete _outputEssence;
2828
}
2929

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

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

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

51-
_outputEssence->setProfile( profile );
52+
Profile::ProfileDesc prof = profileDesc;
53+
_outputEssence->setProfile( prof );
5254
_outputFile->addVideoStream( outputVideo->getVideoDesc() );
5355
_videoFrameBuffer = new Image( outputVideo->getVideoDesc().getImageDesc() );
5456
_frameBuffer = _videoFrameBuffer;
@@ -61,7 +63,7 @@ void StreamTranscoder::init( const std::string& profile )
6163
_inputEssence->setup();
6264

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

73-
_outputEssence->setProfile( profile );
75+
Profile::ProfileDesc prof = profileDesc;
76+
_outputEssence->setProfile( prof );
7477
_outputFile->addAudioStream( outputAudio->getAudioDesc() );
7578
_audioFrameBuffer = new AudioFrame( outputAudio->getAudioDesc().getFrameDesc() );
7679
_frameBuffer = _audioFrameBuffer;

src/AvTranscoder/Transcoder/StreamTranscoder.hpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111

1212
#include <AvTranscoder/File/OutputFile.hpp>
1313

14+
#include <AvTranscoder/Profile.hpp>
1415

1516
namespace avtranscoder
1617
{
@@ -21,7 +22,7 @@ class StreamTranscoder
2122
StreamTranscoder( InputStream& stream, OutputFile& outputFile, const size_t& streamId );
2223
~StreamTranscoder();
2324

24-
void init( const std::string& profile );
25+
void init( const Profile::ProfileDesc& profileDesc );
2526

2627
bool processFrame();
2728

src/AvTranscoder/Transcoder/Transcoder.cpp

Lines changed: 32 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ namespace avtranscoder
99

1010
Transcoder::Transcoder( OutputFile& outputFile )
1111
: _outputFile( outputFile )
12+
, _profile( true )
1213
{
1314
_outputFile.setup();
1415
}
@@ -31,8 +32,36 @@ Transcoder::~Transcoder()
3132
}
3233
}
3334

34-
void Transcoder::add( const std::string& filename, const size_t streamIndex, const std::string& profile )
35+
void Transcoder::add( const std::string& filename, const size_t streamIndex, const std::string& profileName )
3536
{
37+
InputStreamDesc streamDesc( streamIndex, filename, profileName );
38+
add( streamDesc );
39+
}
40+
41+
void Transcoder::add( const std::string& filename, const size_t streamIndex, const Profile::ProfileDesc& profileDesc )
42+
{
43+
_profile.update( profileDesc );
44+
45+
InputStreamDesc streamDesc( streamIndex, filename, profileDesc );
46+
add( streamDesc );
47+
}
48+
49+
void Transcoder::add( const InputStreamsDesc& streamDefs )
50+
{
51+
for( size_t streamDest = 0; streamDest < streamDefs.size(); ++streamDest )
52+
{
53+
add( streamDefs.at( streamDest ) );
54+
}
55+
if( _inputStreams.size() != _streamTranscoders.size() )
56+
throw std::runtime_error( "_inputStreams and _streamTranscoders must have the same number of streams" );
57+
}
58+
59+
void Transcoder::add( const InputStreamDesc& streamDefinition )
60+
{
61+
const std::string filename( streamDefinition.filename );
62+
const size_t streamIndex = streamDefinition.streamId;
63+
const Profile::ProfileDesc profileDesc = streamDefinition.transcodeProfile;
64+
3665
if( ! filename.length() )
3766
{
3867
try
@@ -82,15 +111,15 @@ void Transcoder::add( const std::string& filename, const size_t streamIndex, con
82111
case AVMEDIA_TYPE_VIDEO:
83112
{
84113
StreamTranscoder* streamTranscoder = new StreamTranscoder( referenceFile->getStream( streamIndex ), _outputFile, _streamTranscoders.size() );
85-
streamTranscoder->init( profile );
114+
streamTranscoder->init( profileDesc );
86115
_streamTranscoders.push_back( streamTranscoder );
87116
_inputStreams.push_back( & referenceFile->getStream( streamIndex ) );
88117
break;
89118
}
90119
case AVMEDIA_TYPE_AUDIO:
91120
{
92121
StreamTranscoder* streamTranscoder = new StreamTranscoder( referenceFile->getStream( streamIndex ), _outputFile, _streamTranscoders.size() );
93-
streamTranscoder->init( profile );
122+
streamTranscoder->init( profileDesc );
94123
_streamTranscoders.push_back( streamTranscoder );
95124
_inputStreams.push_back( & referenceFile->getStream( streamIndex ) );
96125
break;
@@ -106,18 +135,6 @@ void Transcoder::add( const std::string& filename, const size_t streamIndex, con
106135
return;
107136
}
108137

109-
void Transcoder::add( const InputStreamsDesc& streamDefs )
110-
{
111-
for( size_t streamDest = 0; streamDest < streamDefs.size(); ++streamDest )
112-
{
113-
add( streamDefs.at( streamDest ).filename,
114-
streamDefs.at( streamDest ).streamId,
115-
streamDefs.at( streamDest ).transcodeProfile );
116-
}
117-
if( _inputStreams.size() != _streamTranscoders.size() )
118-
throw std::runtime_error( "error during settings streams and transcoders" );
119-
}
120-
121138

122139
bool Transcoder::processFrame()
123140
{

src/AvTranscoder/Transcoder/Transcoder.hpp

Lines changed: 40 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
#include <AvTranscoder/CodedStream/InputStream.hpp>
77
#include <AvTranscoder/ProgressListener.hpp>
88
#include <AvTranscoder/DummyInputStream.hpp>
9+
#include <AvTranscoder/Profile.hpp>
910

1011
#include <string>
1112
#include <vector>
@@ -22,29 +23,63 @@ class Transcoder
2223
struct InputStreamDesc {
2324
size_t streamId;
2425
std::string filename;
25-
std::string transcodeProfile;
26+
Profile::ProfileDesc transcodeProfile;
2627

27-
InputStreamDesc( const size_t& sId, const std::string& filename, const std::string& profile )
28+
InputStreamDesc( const size_t& sId, const std::string& filename, const Profile::ProfileDesc& profile )
2829
: streamId( sId )
2930
, filename( filename )
3031
, transcodeProfile( profile )
3132
{
3233
}
34+
35+
InputStreamDesc( const size_t& sId, const std::string& filename, const std::string& profileName )
36+
: streamId( sId )
37+
, filename( filename )
38+
{
39+
try
40+
{
41+
Profile p( true );
42+
transcodeProfile = p.getProfile( profileName );
43+
}
44+
// if the profile doesn't exist
45+
catch( std::exception& e )
46+
{
47+
Profile::ProfileDesc emptyDesc;
48+
emptyDesc[ Profile::avProfileIdentificator ] = "";
49+
emptyDesc[ Profile::avProfileIdentificatorHuman ] = "";
50+
51+
transcodeProfile = emptyDesc;
52+
}
53+
}
3354
};
3455

3556
typedef std::vector< InputStreamDesc > InputStreamsDesc;
3657

3758
Transcoder( OutputFile& outputFile );
3859
~Transcoder();
3960

40-
void add( const std::string& filename, const size_t streamIndex, const std::string& profile );
61+
/**
62+
* @brief Add a stream and set a profile
63+
* @note If profile is empty, add a dummy stream.
64+
*/
65+
void add( const std::string& filename, const size_t streamIndex, const std::string& profileName = "" );
66+
/**
67+
* @brief Add a srteam and set a custom profile
68+
* @note Profile will be updated, be sure to pass unique profile name.
69+
*/
70+
void add( const std::string& filename, const size_t streamIndex, const Profile::ProfileDesc& profileDesc );
71+
/**
72+
* @brief Add a list of streams.
73+
*/
4174
void add( const InputStreamsDesc& streamDefs );
4275

4376
bool processFrame();
4477

4578
void process( ProgressListener& progress );
4679

4780
private:
81+
void add( const InputStreamDesc& streamDefinition );
82+
4883
bool getStreamsNextPacket( std::vector< DataStream >& dataStreams );
4984

5085
private:
@@ -55,6 +90,8 @@ class Transcoder
5590
std::vector< StreamTranscoder* > _streamTranscoders;
5691

5792
std::vector< DummyInputStream* > _dummyInputStreams;
93+
94+
Profile _profile;
5895
};
5996

6097
}

0 commit comments

Comments
 (0)