Commit 3ad5d4df authored by Calvin Walton's avatar Calvin Walton Committed by Nicolas George

lavfi/concat: allow to support inputs with different frame rates

Right now, the concat filter does not set the frame_rate value on any of
the out links. As a result, the default ffmpeg behaviour kicks in - to
copy the framerate from the first input to the outputs.

If a later input is higher framerate, this results in dropped frames; if
a later input is lower framerate it might cause judder.

This patch checks if all of the video inputs have the same framerate, and
if not it sets the out link to use '1/0' as the frame rate, the value
meaning "unknown/vfr".

A test is added to verify the VFR behaviour. The existing test for CFR
behaviour passes unchanged.
parent 85386c36
......@@ -131,8 +131,21 @@ static int config_output(AVFilterLink *outlink)
outlink->h = inlink->h;
outlink->sample_aspect_ratio = inlink->sample_aspect_ratio;
outlink->format = inlink->format;
outlink->frame_rate = inlink->frame_rate;
for (seg = 1; seg < cat->nb_segments; seg++) {
inlink = ctx->inputs[in_no + seg * ctx->nb_outputs];
if (outlink->frame_rate.num != inlink->frame_rate.num ||
outlink->frame_rate.den != outlink->frame_rate.den) {
av_log(ctx, AV_LOG_VERBOSE,
"Video inputs have different frame rates, output will be VFR\n");
outlink->frame_rate = av_make_q(1, 0);
break;
}
}
for (seg = 1; seg < cat->nb_segments; seg++) {
inlink = ctx->inputs[in_no += ctx->nb_outputs];
inlink = ctx->inputs[in_no + seg * ctx->nb_outputs];
if (!outlink->sample_aspect_ratio.num)
outlink->sample_aspect_ratio = inlink->sample_aspect_ratio;
/* possible enhancement: unsafe mode, do not check */
......
......@@ -424,9 +424,11 @@ FATE_FILTER_SAMPLES-$(call ALLYES, VMD_DEMUXER VMDVIDEO_DECODER FORMAT_FILTER PE
fate-filter-gradfun-sample: tests/data/filtergraphs/gradfun
fate-filter-gradfun-sample: CMD = framecrc -i $(TARGET_SAMPLES)/vmd/12.vmd -filter_script $(TARGET_PATH)/tests/data/filtergraphs/gradfun -an -frames:v 20
FATE_FILTER-$(call ALLYES, TESTSRC_FILTER SINE_FILTER CONCAT_FILTER) += fate-filter-concat
FATE_FILTER-$(call ALLYES, TESTSRC_FILTER SINE_FILTER CONCAT_FILTER) += fate-filter-concat fate-filter-concat-vfr
fate-filter-concat: tests/data/filtergraphs/concat
fate-filter-concat: CMD = framecrc -filter_complex_script $(TARGET_PATH)/tests/data/filtergraphs/concat
fate-filter-concat-vfr: tests/data/filtergraphs/concat-vfr
fate-filter-concat-vfr: CMD = framecrc -filter_complex_script $(TARGET_PATH)/tests/data/filtergraphs/concat-vfr
FATE_FILTER-$(call ALLYES, TESTSRC2_FILTER FPS_FILTER MPDECIMATE_FILTER) += fate-filter-mpdecimate
fate-filter-mpdecimate: CMD = framecrc -lavfi testsrc2=r=2:d=10,fps=3,mpdecimate -r 3 -pix_fmt yuv420p
......
testsrc=r=5:n=1:d=2 [v1];
sine=440:b=2:d=1 [a1];
testsrc=r=15:n=1:d=1 [v2];
sine=622:b=2:d=2 [a2];
testsrc=r=8:n=1:d=1 [v3];
sine=880:b=2:d=1 [a3];
[v1][a1][v2][a2][v3][a3] concat=v=1:a=1:n=3
This diff is collapsed.
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment