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)