Skip to content

Commit df3ad65

Browse files
author
Valentin Noel
committed
Wrapping: fix packets writting when input/output packet size asymmetry (comparing streams durations)
1 parent 6b1682c commit df3ad65

File tree

2 files changed

+16
-0
lines changed

2 files changed

+16
-0
lines changed

src/AvTranscoder/file/OutputFile.cpp

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ OutputFile::OutputFile( const std::string& filename )
2020
, _stream ( NULL )
2121
, _filename ( filename )
2222
, _packetCount ( 0 )
23+
, _previousProcessedStreamDuration( 0.0 )
2324
, _verbose ( false )
2425
{
2526
if( ( _formatContext = avformat_alloc_context() ) == NULL )
@@ -179,6 +180,19 @@ IOutputStream::EWrappingStatus OutputFile::wrap( const CodedData& data, const si
179180

180181
av_free_packet( &packet );
181182

183+
// get the current streams
184+
AVStream* currentStream = _formatContext->streams[ streamId ];
185+
// compute its duration
186+
double currentStreamDuration = (double)currentStream->cur_dts * currentStream->time_base.num / currentStream->time_base.den;
187+
188+
if( currentStreamDuration < _previousProcessedStreamDuration )
189+
{
190+
// if the current stream is strictly shorter than the previous, wait for more data
191+
return IOutputStream::eWrappingWaitingForData;
192+
}
193+
194+
_previousProcessedStreamDuration = currentStreamDuration;
195+
182196
_packetCount++;
183197
_frameCount.at( streamId )++;
184198
return IOutputStream::eWrappingSuccess;

src/AvTranscoder/file/OutputFile.hpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -123,6 +123,8 @@ class AvExport OutputFile
123123
std::string _filename;
124124

125125
size_t _packetCount;
126+
127+
double _previousProcessedStreamDuration;
126128

127129
bool _verbose;
128130
};

0 commit comments

Comments
 (0)