43

I am trying to convert a .mov video to .mp4 with ffmpeg:

ffmpeg -i ~/Desktop/Sample.mov ~/Desktop/Sample.mp4

This doesn't work though, and when I try to open the produced video in quicktime it tells me that the file is either corrupted or in a format quicktime doesn't understand.

How do I get this to work?

1
  • Use handbrake for MAC Commented Dec 10, 2016 at 19:10

2 Answers 2

66

To convert videos, I like to use handbrake. You can find it here: https://handbrake.fr/ I use it on Linux but it should work well on MAC too.

For HandBrake:

handbrakecli -i {in-video}.mov -e x264 -E facc -o {out-video}.mp4

For ffmpeg:

ffmpeg -i {in-video}.mov -vcodec h264 -acodec aac {out-video}.mp4
2
  • Handbrake worked. The ffmpeg command doesn't.
    – minseong
    Commented Dec 12, 2016 at 22:34
  • 4
    ffmpeg worked great as above for me
    – Andy
    Commented Mar 24, 2017 at 22:16
26

Copy

You can stream copy if the MOV file contains video and audio that is compatible with MP4:

ffmpeg -i input.mov -c copy -movflags +faststart  output.mp4
  • Stream copy (-c copy) is like a "copy and paste" so the quality is preserved and the process is fast.
  • -movflags +faststart makes an output file that usable for HTML5 streaming, for example, putting all the necessary info to begin playback at the start of the file. If you only care about local desktop usage, you can leave that out.
  • Video formats compatible with MP4 include: H.264, H.265/HEVC, AV1 (new format, so not universally supported), MPEG-4 (old format, not supported in HTML5).
  • Audio formats compatible with MP4 include: AAC, MP3 (playback support depends on player), Opus (new format, so not universally supported).

Encode

This will convert the MOV to H.264 video and AAC audio:

ffmpeg -i input.mov -c:v libx264 -c:a aac -vf format=yuv420p -movflags +faststart output.mp4
  • -c:v libx264 choose encoder libx264 to output H.264 video.
  • -c:a aac choose encoder aac to output AAC audio.
  • -vf format=yuv420p chooses YUV 4:2:0 pixel format. libx264 supports many pixel formats and by default will choose a pixel format that most resembles the input. But not all pixel formats are supported by all players. yuv420p is the most compatible and universally supported.
  • -movflags +faststart same as the Web Optimized option in Handbrake. After encoding completes it moves a chunk of info from the end of file to the beginning so it can start playing faster when viewing via download.

See FFmpeg Wiki: H.264 and FFmpeg Wiki: AAC for more info, including CPU time vs. quality vs. bitrate settings. (x264's default is -preset medium -crf 23)

5
  • You can use -movflags +faststart with -c copy as well. It's just as useful / useless either way, depending on what you want to do with the file. (Allows the file to be streamed, e.g. from a web server.) Also, -c:a aac is a low quality encoder; libfaac is better. Or maybe you can keep the original audio and just transcode the video, e.g. for bitrate or codec reasons, like -c:v libx264 -c:a copy. Commented Jun 26, 2021 at 17:17
  • Also, future readers that want to transcode should have a look at your FFmpeg wiki links for quality vs. encode-time vs. bitrate settings, like -preset slower to spend more CPU time to improve the quality per bitrate tradeoff. Very worth it for encode once, stream many times. And -crf 23 being the default, -crf 26 to quantize more (smaller file), -crf 20 or so to quantize less (higher quality). Commented Jun 26, 2021 at 17:19
  • I get this error when I ran the first ffmpeg command: [mp4 @ 0x55c4fbbfae40] Could not find tag for codec prores in stream #0, codec not currently supported in container Could not write header for output file #0 (incorrect codec parameters ?): Invalid argument Error initializing output stream 0:1 --
    – rlittles
    Commented Sep 7, 2022 at 21:46
  • @PeterCordes really???
    – Michael
    Commented Oct 26, 2022 at 20:30
  • 1
    @Michael: Thanks for the correction, I was mixing up libfaac (even worse than aac) with libfdk_aac (significantly better). That link confirms -c:a aac is still only "fairly good" quality per bitrate, vs. fdk_aac being "excellent", so it's still relatively poor compared to good encoders, or to other codecs like Opus. (It's really too bad it's still not easy to use Opus audio with MP4 containers, instead being stuck with AAC which is burdened by proprietary encoders which still don't do as well as the free libopus. For my own use, if xcoding audio I use -c:a libopus -b:a 80k) Commented Oct 26, 2022 at 21:30

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .