Skip to content

Commit 7543d70

Browse files
author
Clement Champetier
committed
OutputFile: refactore getProgressDuration
Can get progress duration of any stream (by default the first).
1 parent bde8526 commit 7543d70

File tree

2 files changed

+7
-11
lines changed

2 files changed

+7
-11
lines changed

src/AvTranscoder/file/OutputFile.cpp

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -112,10 +112,7 @@ IOutputStream::EWrappingStatus OutputFile::wrap( const CodedData& data, const si
112112

113113
av_free_packet( &packet );
114114

115-
// compute the duration of current stream
116-
AVStream& currentStream = _formatContext.getAVStream( streamId );
117-
double currentStreamDuration = (double)currentStream.cur_dts * currentStream.time_base.num / currentStream.time_base.den;
118-
115+
double currentStreamDuration = getProgressDuration( 0 );
119116
if( currentStreamDuration < _previousProcessedStreamDuration )
120117
{
121118
// if the current stream is strictly shorter than the previous, wait for more data
@@ -197,12 +194,10 @@ void OutputFile::setProfile( const ProfileLoader::Profile& profile )
197194
}
198195
}
199196

200-
double OutputFile::getProgressDuration()
197+
double OutputFile::getProgressDuration( const size_t streamIndex )
201198
{
202-
if( _formatContext.getNbStreams() == 0 )
203-
throw std::runtime_error( "at least one stream must be set to get the progress duration" );
204-
AVStream& firstOutputStream = _formatContext.getAVStream( 0 );
205-
return av_q2d( firstOutputStream.time_base ) * firstOutputStream.cur_dts;
199+
AVStream& outputStream = _formatContext.getAVStream( streamIndex );
200+
return av_q2d( outputStream.time_base ) * outputStream.cur_dts;
206201
}
207202

208203
}

src/AvTranscoder/file/OutputFile.hpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -102,8 +102,9 @@ class AvExport OutputFile
102102
virtual void addMetadata( const std::string& key, const std::string& value );
103103

104104
virtual void setVerbose( bool verbose = false ){ _verbose = verbose; }
105-
106-
virtual double getProgressDuration();
105+
106+
/// By default get the duration, in seconds, of the first output stream
107+
virtual double getProgressDuration( const size_t streamIndex = 0 );
107108

108109
private:
109110
FormatContext _formatContext;

0 commit comments

Comments
 (0)