I am trying to write streamable (fragmented?) mp4 files with FFMpeg. But the default of the FFMpeg bahavior of the -f mp4
format is not this one.
Take for example this AAC-LC MP4 test file save it as aac_lc_in.m4a
and run the ffmpeg
command:
ffmpeg -y -i aac_lc_in.m4a -strict -2 -codec copy -f mp4 aac_lc_out.m4a
The result is a non-streamable file (put it on a server and try to load it in your browser. It only starts after it is completely downloaded). This does not happen with the original file that can be started before the download completes.
I also tried using the mp4
format parameters:
-movflags frag_keyframe+empty_moov
-movflags faststart+frag_keyframe
-movflags faststart+frag_keyframe+empty_moov
-movflags faststart+rtphint+frag_keyframe
-movflags rtphint+frag_keyframe
-movflags rtphint+frag_keyframe -rtpflags latm
but nothing helped. Even if the output file looks very similar to the original one (File format box, sample table boxes, etc.), the generated file is not streamable.
I found the solution. ONLY use the argument -movflags faststart
for the mp4
format. The complete command would be:
ffmpeg -i aac_lc_in.m4a -strict -2 -codec copy -f mp4 -movflags faststart aac_lc_out.m4a
Now the aac_lc_out.m4a
file is played by the browser as soon as you click play.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With