Skip to content

Commit d8afcb8

Browse files
author
Valentin Noel
committed
Transcoder: compute progress duration from output format context
1 parent 5387b95 commit d8afcb8

File tree

1 file changed

+13
-4
lines changed

1 file changed

+13
-4
lines changed

src/AvTranscoder/transcoder/Transcoder.cpp

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
#include <iostream>
77
#include <algorithm>
88
#include <sstream>
9+
#include <libavformat/avformat.h>
910

1011
namespace avtranscoder
1112
{
@@ -310,10 +311,18 @@ void Transcoder::process( IProgress& progress )
310311
{
311312
if( _verbose )
312313
std::cout << "process frame " << frame << std::endl;
313-
if( ! processFrame() )
314-
break;
315-
316-
if( progress.progress( 1 / _outputFps * ( frame ), totalDuration ) == eJobStatusCancel )
314+
315+
bool frameProcessed = processFrame();
316+
if( ! frameProcessed )
317+
break;
318+
319+
int currentDts = _outputFile.getFormatContext().streams[0]->cur_dts;
320+
int timebaseNum = _outputFile.getFormatContext().streams[0]->time_base.num;
321+
int timebaseDen = _outputFile.getFormatContext().streams[0]->time_base.den;
322+
323+
double duration = (double)currentDts * timebaseNum / timebaseDen;
324+
325+
if( progress.progress( duration, totalDuration ) == eJobStatusCancel )
317326
{
318327
break;
319328
}

0 commit comments

Comments
 (0)