Back

/ 2 min read

FFMPEG

Last Updated:

Introduction

I don’t belive you pay Adobe $49 a month just to convert videos. FFMPEG is a free and open-source project consisting of a vast software suite of libraries and programs for handling video, audio, and other multimedia files and streams. It’s a swiss army knife for video processing.

Terminal window
sudo apt-get update
sudo apt-get install ffmpeg

Thanks me later. You already save $49 a month.

Commands

FFMPEG is a command-line tool, so you need to know the commands to use it. Here are some of the most common commands:

Cut Video

Suppose you want to cut a video from 00:00:10 to 00:00:20. Here’s how you can do it:

Terminal window
ffmpeg -i input.mp4 -ss 00:00:10 -to 00:00:20 -c copy output.mp4
FlagDescriptionExample
-iInput fileinput.mp4
-ssStart time00:00:10
-toEnd time00:00:20
-cCodeccopy

Convert Video to GIF

Suppose you want to convert a video to a GIF. Here’s how you can do it:

Terminal window
ffmpeg \
-i input.mp4 \
-vf "fps=10,scale=320:-1:flags=lanczos" \
-c:v gif output.gif
FlagDescriptionExample
-iInput fileinput.mp4
-vfVideo filterfps=10,scale=320:-1:flags=lanczos
-c:vVideo codecgif

Snapshots

Suppose you want to take a snapshot from RTSP or webcam stream. Here’s how you can do it:

Terminal window
ffmpeg \
-f rtsp \
-i rtsp://username:password@ip:port \
-vframes 10 \
output%03d.jpg
FlagDescriptionExample
-fFormatrtsp. Available formats: rtsp, v4l2 (webcam), etc.
-iInput filertsp://username:password@ip:port
-vframesNumber of frames10

Video to Frames

Suppose you want to extract frames from a video. Here’s how you can do it:

Terminal window
ffmpeg -i input.mp4 -vf fps=1 output%03d.png
FlagDescriptionExample
-iInput fileinput.mp4
-vfVideo filterfps=1

Get Audio from Video

Suppose you want to extract audio from a video. Here’s how you can do it:

Terminal window
ffmpeg \
-i input.mp4 \
-vn \
-acodec copy \
-ss 00:00:10 -to 00:00:20 \
output.aac