-
Notifications
You must be signed in to change notification settings - Fork 1.7k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Corrupted video with h264_v4l2m2m at Pi camera resolution #1608
Comments
I'm fairly certain this is FFmpeg getting image strides wrong, or not propagating them between components properly. V4L2 advertises a format which has width, height, and bytesperline (aka stride or pitch). When the format is passed from source to sink the bytesperline needs to be acceptable to both ends. |
Interesting. I tried different widths, and 1280 (40*32) works, 1344 (42*32) works, but 1321 (41*32) does not work. Some more experimentation suggests widths divisible by 64 are the only ones that work. The widths that are broken (including those that are a multiple of 32) also show this message repeatedly in the logs I didn't notice before:
The decoding step (software decoder processing the output of the hardware encoder) also produces a number of repeating error messages when processing the resulting video, apologies for not noticing these earlier:
Would a stride error result in these decoder messages reporting a corrupted stream? Or would it result in correctly encoded H264 data just having the wrong picture? Is it significant that the lines covering the intensity (black and white) seem intact, while it only appears to be the colour information that has the wrong stride? |
Another thread has reminded me that we need to implement the same fix as raspberrypi/linux#4419 for bcm2835-codec (decode, encode and simple ISP). Decode uses the ISP to format convert the final frames. Encode uses them to format convert the source frames. ISP uses the ISP. They all therefore have the same restriction on the stride being a multiple of 32 for yuv420p and yvu420p. |
Does this mean that in order to use h264_v4l2m2m encoder, the output width and height will always need to be divisible by 32? I just ran into this issue and was scratching my head for a while. Do you think there will be a way to lift this limitation? Also, depending on the source (raw yuv420p vs. h264) I sometimes get either scrambled green output, or a segmentation fault with no output. Segmentation fault (using this 1080p30 Big Buck Bunny test video): Scrambled green output: Correct output: FYI, I see the same behavior on the current ffmpeg in the Bullseye repos, and with compiling the latest ffmpeg. |
Quick update - Just repeated the above tests on Buster with h264_omx instead of h264_v4l2m2m and it encodes correctly with no glitches / color overlay. |
That's interesting, that makes me wonder whether the problem is V4L2 reporting the wrong |
Not sure if it's helpful to note, but the RidgeRun(used by Nvidia)/Arducam IMX477 driver exposes a 4032x3040 mode rather than 4056x3040. And I know from experience that their v4l2 h264/265 encoders work at that 4032x3040 resolution. |
Describe the bug
Using H264 hardware encoding only works for certain resolutions. If you use one of the resolutions supported by the Pi camera, the image is corrupted.
To reproduce
This command creates a test image of the same resolution as one of the Pi camera settings. It then encodes it using the hardware H264 encoder, and then immediately decodes it again in software and displays it:
Expected behaviour
I expected the image to be clear, as it is if you change the
size
parameter in the above command to a different value, such as1920x1080
.Actual behaviour
The image is corrupted at 1296x972 and similar resolutions:
System
cat /etc/rpi-issue
)? Arch Linux ARM 64-bitvcgencmd version
)?uname -a
)?Linux 5.10.50-2-ARCH #1 SMP PREEMPT Mon Jul 19 16:00:34 UTC 2021 aarch64 GNU/Linux
Additional info
I was hoping to expand the video from a Pi camera vertically a little, and add a status line with the current time, then encode that as H264 but I found the image was corrupted. It seems it is corrupted at various resolutions around this, but strangely the larger resolution of 1920x1080 is fine.
The text was updated successfully, but these errors were encountered: