Any downsides to always using the -movflags faststart parameter?

9

3

It seems many sites like YouTube suggest moov atom at the front of the file (Fast Start).

ffmpeg does not make this a default behavior, but you can specify it with the -movflags faststart option. I'm wondering if there is any downside to always using this parameter?

Sun

Posted 2014-12-23T15:46:31.797

Reputation: 5 198

Answers

13

Depending on the size of your input it can take some time to perform the second pass to move the moov atom to the beginning of the file.

Without -movflags +faststart

ffmpeg -benchmark -i input.mkv output.mp4
rtime=0m42.701s

With -movflags +faststart

ffmpeg -benchmark -i input.mkv -movflags +faststart output.mp4
rtime=1m4.036s

llogan

Posted 2014-12-23T15:46:31.797

Reputation: 31 929

I did notice a second pass, but I didn't think it would take that long. Nice to know. – Sun – 2014-12-24T21:52:57.873

@sunk818 The time will of course vary depending on your input. – llogan – 2014-12-24T22:19:00.847

In the latest version of ffmpeg (3.x+ or 4.x+), the correct syntax is -movflags faststart indeed (without the + sign). See: https://ffmpeg.org/ffmpeg-formats.html#Options-8

– Siu Ching Pong -Asuka Kenji- – 2018-12-23T14:59:04.697

@SiuChingPong-AsukaKenji- It doesn't really matter if you include the + or not.

– llogan – 2018-12-26T00:17:46.893

9

I guess this thread needs an update. On latest ffmpeg (3.4.1) I get:

$ time ffmpeg -y -f lavfi -i nullsrc=s=hd720:d=600 -preset ultrafast out.mp4
real 0m26.578s
$ time ffmpeg -y -f lavfi -i nullsrc=s=hd720:d=600 -movflags +faststart -preset ultrafast out.mp4
real 0m26.849s

Same results. Now try with a real video:

$ time ffmpeg -y -i Sintel.2010.1080p.mp4 -preset:v ultrafast out.mp4
real 3m38.829s
$ time ffmpeg -y -i Sintel.2010.1080p.mp4 -preset:v ultrafast -movflags +faststart out.mp4
real 3m43.674s

About 2% difference, that could be just noise. Also need to note that "Starting second pass: moving the moov atom to the beginning of the file" phase took no more than couple seconds on 600Mb output file.

Alexander Svetkin

Posted 2014-12-23T15:46:31.797

Reputation: 191

Agreed. I have a 50MB input (mjpeg stream) that is being encoded to mp4 with h264. Without faststart real 0m30.676s. With faststart real 0m30.599s. My ffmpeg version is 4.2. I guess it's safe to say that this doesn't make a big difference anymore, if any at all. – confetti – 2019-10-21T00:36:52.723

3

As you may already know, the information required to write the moov atom or even to know the size of the moov atom isn't available until after the entire file is processed.

The drawbacks to having the moov atom at the start, and the reason many tools don't do it by default, are therefore all related to this fact.

If none of the following are a problem for you, then you can put the moov at the start all times and have no drawbacks.

  • A second pass is required. This potentially doubles the amount of disk I/O as data must be read from input, written to disk, then read from disk and re-written. This can be impractical where I/O speed is very slow, such as when writing to a network drive.

    Note that some software may optimize this by roughly estimating the required size of the moov atom near the start of encoding and reserving this much space, plus a margin of error, at the start of the output. In many cases this would remove the need to read-back and re-write the rest of the file and instead seek to the start and overwrite just a small part, at the cost of using slightly more space for the moov atom than necessary.

  • Output cannot be piped to another command or sent to stdout on the fly, because those mechanisms have no way of doing a second pass.

thomasrutter

Posted 2014-12-23T15:46:31.797

Reputation: 1 473