If you have ever needed to make a small tweak in a video without any complicated tools, this article is for you. Here I will tell you about a tool so versatile that you can not only adjust the playback speed of videos but compress, trim, convert, and even watermark them with your custom logo, all for free and with simple one-line commands.
I create lots of screen recordings for how-to tutorials, but they rarely come out perfect. I might need to trim them, speed up slow sections, slow down fast ones, convert them to GIFs, or compress them for blog uploads.
Traditionally, this means opening a heavyweight video editor like Final Cut Pro, Adobe Premiere, or Lumafusion (on iOS). These programs are fantastic but overkill for my simple needs.
Their complex interfaces, packed with features I never use, turn even small edits like speeding up a video into a 5-10 minute ordeal. That wasted time adds up fast when working on multiple tutorials.
Must Read: How to Open Multiple Apps with Raycast in One Click
Seeking a simpler solution, I stumbled upon FFMPEG – a powerhouse tool that underpins many video editing programs. It’s cross-platform (Mac, Windows, Linux) and handles almost any audio or video file format.
The coolest part is that everything is done with commands straight in your terminal. There’s no separate ‘app’ to launch – you just type your instructions and hit enter.
FFMPEG turns 10-minute tasks into 30-second affairs. Need to convert a video file to a different format? This command does it:
ffmpeg -i input_video.mp4 output_video.avi
(The -i
flag always proceeds the name of an input file, and FFMPEG smartly detects the output format based on the ‘.avi’ extension).
Want to add a watermark to your video? Try this:
ffmpeg -i input_video.mp4 -i watermark.png -filter_complex "overlay=10:10" output_video.mp4
(Here, ‘watermark.png’ is your watermark image, and ‘overlay=10:10’ places it 10 pixels from the top left corner).
Also read: 4 Awesome Tricks to Change the Default Fonts in Excalidraw
The above examples barely scratch the surface. FFMPEG offers a treasure trove of quick command-line tricks for manipulating your audio and video files. Let’s explore some more awesome things you can do!
Installing FFMPEG
Before using the tool, you would need to install it. The best way to install it is using Homebrew (more on it in just a second). If you have homebrew installed on your Mac, go ahead and type this line of code in your terminal:
brew install ffmpeg
(To check if FFMPEG was installed correctly, run ffmpeg --version
in your terminal. If you see a detailed output, congrats. Otherwise, you might need to reinstall it.)
What is Homebrew?
Homebrew is like a magic app store for your Mac, but it works right inside the Terminal window. Instead of visiting websites, downloading files, and dragging things around, you use simple commands to install all sorts of software.
How Homebrew Simplifies Things
Normally, installing an app involves several steps: finding the website, downloading a “.dmg” file, and then either dragging it somewhere or double-clicking to run an installer. Homebrew cuts all that out!
You just find the install command for a program on the Homebrew website (or through a quick Google search) and paste it into your Terminal. Homebrew handles the rest – finding the software, downloading it, and setting everything up.
Installing Homebrew
Here’s the command to install Homebrew on your Mac:
/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"
Checking Your Install
To make sure Homebrew is ready to go, run this command in your Terminal:
brew -v
You should see the version number of Homebrew appear.
Now that you have ffmpeg
installed on your Mac, let’s see how you can tweak your videos and audio seamlessly.
How to tweak your videos using FFMPEG
Frankly, FFMPEG commands look intimidating. But here’s the secret: you don’t need to memorize complex code! I recently discovered that ChatGPT is a fantastic tool for generating FFMPEG commands tailored to your needs. Here’s how it works:
- Tell ChatGPT what you want to do: Do you want to trim a video? Convert it to a different format? Add a soundtrack? Be as specific as possible.
- ChatGPT gives you the command: It will generate a ready-to-use FFMPEG command tailored to your exact needs.
- Try it out! Copy and paste the command into your terminal. In my experience, these commands tend to work perfectly on the first try.
Remember: This is just a taste of what’s possible. ChatGPT can handle a huge range of audio and video editing tasks. Don’t be afraid to experiment and ask for exactly what you need!
Below are the commands that ran perfectly for me:
Converting a video file format
Command:
ffmpeg -i input.mov output.mp4
(The flag -i
is specified before every input file name you write in the command. FFMPEG automatically detects the extension of your output file name and converts the input video to that format.)
Also read: How to Read the New Yorker and Atlantic articles for FREE
(The ‘input.mov’ and ‘output.mp4’ are the names of your input and output files if they are in the same folder as being run in the terminal. If they are elsewhere, you can replace these with their exact path on your system.)
Converting a video to GIF
Command
ffmpeg -i input.mov output.gif
This one’s just an extension of the previous command. We have changed the extension of the output file to ‘gif’.
Compress a video (reduce file size)
Command
ffmpeg -i input.mp4 -vf scale=1280:-1 -c:v libx264 -crf 23 -c:a aac -b:a 128k output.mp4
Explanation:
- -vf scale=1280:-1: Scales the video to a width of 1280 pixels while maintaining the aspect ratio. (
vf
is short for video filter) - -c:v libx264: Sets the video codec to libx264 for H.264 encoding. (
c:v
is for video codec, just likec:a
is for audio codec) - -crf 23: Sets the Constant Rate Factor (CRF) for video quality (lower values mean better quality).
- -c:a aac -b:a 128k: Sets the audio codec to AAC with a bitrate of 128 kbps.
Trim a video
Command
ffmpeg -i input.mp4 -ss 00:00:10 -to 00:00:30 -c copy output.mp4
Explanation:
- -ss 00:00:10: Sets the start time to 00:00:10 (10 seconds).
ss
is taken from the timestamp formatHH:mm:ss
. - -to 00:00:30: Sets the end time to 00:00:30 (30 seconds).
- -c copy: Copies the video and audio streams without re-encoding (for faster execution)
Change resolution (adjust the dimensions of a video)
Command
ffmpeg -i input.mp4 -vf scale=1280:720 output.mp4
Explanation:
- -vf scale=1280:720: Scales the video to a resolution of 1280×720 pixels.
Speed up a video
Command
ffmpeg -i input.mp4 -filter:v "setpts=0.5*PTS" output.mp4
Explanation:
- -filter:v “setpts=0.5*PTS”: Adjusts the presentation timestamp to play the video at twice the speed.
Slowing down a video
Command
ffmpeg -i input.mp4 -filter:v "setpts=2*PTS" output.mp4
This one is the extension of the previous command. Running this command will make the video play at half the speed (double the duration).
Also read: How to Lighten or Darken a Color with Pure CSS
Rotate a video
Command
ffmpeg -i input.mp4 -vf "transpose=1" output.mp4
Explanation:
- vf “transpose=1”: Rotates the video by 90 degrees counterclockwise.
Extract audio from the video
Command
ffmpeg -i input.mp4 -vn -acodec copy output.mp3
Explanation:
- –vn: Disable video recording.
vn
is for “no video”. Similarlyan
is for “no audio” - -acodec copy: Copy the audio codec without re-encoding.
Removing (Stripping) audio from video
Command
ffmpeg -i input_video.mp4 -an output_video.mp4
an
is for “no audio”.
Add watermark to video
Command
ffmpeg -i input.mp4 -i watermark.png -filter_complex "overlay=10:10" output.mp4
Explanation:
- -i watermark.png: Specifies the input image for the watermark.
- –filter_complex “overlay=10:10”: Overlay the watermark image at position (10,10) on the video. (The first 10 is for x (horizontal pixels), and the second one is for y (vertical pixels).
Wrap up
That’s it guys. You now know how you can do pretty much anything with a video. Video editors such as iMovie and others provide a graphical user interface for you to work on your video files, but most (if not all) use FFMPEG under the hood to process video files.
Also, remember that ChatGPT is your best friend when using FFMPEG to manipulate your videos. I have tried FFMPEG with many commands spit out by ChatGPT and almost all of them have run in the first attempt itself.
Another major plus of using ChatGPT is that it can tailor your commands to your exact needs: want the watermark to the bottom right corner? You got it. Want to create a video with just an image and an audio? Got that too.
There’s no other way more seamless than this to make minor tweaks and adjustments to your video and audio files.
If you found it useful, please don’t forget to share it on social media. If you have got a query, please drop a line in the comments or on X (Twitter).
Thanks for reading.