FFmpeg, the video Swiss Army Knife
You may have found yourself in a situation where you have to modify a video or extract its audio. Firing up a complete editor for such simple tasks could be a waste of energy and time.
Table Of Contents
Here are some basic tips for FFmpeg that can sometimes make your workflow more efficient:
Change the aspect ratio of a video without re-encoding
This can be useful when the only thing we want to do is changing the proportions of a video without losing quality.
For example for converting a 4:3 video to an stretched 16:9:
ffmpeg -i in.mp4 -aspect 16:9 -c copy out.mp4
The -c copy
option allows setting up the codec to a copy mode where ffmpeg doesn’t reencode the video and the results are done immediately.
Extracting audio from a file
ffmpeg -i in.mp4 out.mp3
Note: the extensions shown here are completely arbitrary, ffmpeg supports a wide variety of codecs and formats which can be seen with the commands ffmpeg -codecs
and ffmpeg -formats
Cutting a video file without reencoding
ffmpeg -i in.mp4 -ss 00:00:25.0 -codec copy -t 30 out.mp4
In this case the cut starts on second 25 and the video lasts 30 seconds
Converting a video to other format
ffmpeg -i in.ogv -c:v libx264 out.mp4
-c:v libx264
sets the video codec-c:a vorbis
sets the audio codec-r 25
sets the framerate to 25fps-s <1280x720|hd720>
sets the video resolution to 720p-b:v 1M
sets the video bitrate to 1MB/s