Rickrolling Fun with ffmpeg
Image by Brett Jordan on flickr
Remix a classic meme with ffmpeg
In this article, we’re going to cover another bit of open-source commandline software that’s both very powerful and very widespread: ffmpeg
ffmpeg lets you edit, transform, and play video files all by passing in various commands. It can be a little daunting but you can do incredibly powerful stuff with it! We’ll be assuming you have access to a commandline for the rest of this article.
But first we’re going to introduce another very important commandline tool: yt-dlp
Once you follow the instructions for yt-dlp you can now easily download videos off the internet if you have the link. It’s primarily used for YouTube but it can be used on pretty much any embedded video you see online! Now it’s time to download the video we’ll be using in our experiments for the rest of this article: https://www.youtube.com/watch?v=dQw4w9WgXcQ
This is, of course, the original meme to end all memes. The one that will never give you up, nor let you down: the rickroll itself.
So download the video from the command line like so
yt-dlp -f mp4 https://www.youtube.com/watch?v=dQw4w9WgXcQ -o rickroll.mp4
and once it’s downloaded we can start doing some silly stuff. We’re not going to rest until we’ve made this classic meme worse and uglier in every conceivable way!
The first thing we’re going to show you is how to turn the video into an animated gif! This is way easier than you might think:
ffmpeg -i rickroll.mp4 rickroll.gif
Now it might take a minute but when it’s done you should be able to open
rickroll.gif and you’ve got an animated gif!
There’s other pragmatic things we can do as well, like change the size of the video, although in this case let’s have a little more fun. We’re going to really shrink down this video to just ten by ten pixels and also convert it to greyscale.
ffmpeg -i rickroll.mp4 -filter:v scale=5:5,format=gray tinyrick.gif
If you open this up and zoom in you’ll see something like this
You might have to take my word for this being Rick Astley crooning at you until you try it yourself!
Okay, so that’s one fun thing. But are there other silly things we can do to this video? Well we can do a different kind of shrinking of the video, this time not by cutting the size of the video but by cutting the bitrate, which is the amount of data per second encoded in the video.
First, let’s use another part of the ffmpeg toolset. Type
ffprobe -i rickroll.mp4
to get a bunch of text about the way the file was encoded. In particular, note that the video bitrate is
2428 kb/s and the audio bitrate is
128kb/s. So we’re going to need to choose values smaller than that! I’ve already played around with this video a bit to find some good values for ugly meme purposes:
ffmpeg -i rickroll.mp4 -b:v 32k -b:a 16k rickwont.mp4
and you’ll get a video that looks like this
and sounds like you’re listening to it on a dying radio while sitting at the bottom of a swimming pool.
Before we leave this article and stop bothering an old meme video, let’s just try one last bit of silliness, and that’s changing the hue of the video over time:
ffmpeg -i rickroll.mp4 -b:v 64k -b:a 16k -vf "hue=H=10*t:s=10*cos(5*t)" rickcolor.mp4
to get something like:
Now there’s a ton more we can do in terms of serious video editing in ffmpeg. You can attach subtitle files, extract color palettes for modifying other videos, even create a video from a directory of still images. We’ll get into those more in the future but for now, have fun and make memes.
ffmpeg commands for beginners
Introduction to ffmpeg
Making ffmpeg easier
Generating a Color Palette
ffmpeg Fancy Filtering Examples
The origin of rickrolling
Also In The October 2022 Issue
A collection fo gift ideas for the holidays and any time of year!
Learn to make an interactive fiction your reader can't put down with Twine!
Begin your 3D design journey with Blender!
Technology is here to stay, so we should talk about how to be safe when using it.
Programming languages use data types to allocate memory and enforce data integrity.
Find out where 'the cloud" got its name from!
Remix a classic meme with ffmpeg
Dive to new depths with this Minecraft mod!
Improve your encryption skills with Unicode!
Meet a computer that makes fantasy a reality!
Experience a new level of futuristic luxury with your own robot butler.
Find out how your country compares to the rest of the world in CS education
Learn how digitization is being used to help preserve the languages of Indigenous peoples
Find out how social media is being used to build a more peaceful world
Check out what happens when you combine 3D printing with Auxetic geometries!
Collection of interesting stories about technology from October 2022
Breaking down the issue of bias in AI & ML in a one-act play!
Collection of the Learn More links from all of the October 2022 stories, in one place.