Skip to content

Commit 9e0c942

Browse files
author
Clement Champetier
committed
OutputStream: fix getStreamDuration (use av_stream_get_end_pts)
Fix #165
1 parent 382f9be commit 9e0c942

File tree

1 file changed

+6
-1
lines changed

1 file changed

+6
-1
lines changed

src/AvTranscoder/stream/OutputStream.cpp

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,12 @@ OutputStream::OutputStream( OutputFile& outputFile, const size_t streamIndex )
1717
double OutputStream::getStreamDuration() const
1818
{
1919
AVStream& outputStream = _outputFile->getFormatContext().getAVStream( _streamIndex );
20-
return av_q2d( outputStream.time_base ) * outputStream.cur_dts;
20+
#if AVTRANSCODER_FFMPEG_DEPENDENCY && LIBAVFORMAT_VERSION_INT >= AV_VERSION_INT(55, 40, 100)
21+
// returns the pts of the last muxed packet, converted from timebase to seconds
22+
return av_q2d( outputStream.time_base ) * av_stream_get_end_pts( &outputStream );
23+
#else
24+
return av_q2d( outputStream.time_base ) * ( outputStream.pts.val + ( outputStream.pts.num / outputStream.pts.den ) );
25+
#endif
2126
}
2227

2328
IOutputStream::EWrappingStatus OutputStream::wrap( const CodedData& data )

0 commit comments

Comments
 (0)