So, what is FFmpeg? At its core, you can think of it as a black box. You have some data—a video file, an audio file, whatever—you put it into the box, you do something to it, and you get some other output on the other side. It's a set of tools that lets you manipulate media files on a fundamental level. It's the engine underneath so many of the tools you use every day, on YouTube, Netflix, and beyond. This is what's running under the hood."
Week 0: The terminal—your command center
"Before we do anything, let's talk about the terminal. The terminal is your command line interface. It's a powerful and direct way to talk to your computer. For many, it's intimidating, but don't worry. We're going to use it just like a simple tool. To get FFmpeg, you just need to install it. It's like installing a new program on your computer, but we'll do it with a single command."
For Mac: brew install ffmpeg
For Windows: Follow the steps to download a build and add it to your path.
For Linux: sudo apt-get install ffmpeg
Week 1: Your first program—Hello, world!
"The simplest thing to do with FFmpeg is look inside a file. If someone gives you a mystery box, you'd want to know what's inside. The -i flag can be used to do this. The i here stands for input."
ffmpeg -i "my_video.mp4"
"FFmpeg provides a lot of information. It tells you the video format, the bitrate, the frame rate, the audio track, and more."
Week 2: Conversion—the Rosetta Stone of media
"If you have a video that your friend can't play on their phone, it might be in the wrong format. FFmpeg can translate one media format into another, like the Rosetta Stone. For example, you can convert an .mp4 file into a .mov file without changing the video or audio inside. This is called remuxing."
ffmpeg -i "my_video.mp4" -c copy "my_video.mov"
"The -c copy means 'copy the codec.' The media isn't re-encoded, so it's fast with no quality loss. It's just a packaging change."
Week 3: Compression—the magic of size
"If your file is too large to send to your friends, you need to compress it. This is where quality and size become a factor. There is a fundamental trade-off in computer science. If you have a high-resolution photo, it's large. If you reduce the quality, it's a smaller file, but you lose detail. FFmpeg uses a concept called the Constant Rate Factor, or CRF."
ffmpeg -i "my_video.mp4" -c:v libx264 -crf 23 "my_compressed_video.mp4"
"The -crf is a knob for controlling quality. Lower the number (from 51 down to 0), and you get higher quality, but a bigger file. Higher the number, and you get smaller file size, but you lose some quality. A value of 23 is a great starting point for good quality and a reasonable size."
Week 4: Adding a watermark—a lesson in complexity
"What if you want to add a logo to your video? Now there are two inputs: the video and the logo. This is where things get more complex, but the concepts are the same. A filter can be used to layer one input on top of the other."
ffmpeg -i "my_video.mp4" -i "logo.png" -filter_complex "[0:v][1:v] overlay=10:10" "video_with_logo.mp4"
"The -filter_complex takes multiple ingredients and blends them together. [0:v] is the video from the first input. [1:v] is the video from the second input (the logo). The overlay filter places the logo at a specific position (10 pixels from the top and 10 pixels from the left). It's a little more complex, but it's just another set of instructions for the computer."
The final takeaway
"FFmpeg isn't magic. It's just a set of instructions. And as shown here, you can start simple and then build on that knowledge, one command at a time. This is CS50. You got this."