Why can't Quicktime play a movie file encoded by FFmpeg? [duplicate]

When I try to open a movie I just created with the command:

ffmpeg -pattern_type glob -i '*.JPG' -s 640x480 movie.mp4

I get an error from QuickTime:

The document “movie.mp4” could not be opened.
The file may be damaged or may not be a movie file that is compatible with QuickTime Player.

I used the same command on a set of images generated from an iSight time lapse, but in this case the above images are from a digital camera. The resolution is a lot higher, but I am scaling it to 640x480 and I don't see anything in the output that suggests a problem:

Input #0, image2, from '*.JPG':
  Duration: 00:00:04.76, start: 0.000000, bitrate: N/A
    Stream #0:0: Video: mjpeg, yuvj422p(pc), 4928x3264, 25 tbr, 25 tbn, 25 tbc

vs. the working movie:

Input #0, image2, from '*.JPG':
  Duration: 00:01:23.72, start: 0.000000, bitrate: N/A
    Stream #0:0: Video: mjpeg, yuvj420p(pc), 640x480 [SAR 1:1 DAR 4:3], 25 fps, 25 tbr, 25 tbn, 25 tbc

And for the output:

Output #0, mp4, to 'movie.mp4':
  Metadata:
    encoder         : Lavf55.19.104
    Stream #0:0: Video: h264 (libx264) ([33][0][0][0] / 0x0021), yuvj422p, 640x480, q=-1--1, 12800 tbn, 25 tbc
Stream mapping:
  Stream #0:0 -> #0:0 (mjpeg -> libx264)

vs. for the working one:

Output #0, mp4, to 'movie.mp4':
  Metadata:
    encoder         : Lavf55.19.104
    Stream #0:0: Video: h264 (libx264) ([33][0][0][0] / 0x0021), yuvj420p, 640x480 [SAR 1:1 DAR 4:3], q=-1--1, 12800 tbn, 25 tbc
Stream mapping:
  Stream #0:0 -> #0:0 (mjpeg -> libx264)

Aside from the working movie being longer and a lower source resolution, the only difference I can see is that there is an extra "[SAR 1:1 DAR 4:3]" mentioned in the video stream, but I have no idea what this is, or how to try to force it in the non-working movie.

Update: I just downloaded VLC and it plays the movie fine. So I know ffmpeg isn't at fault here.


Based on this StackOverflow answer I would add -pix_fmt yuv420p to your command like this; one of the comments mentions adding -vcodec libx264 as well so it’s included here:

ffmpeg -pattern_type glob -i '*.JPG' -vcodec libx264 -s 640x480 \
-pix_fmt yuv420p movie.mp4

Or you could use the format filter. This example will use the scale filter instead of -s, and the format filter instead of -pix_fmt:

ffmpeg -pattern_type glob -i '*.JPG' -vcodec libx264 \
-vf scale=640:-2,format=yuv420p movie.mp4

Also elaborated on in the official FFmpeg Wiki under the heading “Encoding for dumb players”; emphasis mine:

You may need to use -pix_fmt yuv420p for your output to work in QuickTime and most other players. These players only supports the YUV planar color space with 4:2:0 chroma subsampling for H.264 video. Otherwise, depending on your source, ffmpeg may output to a pixel format that may be incompatible with these players.