I have been making some videos using AI and I couldn't resist editing it with an awesome CLI tool ffmpeg.
Here are some of my favorite ffmpeg commands for quick video editing.
- Overlay audio over a video, lowering the original volume by 80%
#!/bin/bash
video="$1"
audio="$2"
ffmpeg \
-i "$video" \
-i "$audio" \
-filter_complex \
"[1:a]apad[A];[0:a]volume=0.20,[A]amerge[out]" \
-c:v copy -map 0:v -map [out] -y \
"processed_${video:0:10}.mp4"
- Make a video from a single image
#!/bin/bash
image="$1"
audio="$2"
length="$3" #Hh:Mm:Ss
ffmpeg \
-r 0.01 -loop 1 -i "$image" \
-i "$audio" -c:v libx264 \
-tune stillimage -preset ultrafast \
-ss 00:00:00 -t "$length" \
-c:a aac -b:a 96k -pix_fmt yuv420p \
-shortest out.mp4 -y
- Concat multiple videos (listed in a file) into one
#!/bin/bash
ffmpeg \
-f concat -safe 0 \
-i mylist.txt -c copy output.mp4
$ cat mylist.txt
file '/path/to/file1'
file '/path/to/file2'
file '/path/to/file3'
- Split a video given a timestamp
#!/bin/bash
video="$1"
timestamp="$2" # Hh:Mm:Ss
ffmpeg -i "$video" -to "$timestamp" -c copy first.mp4
ffmpeg -i "$video" -ss "$timestamp" -c copy second.mp4
- Trim beginning of the video (Removing ads, intros)
#!/bin/bash
video="$1"
time="$2"
ffmpeg \
-i "$video" -vcodec copy \
-c:a copy -map 0 -ss "$time" \
"trimmed_${video:0:10}.mp4"
Top comments (0)