raspberrypi / raspberrypi/linux

v4l2h264enc doesn't support h264_i_frame_period=1 and h264_v4l2m2m doesn't respect -g parameter

Open
#4,740 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
C
Stars
13.2k
Forks
5.5k
Avg merge
2d 21h
Merged PRs (30d)
21

Description

When setting h264_i_frame_period=1, Gstreamer hangs at 1% using the following command:

gst-launch-1.0 -vvv videotestsrc pattern=snow num-buffers=100 ! video/x-raw,width=1920,height=1080,framerate=30/1 ! v4l2h264enc extra-controls="controls,video_bitrate_mode=0,video_bitrate=25000000,h264_i_frame_period=1,repeat_sequence_header=1" \
! 'video/x-h264,profile=high,level=(string)4.1' ! h264parse ! mp4mux ! filesink location=~/out.mp4 

But when h264_i_frame_period=2, it encodes correctly (frame types verified with ffprobe):

gst-launch-1.0 -vvv videotestsrc pattern=snow num-buffers=100 ! video/x-raw,width=1920,height=1080,framerate=30/1 ! v4l2h264enc extra-controls="controls,video_bitrate_mode=0,video_bitrate=25000000,h264_i_frame_period=2,repeat_sequence_header=1" \
! 'video/x-h264,profile=high,level=(string)4.1' ! h264parse ! mp4mux ! filesink location=~/out.mp4 

I'm unable to test FFmpeg's h264_v4l2m2m encoder's support of a keyframe interval = 1 as it doesn't respect the '-g' flag. FFmpeg throws this warning regardless of the '-g' flag:

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

FFmpeg's issue could be potentially related to - https://trac.ffmpeg.org/ticket/2305

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.

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by reproducing the provided gst-launch-1.0 case at h264_i_frame_period=1 and compare it with the working value of 2. Then investigate the v4l2h264enc and h264_v4l2m2m entry points and the reported GOP-setting warning. Done means the GStreamer case no longer hangs and FFmpeg's -g parameter is respected, with regression coverage where the relevant tests exist.

Written by the indexing model from the issue text.

Assessment

Tech stack
c, linux
Domain
audio-video-rtc, operating-systems
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.