keepcalculator

06 Numbers and Powers

How to Use FFmpeg on Mac: A Practical Guide

Card No. 06·55304 · Updated · Standard formula, shown below

FFmpeg is a powerful command-line tool for converting, recording, and processing audio and video files. On a Mac, you can use it to change formats, compress videos, extract audio, and more—all without installing a heavy GUI app. This guide walks you through installing FFmpeg and running the most common commands, with clear steps and troubleshooting for when things go wrong.

What You’ll Need

  • A Mac running macOS (any recent version, from Catalina to Sonoma)
  • Terminal access (found in /Applications/Utilities/Terminal.app)
  • Homebrew installed (optional but recommended for easy installation)
  • A video or audio file you want to process (e.g., MP4, MOV, MP3)

Step-by-Step

  1. Install Homebrew (if not already installed). Open Terminal and run: /bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)". Follow the prompts; this may take a few minutes.
  2. Install FFmpeg via Homebrew. In Terminal, run: brew install ffmpeg. Homebrew will download and install FFmpeg along with its dependencies. If you already have Homebrew, this is the quickest method.
  3. Verify the installation. Run ffmpeg -version. You should see version information and configuration details. If you see “command not found,” re-check the installation path.
  4. Navigate to your file’s folder. Use cd to change directories. For example, if your video is on the Desktop, run: cd ~/Desktop. You can also drag the folder into Terminal after typing cd to paste the path.
  5. Check your input file. Run ffmpeg -i input.mp4 (replace input.mp4 with your file’s name). This will show file info like codec, resolution, and bitrate. It will also print an error at the end (because no output is specified), but that’s normal.
  6. Convert a video to another format. For example, to convert MP4 to MKV: ffmpeg -i input.mp4 output.mkv. The output format is inferred from the file extension. For MP4 to AVI, use output.avi.
  7. Compress a video (reduce file size). Use the H.264 codec and adjust the CRF (Constant Rate Factor) value. Lower CRF = higher quality, larger file. A common value is 28 for good compression: ffmpeg -i input.mp4 -c:v libx264 -crf 28 -preset fast output.mp4. The -preset controls speed vs. compression efficiency.
  8. Extract audio from a video. To save the audio as MP3: ffmpeg -i input.mp4 -q:a 0 -map a output.mp3. The -map a selects only the audio stream. For lossless audio, use -c:a flac instead.
  9. Resize a video. To scale to 1280×720 (720p): ffmpeg -i input.mp4 -vf scale=1280:720 output.mp4. You can also use scale=-2:720 to keep the aspect ratio (the -2 ensures even dimensions).
  10. Trim a video. To cut from 10 seconds to 30 seconds: ffmpeg -i input.mp4 -ss 10 -t 20 -c copy output.mp4. -ss is the start time, -t is the duration. Using -c copy copies the streams without re-encoding, which is fast but less precise.
  11. Combine audio and video. To replace the audio track in a video: ffmpeg -i video.mp4 -i audio.mp3 -c:v copy -c:a aac -map 0:v:0 -map 1:a:0 output.mp4. The -map options select which streams to use.

Common Mistakes

  • Forgetting to specify the output format. FFmpeg infers the format from the file extension. If you type output without an extension, you’ll get an error.
  • Using the wrong file paths. If your file has spaces, you must quote the filename: ffmpeg -i "my video.mp4".
  • Assuming the codec is supported. Some formats (like WMV) may require additional libraries. If you get “Unknown encoder,” you may need to install a build with more codecs, or convert to a more common format.
  • Overwriting files without asking. FFmpeg will overwrite output files without warning. Use -n to prevent overwriting, or -y to auto-confirm.

Tips

  • Use the -preset option wisely. For H.264 encoding, ultrafast is quick but produces larger files; veryslow gives the best compression but takes longer.
  • Batch process multiple files. Use a loop in Terminal: for i in *.mp4; do ffmpeg -i "$i" "${i%.mp4}.mkv"; done. This converts all MP4 files in the folder to MKV.
  • Check the FFmpeg documentation. The official docs at ffmpeg.org are thorough. Use ffmpeg -h full to see all options.
  • Use -progress to monitor long encodes. Add -progress pipe:1 to see progress in the terminal.

Troubleshooting

  • “command not found” after installation. If Homebrew installed FFmpeg but Terminal can’t find it, your PATH may not include Homebrew’s bin directory. Run export PATH="/opt/homebrew/bin:$PATH" (for Apple Silicon) or export PATH="/usr/local/bin:$PATH" (for Intel) to fix it temporarily. To make it permanent, add that line to your ~/.zshrc file.
  • FFmpeg is slow or hangs. This is often due to a very high resolution or a slow preset. Try lowering the resolution or using a faster preset. Also, ensure your Mac has enough free disk space (FFmpeg needs space for temporary files).
  • “Invalid data found when processing input.” This usually means the file is corrupted or not actually a video/audio file. Try opening the file in QuickTime to see if it plays.
  • Audio is out of sync after conversion. This can happen when using -c copy with trimming. Instead, re-encode the audio: ffmpeg -i input.mp4 -ss 10 -t 20 -c:v libx264 -c:a aac output.mp4.

Frequently Asked Questions

  • Is FFmpeg free? Yes, FFmpeg is free and open-source software. It’s available under the LGPL/GPL license.
  • How do I uninstall FFmpeg? If installed via Homebrew, run brew uninstall ffmpeg.
  • Can I use FFmpeg to convert videos for iPhone? Yes, you can convert to H.264 with AAC audio, which is compatible with iPhone. For example: ffmpeg -i input.mp4 -c:v libx264 -c:a aac -movflags +faststart output.mp4.
  • Does FFmpeg support hardware acceleration on Mac? Yes, you can use -c:v h264_videotoolbox for hardware encoding on Macs with Intel or Apple Silicon. This is faster but may produce slightly lower quality than software encoding.
  • How do I extract a frame from a video? Use ffmpeg -i input.mp4 -ss 00:01:00 -vframes 1 frame.jpg to capture the frame at 1 minute.
  • Why is my output file larger than the input? This often happens when you use a high bitrate or a lossless codec. Use CRF compression (as in step 7) to reduce size, or check the bitrate with -b:v 1000k.

Related

Method: the standard formula for this calculation, rounded as each result states. See how the calculators work or report an error.

More cards in this drawer

The whole Numbers and Powers drawer →