FFmpeg is Wild

I recorded a 1:07 long screen record video to showcase how the pSEO keyword ideas database works. While the video could have been directly uploaded to YouTube and Twitter, I wanted to enhance the watchers’ experience a bit by making it a bit faster and adding nice music.

And a single terminal command did all of this; first, watch the video below, and then I’ll show how.

And it all took me just a few seconds.

Cool, right?

Editing videos with FFmpeg

First, you will need to install the FFmpeg tool for your computer and then start with the command. You can get it from their official website.

For the raw video, I had the following requirements:

  • Make the video a bit faster
  • Compress the video for social media, and
  • Add music at a low volume

For this, first, I created a file called fast.sh in the same folder where my raw video your_raw_video.mov and the music audio.mp3 were present. I copy-pasted the following command into the executable file and got the final video your_final_video.mp4 within seconds (not even minutes).

# Extract duration in seconds
duration=$(ffprobe -v error -show_entries format=duration -of default=noprint_wrappers=1:nokey=1 your_raw_video.mov)

# Calculate new duration after speed up
new_duration=$(bc -l <<< "$duration*0.75")

# Remap audio and video
ffmpeg -i your_raw_video.mov -i audio.mp3 -vcodec libx264 -crf 28 -filter_complex "[0:v]setpts=0.75*PTS[v];[1:a]volume=0.6,atrim=0:$(printf "%.0f" $new_duration)[a]" -map "[v]" -map "[a]" your_final_video.mov

Here’s how you can execute the fast.sh file:

  1. Run chmod +x fast.sh in the terminal in the same folder, and
  2. Run ./fast.sh command in the terminal

And this single terminal command did the following thing to the raw video:

  • Made the video 1.33x faster
  • Compressed the video by 92%, and
  • Added music at 60% volume

The raw screen record video was 1 minute and seconds long and 71.4 MB in file size, and the final video was 50 seconds long and 5.4 MB in file size.

If I had used a video editor tool like iMovie or Adobe Premier Pro, it must have taken me several 5–10 minutes, at least. But FFmpeg did all this in less than 20 seconds.

Now, isn’t that wild?


Recent Posts

Comments

Leave a Reply

Your email address will not be published. Required fields are marked *