ffmpeg commands#
This page contains ffmpeg commands that I find useful. ffmpeg is super powerful and can sometimes be enough for quick media manipulations. For more commands check the ffmpeg documentation page.
Cut a part of a video :#
ffmpeg -i input.mp4 -ss 00:00 -to 00:10 -c:v libx264 -crf 30 output.mp4
- use
ssto select the starting and ending time - to avoid re-enconding the video, use stream copy via
-c, define the video withvand the codec (libx264in the example) - use
-crfto define quality (lesser is better)
Concatenate videos#
ffmpeg -f concat -i input.txt -c copy output.mp4
Create a text file with the files you want to concatenate into a single video or audio file.
file 'video1.mp4'
file 'video2.mp4'
file 'video4.mp4'
- Use
-c copyto avoid re-enconding the videos (they need to have the same base codec)
Add audio to video#
ffmpeg -i input.mp4 -i input.mp3 -c copy -map 0:v:0 -map 1:a:0 output.mp4
- the
-c copyavoid re-encoding the streams - the first
-mapdefines where to start the audio in the video file - the second
-mapdefines where to start the audio in the audio file
Encode audio file to mp3#
ffmpeg -i input.opus -ar 44100 -ac 2 -b:a 128k output.mp3
-ardefines the frequency (here it's44100)-acsets the number of audio channels (here2)-b:adefines the bitrate of the file (here128k)
Add metatags to audio file#
ffmpeg -i input.mp3 -i img.jpg -c copy -map 0 -map 1 -metadata title="title" output.mp3
-i img.jpgadds an image to the audio file-c copyto avoid re-encoding the image file-map 0 -map 1position the image-metadata title="title"defines the title of the file in the metadatas