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.

This commit is contained in:
Jonathan Thomas
2022-09-02 01:09:00 -05:00
parent 61b2221898
commit 60805beec3

View File

@@ -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)