FFmpeg
Concatenate two videos, fading to a second of black between them
ffmpeg \
-i "yourvideo1.mp4" \
-f lavfi -t 1 -i "color=black:s=1920x1080:r=60" \
-f lavfi -t 1 -i "anullsrc=r=48000:cl=2" \
-i "yourvideo2.mp4" \
-filter_complex "[1:v] null [1v]; [2:a] anull [1a];[0:v] fade=t=out:st=300:d=1 [0v]; [0:a] afade=t=out:st=300:d=1 [0a]; [3:v] fade=t=in:st=0:d=1, fade=t=out:st=450:d=1 [2v]; [3:a] afade=t=in:st=0:d=1, afade=t=out:st=450:d=1 [2a]; [0v] [0a] [1v] [1a] [2v] [2a] concat=n=3:v=1:a=1 [v] [a]" -map "[v]" -map "[a]" \
-c:v libx264 \
-crf 18 \
-c:a aac \
output.mp4
Command | Purpose |
-i "yourvideo.mp4" | The first video to concatenate. |
-f lavfi -t 1 -i "color=black:s=1920x1080:r=60" |
Uses the lavfi filter to create one second of black video (without audio - we have to create that separately). It needs to match the resolution of the videos being concatenated. |
-f lavfi -t 1 -i "anullsrc=r=48000:cl=2" | Uses the lavfi filter to create one second of blank audio. |
-i "yourvideo2.mp4" | The second video to concatenate. |
-filter_complex "[eldritch horror]" |
The complex filtergraph specifying how to concatenate the video and audio streams. Note that lavfi filters constitute separate video and audio streams, so they change the numbering.
You need to match the start value for the first video fading out (e.g. fade=t=out:st:=300:d=1) to 1 second before the end of the video. Note the time for fading out the second video is 1 second before the second video's end PLUS the duration of the first video! |
-c:v libx264 | Encode the resulting concenated video in x264. |
-crf 18 | Use constant rate factor 18 to determine the video quality for the resulting video (0-51 with 51 being the worst quality, 18-23 being the typical values in most cases). |
-c:a aac | Encode the audio using aac. |
output.mp4 | The filename for the resulting output video. |
Generating screenshots (frames) of a video
ffmpeg \
-i "yourvideo.mp4" \
-t 300 \
-r 4 \
-qscale:v 2 \
output_%06d.jpg
Command | Purpose |
-i "yourvideo.mp4" | The input video to generate frames for. |
-t 300 | Determines how much of the video to generate frames for (in this case, the first 5 minutes of the video only). |
-r 4 | Determines how many frames per second should be taken, in this case 4 frames for each second. |
-qscale:v 2 | Sets the JPG quality for the resulting frame images. Between 2 and 31, 31 being worst quality. |
output_%06d.jpg | The output name for each frame. %06d means to use 6 digits to represent the frames, so the first frame will be output_000000, the next will be output_000001, etc. |