[FFmpeg-user] Issue with Delayed Packet Writing to MP4 Container Using Hardware Encoder (h264_v4l2m2m) in FFmpeg API

Lisa lisas965624 at gmail.com
Mon Jan 27 10:42:48 EET 2025


Hello. I am trying to store the encoded packets to a mp4 container file
using av_interlenced_write_packet() ffmpeg api.

With Hardware encoder[h264_v4l2m2m] there is an issue when I add 1 second
delay to write encoded Packets to the mp4 container.
While writing the packets there are no errors but the encoded video is not
playing.When verified with *mediainfo* CLI, got some partial metadata about
the video.
NOTE: Without delay there is no issue with recorded video.

   - *Mediainfo output of video without delay*

[image: mediainfo_of_no_delay.png]


   - *Mediainfo output of video with delay*

[image: mediainfo_of_with_delay.png]


The flow of my code is as described in the text and illustrated in the flow
diagram.
...
->send packet to encode
->Receive packet
->then clone the packet with av_packet_clone(sourcePacket)
->modified the pts & dts and
->writing frames to disk using av_interleaved_write_frame
<https://www.ffmpeg.org/doxygen/4.0/group__lavf__encoding.html#ga37352ed2c63493c38219d935e71db6c1>
 (AVFormatContext
<https://www.ffmpeg.org/doxygen/4.0/structAVFormatContext.html> *s
<https://www.ffmpeg.org/doxygen/4.0/llviddspenc_8c.html#a517a4433fe5466cc6af1c80c538b0881>
, AVPacket <https://www.ffmpeg.org/doxygen/4.0/structAVPacket.html> *pkt
<https://www.ffmpeg.org/doxygen/4.0/demuxing__decoding_8c.html#a3d4c6562f0b27cf0cacbbea5c038c090>
)
...
[image: ffmpeg.png]

   1. Why is the issue occurring with a delay of about 1 second?
   2. How can this issue be resolved?
-------------- next part --------------
A non-text attachment was scrubbed...
Name: mediainfo_of_no_delay.png
Type: image/png
Size: 150244 bytes
Desc: not available
URL: <https://ffmpeg.org/pipermail/ffmpeg-user/attachments/20250127/6b78d090/attachment.png>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: mediainfo_of_with_delay.png
Type: image/png
Size: 107259 bytes
Desc: not available
URL: <https://ffmpeg.org/pipermail/ffmpeg-user/attachments/20250127/6b78d090/attachment-0001.png>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: ffmpeg.png
Type: image/png
Size: 67083 bytes
Desc: not available
URL: <https://ffmpeg.org/pipermail/ffmpeg-user/attachments/20250127/6b78d090/attachment-0002.png>


More information about the ffmpeg-user mailing list