I am trying to convert an MP3 file to a fragmented MP4 like this:
ffmpeg -i input.mp3 -strict experimental -acodec aac -b:a 256k -f mp4 \
-movflags faststart+frag_keyframe+empty_moov+separate_moof output.mp4
However, using Bento4 I can see that there is just one giant mdat
object instead of a series of those:
[ftyp] size=8+24
major_brand = isom
minor_version = 200
compatible_brand = isom
compatible_brand = iso2
compatible_brand = iso6
compatible_brand = mp41
[moov] size=8+701
...
[moof] size=8+62364
...
[mdat] size=8+5794679
[mfra] size=8+59
[tfra] size=12+31, version=1
track_ID = 1
length_size_of_traf_num = 0
length_size_of_trun_num = 0
length_size_of_sample_num = 0
[mfro] size=12+4
mfra_size = 67
I think what I want is this:
(source)
But I can't seem to be able to get this from ffmpeg
.
I found some other options here like
$ ffmpeg -h muxer=ismv
...
-frag_duration <int> E.... Maximum fragment duration
-min_frag_duration <int> E.... Minimum fragment duration
-frag_size <int> E.... Maximum fragment size
but playing around with these didn't change the output.
How can I create fragments of a specific sice e.g. ~5 seconds each?
Audio streams have no keyframes which is what MP4 muxer relies on by default to demarcate fragment boundaries. You will have to set a fragment duration.
ffmpeg -i input.mp3 -c:a aac -b:a 256k -f mp4 -movflags +empty_moov+separate_moof -frag_duration 10M output.mp4
faststart
is applicable for regular, non-fragmented outputfrag_keyframe
tells ffmpeg to start fragments at video keyframes but you don't have a video stream.-strict experimental
hasn't been required for the native AAC encoder since 2016.frag_duration
expects a value in microseconds. 10M
= 10 million = 10 seconds.