FFmpeg¶
Cut video¶
- Use
-ssto specify the start time. - Use either:
-tto specify the duration, or-toto specify the end time.
Example:
ffmpeg -i input.avi -ss 00:00:03 -to 00:00:08 -c:v copy -c:a copy output.avi
This cuts a 5-second clip from the input video.
Concatenate videos¶
Method 1¶
Requires all videos to have the same codec, resolution, and frame rate.
Create a text file with the list of videos to concatenate:
file 'input1.mp4'
file 'input2.mp4'
file 'input3.mp4'
Then run:
ffmpeg -f concat -i list.txt -c copy output.mp4
Method 2 (Re-encoding)¶
Use this method if the videos have different codecs, resolutions, or frame rates.
ffmpeg -i input1.mp4 -i input2.mp4 -i input3.mp4 \
-filter_complex "[0:v] [0:a] [1:v] [1:a] [2:v] [2:a] concat=n=3:v=1:a=1 [v] [a]" \
-map "[v]" -map "[a]" output.mp4
Encoding options (e.g. -c:v libx264) can be specified for the output video.
Normalize audio volume¶
First inspect the video:
ffmpeg -i video.avi -af volumedetect -vn -sn -dn -f null /dev/null
The output should be something like:
[Parsed_volumedetect_0 @ 0x7f8ba1c121a0] mean_volume: -16.0 dB
[Parsed_volumedetect_0 @ 0x7f8ba1c121a0] max_volume: -5.0 dB
[Parsed_volumedetect_0 @ 0x7f8ba1c121a0] histogram_0db: 87861
Now scale the maximum volume to 0 dB, which should sound right in most cases:
ffmpeg -i video.avi -c:v copy -filter:a volume=5dB output.avi
Source: Super User
More: FFmpeg wiki
Resize video¶
With manual resolution:
ffmpeg -i input.avi -s 720x480 -c:a copy output.avi
Using the scale filter:
ffmpeg -i input.avi -filter:v scale=720:-1 -c:a copy output.avi
The second value may be specified as -1 for auto-detection (keeping aspect ratio).
Source: Super User
Fade in/out¶
Use -vf fade=in:st=0:d=3 to fade in from the start of the video for 3 seconds.
Use -vf fade=out:st=5:d=3 to fade out from the 5th second for 3 seconds.
For audio, use -af afade= with the same syntax.
Note that if -s / -ss is used, the times in the fade filters still refers to the original video. For example, with -ss 00:00:05, the fade in filter should start at st=5.
Add ID3 tag to MP3¶
Reading: Use standard ffmpeg syntax without output file.
Writing:
ffmpeg -i input.mp3 -c copy -metadata title="Track Title" output.mp3
Use ID3 v2.3: -id3v2_version 3
Remove a tag: Specify its value as an empty string.