1

The Raspberry Pi 4 can encode videos using hardware acceleration by using 64 bit Raspberry Pi OS, a particular ffmpeg fork and the h264_v4l2m2m codec. Alternatively, Ubuntu and the 4.4 version of ffmpeg available via apt also yields the same results (but runs at much lower fps). For example:

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

However, ffmpeg will emit one warning:

Failed to set gop size: Invalid argument

This means that the -g option, and hence information about number/ distance of keyframes, can't be set. Example for setting gop explicitly, which will result in the same warning:

ffmpeg -f v4l2 -s 1280x720 -r 25 -i /dev/video0 -c:v h264_v4l2m2m -g 50 -keyint_min 25 -c:a copy out.mp4

This doesn't seem to be much of a problem when encoding to a video file, which works fine, but makes it impossible to stream the video data to services like YouTube or Twitch.

Using the non-hardware accelerated libx264 instead will enable to set the GOP/ keyframes, and enable streaming to aforementioned platforms. However, without acceleration, the performance makes this practically impossible.

I'm not sure whether this is a problem with the h264_v4l2m2m codec, this ffmepg fork (I've opened an issue report), ffmpeg in general, drivers or something else. I am therefore looking for insights into what causes this and how to either work around or - ideally - solve this issue. In short, how to use hardware acceleration, yet set the GOP/ keyframes?

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Browse other questions tagged or ask your own question.