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
ss
to select the starting and ending time - to avoid re-enconding the video, use stream copy via
-c
, define the video withv
and the codec (libx264
in the example) - use
-crf
to 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 copy
to 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 copy
avoid re-encoding the streams - the first
-map
defines where to start the audio in the video file - the second
-map
defines 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
-ar
defines the frequency (here it's44100
)-ac
sets the number of audio channels (here2
)-b:a
defines 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.jpg
adds an image to the audio file-c copy
to avoid re-encoding the image file-map 0 -map 1
position the image-metadata title="title"
defines the title of the file in the metadatas
Initially published: March 18th, 2021
Generated: November 12th, 2021
Generated: November 12th, 2021