Skip to content

Commit bc424b3

Browse files
Conflicts: src/AvTranscoder/Transcoder/Transcoder.cpp src/AvTranscoder/Transcoder/Transcoder.hpp
2 parents e9d3a33 + 8e4ec34 commit bc424b3

File tree

14 files changed

+123
-70
lines changed

14 files changed

+123
-70
lines changed

app/avTranscoder/avTranscoder.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,11 +26,12 @@ void transcodeVideo( const char* inputfilename, const char* outputFilename )
2626

2727
// init video decoders
2828
InputVideo inputVideo( input.getStream( 0 ) );
29-
Image sourceImage( input.getStream( 0 ).getVideoDesc().getImageDesc() );
29+
ImageDesc imageDesc = input.getStream( 0 ).getVideoDesc().getImageDesc();
30+
Image sourceImage( imageDesc );
3031

3132
// init video encoder
3233
OutputVideo outputVideo;
33-
outputVideo.setProfile( profile.getProfile( "xdcamhd422" ) );
34+
outputVideo.setProfile( profile.getProfile( "xdcamhd422" ), imageDesc );
3435
Image imageToEncode( outputVideo.getVideoDesc().getImageDesc() );
3536

3637
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 );
28+
outputVideo.setProfile( profile, outputVideo.getVideoDesc().getImageDesc() );
2929
}
3030

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

3737
}

src/AvTranscoder/EssenceStream/OutputAudio.cpp

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,9 @@ extern "C" {
1212
#include <AvTranscoder/DatasStructures/AudioFrame.hpp>
1313
#include <AvTranscoder/Profile.hpp>
1414

15+
#include <stdexcept>
16+
#include <cstdlib>
17+
1518
namespace avtranscoder
1619
{
1720

@@ -166,12 +169,21 @@ bool OutputAudio::encodeFrame( DataStream& codedFrame )
166169
#endif
167170
}
168171

169-
void OutputAudio::setProfile( Profile::ProfileDesc& desc )
172+
void OutputAudio::setProfile( Profile::ProfileDesc& desc, const AudioFrameDesc& frameDesc )
170173
{
171-
_audioDesc.setAudioCodec( desc["codec"] );
172-
size_t sample_rate = atoi( desc["sample_rate"].c_str() );
173-
size_t channels = atoi( desc["channels"].c_str() );
174-
_audioDesc.setAudioParameters( sample_rate, channels, av_get_sample_fmt( desc["sample_fmt"].c_str() ) );
174+
if( ! desc.count( Profile::avProfileCodec ) ||
175+
! desc.count( Profile::avProfileSampleFormat ) ||
176+
! desc.count( Profile::avProfileSampleRate ) ||
177+
! desc.count( Profile::avProfileChannel ) )
178+
{
179+
throw std::runtime_error( "The profile " + desc[ Profile::avProfileIdentificatorHuman ] + " is invalid." );
180+
}
181+
182+
_audioDesc.setAudioCodec( desc[ Profile::avProfileCodec ] );
183+
size_t sample_rate = std::strtoul( desc[ Profile::avProfileSampleRate ].c_str(), NULL, 0 );
184+
size_t channels = std::strtoul( desc[ Profile::avProfileChannel ].c_str(), NULL, 0 );
185+
186+
_audioDesc.setAudioParameters( sample_rate, channels, av_get_sample_fmt( desc[ Profile::avProfileSampleFormat ].c_str() ) );
175187

176188
setup();
177189
}

src/AvTranscoder/EssenceStream/OutputAudio.hpp

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

66
#include <AvTranscoder/DatasStructures/AudioDesc.hpp>
77
#include <AvTranscoder/DatasStructures/DataStreamDesc.hpp>
8+
#include <AvTranscoder/DatasStructures/AudioFrame.hpp>
89

910
#include <AvTranscoder/Profile.hpp>
1011

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

31-
void setProfile( Profile::ProfileDesc& desc );
32+
void setProfile( Profile::ProfileDesc& desc, const AudioFrameDesc& frameDesc );
3233

3334
AudioDesc& getAudioDesc() { return _audioDesc; }
3435

src/AvTranscoder/EssenceStream/OutputEssence.hpp

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -49,13 +49,6 @@ class AvExport OutputEssence
4949
*/
5050
virtual bool encodeFrame( DataStream& codedFrame ) = 0;
5151

52-
/**
53-
* @brief Set the profile for the encoder
54-
* @note see Profile to get list of supported profiles
55-
* @param desc description of the selected profile
56-
*/
57-
virtual void setProfile( Profile::ProfileDesc& desc ) = 0;
58-
5952
};
6053

