Skip to content

Restream problem after h264_v4l2m2m encoding #1897

@warez4me

Description

@warez4me

While configuring Go2rtc for transcode RTSP streams on RPi4 with ffmpeg, I encountered a problem using the h264_v4l2m2m encoder.

If the libx264 encoder is used then everything functions normally and predictably. I can get as many copies of the transcoded video stream as I want adding different audio substreams.

But if to use the h264_v4l2m2m encoder that supports some hardware acceleration, then the features of the output video stream that I don't understand begin to appear, which do not allow parallel use of its copy or even use it with added transcoded audio track(s).

Actually, the RTSP output is produced but its video substream is unsuitable for playback.

For example, when using VLC for playback, the codec info is

  • on the left - Ok, starter, link - rtsp://[IP]:8554/stream
  • on the middle - bad video, starter, link - rtsp://[IP]:8554/stream?video=all&audio=all
  • on the right - bad video, follower, link - rtsp://[IP]:8554/stream
Image

ffprobe for "good" case when consumer is a 1st who opens the stream

$ ffprobe -v error -hide_banner -of default=noprint_wrappers=0 -print_format flat  -select_streams v:0 -show_entries frame=pict_type rtsp://raspberrypi:8554/8m_2
[rtsp @ 0x5555a84fd370] method SETUP failed: 461 Unsupported transport
frames.frame.0.pict_type="I"
frames.frame.1.pict_type="P"
frames.frame.2.pict_type="P"
...
frames.frame.2.pict_type="P"
frames.frame.12.pict_type="I"
frames.frame.13.pict_type="P"
...
^C

for "bad" case when the stream is already opened by another consumer

$ ffprobe -v error -hide_banner -of default=noprint_wrappers=0 -print_format flat  -select_streams v:0 -show_entries frame=pict_type rtsp://raspberrypi:8554/8m_2
[rtsp @ 0x5555a6b1d370] method SETUP failed: 461 Unsupported transport
[h264 @ 0x5555a6b23770] non-existing PPS 0 referenced
    Last message repeated 1 times
[h264 @ 0x5555a6b23770] decode_slice_header error
[h264 @ 0x5555a6b23770] no frame!
[h264 @ 0x5555a6b23770] non-existing PPS 0 referenced
    Last message repeated 1 times
[h264 @ 0x5555a6b23770] decode_slice_header error
[h264 @ 0x5555a6b23770] no frame!
...
^C

I've tried to compare the libx264 and h264_v4l2m2m generated streams both with capturing live RTSP stream by tcpdump or by redirecting ffmpeg output to file and then using stream analyzer to examine the differences.

Unfortunately my skill isn't good enough to see the source of problem.
Moreover, the "m2m" h264 stream looks more "canonical" to me.
But the stream from libx264, even without the visible presence of SPS/PPS headers, can be remuxed again, and the stream from h264_v4l2m2m turns out to be unusable with any attempt to use it for remux or copy.

I think this problem is a kinda synthetic and related to both Go2rtc and ffmpeg itself. It's not HW-related because I can use multiple transcoded streams if they were configured the same way, but under different names.

  • The Go2rtc is under suspicion because the 1st transcoded instance is good.
  • The ffmpeg is under suspicion because the libx264 codec's output stream doesn't have problems

If the Go2rtc is a rock-solid and its way to manipulate streams with ffmpeg is the only possible one - Ok, I'll agree if it can be clearly explained.

I will list the ffmpeg related questions below hoping on the experience and knowledge of the go2rtc community.

  • is there a fundamental possibility of obtaining the output h264 video stream after h264_v4l2m2m with parameters similar to those obtained after libx264?
  • perhaps the problem is related to the way the memory or CPU is used during the encoding process?
  • is there documentation for h264_v4l2m2m encoder with information on how to control it through ffmpeg parameters?

P.S. if required I can share any captured or redirected data.

Metadata

Metadata

Assignees

No one assigned

    Labels

    questionFurther information is requested

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions