A collection of ffmpeg shell scripts for basic editing tasks
- audio-silence
- combine-clips
- clip-time
- correct-clip
- crossfade-clips
- ebu-meter
- extract-frame
- fade-clip
- fade-normalize
- fade-title
- img2video
- loudnorm
- normalize
- overlay-clip
- overlay-pip
- pan-scan
- scene-cut
- scene-detect
- scene-images
- scene-time
- subs2transcript
- subtitle-add
- scopes
- tile-thumbnails
- trim-clip
- vid2gif
- waveform
- webp
- xfade
- zoompan
ffmpeg scripts install youtube
create a bin directory in your home to add the scripts to
mkdir -p ~/bin
if you are using bash add the following code to your ~/.bashrc
if [ -d "$HOME/bin" ]; then
PATH="$HOME/bin:$PATH"
fi
if you are using zsh add the following code to your ~/.zshenv file
typeset -U PATH path
path=("$HOME/bin" "$path[@]")
export PATH
- source your ~/.bashrc if you are using the bash shell
source ~/.bashrc
- source your ~/.zshenv if you are using the zsh shell
source ~/.zshenv
create a git directory in you home folder to download the scripts into, or use any other location in your file system
mkdir -p ~/git
change directory in the git directory
cd ~/git
clone the git repository
git clone https://github.com/NapoleonWils0n/ffmpeg-scripts.git
update the scripts using git pull
you can now either copy the scripts into the ~/bin directory in your home, or create symbolic links from the scripts in the ~/git/ffmpeg-scripts directory to the ~/bin directory
creating a symbolic link
ln -s path/to/source path/to/destination
example
ln -s ~/git/ffmpeg-scripts/trim-clip ~/bin
install ffmpeg on debian or ubuntu, for other linux distros see the documentation for your package manager
sudo apt install ffmpeg
open a terminal and run the following commands to install the xcode command line tools, homebrew and ffmpeg
- xcode command line tools install
xcode-select --install
- homebrew install
ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"
- ffmpeg install with libfdk_aac
brew tap homebrew-ffmpeg/ffmpeg
brew install homebrew-ffmpeg/ffmpeg/ffmpeg --with-fdk-aac --HEAD
- ffmpeg upgrade
brew update && brew upgrade homebrew-ffmpeg/ffmpeg/ffmpeg --fetch-HEAD
switch to root and install the ffmpeg package
pkg install ffmpeg
you can also install ffmpeg from ports, or use poudriere to build the ffmpeg package
note the ebumeter script uses ffplay which isnt installed with the ffmpeg package, so you need to build ffmpeg with the sdl option enable from ports or with poudriere
if you want to use the libfdk_aac audio you should also enable that option when building the ffmpeg port, and build the lame package for mp3 support
install the windows subsystem for linux and then install a linux distro like ubuntu, then follow the linux install instructions
audio-silence add silent audio to a video clip
If the video doesnt have an audio track the script copies the video track, and adds a silent audio track to match the duration of the video and creates a new video clip
If the video has a video and audio track the script only copies the video track, and adds a silent audio track to match the duration of the video and creates a new video clip.
- script usage
audio-silence -i infile.(mp4|mkv|mov|m4v) -c (mono|stereo) -r (44100|48000) -o outfile.mp4
-i infile.(mp4|mkv|mov|m4v) -c (mono|stereo) : optional agument # default is mono -r (44100|48000) : optional agument # default is 44100 -o outfile.mp4 : optional agument # default is infile-name-silence-date-time
Batch process files in the current working directory
Note we omit the -o option to use the default outfile name, which is infile-name-silence-date-time
audio-silence batch process without specifying the -c and -r options using the defaults of -c mono and -r 44100
find . -type f -name "*.mp4" -exec sh -c \
'audio-silence -i "${0}"'
"{}" \;
audio-silence batch process and override the defaults with the -c and -r options
find . -type f -name "*.mp4" -exec sh -c \
'audio-silence -i "${0}" -c stereo -r 48000'
"{}" \;
convert timestamps into start and duration
- script usage
clip-time -i input -o output
combine an image or video file with an audio clip
- script usage
combine-clip -i infile.(mp4|mov|mkv|m4v|png|jpg) -a audio.(m4a|aac|wav|mp3) -o outfile.mp4
-i infile.(mp4|mkv|mov|m4v|png|jpg) -a audio.(m4a|aac|wav|mp3) -o outfile.mp4 : optional agument # defaults is infile-name-combined-date-time
Batch process files in the current working directory
Note we omit the -o option to use the default outfile name, infile-name-combined-date-time
- batch combine video and audio files into video clips
The video and audio files you want to combine must have the same name
for example
file1.mp4 file1.wav file2.mp4 file2.wav
running the following code will combine file1.mp4 with file1.wav and file2.mp4 with file2.wav
find . -type f -name "*.mp4" -exec sh -c \
'combine-clip -i "${0}" -a "${0%.*}.wav"' \
"{}" \;
- batch combine images and audio files into video clips
The images and audio files you want to combine must have the same name
for example
file1.png file1.wav file2.png file2.wav
running the following code will combine file1.png with file1.wav and file2.png with file2.wav
find -s . -type f -name "*.png" -exec sh -c \
'combine-clip -i "${0}" -a "${0%.*}.wav"' \
"{}" \;
- curves code based on:
converting gimp curves files for ffmpeg
correct a video clip by using a gimp curve converted into a ffmpeg curves filter command, to adjust the levels and white balance
- requires a curve file created with the following script
- script usage
correct-clip -i infile.(mp4|mkv|mov|m4v) -c curve.txt -o outfile.mp4
-i infile.(mp4|mkv|mov|m4v) -c curve.txt -o outfile.mp4 :optional agument # default is infile-name-corrected-date-time
Batch process files in the current working directory
Note we omit the -o option to use the default outfile name, infile-name-corrected-date-time
The video and gimp curve text files you want to combine must have the same name
for example
file1.mp4 file1.txt file2.mp4 file2.txt
running the following code will correct file1.mp4 with file1.txt gimp curve file and file2.mp4 with file2.txt gimp curve file
find . -type f -name "*.mp4" -exec sh -c \
'correct-clip -i "${0}" -c "${0%.*}.txt"' \
"{}" \;
cross fade 2 video clips with either a 1 or 2 second cross fade the videos must have the same codecs, size and frame rate
- script usage
crossfade-clips -a clip1.(mp4|mkv|mov|m4v) -b clip2.(mp4|mkv|mov|m4v) -d (1|2) -o outfile.mp4
-a clip1.(mp4|mkv|mov|m4v) : first clip -b clip2.(mp4|mkv|mov|m4v) : second clip -d (1|2) : cross fade duration :optional agument # default is 1 second -o outfile.mp4 : optional agument # default is infile-name-xfade-date-time
ffplay ebu meter
- script usage
ebu-meter -i infile.(mp4|mov|mkv|m4v|webm|m4a|aac|wav|mp3) -t (00)
-t = luf target, eg 16
extract a frame from a video and save as a png image
Note that you can use two different time unit formats: sexagesimal (HOURS:MM:SS.MILLISECONDS, as in 01:23:45.678), or in seconds. If a fraction is used, such as 02:30.05, this is interpreted as “5 100ths of a second”, not as frame 5. For instance, 02:30.5 would be 2 minutes, 30 seconds, and a half a second, which would be the same as using 150.5 in seconds.
- script usage
extract-frame -i infile.(mp4|mov|mkv|m4v|webm) -s 00:00:00.000 -o outfile.mp4
-i infile.(mp4|mov|mkv|m4v|webm) -s 00:00:00.000 : optional argument # default is 00:00:00 -o outfile.png : optional agument # default is infile-name-frame-date-time
Batch process files in the current working directory
Note we omit the -o option to use the default outfile name, infile-name-frame-date-time
- extract frame with default option of 00:00:00
find . -type f -name "*.mp4" -exec sh -c \
'extract-frame -i "${0}"' \
"{}" \;
- extract frame at 30 seconds into the video
find . -type f -name "*.mp4" -exec sh -c \
'extract-frame -i "${0}" -s 00:00:30' \
"{}" \;
fade video and audio in and out
- script usage
fade-clip -i video.(mp4|mkv|mov|m4v) -d (0.[0-9]|1) -o outfile.mp4
-i infile.(mp4|mkv|mov|m4v) -d (0.[0-9]|1) : optional agument # default is 0.5 -o outfile.mp4 : optional agument # default is infile-name-fade-date-time
Batch process files in the current working directory
Note we omit the -o option to use the default outfile name, infile-name-fade-date-time
- fade-clip with default option of 0.5
find . -type f -name "*.mp4" -exec sh -c \
'fade-clip -i "${0}"' \
"{}" \;
- fade-clip and override the default option of 0.5 with -d 1 for a 1 second fade
find . -type f -name "*.mp4" -exec sh -c \
'fade-clip -i "${0}" -d 1' \
"{}" \;
fade video and audio in and out and normalize
- script usage
fade-normalize -i video.(mp4|mkv|mov|m4v) -d (0.[0-9]|1) -o outfile.mp4
-i infile.(mp4|mkv|mov|m4v) -d (0.[0-9]|1) : optional agument # default is 0.5 -o outfile.mp4 : optional agument # default is infile-name-normalized-date-time
Batch process files in the current working directory
find . -type f -name "*.mp4" -exec sh -c \
'fade-normalize -i "${0}" -d 0.5' \
"{}" \;
fade video and audio in and out, normalize the audio and create video a lower third title from the filename
- script usage
fade-title -i infile.(mp4|mkv|mov|m4v) -d (0.[0-9]|1) -s 000 -e 000 -o outfile.mp4
-i infile.(mp4|mkv|mov|m4v) -d (0.[0-9]|1) : from 0.1 to 0.9 or 1 : optional agument # default is 0.5 -s 000 : from 000 to 999 -e 000 : from 000 to 999 -o outfile.mp4 : optional agument # default is infile-name-title-date-time
Batch process files in the current working directory
find . -type f -name "*.mp4" -exec sh -c \
'fade-title -i "${0}" -d 0.5 -s 10 -e 20' \
"{}" \;
convert an image into a video file
- script usage
img2video -i infile.(png|jpg|jpeg) -d (000) -o outfile.mp4
-i infile.(mp4|mkv|mov|m4v) -d (000) : duration -o outfile.mp4 : optional agument # default is infile-name-video-date-time
Batch process files in the current working directory
Note we omit the -o option to use the default outfile name, infile-name-video-date-time
Batch convert png in the current directory into video clips with a 30 second duration
find . -type f -name "*.png" -exec sh -c \
'img2video -i "${0}" -d 30' \
"{}" \;
ffmpeg loudnorm
- script usage
loudnorm -i infile.(mkv|mp4|mov|m4v|m4a|aac|wav|mp3)
normalize audio levels
- script usage
normalize -i infile.(mp4|mkv|mov|m4v|aac|m4a|wav|mp3) -o outfile.(mp4|mkv|mov|m4v|aac|m4a|wav|mp3)
-i infile.(mp4|mkv|mov|m4v|aac|m4a|wav|mp3) -o outfile.(mp4|mkv|mov|m4v|aac|m4a|wav|mp3) : optional agument # default is infile-name-normalize-date-time-extension
Batch process files in the current working directory
Note we omit the -o option to use the default outfile name, infile-name-normalize-date-time
Batch normalize mp4 videos in the current directory
find . -type f -name "*.mp4" -exec sh -c \
'normalize -i "${0}"' \
"{}" \;
overlay one video clip on top of another video clip
- script usage
overlay-clip -i infile.(mp4|mkv|mov|m4v) -v infile.(mp4|mkv|mov|m4v) -p [0-999] -o oufile.mp4
+ -i infile.(mp4|mkv|mov|m4v) : bottom video + -v infile.(mp4|mkv|mov|m4v) : overlay video + -p [0-999] : time to overlay the video + -o outfile.mp4 : optional agument # default is infile-name-overlay-date-time
create a picture in picture
- script usage
overlay-pip -i infile.(mp4|mkv|mov|m4v) -v infile.(mp4|mkv|mov|m4v) -p [0-999]
-m [00] -x (tl|tr|bl|br) -w [000] -f (0.1-9|1) -b [00] -c colour -o outfile.mp4
overlay-pip -i infile.(mp4|mkv|mov|m4v) -v infile.(mp4|mkv|mov|m4v) -p [0-999] -m [00] -x (tl|tr|bl|br) -w [000] -f (0.1-9|1) -o outfile.mp4 -i infile.(mp4|mkv|mov|m4v) : bottom video -v infile.(mp4|mkv|mov|m4v) : overlay video -p [0-999] : time to overlay the video -m [00] : margin defaults to 0 -x (tl|tr|bl|br) : pip postion - defaults to tr -w [000] : width - defaults to 1/4 of vide size -f (0.1-9|1) : fade from 0.1 to 1 - defaults to 0.2 -b [00] : border -c colour : colour -o outfile.mp4 : optional agument # if option not provided defaults to infile-name-pip-date-time"
pan image
- script usage
pan-scan -i infile.(png|jpg|jpeg) -d (000) -p (l|r|u|d) -o outfile.mp4
pan-scan -i infile.(png|jpg|jpeg) -d (000) -p (l|r|u|d) -o outfile.mp4 -i = infile.(png|jpg|jpeg) -d = duration : from 1-999 -p = position : left, right, up, down -o = outfile.mp4 : optional agument # default is infile-name-pan-date-time
scene-cut takes a cut file and video and cuts the video into clips
- script usage
scene-cut -i input -c cutfile
- example usage
scene-cut -i input -c cutfile -i input.(mp4|mov|mkv|m4v) -c cutfile
ffmpeg requires a start point and a duration, not an end point
cut file - hours, minutes, seconds in this example we create 2 - 30 seconds clips
a 30 second clip that starts at 00:00:00 and another 30 second clip that starts at 00:01:00
00:00:00,00:00:30 00:01:00,00:00:30
cut file - seconds in this example we create 2 - 30 seconds clips
a 30 second clip that starts at 0 and another 30 second clip that starts at 60
0,30 60,30
scene-detect takes a video file and a threshold for the scene detection from 0.1 to 0.9 you can also use the -s and -e options to set a range for thew scene detection, if you dont specify a range scene detection will be perform on the whole video
ffmpeg scene detection - automatically cut videos into separate scenes
ffmpeg scene detection - version 2 - specify a range in the video and cut into separate scenes
ffmpeg scene detect - version 3 - sexagesimal format - hours, minutes, seconds
- script usage
scene-detect -s 00:00:00 -i infile -e 00:00:00 -t (0.1 - 0.9) -f sec -o outfile
- example usage
scene-detect -s 00:00:00 -i infile -e 00:00:00 -t (0.1 - 0.9) -f sec -o outfile -s 00:00:00 : start time -i input.(mp4|mov|mkv|m4v) -e 00:00:00 : end time -t (0.1 - 0.9) # threshold -f sec # output in seconds -o output.txt
scene-images takes a video file and a cut file, created with the scene-detect script either in seconds or sexagesimal format and then creates an image for each cut point
- script usage
scene-images -i input -c cutfile
- example usage
scene-images -i input -c cutfile -i input.(mp4|mov|mkv|m4v) -c cutfile
scene-time takes a cut file, created with the scene-detect script either in seconds or sexagesimal format
0:00:00 0:00:11.875000 0:00:15.750000
The script creates clips by subtracting the cut point from the start point and converts sexagesimal format and then creates a file with the start point a comma and then the duration of the clip
the output of the scene-time script is used with the scene-cut script to create the clips
0,11.875 11.875,3.875
- script usage
scene-time -i input -o output
- example usage
scene-time -i input -o output -i input -o output
add subtitles to a video file
- script usage
subtitle-add -i video.(mp4|mov|mkv|m4v) -s subtitle.srt -o outfile.mp4
-i infile.(mp4|mkv|mov|m4v) -s subtitle.srt -o outfile.mp4 : optional agument # default is infile-name-subs-date-time
Batch process files in the current working directory
Note we omit the -o option to use the default outfile name, infile-name-subs-date-time
The video and subtitle files you want to combine must have the same name
for example
file1.mp4 file1.srt file2.mp4 file2.srt
running the following code will run the subtitle-add script and combine file1.mp4 with file1.srt and file2.mp4 with file2.srt
find . -type f -name "*.mp4" -exec sh -c \
'subtitle-add -i "${0}" -s "${0%.*}.srt"' \
"{}" \;
ffplay video scopes youtube video
- script usage
scopes -i infile
scopes -o infile
scopes -p infile
scopes -s infile
scopes -w infile
scopes -v infile
-i infile = histogram -o infile = rgb overlay -p infile = rgb parade -s infile = rgb overlay and parade -w infile = waveform -v infile = vector scope -h = help
create thumbnails froma a video and tile into an image
Note that you can use two different time unit formats: sexagesimal (HOURS:MM:SS.MILLISECONDS, as in 01:23:45.678), or in seconds. If a fraction is used, such as 02:30.05, this is interpreted as “5 100ths of a second”, not as frame 5. For instance, 02:30.5 would be 2 minutes, 30 seconds, and a half a second, which would be the same as using 150.5 in seconds.
- script usage
tile-thumbnails -i infile.(mp4|mkv|mov|m4v|webm) \
-s 00:00:00.000 -w 000 -t 0x0 -p 00 -m 00 -c color -o outfile.png
tile-thumbnails -i infile.(mp4|mkv|mov|m4v|webm) \ -s 00:00:00.000 -w 000 -t 0x0 -p 00 -m 00 -c color -o outfile.png -i infile.(mp4|mkv|mov|m4v|webm) -s seek into the video file : default 00:00:05 -w thumbnail width : 160 -t tile layout format width x height : 4x3 : default 4x3 -p padding between images : default 7 -m margin : default 2 -c color = https://ffmpeg.org/ffmpeg-utils.html#color-syntax : default black -o outfile.png :optional agument # if option not provided defaults to infile-name-tile-date-time.png
If the tiled image only creates one thumbnail from the video and the rest of the image is black, then the issue may be the frame rate of the video
you can check the videos frame rate with ffmpeg
ffmpeg -i infile.mp4
if the framerate is 29.97 instead of 30 then you can use ffmpeg to change the framerate and fix the issue
ffmpeg -i infile.mp4 -vf fps=fps=30 outfile.mp4
batch process videos and create thumbnails from the videos and tile into an image
find . -type f -name "*.mp4" -exec sh -c \
'tile-thumbails -i "${0}" -s 00:00:10 -w 200 -t 4x4 -p 7 -m 2 -c white' \
"{}" \;
trim video clip
Note that you can use two different time unit formats: sexagesimal (HOURS:MM:SS.MILLISECONDS, as in 01:23:45.678), or in seconds. If a fraction is used, such as 02:30.05, this is interpreted as “5 100ths of a second”, not as frame 5. For instance, 02:30.5 would be 2 minutes, 30 seconds, and a half a second, which would be the same as using 150.5 in seconds.
- script usage
trim-clip -s 00:00:00.000 -i infile.(mp4|mov|mkv|m4v|aac|m4a|wav|mp3) \
-t 00:00:00.000 -o outfile.(mp4|aac|mp3|wav)
-s 00:00:00.000 : start time -i infile.(mp4|mov|mkv|m4v|aac|m4a|wav|mp3) -t 00:00:00.000 : number of seconds after start time -o outfile.(mp4|aac|mp3|wav) : optional agument # default infile-name-trimmed-date-time.(mp4|aac|mp3|wav)
Batch process files in the current working directory
Note we omit the -o option to use the default outfile name, infile-name-trimmed-date-time
Batch trim all the mp4 files in the current directory, from 00:00:00 to 00:00:30
find . -type f -name "*.mp4" -exec sh -c \
'trim-clip -s 00:00:00 -i "${0}" -t 00:00:30' \
"{}" \;
create a gif animation from a video
- script usage
vid2gif -s 00:00:00.000 -i infile.(mp4|mov|mkv|m4v) -t 00:00:00.000 -f [00] -w [0000] -o outfile.gif
vid2gif -s 00:00:00.000 -i infile.(mp4|mov|mkv|m4v) -t 00:00:00.000 -f [00] -w [0000] -o outfile.gif -s 00:00:00.000 : start time -i infile.(mp4|mov|mkv|m4v) -t 00:00:00.000 : number of seconds after start time -f [00] : framerate -w [0000] : width -o outfile.gif :optional agument # if option not provided defaults infile-name-gif-date-time.gif
create a waveform from an audio or video file and save as a png
- script usage
waveform -i infile.(mp4|mkv|mov|m4v|webm|wav|aac|m4a|mp3) -o oufile.png
-i infile.(mp4|mkv|mov|m4v|webm|aac|m4a|wav|mp3) -o outfile.png : optional agument # default is infile-name-waveform-date-time
Batch process files in the current working directory
Note we omit the -o option to use the default outfile name, infile-name-waveform-date-time
Create waveform images from all the mp4 fies in the current directory
find . -type f -name "*.mp4" -exec sh -c \
'waveform -i "${0}"' \
"{}" \;
create a animated webp image from a video with ffmpeg
- script usage
webp -i input -c 0-6 -q 0-100 -f 15 -w 600 -p none -o output.webp
-i input.webp -c compression level: 0 - 6 : default 4 -q quality: 0 - 100 : default 80 -f framerate: default 15 -w width: default 600px -p preset: none|default|picture|photo|drawing|icon|text : default none -o output.webp :optional agument # if option not provided defaults infile-name.webp
Batch process files in the current working directory
find . -type f -name "*.mp4" -exec sh -c 'webp -i "${0}"' "{}" \;
apply a transition between two clips with the xfade filters
- script usage
xfade -a clip1.(mp4|mkv|mov|m4v) -b clip2.(mp4|mkv|mov|m4v) -d duration -t transition -f offset -o outfile.mp4
- help
# ffmpeg xfade transitions xfade -a clip1.(mp4|mkv|mov|m4v) -b clip2.(mp4|mkv|mov|m4v) -d duration -t transition -f offset -o outfile.mp4 -a clip1.(mp4|mkv|mov|m4v) : first clip -b clip2.(mp4|mkv|mov|m4v) : second clip -d duration : transition duration -t transition : transition -f offset : offset -o outfile.mp4 : optional agument # if option not provided defaults to infile-name-xfade-date-time + transitions circleclose, circlecrop, circleopen, diagbl, diagbr, diagtl, diagtr, dissolve, distance fade, fadeblack, fadegrays, fadewhite, hblur, hlslice, horzclose, horzopen, hrslice pixelize, radial, rectcrop, slidedown, slideleft, slideright, slideup, smoothdown smoothleft, smoothright, smoothup, squeezeh, squeezev, vdslice, vertclose, vertopen, vuslice wipebl, wipebr, wipedown, wipeleft, wiperight, wipetl, wipetr, wipeup
convert a image to video and apply the ken burns effect to the clip
- script usage
zoompan -i infile.(png|jpg|jpeg) -d (000) -z (in|out) -p (tl|c|tc|tr|bl|br) -o outfile.mp4
-i infile.(png|jpg|jpeg) -d duration : from 1-999 -z zoom : in or out -p position : zoom to location listed below -o outfile.mp4 : optional agument # default is infile-name-zoompan-date-time
+------------------------------+
+tl tc tr+
+ +
+ c +
+ +
+bl br+
+------------------------------+
Batch process files in the current working directory
Note we omit the -o option to use the default outfile name, infile-name-zoompan-date-time
Batch process all the png files in the current working directory, apply the zoompan script with a 5 second duration, zoom in to the center of the image
find . -type f -name "*.png" -exec sh -c \
'zoompan -i "${0}" -d 5 -z in -p c' \
"{}" \;