Skip to content

Commit 1227622

Browse files
committed
Merge pull request #12 from cchampet/move_init_to_process
Transcoder clean
2 parents 1ab31ca + 4be8bce commit 1227622

File tree

6 files changed

+87
-79
lines changed

6 files changed

+87
-79
lines changed

app/genericProcessor/genericProcessor.cpp

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -114,14 +114,11 @@ int main( int argc, char** argv )
114114
// set verbose of all stream
115115
transcoder.setVerbose( verbose );
116116
transcoder.setProcessMethod( avtranscoder::eProcessMethodLongest );
117-
transcoder.init();
118117

119118
if( verbose )
120119
std::cout << "start Transcode" << std::endl;
121120

122121
avtranscoder::ConsoleProgress progress;
123-
124-
// video re-wrapping or transcoding if necessary
125122
transcoder.process( progress );
126123

127124
std::cout << std::endl;

src/AvTranscoder/transcoder/StreamTranscoder.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -259,7 +259,7 @@ StreamTranscoder::~StreamTranscoder()
259259

260260
void StreamTranscoder::init()
261261
{
262-
// rewrap
262+
// rewrap case: no need to take care of the latency of codec
263263
if( ! _inputEssence )
264264
return;
265265

src/AvTranscoder/transcoder/Transcoder.cpp

Lines changed: 67 additions & 62 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,11 @@ Transcoder::Transcoder( OutputFile& outputFile )
2222
, _mainStreamIndex( 0 )
2323
, _verbose( false )
2424
{
25+
// Initialize the OutputFile
2526
_outputFile.setup();
27+
28+
// Print no output from ffmpeg
29+
av_log_set_level( AV_LOG_QUIET );
2630
}
2731

2832
Transcoder::~Transcoder()
@@ -252,19 +256,17 @@ void Transcoder::init()
252256
bool Transcoder::processFrame()
253257
{
254258
if( _streamTranscoders.size() == 0 )
255-
{
256259
return false;
257-
}
258260

259261
if( _verbose )
260262
std::cout << "process frame" << std::endl;
263+
261264
for( size_t streamIndex = 0; streamIndex < _streamTranscoders.size(); ++streamIndex )
262265
{
263266
if( _verbose )
264267
std::cout << "process stream " << streamIndex << "/" << _streamTranscoders.size() - 1 << std::endl;
265268

266269
bool streamProcessStatus = _streamTranscoders.at( streamIndex )->processFrame();
267-
268270
if( ! streamProcessStatus )
269271
{
270272
_streamTranscoders.clear();
@@ -276,51 +278,30 @@ bool Transcoder::processFrame()
276278

277279
void Transcoder::process( IProgress& progress )
278280
{
279-
size_t frame = 0;
280-
281-
if( ! _streamTranscoders.size() )
282-
{
281+
if( _streamTranscoders.size() == 0 )
283282
throw std::runtime_error( "missing input streams in transcoder" );
284-
}
285-
283+
284+
manageInfinityStreamFromProcessMethod();
285+
286286
if( _verbose )
287287
std::cout << "begin transcoding" << std::endl;
288+
init();
288289

289290
_outputFile.beginWrap();
290291

291-
double totalDuration = std::numeric_limits<double>::max();
292-
switch( _eProcessMethod )
293-
{
294-
case eProcessMethodShortest :
295-
totalDuration = getMinTotalDuration();
296-
break;
297-
case eProcessMethodLongest :
298-
totalDuration = getMaxTotalDuration();
299-
break;
300-
case eProcessMethodBasedOnStream :
301-
totalDuration = getStreamDuration( _mainStreamIndex );
302-
break;
303-
case eProcessMethodInfinity :
304-
totalDuration = std::numeric_limits<double>::max();
305-
break;
306-
}
292+
double totalDuration = getTotalDurationFromProcessMethod();
307293

308-
if( _verbose )
309-
av_log_set_level( AV_LOG_DEBUG );
310-
311-
while( 1 )
294+
size_t frame = 0;
295+
bool frameProcessed = true;
296+
while( frameProcessed )
312297
{
313298
if( _verbose )
314299
std::cout << "process frame " << frame << std::endl;
315300

316-
bool frameProcessed = processFrame();
317-
if( ! frameProcessed )
318-
break;
301+
frameProcessed = processFrame();
319302

320303
if( progress.progress( _outputFile.getProgressDuration(), totalDuration ) == eJobStatusCancel )
321-
{
322304
break;
323-
}
324305

325306
++frame;
326307
}
@@ -335,34 +316,6 @@ void Transcoder::setProcessMethod( const EProcessMethod eProcessMethod, const si
335316
{
336317
_eProcessMethod = eProcessMethod;
337318
_mainStreamIndex = indexBasedStream;
338-
339-
for( size_t i = 0; i < _streamTranscoders.size(); ++i )
340-
{
341-
switch( _eProcessMethod )
342-
{
343-
case eProcessMethodShortest :
344-
if( _streamTranscoders.at( i )->getDuration() == getMinTotalDuration() )
345-
_streamTranscoders.at( i )->setInfinityStream( false );
346-
else
347-
_streamTranscoders.at( i )->setInfinityStream( true );
348-
break;
349-
case eProcessMethodLongest :
350-
if( _streamTranscoders.at( i )->getDuration() == getMaxTotalDuration() )
351-
_streamTranscoders.at( i )->setInfinityStream( false );
352-
else
353-
_streamTranscoders.at( i )->setInfinityStream( true );
354-
break;
355-
case eProcessMethodBasedOnStream :
356-
if( i != _mainStreamIndex )
357-
_streamTranscoders.at( i )->setInfinityStream( true );
358-
else
359-
_streamTranscoders.at( i )->setInfinityStream( false );
360-
break;
361-
case eProcessMethodInfinity :
362-
_streamTranscoders.at( i )->setInfinityStream( true );
363-
break;
364-
}
365-
}
366319
}
367320

368321
void Transcoder::setVerbose( bool verbose )
@@ -373,6 +326,10 @@ void Transcoder::setVerbose( bool verbose )
373326
(*it)->setVerbose( _verbose );
374327
}
375328
_outputFile.setVerbose( _verbose );
329+
330+
// Print stuff which is only useful for ffmpeg developers.
331+
if( _verbose )
332+
av_log_set_level( AV_LOG_DEBUG );
376333
}
377334

378335
void Transcoder::addRewrapStream( const std::string& filename, const size_t streamIndex )
@@ -528,4 +485,52 @@ double Transcoder::getMaxTotalDuration() const
528485
return maxTotalDuration;
529486
}
530487

488+
double Transcoder::getTotalDurationFromProcessMethod() const
489+
{
490+
switch( _eProcessMethod )
491+
{
492+
case eProcessMethodShortest :
493+
return getMinTotalDuration();
494+
case eProcessMethodLongest :
495+
return getMaxTotalDuration();
496+
case eProcessMethodBasedOnStream :
497+
return getStreamDuration( _mainStreamIndex );
498+
case eProcessMethodInfinity :
499+
return std::numeric_limits<double>::max();
500+
default:
501+
return getMaxTotalDuration();
502+
}
503+
}
504+
505+
void Transcoder::manageInfinityStreamFromProcessMethod()
506+
{
507+
for( size_t i = 0; i < _streamTranscoders.size(); ++i )
508+
{
509+
switch( _eProcessMethod )
510+
{
511+
case eProcessMethodShortest :
512+
if( _streamTranscoders.at( i )->getDuration() == getMinTotalDuration() )
513+
_streamTranscoders.at( i )->setInfinityStream( false );
514+
else
515+
_streamTranscoders.at( i )->setInfinityStream( true );
516+
break;
517+
case eProcessMethodLongest :
518+
if( _streamTranscoders.at( i )->getDuration() == getMaxTotalDuration() )
519+
_streamTranscoders.at( i )->setInfinityStream( false );
520+
else
521+
_streamTranscoders.at( i )->setInfinityStream( true );
522+
break;
523+
case eProcessMethodBasedOnStream :
524+
if( i != _mainStreamIndex )
525+
_streamTranscoders.at( i )->setInfinityStream( true );
526+
else
527+
_streamTranscoders.at( i )->setInfinityStream( false );
528+
break;
529+
case eProcessMethodInfinity :
530+
_streamTranscoders.at( i )->setInfinityStream( true );
531+
break;
532+
}
533+
}
534+
}
535+
531536
}

src/AvTranscoder/transcoder/Transcoder.hpp

Lines changed: 19 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,9 @@ enum EProcessMethod
4343
class AvExport Transcoder
4444
{
4545
public:
46-
46+
/**
47+
* @note Set FFmpeg log level to quite.
48+
*/
4749
Transcoder( OutputFile& outputFile );
4850

4951
~Transcoder();
@@ -112,7 +114,9 @@ class AvExport Transcoder
112114

113115
/**
114116
* @brief Process all the streams, and ended the process depending on the transcode politic.
115-
* @param progress
117+
* @note The function manages all process: init(), beginWrap(), processFrame()s, and endWrap().
118+
* @param progress: choose a progress, or create your own in C++ or in bindings by inherit IProgress class.
119+
* @see IProgress
116120
*/
117121
void process( IProgress& progress );
118122

@@ -124,20 +128,19 @@ class AvExport Transcoder
124128

125129
/**
126130
* @brief Set the transcodage politic.
127-
* @note Call it after adding the streams.
128131
* @note By default eProcessMethodLongest.
129132
* @param indexBasedStream: in case of process method eProcessMethodBasedOnStream, stop transcode at the end of the indicated stream.
130133
*/
131134
void setProcessMethod( const EProcessMethod eProcessMethod, const size_t indexBasedStream = 0 );
132135

133136
/**
134-
* @brief Set verbose mode for the Transcoder and its streams.
137+
* @brief Set verbose mode for the Transcoder, its streams, and its output file.
135138
* @note If you call it before adding the streams, no verbose mode will be set for the new streams.
139+
* @note set av log level to AV_LOG_DEBUG
136140
*/
137141
void setVerbose( bool verbose = true );
138142

139143
private:
140-
141144
void addRewrapStream( const std::string& filename, const size_t streamIndex );
142145

143146
void addTranscodeStream( const std::string& filename, const size_t streamIndex, const size_t subStreamIndex, const size_t offset ); ///< Get profile from input
@@ -164,6 +167,17 @@ class AvExport Transcoder
164167
*/
165168
double getMaxTotalDuration() const;
166169

170+
/**
171+
* @brief Get the duration of the output program
172+
* @note Depends on the streams, the process method, and the main stream index.
173+
*/
174+
double getTotalDurationFromProcessMethod() const;
175+
176+
/**
177+
* @brief Set for each StreamTranscoder if it is an infinity stream (switch to generator at the end of the stream).
178+
*/
179+
void manageInfinityStreamFromProcessMethod();
180+
167181
private:
168182
OutputFile& _outputFile; ///< The output media file after process.
169183
std::vector< InputFile* > _inputFiles; ///< The list of input files which contain added streams.

test/pyTest/testTranscoderAdd.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,5 @@ def testAddStreamTranscoder():
2525

2626
# process
2727
progress = av.NoDisplayProgress()
28-
transcoder.init()
2928
transcoder.process( progress )
3029

test/pyTest/testTranscoderTranscode.py

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@ def testTranscodeWave24b48kmono():
1717

1818
transcoder.add( inputFileName, 0, "wave24b48kmono" )
1919

20-
transcoder.init()
2120
progress = av.ConsoleProgress()
2221
transcoder.process( progress )
2322

@@ -47,7 +46,6 @@ def testTranscodeWave16b48kmono():
4746

4847
transcoder.add( inputFileName, 0, "wave16b48kmono" )
4948

50-
transcoder.init()
5149
progress = av.ConsoleProgress()
5250
transcoder.process( progress )
5351

@@ -77,7 +75,6 @@ def testTranscodeWave16b48kmono():
7775

7876
# transcoder.add( inputFileName, 0, "dnxhd120" )
7977

80-
# transcoder.init()
8178
# progress = av.ConsoleProgress()
8279
# transcoder.process( progress )
8380

@@ -106,7 +103,6 @@ def testTranscodeWave16b48kmono():
106103

107104
# transcoder.add( inputFileName, 0, "dnxhd185" )
108105

109-
# transcoder.init()
110106
# progress = av.ConsoleProgress()
111107
# transcoder.process( progress )
112108

@@ -135,7 +131,6 @@ def testTranscodeWave16b48kmono():
135131

136132
# transcoder.add( inputFileName, 0, "dnxhd185x" )
137133

138-
# transcoder.init()
139134
# progress = av.ConsoleProgress()
140135
# transcoder.process( progress )
141136

@@ -164,7 +159,6 @@ def testTranscodeWave16b48kmono():
164159

165160
# transcoder.add( inputFileName, 0, "xdcamhd422" )
166161

167-
# transcoder.init()
168162
# progress = av.ConsoleProgress()
169163
# transcoder.process( progress )
170164

@@ -213,7 +207,6 @@ def testTranscodeWave16b48kmono():
213207

214208
# transcoder.add( inputFileName, 0, customProfile )
215209

216-
# transcoder.init()
217210
# progress = av.ConsoleProgress()
218211
# transcoder.process( progress )
219212

0 commit comments

Comments
 (0)