Skip to content

Commit fea8586

Browse files
update profile and profile usage in transcoder
1 parent 67e903c commit fea8586

File tree

3 files changed

+105
-104
lines changed

3 files changed

+105
-104
lines changed

app/avTranscoder/avTranscoder.cpp

Lines changed: 30 additions & 82 deletions
Original file line numberDiff line numberDiff line change
@@ -20,122 +20,71 @@ void transcodeVideo( const char* inputfilename, const char* outputFilename )
2020
{
2121
using namespace avtranscoder;
2222

23-
av_log_set_level( AV_LOG_FATAL );
24-
//av_log_set_level( AV_LOG_DEBUG );
23+
// av_log_set_level( AV_LOG_DEBUG );
2524

26-
InputFile inputFile( inputfilename );
27-
inputFile.analyse();
25+
InputFile input( inputfilename );
26+
input.analyse();
2827

29-
// init video decoders
30-
InputStreamVideo inputStreamVideo( inputFile.getStream( 0 ) );
28+
input.readStream( input.getProperties().videoStreams.at( 0 ).streamId );
3129

32-
// init audio decoders
33-
//InputStreamAudio inputStreamAudio( inputFile.getStream( 1 ) );
34-
//InputStreamAudio inputStreamAudioRight( inputFile.getStream( 2 ) );
30+
// init video decoders
31+
InputStreamVideo inputStreamVideo( input.getStream( 0 ) );
32+
Image sourceImage( inputStreamVideo.getVideoDesc().getImageDesc() );
3533

36-
// init video & audio encoders
34+
// init video encoder
3735
OutputStreamVideo outputStreamVideo;
38-
39-
VideoDesc& videoDesc = outputStreamVideo.getVideoDesc();
40-
41-
Pixel oPixel;
42-
43-
oPixel.setSubsampling( eSubsampling422 );
44-
oPixel.setBitsPerPixel( 16 );
45-
46-
ImageDesc imageDesc;
47-
imageDesc.setWidth ( inputFile.getProperties().videoStreams.at(0).width );
48-
imageDesc.setHeight( inputFile.getProperties().videoStreams.at(0).height );
49-
imageDesc.setPixel ( oPixel );
50-
51-
Image sourceImage( imageDesc );
52-
53-
videoDesc.setVideoCodec( "mpeg2video" );
54-
videoDesc.set( "b", 5000 );
55-
56-
try
57-
{
58-
videoDesc.set( "unknownParameter", 120000000 );
59-
}
60-
catch( const std::exception& e )
61-
{
62-
std::cout << "[ERROR] " << e.what() << std::endl;
63-
}
64-
65-
videoDesc.setTimeBase( 1, 25 ); // 25 fps
66-
67-
videoDesc.setImageParameters( sourceImage.desc() );
68-
69-
//videoDesc.initCodecContext();
70-
71-
if( !outputStreamVideo.setup( ) )
72-
{
73-
throw std::runtime_error( "error during initialising video output stream" );
74-
}
75-
76-
Image imageToEncode( sourceImage );
36+
outputStreamVideo.setProfile( "xdcamhd422" );
37+
Image imageToEncode( outputStreamVideo.getVideoDesc().getImageDesc() );
38+
7739
DataStream codedImage;
7840

79-
80-
// OutputStreamAudio osAudioLeft ( ); // "AudioStreamEncoder" / "AudioOutputStream" ?
81-
// OutputStreamAudio osAudioRight( );
82-
// OutputStreamAudio osAudioLfe ( );
83-
8441
// setup wrapper
85-
OutputFile of( outputFilename ); // "Format" ? to keep libav naming
42+
//mxftkwrapper::MxftkOutputFile of( outputFilename );
43+
OutputFile of( outputFilename );
8644

8745

8846
if( ! of.setup( ) )
8947
{
90-
throw std::runtime_error( "error during setup output file" );
48+
std::cout << "error during setup output file" << std::endl;
49+
exit( -1 );
9150
}
9251

93-
of.addVideoStream( inputFile.getStream( 0 ).getVideoDesc() );
94-
/*of.addAudioStream();
95-
of.addAudioStream();
96-
of.addAudioStream();
97-
of.addAudioStream();*/
98-
99-
100-
/*eVideoLeft = wrapper.createVideoEncoder( );
101-
eVideoRight = wrapper.createVideoEncoder( dVideo );
102-
103-
eAudioLeft = wrapper.createAudioEncoder( 2 );
104-
105-
106-
wrapper.createAudioEncoder( eAudioLeft, 2 );*/
107-
108-
// AudioFrameDesc audioFrameDesc;
109-
// AudioFrame sourceAudio( audioFrameDesc );
110-
52+
of.addVideoStream( outputStreamVideo.getVideoDesc() );
11153

54+
of.beginWrap();
11255

11356
ColorTransform ct;
11457

11558

11659
// Encodage/transcodage
11760
std::cout << "start transcoding" << std::endl;
11861

119-
size_t frame = 0;
62+
size_t frame = 1;
12063

12164
while( inputStreamVideo.readNextFrame( sourceImage ) )
12265
{
12366
std::cout << "\rprocess frame " << frame << std::flush;
124-
67+
12568
ct.convert( sourceImage, imageToEncode );
12669

127-
outputStreamVideo.encodeFrame( imageToEncode, codedImage );
128-
129-
of.wrap( codedImage, 0 );
70+
if( outputStreamVideo.encodeFrame( imageToEncode, codedImage ) )
71+
of.wrap( codedImage, 0 );
13072

13173
++frame;
13274
}
75+
76+
while( outputStreamVideo.encodeFrame( codedImage ) )
77+
{
78+
of.wrap( codedImage, 0 );
79+
}
80+
81+
of.endWrap();
13382
std::cout << std::endl;
13483
}
13584

