Skip to content

Commit 232755c

Browse files
author
Clement Champetier
committed
Profile: set aprofile with a profile desc and a video/audio desc
* OutpuEssence doesn't have a setProfile function: need to know if the essence is video or audio to set its profile. * OutputVideo: set the profile with a profile desc + ImageDesc. * OutputAudio: set the profile with a profile desc + FrameDesc. * Profile: add const string to properly named the option in the profile.
1 parent 32b75bb commit 232755c

File tree

8 files changed

+70
-49
lines changed

8 files changed

+70
-49
lines changed

src/AvTranscoder/EssenceStream/OutputAudio.cpp

Lines changed: 16 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,20 @@ 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+
_audioDesc.setAudioParameters( sample_rate, channels, av_get_sample_fmt( Profile::avProfileSampleFormat.c_str() ) );
175186

176187
setup();
177188
}

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: 28 additions & 30 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,25 +179,24 @@ 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-
// if not specified in the profile desc: 1920*1080, 25 fps, with pixel aspect ratio = 1
182-
const size_t width = ( desc.find( "width" ) != desc.end() ) ? atoi( desc[ "width" ].c_str() ) : 1920;
183-
const size_t height = ( desc.find( "height" ) != desc.end() ) ? atoi( desc[ "height" ].c_str() ) : 1080;
184-
const size_t frameRate = ( desc.find( "r" ) != desc.end() ) ? atoi( desc[ "r" ].c_str() ) : 25;
185-
const size_t par = ( desc.find( "par" ) != desc.end() ) ? atoi( desc[ "par" ].c_str() ) : 1;
186-
const AVPixelFormat pix_fmt = static_cast<AVPixelFormat>( atoi( 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+
}
187190

188-
_videoDesc.setVideoCodec( desc[ "codec" ] );
189-
_videoDesc.setTimeBase( 1, frameRate );
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+
}
190196

191-
avtranscoder::ImageDesc imageDesc;
192-
avtranscoder::Pixel pixel( pix_fmt );
193-
// @todo: set par of pixel
194-
imageDesc.setPixel( pixel );
195-
imageDesc.setWidth( width );
196-
imageDesc.setHeight( height );
197-
imageDesc.setDar( width, height );
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 );
198200
_videoDesc.setImageParameters( imageDesc );
199201

200202
for( Profile::ProfileDesc::iterator it = desc.begin(); it != desc.end(); ++it )
@@ -205,17 +207,15 @@ void OutputVideo::setProfile( Profile::ProfileDesc& desc )
205207
continue;
206208
if( (*it).first == Profile::avProfileType )
207209
continue;
208-
if( (*it).first == "codec" )
210+
if( (*it).first == Profile::avProfileCodec )
209211
continue;
210-
if( (*it).first == "pix_fmt" )
212+
if( (*it).first == Profile::avProfilePixelFormat )
211213
continue;
212-
if( (*it).first == "width" )
214+
if( (*it).first == Profile::avProfileWidth )
213215
continue;
214-
if( (*it).first == "height" )
216+
if( (*it).first == Profile::avProfileHeight )
215217
continue;
216-
if( (*it).first == "r" )
217-
continue;
218-
if( (*it).first == "par" )
218+
if( (*it).first == Profile::avProfileFrameRate )
219219
continue;
220220

221221
try
@@ -238,17 +238,15 @@ void OutputVideo::setProfile( Profile::ProfileDesc& desc )
238238
continue;
239239
if( (*it).first == Profile::avProfileType )
240240
continue;
241-
if( (*it).first == "codec" )
242-
continue;
243-
if( (*it).first == "pix_fmt" )
241+
if( (*it).first == Profile::avProfileCodec )
244242
continue;
245-
if( (*it).first == "width" )
243+
if( (*it).first == Profile::avProfilePixelFormat )
246244
continue;
247-
if( (*it).first == "height" )
245+
if( (*it).first == Profile::avProfileWidth )
248246
continue;
249-
if( (*it).first == "r" )
247+
if( (*it).first == Profile::avProfileHeight )
250248
continue;
251-
if( (*it).first == "par" )
249+
if( (*it).first == Profile::avProfileFrameRate )
252250
continue;
253251

254252
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/Transcoder/StreamTranscoder.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ StreamTranscoder::StreamTranscoder(
6464
OutputVideo* outputVideo = new OutputVideo();
6565

6666
_outputEssence = outputVideo;
67-
_outputEssence->setProfile( profile );
67+
outputVideo->setProfile( profile, _inputStream->getVideoDesc().getImageDesc() );
6868

6969
_outputStream = &outputFile.addVideoStream( outputVideo->getVideoDesc() );
7070
_videoFrameBuffer = new Image( outputVideo->getVideoDesc().getImageDesc() );
@@ -80,7 +80,7 @@ StreamTranscoder::StreamTranscoder(
8080
OutputAudio* outputAudio = new OutputAudio();
8181

8282
_outputEssence = outputAudio;
83-
_outputEssence->setProfile( profile );
83+
outputAudio->setProfile( profile, _inputStream->getAudioDesc().getFrameDesc() );
8484

8585
_outputStream = &outputFile.addAudioStream( outputAudio->getAudioDesc() );
8686
_audioFrameBuffer = new AudioFrame( outputAudio->getAudioDesc().getFrameDesc() );
@@ -118,7 +118,7 @@ StreamTranscoder::StreamTranscoder(
118118
OutputAudio* outputAudio = new OutputAudio();
119119

120120
_outputEssence = outputAudio;
121-
_outputEssence->setProfile( profile );
121+
outputAudio->setProfile( profile, outputAudio->getAudioDesc().getFrameDesc() );
122122

123123
_outputStream = &outputFile.addAudioStream( outputAudio->getAudioDesc() );
124124
_audioFrameBuffer = new AudioFrame( outputAudio->getAudioDesc().getFrameDesc() );
@@ -131,7 +131,7 @@ StreamTranscoder::StreamTranscoder(
131131
OutputVideo* outputVideo = new OutputVideo();
132132

133133
_outputEssence = outputVideo;
134-
_outputEssence->setProfile( profile );
134+
outputVideo->setProfile( profile, outputVideo->getVideoDesc().getImageDesc() );
135135

136136
_outputStream = &outputFile.addVideoStream( outputVideo->getVideoDesc() );
137137
_videoFrameBuffer = new Image( outputVideo->getVideoDesc().getImageDesc() );

0 commit comments

Comments
 (0)