6154
}

src/AvTranscoder/EssenceStream/OutputVideo.cpp

Lines changed: 33 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,9 @@ extern "C" {
1515
#include <AvTranscoder/DatasStructures/Image.hpp>
1616
#include <AvTranscoder/Profile.hpp>
1717

18+
#include <stdexcept>
19+
#include <cstdlib>
20+
1821
namespace avtranscoder
1922
{
2023

@@ -176,11 +179,25 @@ bool OutputVideo::encodeFrame( DataStream& codedFrame )
176179
#endif
177180
}
178181

179-
void OutputVideo::setProfile( Profile::ProfileDesc& desc )
182+
void OutputVideo::setProfile( Profile::ProfileDesc& desc, const avtranscoder::ImageDesc& imageDesc )
180183
{
181-
_videoDesc.setVideoCodec( desc[ "codec" ] );
182-
_videoDesc.setTimeBase( 1, 25 ); // 25 fps
183-
_videoDesc.setImageParameters( 1920, 1080, av_get_pix_fmt( desc[ "pix_fmt" ].c_str() ) );
184+
if( ! desc.count( Profile::avProfileCodec ) ||
185+
! desc.count( Profile::avProfilePixelFormat ) ||
186+
! desc.count( Profile::avProfileFrameRate ) )
187+
{
188+
throw std::runtime_error( "The profile " + desc[ Profile::avProfileIdentificatorHuman ] + " is invalid." );
189+
}
190+
191+
if( ( desc.count( Profile::avProfileWidth ) && std::strtoul( desc[ Profile::avProfileWidth ].c_str(), NULL, 0 ) != imageDesc.getWidth() ) ||
192+
( desc.count( Profile::avProfileHeight ) && std::strtoul( desc[ Profile::avProfileHeight ].c_str(), NULL, 0 ) != imageDesc.getHeight() ) )
193+
{
194+
throw std::runtime_error( "Invalid imageDesc with the profile " + desc[ Profile::avProfileIdentificatorHuman ] + "." );
195+
}
196+
197+
_videoDesc.setVideoCodec( desc[ Profile::avProfileCodec ] );
198+
const size_t frameRate = std::strtoul( desc[ Profile::avProfileFrameRate ].c_str(), NULL, 0 );
199+
_videoDesc.setTimeBase( 1, frameRate );
200+
_videoDesc.setImageParameters( imageDesc );
184201

185202
for( Profile::ProfileDesc::iterator it = desc.begin(); it != desc.end(); ++it )
186203
{
@@ -190,13 +207,15 @@ void OutputVideo::setProfile( Profile::ProfileDesc& desc )
190207
continue;
191208
if( (*it).first == Profile::avProfileType )
192209
continue;
193-
if( (*it).first == "codec" )
210+
if( (*it).first == Profile::avProfileCodec )
211+
continue;
212+
if( (*it).first == Profile::avProfilePixelFormat )
194213
continue;
195-
if( (*it).first == "pix_fmt" )
214+
if( (*it).first == Profile::avProfileWidth )
196215
continue;
197-
if( (*it).first == "width" )
216+
if( (*it).first == Profile::avProfileHeight )
198217
continue;
199-
if( (*it).first == "height" )
218+
if( (*it).first == Profile::avProfileFrameRate )
200219
continue;
201220

202221
try
@@ -219,13 +238,15 @@ void OutputVideo::setProfile( Profile::ProfileDesc& desc )
219238
continue;
220239
if( (*it).first == Profile::avProfileType )
221240
continue;
222-
if( (*it).first == "codec" )
241+
if( (*it).first == Profile::avProfileCodec )
242+
continue;
243+
if( (*it).first == Profile::avProfilePixelFormat )
223244
continue;
224-
if( (*it).first == "pix_fmt" )
245+
if( (*it).first == Profile::avProfileWidth )
225246
continue;
226-
if( (*it).first == "width" )
247+
if( (*it).first == Profile::avProfileHeight )
227248
continue;
228-
if( (*it).first == "height" )
249+
if( (*it).first == Profile::avProfileFrameRate )
229250
continue;
230251

231252
try

src/AvTranscoder/EssenceStream/OutputVideo.hpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ extern "C" {
1212

1313
#include <AvTranscoder/DatasStructures/VideoDesc.hpp>
1414
#include <AvTranscoder/DatasStructures/DataStreamDesc.hpp>
15+
#include <AvTranscoder/DatasStructures/Image.hpp>
1516

1617
#include <AvTranscoder/Profile.hpp>
1718

@@ -43,7 +44,7 @@ class AvExport OutputVideo : public OutputEssence
4344
*/
4445
bool encodeFrame( DataStream& codedFrame );
4546

46-
void setProfile( Profile::ProfileDesc& desc );
47+
void setProfile( Profile::ProfileDesc& desc, const avtranscoder::ImageDesc& imageDesc );
4748

4849
VideoDesc& getVideoDesc() { return _videoDesc; }
4950

src/AvTranscoder/Profile.cpp

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,14 @@ const std::string Profile::avProfileIdentificatorHuman( "avProfileLong" );
1919
const std::string Profile::avProfileType( "avProfileType" );
2020
const std::string Profile::avProfileTypeVideo( "avProfileTypeVideo" );
2121
const std::string Profile::avProfileTypeAudio( "avProfileTypeAudio" );
22-
22+
const std::string Profile::avProfileCodec( "codec" );
23+
const std::string Profile::avProfilePixelFormat( "pix_fmt" );
24+
const std::string Profile::avProfileSampleFormat( "sample_fmt" );
25+
const std::string Profile::avProfileFrameRate( "r" );
26+
const std::string Profile::avProfileSampleRate( "ar" );
27+
const std::string Profile::avProfileChannel( "channel" );
28+
const std::string Profile::avProfileWidth( "width" );
29+
const std::string Profile::avProfileHeight( "height" );
2330

2431
Profile::Profile( bool autoload )
2532
{

src/AvTranscoder/Profile.hpp

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,16 @@ class Profile
1818

1919
static const std::string avProfileTypeVideo;
2020
static const std::string avProfileTypeAudio;
21+
22+
static const std::string avProfileCodec;
23+
static const std::string avProfilePixelFormat;
24+
static const std::string avProfileSampleFormat;
25+
static const std::string avProfileFrameRate;
26+
static const std::string avProfileSampleRate;
27+
static const std::string avProfileChannel;
28+
29+
static const std::string avProfileWidth;
30+
static const std::string avProfileHeight;
2131

2232
// typedef std::pair< std::string, std::string > KeyDesc;
2333
typedef std::map< std::string, std::string > ProfileDesc;

src/AvTranscoder/Profiles/DNxHD.hpp

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -10,28 +10,31 @@ void loadDNxHD( Profile::ProfilesDesc& profiles )
1010
dnxhd120[ Profile::avProfileIdentificator ] = "dnxhd120";
1111
dnxhd120[ Profile::avProfileIdentificatorHuman ] = "DNxHD 120";
1212
dnxhd120[ Profile::avProfileType ] = Profile::avProfileTypeVideo;
13-
dnxhd120[ "codec" ] = "dnxhd";
13+
dnxhd120[ Profile::avProfileCodec ] = "dnxhd";
1414
dnxhd120[ "b" ] = "120000000";
15-
dnxhd120[ "pix_fmt" ] = "yuv422p";
15+
dnxhd120[ Profile::avProfilePixelFormat ] = "yuv422p";
1616
dnxhd120[ "g" ] = "1";
17+
dnxhd120[ Profile::avProfileFrameRate ] = "25";
1718

1819
Profile::ProfileDesc dnxhd185;
1920
dnxhd185[ Profile::avProfileIdentificator ] = "dnxhd185";
2021
dnxhd185[ Profile::avProfileIdentificatorHuman ] = "DNxHD 185";
2122
dnxhd185[ Profile::avProfileType ] = Profile::avProfileTypeVideo;
22-
dnxhd185[ "codec" ] = "dnxhd";
23+
dnxhd185[ Profile::avProfileCodec ] = "dnxhd";
2324
dnxhd185[ "b" ] = "185000000";
24-
dnxhd185[ "pix_fmt" ] = "yuv422p";
25+
dnxhd185[ Profile::avProfilePixelFormat ] = "yuv422p";
2526
dnxhd185[ "g" ] = "1";
27+
dnxhd185[ Profile::avProfileFrameRate ] = "25";
2628

2729
Profile::ProfileDesc dnxhd185x;
2830
dnxhd185x[ Profile::avProfileIdentificator ] = "dnxhd185x";
2931
dnxhd185x[ Profile::avProfileIdentificatorHuman ] = "DNxHD 185 X";
3032
dnxhd185x[ Profile::avProfileType ] = Profile::avProfileTypeVideo;
31-
dnxhd185x[ "codec" ] = "dnxhd";
33+
dnxhd185x[ Profile::avProfileCodec ] = "dnxhd";
3234
dnxhd185x[ "b" ] = "185000000";
33-
dnxhd185x[ "pix_fmt" ] = "yuv422p10";
35+
dnxhd185x[ Profile::avProfilePixelFormat ] = "yuv422p10";
3436
dnxhd185x[ "g" ] = "1";
37+
dnxhd185x[ Profile::avProfileFrameRate ] = "25";
3538

3639
profiles.push_back( dnxhd120 );
3740
profiles.push_back( dnxhd185 );

src/AvTranscoder/Profiles/Wave.hpp

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -12,21 +12,21 @@ void loadWave( Profile::ProfilesDesc& profiles )
1212
wave24b48kMono[ Profile::avProfileIdentificatorHuman ] = "Wave 24bits 48kHz mono";
1313
wave24b48kMono[ Profile::avProfileType ] = Profile::avProfileTypeAudio;
1414

15-
wave24b48kMono[ "codec" ] = "pcm_s24le";
16-
wave24b48kMono[ "sample_fmt" ] = "s32";
17-
wave24b48kMono[ "sample_rate" ] = "48000";
18-
wave24b48kMono[ "channels" ] = "1";
15+
wave24b48kMono[ Profile::avProfileCodec ] = "pcm_s24le";
16+
wave24b48kMono[ Profile::avProfileSampleFormat ] = "s32";
17+
wave24b48kMono[ Profile::avProfileSampleRate ] = "48000";
18+
wave24b48kMono[ Profile::avProfileChannel ] = "1";
1919

2020
Profile::ProfileDesc wave16b48kMono;
2121

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

26-
wave16b48kMono[ "codec" ] = "pcm_s16le";
27-
wave16b48kMono[ "sample_fmt" ] = "s16";
28-
wave16b48kMono[ "sample_rate" ] = "48000";
29-
wave16b48kMono[ "channels" ] = "1";
26+
wave16b48kMono[ Profile::avProfileCodec ] = "pcm_s16le";
27+
wave16b48kMono[ Profile::avProfileSampleFormat ] = "s16";
28+
wave16b48kMono[ Profile::avProfileSampleRate ] = "48000";
29+
wave16b48kMono[ Profile::avProfileChannel ] = "1";
3030

3131
profiles.push_back( wave24b48kMono );
3232
profiles.push_back( wave16b48kMono );

src/AvTranscoder/Profiles/XdCamHd422.hpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ void loadXdCamHD422( Profile::ProfilesDesc& profiles )
1313
xdCamHd422[ Profile::avProfileType ] = Profile::avProfileTypeVideo;
1414

1515

16-
xdCamHd422[ "codec" ] = "mpeg2video";
16+
xdCamHd422[ Profile::avProfileCodec ] = "mpeg2video";
1717
xdCamHd422[ "profile" ] = "0"; // FF_PROFILE_MPEG2_422
1818
xdCamHd422[ "level" ] = "2";
1919

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

27-
xdCamHd422[ "pix_fmt" ] = "yuv422p";
28+
xdCamHd422[ Profile::avProfilePixelFormat ] = "yuv422p";
2829

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

0 commit comments

Comments
 (0)