My Daily Uses for FFMPEG

Explaining three FFMPEG commands I use very often.

FFMPEG on a command-line execution of an FFMPEG command Written by Okom on Nov 23, 2024 in Personal. Last edited: Nov 23, 2024.

What is FFMPEG?

FFMPEG is a complete, cross-platform solution to record, convert and stream audio and video. FFMPEG is a command-line/terminal tool, but some GUI frontends that are built on FFMPEG are available such as Videomass or HandBrake.

My usage examples

Some FFMPEG commands I use the most often. Assume the input file to be named as "input" and the output file as "out".

All the examples shown are made with the required input files in the same folder as the FFMPEG command is executed in.

Clipping and scaling a video

I use this command every time I need to share a quick video clip with someone and the content of the video is more important than the perfect quality.

ffmpeg -ss 53 -to 1:06.5 -i input.mp4 -vf scale=900:-2 -map 0:v -map 0:3 -crf 27 out.mp4
  • -ss 53: start the video at 53 seconds from the input file
  • -to 1:06.5: end the video at 1 minute 6.5 seconds (output video length: 13.5 seconds)
  • -i input.mp4: input file
  • -vf scale=900:-2: scale the input file to (width 900 px) x (calculated height with 2-pixel accuracy following the aspect ratio of the input file)
  • -map: choose stream from the input file
  • 0:v: from the first input file (0) choose the video stream (v)
  • 0:3: from the first input file (0) choose the third stream (3), in my case the game audio stream
  • -crf 27: a constant rate factor to reduce the quality of the video; default is 23, higher means lower quality
  • out.mp4: output file

The video files I usually process are my OBS recordings which I've configured to record 6 streams: 1 video and 5 audio streams, thus I need to specify which of these streams I want to map to the output video file. By default, it would map 0:v and 0:a, which in my case would be the video stream and my microphone audio stream.

Paused video in a media player showing information about the video file
A frame from the 13.5-second, 3.6 MB output video with the file information visible. Video player used: mpv.

Scaling down and transcoding an image

I use this command if I want to produce a smaller file size version of an image where the quality isn't the highest priority.

ffmpeg -i input.png -vf scale=(iw/1.5):(ih/1.5) out.jpg
  • -i input.png: input file
  • -vf scale=(iw/1.5):(ih/1.5): scale the input file to (input width / 1.5) x (input height / 1.5)
  • out.jpg: output file

Note the file format change in the output file to jpg, which is a lossy format and usually produces smaller file sizes.

PNG image of a MCC lobby screen
input.png, 1.48 MB.
JPG image of a MCC lobby screen
out.jpg, 95.2 KB.

Concatenating videos together

If I want to combine multiple video clips into a single file, I use this method. You first need to make a text file input.txt and type your input files in there like so:

file 'input1.mp4'
file 'input2.mp4'
file 'input3.mp4'
The example contents of a text file required for this video concatenation method.

All input files must have the same streams (same codecs, same time base, etc.), which should be the case, if you created all the input files with the same FFMPEG command such as the one shown earlier.

Then use the following FFMPEG command to concatenate them:

ffmpeg -f concat -i input.txt -c copy out.mp4
  • -f concat: demuxes a list of files one after another
  • -i input.txt: input file
  • -c copy: select the streamcopy encoder with no decoding or encoding; copying the same video and audio streams
  • out.mp4: output file
Video made from concatenating three 2-second video clips together.

Thoughts about FFMPEG

FFMPEG has saved me unmeasurable amounts of time, made me understand how media files are made up, and made me more conscious about file sizes and how to optimize them.

If you're looking to install FFMPEG on Windows, I suggest downloading it through Chocolatey.