13685
int main( int argc, char** argv )
13786
{
138-
if( argc != 2 )
87+
if( argc != 3 )
13988
{
14089
std::cout << "av++ require a media filename" << std::endl;
14190
return( -1 );
@@ -145,8 +94,7 @@ int main( int argc, char** argv )
14594

14695
try
14796
{
148-
// example of video Transcoding
149-
transcodeVideo( argv[1], "transcodedVideo.avi" );
97+
transcodeVideo( argv[1], argv[2] );
15098
}
15199
catch( std::exception &e )
152100
{

src/AvTranscoder/OutputStreamVideo.cpp

Lines changed: 33 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -184,7 +184,30 @@ void OutputStreamVideo::setProfile( const std::string& profile )
184184
m_videoDesc.setTimeBase( 1, 25 ); // 25 fps
185185
m_videoDesc.setImageParameters( 1920, 1080, av_get_pix_fmt( prof["pix_fmt"].c_str() ) );
186186

187-
m_videoDesc.set( "b", prof["b"] );
187+
for( Profile::ProfileDesc::iterator it = prof.begin(); it != prof.end(); ++it )
188+
{
189+
if( (*it).first == "avProfile" )
190+
continue;
191+
if( (*it).first == "avProfileLong" )
192+
continue;
193+
if( (*it).first == "codec" )
194+
continue;
195+
if( (*it).first == "pix_fmt" )
196+
continue;
197+
if( (*it).first == "width" )
198+
continue;
199+
if( (*it).first == "height" )
200+
continue;
201+
202+
try
203+
{
204+
m_videoDesc.set( (*it).first, (*it).second );
205+
}
206+
catch( std::exception& e )
207+
{
208+
std::cout << "warning: " << e.what() << std::endl;
209+
}
210+
}
188211

189212
setup();
190213

@@ -203,8 +226,16 @@ void OutputStreamVideo::setProfile( const std::string& profile )
203226
if( (*it).first == "height" )
204227
continue;
205228

206-
m_videoDesc.set( (*it).first, (*it).second );
229+
try
230+
{
231+
m_videoDesc.set( (*it).first, (*it).second );
232+
}
233+
catch( std::exception& e )
234+
{
235+
std::cout << "2.warning: " << e.what() << std::endl;
236+
}
207237
}
238+
208239
}
209240

210241
}

src/AvTranscoder/Profiles/XdCamHd422.hpp

Lines changed: 42 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -15,32 +15,36 @@ void loadXdCamHD422( Profile::ProfilesDesc& profiles )
1515
xdCamHd422[ "codec" ] = "mpeg2video";
1616
xdCamHd422[ "profile" ] = "0"; // FF_PROFILE_MPEG2_422
1717
xdCamHd422[ "level" ] = "2";
18+
1819
xdCamHd422[ "g" ] = "12";
1920
xdCamHd422[ "bf" ] = "2"; // max_b_frames
2021
xdCamHd422[ "dtg_active_format" ] = "10"; // FF_DTG_AFD_16_9
21-
xdCamHd422[ "qmin" ] = "1";
22-
xdCamHd422[ "dc" ] = "2";
22+
xdCamHd422[ "qmin" ] = "2";
23+
xdCamHd422[ "qmax" ] = "12";
24+
xdCamHd422[ "dc" ] = "2"; // 10 - 8 = 2
2325

2426
xdCamHd422[ "pix_fmt" ] = "yuv422p";
2527

