Skip to content

Latest commit

 

History

History
298 lines (208 loc) · 5.83 KB

ffmpeg-tips.org

File metadata and controls

298 lines (208 loc) · 5.83 KB

ffmpeg tips

Extracting audio

Extracting audio from video

Extracting audio from a video file

ffmpeg -i infile.mp4 -vn -c:a copy outfile.m4a

Batch extracting audio from video

Batch extract audio from video with find

find . -type f -name "*.mp4" -exec sh -c \
'ffmpeg -i "${0}" -vn -c:a copy "${0%.*}.m4a"' \
"{}" \;

Extract video tracks

extract video with ffmpeg

ffmpeg extract video

ffmpeg -i infile.mp4 -an -c:v copy outfile.mp4

batch extract video with ffmpeg

ffmpeg batch extract video

find . -type f -name "*.mp4" -exec sh -c \
'ffmpeg -i "${0}" -an -c:v copy "${0%.*}-extracted.mp4"' \
"{}" \;

change framerate with ffmpeg

change a videos framerate to 30fps

ffmpeg -i infile.mp4 -filter:v fps=fps=30 outfile.mp4

change framereate batch process

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"' \
"{}" \;

convert stereo to mono

ffmpeg -i infile.mp4 -ac 1 outfile.mp4

convert stereo to mono batch process

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

change audio rate to 44100

ffmpeg -i infile.mp4 -ar 44100 outfile.mp4

change audio rate batch process

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 video to 1080

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 video to 1080 batch process

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 video

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

Extract frame as image

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 mkv to mp4

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

Convert audio

Convert wav to m4a

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"' "{}" \;

Convert wav to mp3

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"' "{}" \;

ffmpeg concat clips

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

Closed captions

Extracting, adding and deleting closed captions from videos

youtube_dl download subtitles

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 closed captions to srt

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 add subtitles to video

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

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

ccextractor

Closed caption extractor for MPEG and H264 files

Extract closed captions from video and save as a srt file

ccextractor infile.mp4

Linux ccextractor install

sudo apt install ccextractor

Freebsd ccextractor install

Freebsd ccextractor install

pkg install ccextractor

convert ipad video to 1080

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