Personal collection of basic examples / scripts.
FFmpeg Documentation
A complete, cross-platform solution to record, convert and stream audio and video.
- FFmpeg Examples
- Table of contents
Various converstion commands between audio, images & video.
ffmpeg -y -i "input.mp4" -vf palettegen "palette.png"
ffmpeg -y -i "input.mp4" -i palette.png -filter_complex paletteuse -r 10 -s "320x480" "output.gif"
ffmpeg -ignore_loop 0 -i "image.gif" -i "audio.mp3" -c:a copy -c:v libx264 -shortest "output.mp4"
ffmpeg -i "audio.mp3" -ignore_loop 0 -i "image.gif" -vf "scale=trunc(iw/2)*2:trunc(ih/2)*2" -shortest -strict -2 -c:v libx264 -threads 4 -c:a aac -b:a 192k -pix_fmt yuv420p -shortest "output.mp4"
ffmpeg -loop 1 -i "image.jpg" -i "audio.mp3" -shortest -acodec copy -vcodec mjpeg "output.mp4"
Remove black bars from edge of video files w/ preview.
ffmpeg -i "input.mp4" -vframes 10 -vf cropdetect -f null -
ffplay -vf crop=1280:720:0:0 "input.mp4"
ffmpeg -i "input.mp4" -vf crop=1280:720:0:0 -c:a copy "output.mp4"
Resize video file without cropping.
ffmpeg -i "input.mp4" -vf "pad=ih*16/9:ih:(ow-iw)/2:(oh-ih)/2,scale=1152:864" "ouput.mp4"
Chop video duration based off timecode 'HH:MM:SS.ffff'
ffmpeg -ss 00:06:10 -i "input.mkv" -c copy -avoid_negative_ts make_zero "output.mkv"
Work with subtitles.
ffmpeg -i "input.mp4" -i "subtitles.srt" -c:s mov_text -c:v copy -c:a copy "output.mp4"
Reference Video to make a picture slideshow with
a single terminal command. The command below will take *.jpg pics in a directory and cycle
through them one every four seconds (that is, framerate of 0.25
):
cat *.jpg | ffmpeg -framerate 0.25 -f image2pipe -i - "output.mkv"
Or, add a music track as well:
cat *.jpg | ffmpeg -framerate 0.25 -f image2pipe -i SONG.mp3 -acodec copy "output.mkv"
Stitch videos together into one file.
<#
.SYNOPSIS
Concatenate files using ffmpeg
.DESCRIPTION
Concatenate means to link together or join.
For example, concatenating these files below assuming they were 30sec in length?
would result in an output file with a 90sec duration.
.NOTES
Probably don't have to output temp.txt for concat
#>
$cat = "
file 'input1.mp4'
file 'input2.mp4'
file 'input3.mp4'
"
# Create 'cat.txt' example
($cat -split "[\r\n]+") | Set-Content $PSScriptRoot\cat.txt
# Example 'input' files clearly do not actually exist.
# ERROR is likely to occurs on 'ffmpeg call'.
# Concatenate the files
ffmpeg -f concat -safe 0 -i "cat.txt" -c copy "output.mp4"