Open dustinkerstein opened 2 years ago
Quick update - This may be specific to the ffmpeg h264_v4l2m2m encoder. I don't believe I can replicate this with Gstreamer's v4l2h264enc. I will double check and update the title accordingly.
Sorry, meant to respond earlier. I was suspecting that it may be an FFmpeg issue.
The standard V4L2 spec requires the H264 header bytes to be sent with the first frame. There is V4L2_CID_MPEG_VIDEO_HEADER_MODE which accepts V4L2_MPEG_VIDEO_HEADER_MODE_SEPARATE or V4L2_MPEG_VIDEO_HEADER_MODE_JOINED_WITH_1ST_FRAME. https://www.kernel.org/doc/html/latest/userspace-api/media/v4l/ext-ctrls-codec.html. It's currently not implemented, but could be relatively easily as it should map to MMAL_PARAMETER_VIDEO_ENCODE_HEADERS_WITH_FRAME (currently set on the encoder from bcm2835_codec_create_component
FFmpeg does try to set that (see https://github.com/FFmpeg/FFmpeg/blob/master/libavcodec/v4l2_m2m_enc.c#L196), but AFAIK there is no obligation for the encoder to implement it.
Ok, interesting. I haven't tested much to see if there are any real ramifications beyond the warnings/errors in FFmpeg. Do you think it's relatively benign, or could it cause issues?
When encoding with the hardware accelerated v4l2 h264 encoders, the resulting file is playable, but there is a discrepancy between the encoded frames and packets. Starting with a YUV file created by:
libcamera-vid --width 4096 --height 3040 -t 1000 --codec yuv420 -o ~/out.yuv
And then encoding it with:
ffmpeg -y -f rawvideo -pix_fmt yuv420p -s:v 4096x3040 -r 10 -i ~/out.yuv -filter:v scale=1920:1088 -c:v h264_v4l2m2m -b:v 25M -v verbose ~/out.mp4
Results in a discrepancy between the encoded/muxed frames:
While I'm able to play this video in VLC, when I attempt to extract the frames with
ffmpeg -y -i out.mp4 -v verbose -pix_fmt rgb24 camera_%04d.png
, something seems a bit wrong:When I encode the out.yuv file with libx264, I do not see this discrepancy in the encoded/muxed frames and I am able to then extract the frames without error from the encoded file.
I am testing on a Compute Module 4 + Official IO Board + Bullseye Lite 64bit + 5.10.63-v8+ Kernel. Full system info here - https://pastebin.com/654vBepL
Let me know if you need any further info or help replicating.