dark mode light mode Search Menu
Search

Rickrolling Fun with ffmpeg

Brett Jordan on flickr

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.

Learn More

ffmpeg tutorial

https://github.com/leandromoreira/ffmpeg-libav-tutorial

ffmpeg commands for beginners

https://ostechnix.com/20-ffmpeg-commands-beginners/

Introduction to ffmpeg

https://programminghistorian.org/en/lessons/introduction-to-ffmpeg

Making ffmpeg easier

https://amiaopensource.github.io/ffmprovisr/

ffmpeg

https://avpres.net/FFmpeg/

Generating a Color Palette

http://johnriselvato.com/ffmpeg-how-to-generate-a-color-palette-from-a-video-and-apply-it-to-another/

ffmpeg Fancy Filtering Examples

https://trac.ffmpeg.org/wiki/FancyFilteringExamples

The origin of rickrolling

https://www.youtube.com/watch?v=QMW4AqbuSGg