Extracting audio from a video file
ffmpeg -i infile.mp4 -vn -c:a copy outfile.m4a
Batch extract audio from video with find
find . -type f -name "*.mp4" -exec sh -c \
'ffmpeg -i "${0}" -vn -c:a copy "${0%.*}.m4a"' \
"{}" \;
ffmpeg extract video
ffmpeg -i infile.mp4 -an -c:v copy outfile.mp4
ffmpeg batch extract video
find . -type f -name "*.mp4" -exec sh -c \
'ffmpeg -i "${0}" -an -c:v copy "${0%.*}-extracted.mp4"' \
"{}" \;
change a videos framerate to 30fps
ffmpeg -i infile.mp4 -filter:v fps=fps=30 outfile.mp4
change frame batch process to 30fps
find . -type f -name "*.mp4" -exec sh -c \
'ffmpeg -i "${0}" -filter:v fps=fps=30 "${0%.*}-framerate.mp4"' \
"{}" \;
ffmpeg -i infile.mp4 -ac 1 outfile.mp4
change frame batch process to 30fps
find . -type f -name "*.mp4" -exec sh -c \
'ffmpeg -i "${0}" -ac 1 "${0%.*}-mono.mp4"' \
"{}" \;
change audio rate to 44100
ffmpeg -i infile.mp4 -ar 44100 outfile.mp4
change audio rate to 44100 batch process
find . -type f -name "*.mp4" -exec sh -c \
'ffmpeg -i "${0}" -ar 44100 "${0%.*}-audiorate.mp4"' \
"{}" \;
scale and pad a video to 1080
ffmpeg -i fps.mp4 -vf "scale=-1:1080,pad=1920:ih:(ow-iw)/2" outfile.mp4
scale and pad a video to 1080 batch process
find . -type f -name "*.mp4" -exec sh -c \
'ffmpeg -i "${0}" -vf "scale=-1:1080,pad=1920:ih:(ow-iw)/2" "${0%.*}-1080.mp4"' \
"{}" \;
Trim a video clip with a new start and end point
ffmpeg \
-ss 00:00:30 \
-i infile.mp4 \
-t 00:01:30 \
-c:a copy \
-c:v libx264 -profile:v high -pix_fmt yuv420p \
-movflags +faststart -f mp4 outfile.mp4
Find all mp4 or mkv files and extract a frame as a png image
find . -type f -name "*.[mp4kv]*" -exec sh -c \
'ffmpeg -ss 00:00:05 -i "$1" -q:v 2 -f image2 -vframes 1 "${1%.*}.png" -hide_banner' sh {} \;
Convert a mkv video to a mp4 file to import into your video editor like Final Cut Pro
ffmpeg -i infile.mkv \
-c:v libx264 -crf 18 -profile:v high \
-pix_fmt yuv420p -movflags +faststart -f mp4 \
outfile.mp4
Find wav files and convert to m4a
find . -type f -name "*.wav" -exec sh -c \
'ffmpeg -i "$0" -map 0:0 -c:a aac -b:a 320k "${0%.*}.m4a"' "{}" \;
Find wav files and convert to mp3
find . -type f -name "*.wav" -exec sh -c \
'ffmpeg -i "$0" -map 0:0 -c:a libmp3lame -b:a 320k "${0%.*}.mp3"' "{}" \;
create a list of all the mp4s in the current directory
printf "file '%s'\n" *.mp4 > list.txt
use ffplay to play the list of videos in the text file
ffmpeg -f concat -i list.txt -c copy outfile.mp4
use ffmpeg to concat the video file in the text file
ffmpeg -f concat -i list.txt -c copy outfile.mp4
use subshell to generate a list of the mp4s in the current directory
ffmpeg -f concat -i <( for f in *.mp4; do echo "file '$(pwd)/$f'"; done ) outfile.mp4
Extracting, adding and deleting closed captions from videos
youtube_dl download subtitles from video
youtube-dl --write-sub --sub-lang en --skip-download 'youtube-url'
youtube-dl batch download subtitles from a text file with youtube urls
youtube-dl --write-sub --sub-lang en --skip-download -a links.txt
convert scc closed captions to srt subtitles, and remove text formatting and font tags for youtube
ffmpeg -i infile.scc -c:s text outfile.srt
convert the vtt subtitles from youtube to srt format
ffmpeg -i infile.vtt -c:s text outfile.srt
batch convert vtt subtitles to srt format
find . -type f -name "*.vtt" -exec sh -c 'ffmpeg -i "$0" \
-c:s text "${0%.*}.srt"' "{}" \;
ffmpeg -i infile.mp4 \
-f srt -i infile.srt \
-c:a copy -c:v copy -c:s \
mov_text -metadata:s:s:0 \
language=eng \
-movflags +faststart \
outfile.mp4
remove close captions from video without re encode
ffmpeg -i infile.mp4 \
-c copy \
-bsf:v "filter_units=remove_type=6" \
-movflags +faststart \
outfile.mp4
Closed caption extractor for MPEG and H264 files
Extract closed captions from video and save as a srt file
ccextractor infile.mp4
sudo apt install ccextractor
Freebsd ccextractor install
pkg install ccextractor
convert to 1080 30fps
ffmpeg \
-i infile.mp4 \
-vf "scale=-1:1080,pad=1920:ih:(ow-iw)/2,fps=fps=30" \
outfile.mp4
convert to 1080 30fps mono
ffmpeg \
-i infile.mp4 \
-vf "scale=-1:1080,pad=1920:ih:(ow-iw)/2,fps=fps=30" \
-ac 1 outfile.mp4