Hello FFmpeg developers,
We found a timestamp time-base mismatch in overlay_vulkan while developing
the GPU film-border composition path in Film Grain Studio.
framesync_inject_frame() rescales each input frame's PTS into the
framesync time base. overlay_vulkan_blend() copies the main input's
frame properties to the output, but overlay_vulkan_config_output()
does not explicitly align the output link and framesync time bases.
With two consecutive overlay_vulkan filters and mismatched input
time bases, the first overlay's incorrect timestamps can cause the
second overlay to buffer a large number of frames. On a T600 this
led to VK_ERROR_OUT_OF_DEVICE_MEMORY.
The candidate below explicitly uses the main input time base for
both framesync and the output link, following the clock selection
approach of overlay_cuda. This also avoids changing the unit of
the copied main-frame duration.
Tested on Windows, NVIDIA RTX 4080, FFmpeg source
359c82515228774eb683dffce9d623b6b4a2fa53, with the candidate and
our existing Vulkan host-image-copy opt-out patch.
Two consecutive Vulkan overlays, followed by cropping back to the
original image, produced the same framehash files as the direct
reference for all three cases:
- 1/1000 main, 1/24000 secondary: 240 frames
- 1/90000 main, 1/24 secondary: 240 frames
- VFR, 1/1000 main, 1/24000 secondary: 240 frames
In each case the time base, PTS, frame durations and SHA-256 hashes
of all 240 frames matched exactly. No common-time-base workaround
was used.
Example reproduction (Windows command line, using our build's
host-image-copy opt-out; omit that option in stock FFmpeg):
ffmpeg -hide_banner -v verbose -copyts -init_hw_device
vulkan=vk:0,disable_multiplane=1,disable_host_image_copy=1
-filter_hw_device vk -f lavfi -i
testsrc2=size=320x180:rate=24000/1001:duration=10.01 -f lavfi -i
color=c=gray:size=384x216:rate=24000/1001:duration=0.05
-filter_complex
"[0:v]format=p010le,settb=1/1000,hwupload,split=2[exact][clock];[clock]scale_vulkan=w=384:h=216:scaler=nearest[base];[1:v]trim=end_frame=1,settb=1/24000,setpts=0,format=p010le,hwupload[stock];[base][stock]overlay_vulkan=x=0:y=0[art];[art][exact]overlay_vulkan=x=32:y=18,hwdownload,format=p010le,crop=320:180:32:18[v]"
-map "[v]" -an -c:v rawvideo -pix_fmt p010le -threads:v 1 -fps_mode:v
passthrough -enc_time_base:v filter -f framehash -hash sha256
overlay.framehash
Reference:
ffmpeg -hide_banner -copyts -f lavfi -i
testsrc2=size=320x180:rate=24000/1001:duration=10.01 -vf
format=p010le,settb=1/1000 -an -c:v rawvideo -pix_fmt p010le
-threads:v 1 -fps_mode:v passthrough -enc_time_base:v filter -f
framehash -hash sha256 reference.framehash
This is an RFC, not a merge-ready submission. Full FATE and general
two-moving-input regression tests have not yet been run. In
particular, we would welcome feedback on whether forcing framesync
to the main time base is preferred over preserving its finer clock
and rescaling the outgoing PTS instead. The former may round
secondary timestamps when its time base is finer.
The patch was developed with AI assistance and tested on physical
hardware by the Film Grain Studio project.
Candidate patch:
diff --git a/libavfilter/vf_overlay_vulkan.c b/libavfilter/vf_overlay_vulkan.c
--- a/libavfilter/vf_overlay_vulkan.c
+++ b/libavfilter/vf_overlay_vulkan.c
@@ -190,6 +190,10 @@ static int
overlay_vulkan_config_output(AVFilterLink *outlink)
if (err < 0)
return err;
+ /* The output copies the main frame's properties. Keep framesync in
+ * the same time base as the output link so PTS and duration agree. */
+ s->fs.time_base = outlink->time_base = avctx->inputs[0]->time_base;
+
return ff_framesync_configure(&s->fs);
}
Thank you for reviewing this approach.
Film Grain Studio / rampageX
_______________________________________________
ffmpeg-devel mailing list -- [email protected]
To unsubscribe send an email to [email protected]