Skip to content

Commit

Permalink
Merge pull request #845 from OpenShot/invalid-number-frames
Browse files Browse the repository at this point in the history
Detect video length (i.e. # of video frames) from Video Metadata
  • Loading branch information
jonoomph authored Sep 3, 2022
2 parents 61b2221 + 5f692f1 commit cfca6e7
Showing 1 changed file with 11 additions and 2 deletions.
13 changes: 11 additions & 2 deletions src/FFmpegReader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -821,6 +821,12 @@ void FFmpegReader::UpdateVideoInfo() {
info.duration = float(info.file_size) / info.video_bit_rate;
}

// Get the # of video frames (if found in stream)
// Only set this 1 time (this method can be called multiple times)
if (pStream->nb_frames > 0 && info.video_length <= 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
Expand All @@ -831,8 +837,11 @@ 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)
// Only set this 1 time (this method can be called multiple times)
if (info.video_length <= 0) {
info.video_length = round(info.duration * info.fps.ToDouble());
}
}

// Add video metadata (if any)
Expand Down

0 comments on commit cfca6e7

Please sign in to comment.