Cut and Stitch Clips with ffmpeg
For quick and dirty editing of audio and video in the terminal, ffmpeg can do the job.
DaVinci isn't around, or you don't want to leave the lovely ascii of the terminal. Go find ffmpeg.
Cutting Clips with ffmpeg
ffmpeg can copy or transcode video. If you give it a start and/or stop timestamp, it can do clips or subsections of the video.
ffmpeg -i input.webm -ss 00:42:41 -to 00:42:44 output.mp4
-ss
is the starting sample-to
is the end of the clip
Timestamps can be in hh:mm:ss format or in seconds.
Stitching Together Clips with ffmpeg
ffmpeg can combine videos into a single video. There are apparently several methods for this. The one I've used successfully is reliable but very wordy:
ffmpeg -i input1.mp4 -i input2.mp4 -filter_complex "[0:v] [0:a] [1:v] [1:a] concat=n=2:v=1:a=1 [v] [a]" -map "[v]" -map "[a]" output.mp4
-i
marks the input. Use multiple of these.-filter_complex
is... complex. I don't get it all. In essence, you're describing your inputs and outputs. We're going to take all the video and audio inputs and output audio and videon=2
- we have 2 inputs, son
is 2. Adjust to number of inputs.-map
designates input streams that are used in output, here both video and audio
There's probably a better or easier method for this. Do any of ya'll know of one? Please let me know.
Remove Letterboxing
Sometimes you get a video that has black bars on the top and bottom. You can remove this with the crop
filter in ffmpeg. First, you need to detect where the letterboxes are, and ffmpeg can help you with that too.
At a timestamp that shows the letterboxing clearly (say, 00:00:30), run:
ffplay -ss 00:00:30 -i input.mp4 -vf cropdetect
This will output a lot of playback logging, including a line like:
crop=1920:800:0:140
Take this and feed into the -vf
video filter when outputting the new video:
ffmpeg -i input.mp4 -vf "crop=1920:800:0:140" output.mp4
And it'll come out the the black bars trimmed away (and at a new resolution, mind you).