FFmpeg Quick Hacks
::: by V. Subhash :::
An easy FFmpeg tutorial, hack collection and quick-reference
Learn to create, edit, enhance and convert multimedia files using FFmpeg, the most versatile open source audio and video processing tool available for Linux, Mac and Windows users. After reading this book, you will be able to work with video and audio files, images, text, animations, fonts, subtitles and metadata like a pro.
This book begins with a simple introduction to FFmpeg executables — ffmpeg, ffprobe and ffplay, and explains how you can use them to process multimedia containers, streams, audio channels, maps and metadata. It then describes how you can easily edit, enhance and convert audio, video, image and text files. There are dedicated chapters for filters, audio, subtitles and metadata, as well as a big collection of FFmpeg tips and tricks. Sample lists of FFmpeg filters, encoders, decoders, formats and codecs are also available as appendices. The book is richly illustrated with screenshots and syntax-highlighted code snippets, all in 𝓕𝓤𝓛𝓛 𝓒🍅𝓛🍅𝓤𝓡. It is based on the latest Long Term Support (LTS) version of FFmpeg.
FFmpeg Quick Hacks is for anyone who needs to edit or process multimedia files including studio professionals, broadcast personnel, video content creators (such as Youtubers), podcasters, librarians, archivists and webmasters. It will be indispensable for those wanting to process a variety of multimedia files from the command line and inside shell scripts or custom-built software.
You will learn to:
- Convert from one format to another video-to-video, video-to-audio, video-to-image, image-to-video, video-to-animation, animation-to-video, text-to-audio, text-to-video
- Edit video files by cutting them with and without re-encoding, appending (joining clips together), resizing, changing frame rate and aspect ratio, mixing in audio
- Use filters to rotate, flip, crop, overlay (side-by-side or inset), remove logos, blur, smooth and sharpen, apply transitions as well as speed up or down playback
- Edit audio files by changing, normalizing or compressing volume, mixing and splitting channels and detecting silence. Also, learn to generate waveforms as video or image
- Add subtitles, place them anywhere on the screen, use custom fonts and colors, and use different languages
- Set metadata such as MP3 tags for and album art, set global and stream-specific metadata. And, learn how to import, export and remove metadata
- Automate your FFmpeg tasks
The FFMPEG Quick Hacks book has been withdrawn. A new updated version may be available in 2022 or 2023.
|Colour paperback||Barnes & Noble||$44.99|
This sample is a low-resolution watermarked PDF but it is fully functional.
Video demos for the code examples in the book
All-in-one video demo at the end of the book
How to fade in fade out audio and video
Convert a video into an animated image
This is my software implementation for Chandler Bing's ‘Run, Yasmine! Run!’ challenge.
ffmpeg -y -i baywatch.m4v \ -filter_complex "fps=7,scale=w=320:h=-1:flags=lanczos,split[v1][v2]; [v1]palettegen=stats_mode=diff[p]; [v2][p]paletteuse=dither=bayer:bayer_scale=4" \ run-yasmine-run-4.gif
This command creates a GIF animation with good frame quality and file size, but the motion is not smooth.
If you change the filter to
paletteuse=dither=bayer:bayer_scale=0, you get smoother motion but bigger file size and a dotted texture.
Instead of creating an animated GIF, which is limited to 256 colours, try creating an animated PNG. A PNG file supports millions of colours. ImageMagick is the tool you should use, not FFmpeg.
magick animated.gif animated.apng
If you convert from PNG source files (instead of the already downsampled image frames in the animated GIF), you will be able to create an animated PNG with richer colours.
For my first fiction title Unlikely Stories, I initially used an animated GIF. When I learned about APNG file, I was able to eliminate the effects of downsampling.
magick -delay 200 -loop 0 \ chapter-image-*.png \ -units PixelsPerInch -density 72 -resize '>x400' \ animation-unlikely-stories.apng
Animated GIF Animated PNG
When converting from a video to an animated PNG, you can use FFmpeg.
ffmpeg -i bw.m4v \ -vf "scale=w=250:h=-2, hqdn3d, fps=6" \ -dpi 72 -plays 0 \ bw.apng
Generate noise in audio and video
Bleep part of a video
Add audio waveforms to video
Reverse audio and video
MP3-to-MP4 or audio-to-video conversion using audio power spectrum filter
How to add echo to a video
Blurring a portion of a video
Write text on video
Render transparent GIF on video with infinite looping
Replace green-screen background on another video
Fade into another video using a transition effect
Slow down a video
Ms. Lennon's original video is available on her channel.
After slowing down a Tom & Jerry video, I was able to confirm poltergeist activity in a doll.
Subtitle a video
In the subtitle file (SSA), I used the following style for using my own custom font and other subtitle display settings.
A stop-motion video created using Cheese and FFmpeg
- Increase volume using FFMPEG and or Audacity for Dynamic Range Compression
Acknowledgements & Thanks
- "Rowdy" Roddy Piper/John Carpenter (They Live)
- Alaska Granny
- Amazing Lucas
- Barbara 2.0
- 'Beto' O'Rourke (Born to be president… ial campaign)
- Jack Benny (The Jack Benny Program)
- Jean-Claude Van Damme (public-domain videos)
- ‘Jerome Weiselberry’
- Jimmy Fallon (Tonight Show)
- Laurie Lennon
- Naomi 'Sexy Cyborg' Wu
- Sara Gonzales Unfiltered
- Yasmine Bleeth (Baywatch)
Use an RSS feed-reader such as Liferea, Thunderbird/Seamonkey or RSS Owl if you would like to anonymously subscribe to these channels. If you have no choice but to use Android, then use my app Subhash Browser & RSS Reader. It is also FREE.
Some other videos that I have created using FFmpeg
- Climate Change teen's message - improved, expletives deleted, bleeped & subtitled
In 2018, a Linux update ensured that all swear words in the kernel code submits will be automatically replaced. For example, 'f***' would be replaced with the word 'hug'. I did the same to a speech by a Swedish climate teen.
- Alexandria Ocasio-Cortez, meet Garbage Disposal
- FAA under AOC Socialist administration
- Rachel Maddow crying offscreen footage
- "So many people don't share Google's values!"
- Can the New York Times legally copy Naomi Wu's video without permission?
- Joe Biden is US comedy relief
- Jennifer Lawrence and Steve Buscemi deep-fake videos composited with images, text, background colour boxes
FFmpeg is a command-line program. If you are going to use it a lot, then you might as well become an expert at the command-line. Here is is one of my other books that will make your terminal time more fun and easy. The ebook is FREE and the paperback is syntax-highlighted in FULL-COLOUR.