Regression in h264_v4l2m2m? Fragmented mp4, ffmpeg, movflag “empty_moov"
Describe the bug
[I posteted the same question here]
I’m using ffpmeg with hardware acceleration (h264_v4l2m2m) to generate an fragmented mp4 file.
ffmpeg -hide_banner -f lavfi -i testsrc2=size=1920x1080
-vcodec h264_v4l2m2m -t 10 -bf 0
-movflags frag_keyframe+empty_moov+default_base_moof h264_v4l2m2m.mp4
Actually with the above movflags including “empty_mov” the file is generated but it's not playable in ffplay or vlc (Error: “No start code...”). This happens in 32 bit or 64 bit version of latest Raspberry Pi OS.
ffplay h264_v4l2m2m.mp4 [extract_extradata @ 0x7f6c002d80] No start code is found.B f=0/0 h264_v4l2m2m.mp4: could not find codec parameters
Using the same command In Raspbian "Buster" with h264_v4l2m2m and h264_omx the generated file is working fine. So can this be a regression from Buster to Bullseye?
Steps to reproduce the behaviour
Steps to reproduce Generate an fragmented mp4 file with the following command:
ffmpeg -hide_banner -f lavfi -i testsrc2=size=1920x1080
-vcodec h264_v4l2m2m -t 10 -bf 0
-movflags frag_keyframe+empty_moov+default_base_moof h264_v4l2m2m.mp4
Try to play the file in with the above mentioned command and try to play the file in ffplay or VLC.
Device (s)
Raspberry Pi 4 Mod. B
System
cat /etc/rpi-issue Raspberry Pi reference 2022-01-28 Generated using pi-gen, https://github.com/RPi-Distro/pi-gen, fbe448ccdc995d295d24c7596e5f0ef62cc2488f, stage4
vcgencmd version Mar 24 2022 13:19:26 Copyright (c) 2012 Broadcom version e5a963efa66a1974127860b42e913d2374139ff5 (clean) (release) (start) uname -a Linux raspberrypi 5.15.32-v8+ #1538 SMP PREEMPT Thu Mar 31 19:40:39 BST 2022 aarch64 GNU/Linux
Logs
mp4info h264_v4l2m2m.mp4 File: major brand: iso5 minor version: 200 compatible brand: iso5 compatible brand: iso6 compatible brand: mp41 fast start: yes
Movie: duration: 0 (media timescale units) duration: 0 (ms) time scale: 1000 fragments: yes
Found 1 Tracks Track 1: flags: 3 ENABLED IN-MOVIE id: 1 type: Video duration: 0 ms language: und media: sample count: 0 timescale: 12800 duration: 0 (media timescale units) duration: 0 (ms) bitrate (computed): 1160.065 Kbps sample count with fragments: 251 duration with fragments: 128000 duration with fragments: 10000 (ms) display width: 1920.000000 display height: 1080.000000 Sample Description 0 Coding: avc1 (H.264) Codec String: avc1.000000 AVC Profile: 0 AVC Profile Compat: 0 AVC Level: 0 AVC NALU Length Size: 0 AVC SPS: [] AVC PPS: [] Width: 1920 Height: 1080 Depth: 24
mp4info libx264.mp4
File: major brand: iso5 minor version: 200 compatible brand: iso5 compatible brand: iso6 compatible brand: mp41 fast start: yes
Movie: duration: 0 (media timescale units) duration: 0 (ms) time scale: 1000 fragments: yes
Found 1 Tracks Track 1: flags: 3 ENABLED IN-MOVIE id: 1 type: Video duration: 0 ms language: und media: sample count: 0 timescale: 12800 duration: 0 (media timescale units) duration: 0 (ms) bitrate (computed): 5452.421 Kbps sample count with fragments: 250 duration with fragments: 128000 duration with fragments: 10000 (ms) display width: 1920.000000 display height: 1080.000000 Sample Description 0 Coding: avc1 (H.264) Codec String: avc1.640028 AVC Profile: 100 (High) AVC Profile Compat: 0 AVC Level: 40 AVC NALU Length Size: 4 AVC SPS: [67640028acb200f0044fcb80880000030008000003019078c19240] AVC PPS: [68ebc3cb22c0] Width: 1920 Height: 1080 Depth: 24
Generating with h264_v4l2m2m
Input #0, lavfi, from 'testsrc2=size=1920x1080':
Duration: N/A, start: 0.000000, bitrate: N/A
Stream #0:0: Video: rawvideo (I420 / 0x30323449), yuv420p, 1920x1080 [SAR 1:1 DAR 16:9], 25 tbr, 25 tbn, 25 tbc
File 'h264_v4l2m2m.mp4' already exists. Overwrite? [y/N] y
Stream mapping:
Stream #0:0 -> #0:0 (rawvideo (native) -> h264 (h264_v4l2m2m))
Press [q] to stop, [?] for help
[h264_v4l2m2m @ 0x55c29011e0] Using device /dev/video11
[h264_v4l2m2m @ 0x55c29011e0] driver 'bcm2835-codec' on card 'bcm2835-codec-encode' in mplane mode
[h264_v4l2m2m @ 0x55c29011e0] requesting formats: output=YU12 capture=H264
[h264_v4l2m2m @ 0x55c29011e0] Failed to set gop size: Invalid argument
Output #0, mp4, to 'h264_v4l2m2m.mp4':
Metadata:
encoder : Lavf58.45.100
Stream #0:0: Video: h264 (h264_v4l2m2m) (avc1 / 0x31637661), yuv420p, 1920x1080 [SAR 1:1 DAR 16:9], q=-1--1, 200 kb/s, 25 fps, 12800 tbn, 25 tbc
Metadata:
encoder : Lavc58.91.100 h264_v4l2m2m
[mp4 @ 0x55c2900060] Timestamps are unset in a packet for stream 0. This is deprecated and will stop working in the future. Fix your code to set the timestamps properly
[mp4 @ 0x55c2900060] Encoder did not produce proper pts, making some up.
frame= 250 fps= 50 q=-0.0 Lsize= 1449kB time=00:00:09.96 bitrate=1191.7kbits/s speed= 2x
video:1416kB audio:0kB subtitle:0kB other streams:0kB global headers:0kB muxing overhead: 2.321112%
Additional context
When using libx264 in the actual version of Rasberrry Pi OS 32 and 64 bit everything is fine an the file is playable.
When using movflags without “empty_mov” the file is playable but only the video in the first segment is played the following video segments are ignored. For sending the video as stream to a browser the file has to be fully fragmented.