FFmpeg Converts ANYTHING -
The Trick Book I Wish I Had
This issue is brought to you by:
Learn backend development the smart way with boot.dev
Use the code DEVOPSTOOLBOX to get 25% off your first payment for boot.dev.
|
|
The title of this newsletter isn't an exaggeration.
There's a single, free tool that can genuinely convert, create, and manipulate almost any media file you throw at it.
It’s the hidden engine powering everything from YouTube, through OBS, online media converters, to the video player on your phone.
When I first heard of it, probably 7-8 years ago, not only I didn't know half the things it could do (GIFs? seriously??) I would literally go on StackOverflow and copy paste my way to a WAV -> MP3 conversion.
So this, is the guide I with I had back then. And if "guide" is too big of a promise, then a trick booklet.
A problem we all face is digital clutter.
When you need to create a GIF, you search for an "online GIF creator" (or try looking for an existing one bc you don't have the skills).
When a video file is too big to email, you look for a "video compressor" or pay the price for an overkill hosting solution.
Need to grab the audio from a clip? That’s another tool.
Most people solve this by using a patchwork of different apps and websites for each specific task.
The issue is that this approach is inefficient and often risky.
You end up uploading your files to questionable servers, navigating websites littered with ads, and running unknown code in your browser.
All for a simple conversion you could have done locally, in 5 seconds, with a tool you probably already have installed.
Worse yet, most of these services are just fancy wrappers for that very same tool anyway.
So, how can we solve this differently?
By going directly to the source.
Instead of relying on a dozen different tools, you can use FFmpeg’s simple command-line interface to do it all yourself, faster and more securely.
It might seem intimidating, like a cryptic language for "genius dark basement engineers," but the truth is you don't need to be an expert.
You just need a handful of copy-paste commands to handle 99% of your media needs.
Ready to put it into action?
Key FFmpeg flags to remember:
"-i" holds the input
"-vf" - video filter, will hold, well, the filter, but also a set of comma-separated key value pairs
"-c:v" - converters like libx264 / mp3 etc
"-vn" - used when it's audio only, stands for "video no" or "no video"
The output file always comes last. And that's, pretty much it...
Here's a good list to remember, just replace the placeholder file names with your own, or parametrize them into your local snippets:
- Create a High-Quality GIF from a Video
Instead of using shady online converters, you can create a perfectly sized GIF with one line:
ffmpeg -i input.mp4 -vf "fps=10,scale=920:-1:flags=lanczos" output.gif
- What it does: The -vf (video filter) flag is where the magic happens. We're setting the GIF to 10 frames per second (fps=10) and scaling its width to 920 pixels. The -1 for the height tells FFmpeg to automatically calculate it to maintain the original aspect ratio. lanczos is a high-quality resizing algorithm, especially good for downscaling.
2. Create a High-Quality GIF from a Video
Yes, FFmpeg handles images, too! This is perfect for quickly optimizing images for a website without opening a heavy application.
ffmpeg -i large_image.png -vf "scale=800:-1" compressed_image.jpg
- What it does: Just like with the GIF, we use the scale filter. We set the width to 800 pixels and use -1 to preserve the aspect ratio, avoiding the "lovely distorted image" problem mentioned in the script.
3. Rip Audio from a Video File
Need to extract audio from a ckip? Incredibly useful for saving podcasts, music, or talks from video clips.
ffmpeg -i video_with_audio.mp4 -vn -c:a mp3 audio_only.mp3
4. Compress a Video (The Smart Way)
This is one of FFmpeg's main selling points. The following command uses a popular codec to drastically reduce file size while maintaining great quality.
ffmpeg -i huge_video.mp4 -c:v libx264 -crf 23 smaller_video.mp4
- What it does: We're setting the video codec (-c:v) to libx264, a widely used standard. The crf (Constant Rate Factor) value of 23 is a fantastic default that provides a great balance between quality and file size. A lower number means higher quality (and a larger file), while a higher number does the opposite.
5. Need to burn text directly onto a video? FFmpeg can do that without re-rendering in a complex video editor.
ffmpeg -i input.mp4 -vf "drawtext=text='Your Text Here':fontcolor=white:fontsize=24:x=10:y=10" output_watermarked.mp4
- What it does: We use the drawtext video filter to specify the text, color, size, and x and y coordinates for where it should appear on the screen.
While this is my list that covers most of the common tasks I use FFmpeg daily, I can't remember each and every flag and configuration.
My trick is Atuin, and specifically, Atuin scripts!
Every time I use a one line FFmpeg command, I script it using Atuin, parameterize anything worth tweaking later, and use my arsenal of snippets when I need a gif, audio channel fixing, compressing a video and what not!
Thank you for reading.
Feel free to reply directly with any question or feedback.
Have a great weekend!
Whenever you’re ready, here’s how I can help you:
|
|