rpi-ffmpeg icon indicating copy to clipboard operation
rpi-ffmpeg copied to clipboard

h264_v4l2m2m: "Failed to set gop size: Invalid argument"

Open domsson opened this issue 1 year ago • 7 comments

I'm trying to stream from a Raspberry Pi 4 via RMTP, using hardware acceleration through h264_v4l2m2m. With this fork of ffmpeg, hardware acceleration works. However, the following warning can be observed:

[h264_v4l2m2m @ 0x55d588da10] Failed to set gop size: Invalid argument

I assume h264_v4l2m2m doesn't know what to do with the -g argument? The issue can be observed even with a simple use-case as the following:

ffmpeg -i big_buck_bunny_720p_10mb.mp4 -c:v h264_v4l2m2m -c:a copy out.mp4

The warning doesn't seem to be a problem when encoding to a file; everything works out okay in that case. However, when streaming to a platform like Twitch or YouTube, those platforms won't accept or be able to process the stream. I suspect this has to do with the above error, for two reasons:

  1. When replacing -c:v h264_v4l2m2m with -c:v libx264, the warning disappears and the platforms will process and display the stream (but the Pi will be on the brink of dying due to the lack of hardware acceleration)
  2. Twitch and YouTube both explicitly require a keyframe interval of 2, and if I understand correctly, that is directly related to gop/ the -g argument

Observe the difference in what Twitch makes of the incoming RMTP stream when using libx264, vs. h264_v4l2m2m, with all other settings/ arguments being the same:

libx264 (stream online, but Pi burns up and drops frames) image

h264_v4l2m2m (stream offline, but Pi is happy and doesn't drop frames) image

Is there any chance h264_v4l2m2m will be able to set the gop / keyframes in the future? This would be huge, as it would enable direct streaming from a Raspberry Pi.

Thank you for your work on this fork.

domsson avatar Oct 15 '22 12:10 domsson