FFmpeg is a command-line tool for converting media files fast without losing quality. In this article, I will show you how to use FFmpeg on Windows or Mac. I will also cover how to use FFmpeg with GUI in case you don’t like using the command line tool.
Many can work with FFmpeg for advanced features. For example, you can use yt-dlp + FFmpeg to download 4K YouTube videos.
FFmpeg Installation on Mac
It is quite straightforward tp install FFmpeg on a Mac with Homebrew. If you don’t have Homebrew installed on your Mac, you can open Terminal and run the following command:
/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"
Once complete, run the command below to install FFmpeg on your Mac.
brew install ffmpeg
After successful installation, you can open the Terminal and verify the installation by typing “ffmpeg -version”. If everything is set up correctly, you should see information about the installed version of FFmpeg.
Install FFmpeg on Windows
Installing FFmpeg on Windows requires a few additional steps compared to the macOS installation. Here’s a step-by-step guide to help you through the process:
- Open your web browser and go to the FFmpeg official website.
- Look for the “Download” or “Get the packages” section on the homepage.
- Scroll down and find the “Windows” section. Here, you have two options: a static build or a shared build. The static build is self-contained, while the shared build requires additional DLL files. For simplicity, we will focus on the static build.
- Click on the “Link” under the static build column, corresponding to your system architecture (32-bit or 64-bit).
- Once the download is complete, extract the downloaded file to your User folder and then you can open a Command prompt to use FFmpeg. If you want to make FFmpeg accessible from anywhere on your system, follow along.
- You will have several executable files, including ffmpeg.exe. You may want to add its location to the system’s PATH environment variable. This can be done by following these steps:
- Right-click on “My Computer” or “This PC” and select “Properties.”
- In the System Properties window, click on “Advanced system settings” on the left-hand side.
- In the System Properties dialog box, click on the “Environment Variables” button.
- In the Environment Variables dialog box, locate the “Path” variable under the System variables section and click on “Edit.”
- Click on “New” and enter the path to the folder where FFmpeg is located (e.g., C:\ffmpeg\bin) and click “OK” to save the changes.
After completing these steps, open Command Prompt and type ffmpeg -version to verify that FFmpeg is successfully installed and accessible from the command line.
Basic Usage and Commands
Now that you have FFmpeg installed on your Mac or Windows system, let’s explore some basic usage examples and commands. For Windows, you should replace “ffmpeg” with “ffmpeg.exe”.
Converting a Video File Format: To convert a video file from one format to another, use the following command:
ffmpeg -i input.mp4 output.avi
- Replace input.mp4 with the name of your input file and output.avi with the desired name for the output file. FFmpeg will automatically detect the file format based on the file extension.
Extracting Audio from a Video: To extract the audio from a video file, use the following command:
ffmpeg -i input.mp4 -vn output.mp3
- The -vn option tells FFmpeg not to include any video in the output.
Resizing and Cropping Videos: To resize a video, use the -s option followed by the desired width and height:
ffmpeg -i input.mp4 -s 1280x720 output.mp4
To crop a video, use the -vf option followed by the crop filter:
ffmpeg -i input.mp4 -vf "crop=640:480:10:20" output.mp4
- In this example, the crop filter crops the video to a width of 640 pixels, height of 480 pixels, starting at the coordinates (10, 20).
These are just a few examples of the basic usage of FFmpeg. The tool offers various options and filters to manipulate audio and video files. Refer to FFmpeg’s documentation and online resources for more comprehensive command examples.
Advanced Techniques and Filters
FFmpeg provides an extensive set of advanced techniques and filters that allow you to enhance your multimedia processing capabilities. Here are a few noteworthy ones:
Batch convert
Convert all files in the same folder. The following command converts all FLAC files to ALAC with Windows Powershell.
ls -recurse -include *.flac | %{C:\the location path of FFmpeg\ffmpeg.exe -i $_.FullName -c:v copy -acodec alac ($_.DirectoryName+"\\"+$_.BaseName+'.m4a')}
If you want to use a bat file to run FFmpeg command, replace “%” with “%%”. For example, to convert all image files to WebP, save the following in a bat file:
@echo off
for %%i in (*.*) do ffmpeg -i "%%i" "%%~ni.webp"
For Mac users, you should use this command:
for f in *.flac;do ffmpeg -i "$f" -c:v copy -c:a alac "${f%flac}.m4a";done
Concatenating Videos
You can concatenate multiple video files into a single output file by using the concat demuxer. This allows you to merge videos without re-encoding them, resulting in faster processing times. Let’s say I have three files that we want to concatenate – each of them with one video and audio stream. The concat filter command would look like this:
ffmpeg -i input1.mp4 -i input2.webm -i input3.mov \
-filter_complex "[0:v:0][0:a:0][1:v:0][1:a:0][2:v:0][2:a:0]concat=n=3:v=1:a=1[outv][outa]" \
-map "[outv]" -map "[outa]" output.mkv
Creating Animated GIFs
FFmpeg can convert a video into an animated GIF, a popular format for sharing short, looping clips. The following command creates an animated GIF from a video:
ffmpeg -i input.mp4 -vf "fps=10,scale=320:-1:flags=lanczos" output.gif
Adjust the fps and scale values to control the frame rate and size of the output GIF.
Adding Watermarks
You can add watermarks, logos, or text overlays to your videos using the overlay filter. This filter allows you to specify the position and duration of the overlay.
Add a watermark to the center of a video with FFmpeg and Editframe: You can use the following command to add a watermark image in the center of the video:
ffmpeg -i car.mp4 -i watermark.png -filter_complex "format=rgba,scale=w=326:h=490:force_original_aspect_ratio=decrease [logo]; [logo]overlay=(W-w)/2:(H-h)/2:format=auto,format=yuv420p" -c:a copy watermark.mp4
These are just a few examples, but FFmpeg offers many more advanced techniques and filters to explore. Experimentation and practice are key to mastering FFmpeg’s full potential.
FFmpeg GUI
While FFmpeg is primarily a command-line tool, there are graphical user interfaces (GUIs) available that provide a more user-friendly interface for users who prefer a visual approach. Some popular FFmpeg GUIs for Windows include “FFmpegYAG” and “WinFF,” while “FF Works” and “Adapter” are popular choices for Mac users.
For iPhone and Mac users, you can also use Shortcuts app to run FFmpeg commands. For example, I have made a Mac shortcut to convert FLAC to ALAC with FFmpeg.
These GUIs provide a graphical interface for selecting input and output files, choosing encoding options, and running FFmpeg commands. They can be a great starting point for beginners or users who are more comfortable with a visual interface.
Troubleshooting and FAQs
- FFmpeg is not recognized as an internal or external command: This error usually occurs when FFmpeg’s installation directory is not added to the system’s PATH environment variable. Make sure to follow the installation instructions mentioned earlier to resolve this issue.
- Unsupported codec or format errors: FFmpeg supports a vast range of codecs and formats, but it may lack support for some proprietary or uncommon codecs. If you encounter an unsupported codec error, try installing the necessary codecs or consider re-encoding the file using a different codec.
- Problems with audio/video synchronization: Audio/video synchronization issues can sometimes occur when converting or manipulating multimedia files. In such cases, you can use FFmpeg’s -async option to adjust the audio delay and synchronize it with the video.
These are just a few common troubleshooting tips. If you encounter any other issues, refer to the FFmpeg documentation, online forums, or the respective GUI’s support channels for assistance.
In conclusion, FFmpeg is a powerful tool that empowers Windows and Mac users to handle multimedia files easily. By mastering FFmpeg and its various techniques and filters, you can unlock a wide range of possibilities for audio and video processing. So, roll up your sleeves, dive into the world of FFmpeg, and unleash your creativity!