[Libav-user] Possible to add new stream to fragmented MP4 after avformat_write_header?

Fredrik Orderud forderud at gmail.com
Tue May 20 13:38:18 EEST 2025


Hi. I'm working on a https://github.com/forderud/AppWebStream project
for generating fragmented MP4 videos that are directly consumable by
web browsers with low latency. The project is manual parsing of some
MP4 metadata atoms for parameters not directly exposed through the
FFMPEG API, such as DPI.

I want to be able to change the DPI at run-time, so that pixel-spacing
information is preserved even if the video is zoomed. However, DPI is
only transmitted once initially as part of the "moov" movie box atom,
and not per-frame. I therefore assume that I'll need to create a new
stream with avformat_new_stream() to trigger transmission of a new
"moov" atom. My problem then is that the documentation states that
avformat_new_stream() should be called by the user before
avformat_write_header(), which cannot be honored since I'm already
streaming.

Is is possible to somehow work around this limitation, so that I can
add a new stream to a fragmented MP4 movie at any time? Alternatively,
any ideas for how to change the DPI dynamically?

Thanks in advance,
Fredrik


More information about the Libav-user mailing list