From 60805beec3ab00a2ec7d528f488bf9cb99ac148e Mon Sep 17 00:00:00 2001 From: Jonathan Thomas Date: Fri, 2 Sep 2022 01:09:00 -0500 Subject: [PATCH] Adding support for detecting video_length (i.e. # of video frames) from the metadata, instead of calculating from duration * fps. This is occasionally different by a small amount, and in my testing, the metadata is more accurate. --- src/FFmpegReader.cpp | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/src/FFmpegReader.cpp b/src/FFmpegReader.cpp index c7ab22b6..78f1a232 100644 --- a/src/FFmpegReader.cpp +++ b/src/FFmpegReader.cpp @@ -821,6 +821,11 @@ void FFmpegReader::UpdateVideoInfo() { info.duration = float(info.file_size) / info.video_bit_rate; } + // Get the # of video frames (if found in stream) + if (pStream->nb_frames > 0) { + info.video_length = pStream->nb_frames; + } + // No duration found in stream of file if (info.duration <= 0.0f) { // No duration is found in the video stream @@ -831,8 +836,10 @@ void FFmpegReader::UpdateVideoInfo() { // Yes, a duration was found is_duration_known = true; - // Calculate number of frames - info.video_length = round(info.duration * info.fps.ToDouble()); + // Calculate number of frames (if not already found in metadata) + if (info.video_length <= 0) { + info.video_length = round(info.duration * info.fps.ToDouble()); + } } // Add video metadata (if any)