1

Hi recently I am converted some videos to MP4 using FFMpeg but When I am trying to stream this video files, player needs to load a file completely, until it starts to play, I am trying to find a way to make it start play a file right from the start and keep on loading as well. I am using this FFMpeg command for conversion:

ffmpeg -i input.mp4 -vcodec libx264 -vpre default -crf 28 -ac 1 -ar 44100 -b 284k -ab 70k -r 15 -s 640x360 output.mp4 2>&1

3 Answers3

5

This is happening because mp4 format has its moov info at the tail of the file. The information is required for flash players before the file can be progressively download and play. Therefore if the info is in the end of file, it has to be fully downloaded, which is terrible, user-experience-wise.

From your answer you can compile a separate tool provided in ffmpeg - qt-faststart to post-process the mp4 file and then use the mp4 file for video streaming.

Specially, you can download a copy of source code for ffmpeg, and go to tools folder and run:

make qt-faststart

then you will have a tool named qt-faststart in tools directory. Then you can run:

qt-faststart input.mp4 output.mp4

and put output.mp4 to your streaming folder and the new mp4 file will be progressively downloaded while playing.

Alternatively another option is to do this during transcoding time as suggested in previous answers, but the command line is provided wrong, it should be:

-movflags +faststart

in your ffmpeg command line. It will do the same thing as you transcode.

So there are your two easiest solution to this, hope the best of luck!

JasonYang
  • 686
  • 7
  • 14
  • I am using MP4Box, now it is working fine. – Hamza Iqbal Oct 25 '14 at 13:56
  • Well, yes, MP4Box can do it too, in the same mechanism, as well as some other software as well. Thought you were looking for a ffmpeg solution. – JasonYang Oct 25 '14 at 14:59
  • Yes @JasonYang I am looking for ffmpeg solution but when I am using ffmpeg with this command 'ffmpeg -i input.mp4 -movflags +faststart -vcodec libx264 -vpre default -crf 28 -ac 1 -ar 44100 -b 284k -ab 70k -r 15 -s 640x360 output.mp4 2>&1' It give this error: 'Unrecognized option movflags' – Hamza Iqbal Oct 25 '14 at 16:50
  • @HamzaIqbal Your ffmpeg build is way too old. See a [ffmpeg compile guide](https://trac.ffmpeg.org/wiki/CompilationGuide/Ubuntu) or [download a build of ffmpeg](http://johnvansickle.com/ffmpeg/). – llogan Oct 26 '14 at 19:10
2

For streaming, the moov atom needs to be at the beginning of the file, rather than the end. For ffmpeg, try adding:

-movflags faststart
MisterNeutron
  • 3,359
  • 3
  • 17
  • 20
0

You can always test with this tool - http://renaun.com/blog/2010/06/qtindexswapper-2/

emaxsaun
  • 4,191
  • 2
  • 13
  • 13
  • I am using FFmpeg in linux php server, how I do this in linux? – Hamza Iqbal Oct 23 '14 at 22:24
  • I am not really familiar with FFMPEG, but the issue you are having is basically because your MP4 file's MOOV ATOM is at the end of the file, not at the beginning, so the entire file has to be downloaded first before it can be played back. I was just suggesting to try this tool to confirm that it would fix the issue, that's all. – emaxsaun Oct 24 '14 at 14:57
  • Yeah, the other tools for fixing it, like qtindexswapper and MP4 FastStart (http://www.datagoround.com/lab/) are not server-side applications. So, you could fix your videos using either of them, but you'd be doing it on your PC, and then uploading the result. Tapping into the existing ffmpeg options is a better solution if you're already using ffmpeg to encode. – MisterNeutron Oct 24 '14 at 15:25