From 3a530660d0da40e212fce8066c591bfaade364a7 Mon Sep 17 00:00:00 2001 From: Adrien Destugues Date: Fri, 30 Dec 2016 17:30:41 +0100 Subject: [PATCH] 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. --- src/add-ons/media/plugins/ffmpeg/AVFormatReader.cpp | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/add-ons/media/plugins/ffmpeg/AVFormatReader.cpp b/src/add-ons/media/plugins/ffmpeg/AVFormatReader.cpp index b28ead061c..796770d3cd 100644 --- a/src/add-ons/media/plugins/ffmpeg/AVFormatReader.cpp +++ b/src/add-ons/media/plugins/ffmpeg/AVFormatReader.cpp @@ -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;