This should do the trick:
ffmpeg -re -i infile.ext -g 52 \
-c:a aac -b:a 64k -c:v libx264 -b:v 448k \
-f mp4 -movflags frag_keyframe+empty_moov \
output.mp4
frag_keyframe
causes fragmented output,empty_moov
will cause output to be 100% fragmented; without this the first fragment will be muxed as a short movie (usingmoov
) followed by the rest of the media in fragments,-re
is useful when live streaming (use input media frame rate), do not use it if you are creating a file,-g 52
forces (at least) every 52nd frame to be a keyframe
To calculate a healthy keyframe interval please see the paragraphs about fragment sizes in the docs of my streaming server. – You can also consider using WebM which is a free alternative to H.264 (and has better support on some platforms than fragmented mp4).
Important note: FFMpeg’s muxer will set the Duration in both tkhd
and mdhd
atoms to 0xffffffff for each track. This causes problems in some players (for example Quicktime will not play such files). You should find a tool and change it to zero (0x00000000).