ffmpeg: use stream frame count, if provided.

Not sure why that was commented out. Computing the frame count back from
the frame duration and stream duration can be inaccurate (especially for
long frame durations and/or short streams). It is important that the
stream ends exactly when expected. If it ends earlier than the announced
frame count, an app may be stuck forever waiting for the end, or would
interpret it as a read error. If it is too long, a buffer overflow may
occur.
This commit is contained in:
Adrien Destugues 2016-12-30 17:30:41 +01:00
parent b480a593f2
commit 3a530660d0

View File

@ -29,7 +29,7 @@ extern "C" {
#include "Utilities.h"
//#define TRACE_AVFORMAT_READER
#define TRACE_AVFORMAT_READER
#ifdef TRACE_AVFORMAT_READER
# define TRACE printf
# define TRACE_IO(a...)
@ -1255,13 +1255,13 @@ AVFormatReader::Stream::GetStreamInfo(int64* frameCount,
#endif
*frameCount = fStream->nb_frames;
// if (*frameCount == 0) {
if (*frameCount == 0) {
// Calculate from duration and frame rate
*frameCount = (int64)(*duration * frameRate / 1000000LL);
TRACE(" frameCount calculated: %lld, from context: %lld\n",
*frameCount, fStream->nb_frames);
// } else
// TRACE(" frameCount: %lld\n", *frameCount);
} else
TRACE(" frameCount: %lld\n", *frameCount);
*format = fFormat;