Skip to content

Commit

Permalink
prefer r_frame_rate over avg_frame_rate
Browse files Browse the repository at this point in the history
AVStream.r_frame_rate (tbr in ffmpeg/ffprobe output) gives the more
common, standard frame rates smart phone cameras. It is what ffmpeg CLI
uses if you use it to convert variable frame rate to constant.

Extend the variable frame rate heuristic in property
"meta.media.variable_frame_rate" by checking for bizarre
AVStream.avg_frame_rate values.

This also fixes a bug where raw DV files are reporting 60000 (sixty
thousand) frames per second--at least with version 6 or 7 of FFmpeg.
  • Loading branch information
ddennedy committed May 15, 2024
1 parent 23b79f5 commit 4c4053f
Showing 1 changed file with 16 additions and 3 deletions.
19 changes: 16 additions & 3 deletions src/modules/avformat/producer_avformat.c
Original file line number Diff line number Diff line change
Expand Up @@ -1309,10 +1309,23 @@ static void find_first_pts(producer_avformat self, int video_index)
}
av_packet_unref(&pkt);
}
if (vfr_counter >= VFR_THRESHOLD)

// Determine if this is variable frame rate video
int vfr = vfr_counter >= VFR_THRESHOLD;
if (!vfr) {
AVStream *stream = self->video_format ? self->video_format->streams[video_index] : NULL;
if (stream) {
int d = stream->avg_frame_rate.den;
vfr = d != 0 && d != 1 && d != 2 && d != 125 && d != 1001;
}
}
if (vfr) {
mlt_properties_set_int(MLT_PRODUCER_PROPERTIES(self->parent),
"meta.media.variable_frame_rate",
1);
}

// Reset context position
av_seek_frame(context, -1, 0, AVSEEK_FLAG_BACKWARD);
}

Expand Down Expand Up @@ -2734,12 +2747,12 @@ static int video_codec_init(producer_avformat self, int index, mlt_properties pr
get_aspect_ratio(properties, stream, codec_params);

// Start with the muxer frame rate.
AVRational frame_rate = stream->avg_frame_rate;
AVRational frame_rate = stream->r_frame_rate;
double fps = av_q2d(frame_rate);

// Verify and sanitize the muxer frame rate.
if (isnan(fps) || isinf(fps) || fps == 0) {
frame_rate = stream->r_frame_rate;
frame_rate = stream->avg_frame_rate;
fps = av_q2d(frame_rate);
}
// With my samples when r_frame_rate != 1000 but avg_frame_rate is valid,
Expand Down

0 comments on commit 4c4053f

Please sign in to comment.