26-
2728
// color informations are not used in FFmpeg/LibAV for Mpeg2
28-
// xdCamHd422[ "colorspace" ] = "AVCOL_SPC_BT709";
29-
// xdCamHd422[ "color_trc" ] = "AVCOL_SPC_BT709";
30-
// xdCamHd422[ "color_primaries" ] = "AVCOL_SPC_BT709";
31-
// xdCamHd422[ "color_range" ] = "AVCOL_RANGE_MPEG";
29+
xdCamHd422[ "colorspace" ] = "1"; // AVCOL_SPC_BT709
30+
xdCamHd422[ "color_trc" ] = "1"; // AVCOL_SPC_BT709
31+
xdCamHd422[ "color_primaries" ] = "1"; // AVCOL_SPC_BT709
32+
xdCamHd422[ "color_range" ] = "1"; // AVCOL_RANGE_MPEG
3233

3334
xdCamHd422[ "timecode_frame_start" ] = "900000"; // 10:00:00:00
3435

35-
xdCamHd422[ "b" ] = "50000000";
36-
xdCamHd422[ "minrate" ] = "50000000";
37-
xdCamHd422[ "maxrate" ] = "50000000";
36+
xdCamHd422[ "b" ] = "50M";
37+
xdCamHd422[ "bt" ] = "4M"; // bitrate tolerance
38+
xdCamHd422[ "minrate" ] = "50M";
39+
xdCamHd422[ "maxrate" ] = "50M";
40+
3841

39-
xdCamHd422[ "bufsize" ] = "50000000";
40-
xdCamHd422[ "rc_max_vbv_use" ] = "1";
41-
xdCamHd422[ "rc_min_vbv_use" ] = "1";
42+
43+
xdCamHd422[ "bufsize" ] = "17825792";
44+
// xdCamHd422[ "lmin" ] = "0";
4245
xdCamHd422[ "lmin" ] = "1*QP2LAMBDA";
43-
xdCamHd422[ "field_order" ] = "tb";
46+
// xdCamHd422[ "field_order" ] = "tb";
47+
// xdCamHd422[ "field_order" ] = "2";
4448

4549
// research modes
4650
xdCamHd422[ "me_method" ] = "dia";
@@ -54,17 +58,35 @@ void loadXdCamHD422( Profile::ProfilesDesc& profiles )
5458
xdCamHd422[ "subcmp" ] = "sse"; // me_sub_cmp
5559
xdCamHd422[ "precmp" ] = "sse"; // me_pre_cmp
5660

57-
xdCamHd422[ "rc_max_vbv_use" ] = "1";
58-
xdCamHd422[ "rc_min_vbv_use" ] = "1";
61+
xdCamHd422[ "rc_max_vbv_use" ] = "0.3333333";
62+
xdCamHd422[ "rc_min_vbv_use" ] = "3";
63+
64+
xdCamHd422[ "rc_init_occupancy" ] = "17825792";
65+
xdCamHd422[ "rc_buf_aggressivity" ] = "1"; // default value
5966

6067
xdCamHd422[ "global_quality" ] = "1*QP2LAMBDA"; // 1 * FF_QP2LAMBDA
6168

62-
xdCamHd422[ "flags" ] = "cgop"; // open GOP
69+
xdCamHd422[ "b_qoffset" ] = "1.25";
70+
xdCamHd422[ "b_qfactor" ] = "1.25";
71+
xdCamHd422[ "i_qoffset" ] = "0";
72+
xdCamHd422[ "i_qfactor" ] = "-0.8";
73+
xdCamHd422[ "flags" ] = "+cgop"; // open GOP
74+
75+
xdCamHd422[ "flags" ] = "+ilme"; // use interlaced motion estimation
76+
xdCamHd422[ "flags" ] = "+ildct"; // use interlaced DCT
77+
xdCamHd422[ "flags" ] = "+qscale";
78+
79+
80+
xdCamHd422[ "intra_vlc" ] = "1";
81+
xdCamHd422[ "non_linear_quant" ] = "1";
82+
83+
xdCamHd422[ "sc_threshold" ] = "1000000000";
84+
6385

64-
// xdCamHd422[ "intra_vlc" ] = "1";
65-
// xdCamHd422[ "non_linear_quant" ] = "1";
86+
xdCamHd422[ "threads" ] = "5";
6687

67-
xdCamHd422[ "threads" ] = "6";
88+
// xdCamHd422[ "thread_type" ] = "frame";
89+
6890

6991
profiles.push_back( xdCamHd422 );
7092
}

0 commit comments

Comments
 (0)