[Bug]: Realtime-paced H.264 VAAPI decode fails -- unpaced decode works (TigerLake, UHD G4, iHD 25.2.3)
- Dominant language
- C
- Stars
- 1.2k
- Forks
- 383
- Avg merge
- 8d 18h
- Merged PRs (30d)
- 4
Description
### Which component impacted?
Decode
### Is it regression? Good in old configuration?
None
### What happened?
I get repeated "failed to sync surface" errors on my security camera processing pipeline (Frigate NVR on a Ubuntu VM on a promox host, but it also occurs on bare metal). It only happens on irregular paced streams. I can repro it on bare metal with a synthetic stream.
CPU: i3-1115G4
GPU: UHD G4 (PCI 0x9a78)
iHD 25.2.3 (Debian 13 intel-media-va-driver25.2.3+dfsg1-1)
kernel 7.0.14-5-pve (Proxmox VE 9.2)
livba 2.22.0
I can provide a libva trace if you can't repro yourself.
The error is always the same:
```
[AVHWFramesContext @ ...] Failed to sync surface 0x5: 1 (operation failed).
[hwdownload @ ...] Failed to download frame: -5.
[vf#0:0 @ ...] Error while filtering: Input/output error
```
I've isolated it using a synthetic stream:
```
# 1. Generate a ~10 fps variable-frame-rate H.264 test stream -- the select filters mod 4 and mod 7 frames to simulate irregular arrivals
ffmpeg -f lavfi -i testsrc2=size=1280x720:rate=30 -t 600 \
-vf "select='eq(mod(n\,4)\,0)+eq(mod(n\,7)\,0)'" -fps_mode vfr \
-c:v libx264 -profile:v main -level 3.1 -g 10 -bf 0 -refs 1 -pix_fmt yuv420p -y synth.mkv
# 2. Decode via VAAPI with -re. Fails within ~4 minutes:
ffmpeg -re -hwaccel vaapi -hwaccel_device /dev/dri/renderD128 -hwaccel_output_format vaapi \
-i synth.mkv -vf fps=5,scale_vaapi=w=1280:h=720,hwdownload,format=nv12 \
-f rawvideo -pix_fmt yuv420p -y /dev/null
# 3. Control: remove -re and the same file decodes to completion with zero errors.
```
Interestingly, in the VM, which is running iHD 24.3.4 with a GPU passthrough, has both constant and variable rate cameras. The variable rate stream works but a constant frame rate stream breaks (as opposed to on the bare metal where a VFR breaks and a CFR works). So I suspect some race condition in the decode path. I don't see any kernel errors, GPU hangs, etc.
I also don't see any errors if I switch to software decode or QSV path (h264_qsv) on the same GPU.
I didn't see any other issues, the closest are #1818 which shows up in the kernel and #160 which has a truncated input. The same [issue](https://github.com/blakeblackshear/frigate/discussions/23319) is reported by other Frigate users on Gen 12 hardware.
### What's the usage scenario when you are seeing the problem?
Video Analytics
### What impacted?
_No response_
### Debug Information
_No response_
### Do you want to contribute a patch to fix the issue?
None
Contributor guide
Assessment
This issue has not been assessed yet.