Not sure what's going on here but I can't seem to get consistent audio sync capturing from HDMI with ffmpeg. I can get consistent results from OBS no problem (video is always 100ms or thereabouts ahead), even though I have everything set up the same on there, but OBS on Linux does not allow for the input colour range to be changed. This is a known issue that doesn't look like it'll get fixed any time soon. So unless I stick with limited range video, OBS is not the preferable option. OBS does support custom ffmpeg settings, but these appear to only affect the output, which already supports full range anyway. I would like to know what OBS is doing with ffmpeg under the hood but I've not found a way of viewing this.
A big chunk of my command is irrelevant to the issue but best include it all. I was previously using ALSA, but for the sake of consistency with OBS I've switched to Pulse. Behaviour seems similar. I can attempt to sync it up with -itsoffset
, but as soon as I've managed to get the sync close it'll already be way off again. The audio sounds fine, and the output sample rate of 48kHz matches with the input. I've also thrown both -vsync
, -async
and -force_key_frames
at it as others have suggested online for these things.
ffmpeg -hide_banner -f pulse -async 1 -i default -itsoffset 0 -f v4l2 -vsync 1 -i /dev/video0 -force_key_frames 0 -pix_fmt yuv420p -src_range 1 -dst_range 1 -color_range 2 -framerate 60 -r 60 -video_size 1920x1080 -vf setpts="(PTS-STARTPTS)" -c:v libx264 -c:a flac -crf 12 -dn -sn -map_metadata -1 -preset veryfast -f matroska capture.mkv
Here's my log from letting an effectively identical command run for 26 seconds. It doesn't look too good but I'm not sure what it means:
https://gofile.io/?c=nEHyj3
As suggested by Xtoforas on Reddit, I have tried using -use_wallclock_as_timestamps 1
and -copyts
, but I saw no improvement with -use_wallclock_as_timestamps 1
and -copyts
broke the audio, and probably isn't what I want anyway.
-af aresample=async=1,asetpts=PTS-STARTPTS
.