A compilation of FFmpeg commands that I have found helpful. Leaving it here for my reference (as well as for anyone it may be of help).
Note: I specified common formats like avi, mp4 for the sake of clarity, but ffmpeg works a lot of formats, so don't hesistate to try any video/audio format you find desirable.

The basic structure of a command

Stream copy flag

Knowing about this flag and where to use it can save a lot of conversion time. If you are sure that the video stream doesn't need to be re-encoded, you can apply the -c copy flag to skip it. An example of where this applies is when you concat some files in the same format. An example where this doesn't apply is when you change the dimensions of the video. You can still use -c:a copy which copies the audio stream when you are doing operations only on the video, and -c:v copy when you operate only on the audio.

Changing the dimensions of the video

ffmpeg -i input.avi -vf scale=$w:$h output.avi
Where $w and $h are to be replaced with the desired height and width respectively. If you want to specify one of the parameters, you can set the other to -1 to maintain fixed aspect ratio. For example, you can convert to 1080p like so:
ffmpeg -i input.avi -vf scale=-1:1080 output.avi

Concatenating a bunch of files

First you need to make a list.txt file which lists all the files that need to be concatenated. Here is an example of how that file can look like (assuming all the files are in the same folder):
file 'start.avi'
file 'middle.avi'
file 'end.avi'
Then run the following command in the same folder:
ffmpeg -f concat -safe 0 -i list.txt merge.mp4
This will concat the specified files into a single mp4 file. You can use other video filters along with this command as well and it will be applied to each input file.

Batch converting files in a folder

This will convert all the avi files in the current folder to mp4 files. You can change to work with other formats. If you are converting to the same format make sure to store the output files in a different folder else it may get stuck in an infinite loop.

Basic Fade effects

ffmpeg -i input.avi -vf "fade=t=in:st=$s:d=$d" output.avi

Horizontally stacking 2 videos

ffmpeg -i left.mp4 -i right.mp4 -filter_complex hstack output.mp4

HomePages/GMP/FFmpegCommands last edited by GMP on 12/21/2022 3:11 PM
Page History Latest diff List referrers View Source