Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to create streamable audio file with ffmpeg?

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.

like image 704
4 revs, 2 users 76% Avatar asked Oct 22 '22 11:10

4 revs, 2 users 76%


1 Answers

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.

like image 140
4 revs, 2 users 76% Avatar answered Oct 24 '22 02:10

4 revs, 2 users 76%