3
  • Raspberry Pi 4, 4 GB
  • Rapsberry Pi OS Lite, 64 bit (2022-09-22)
  • Kernel 5.15.61-v8+
  • ffmpeg 4.3.4-0+deb11u1+rpt3

config.txt has the following relevant entry:

# Enable DRM VC4 V3D driver
dtoverlay=vc4-kms-v3d

According to my research, it would seem that the RPI4 is capable of hardware-accelerated video encoding using ffmpeg (from v4.3 on) via the h264_v4lm2m2 codec. ffmpeg -codecs and ffmpeg -encoders shows this codec to be available. Other people with a similar setup have gotten this to work successfully.

When I try this:

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

It gives me two warnings (see last two lines), but proceeds to encode the file anyway:

[h264_v4l2m2m @ 0x557353b190]  <<< v4l2_encode_init: fmt=0/-1
[h264_v4l2m2m @ 0x557353b190] Using device /dev/video11
[h264_v4l2m2m @ 0x557353b190] driver 'bcm2835-codec' on card 'bcm2835-codec-encode' in mplane mode
[h264_v4l2m2m @ 0x557353b190] requesting formats: output=YU12 capture=H264
[h264_v4l2m2m @ 0x557353b190] Failed to set number of B-frames: Invalid argument
[h264_v4l2m2m @ 0x557353b190] Failed to set gop size: Invalid argument

Hardware acceleration seems to work, as it encodes at ~130 fps. However, the resulting file is corrupted and can't be played.

What am I missing?

1
  • @jsotola Not sure if warnings or errors, as it doesn't specify. Either way, those are the only indication of something potentially going wrong. And good catch - they are indeed. I've changed my wording accordingly.
    – domsson
    Oct 14, 2022 at 3:40

1 Answer 1

1

I eventually got this to work by swapping out the ffmpeg provided by apt and instead compiling the fork by jc-kynesim, which can be found at github.com/jc-kynesim/rpi-ffmpeg.

With this, it works, although I still get the following warning/ error:

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

The encoding was a bit slower than before, clocking in at ~100 fps.

I don't know if the reason this fixed the problem is because this version of ffmpeg contains patches that solve the underlying problem, or if installing the numerous packages required for compilation actually brought in additional dependencies that were missing before. I've created an issue report on GitHub.

2
  • How to recompile ffmpeg using rpi-ffmpeg?
    – Hassaan
    Dec 14, 2023 at 18:25
  • @Hassaan clone/ download rpi-ffmpeg, then look up a compilation guide for ffmpeg and work through it accordingly.
    – domsson
    Dec 19, 2023 at 6:59

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.