Search code examples
ffmpegmp4libavmedia-sourcelibx264

muxing streamable segmented mp4 with libav


currently i have an application that is supposed to send fragmented mp4 data over a websocket to a client for it to be played there.

i have a working implementation that pipes the raw frames to a spawned ffmpeg process and then reads fragmented mp4 segments from the output pipe before it sends those on to the client where the client then displays the video correctly.

my problem is that when i try to make an implementation using libav it doesnt seem to work. my libav config uses libx264 to encode the frames before muxing them to a mp4, but when i try to play the provided segments in a browser using MSE it spits out an error. after having checked chrome://media-internals i have figured out that chrome complains when i provide the moov box that is one of the two initialization boxes of a fmp4 stream.

chrome apparently has a problem with parsing that box when its sent from libav, but not when its sent from ffmpeg.

my question is: What is the correct muxer configuration of libav so that it creates a fragmented mp4 stream where the client can recieve media boxes from the middle, after having been provided the init boxes?


Solution

  • I managed to solve my own problem.

    The issue i had was that i forgot to enable the AV_CODEC_FLAG_GLOBAL_HEADER flag in the encoder. this fixed my mp4 as the encoder put all the encoder flags in the header instead of with the media segments