Examples use input.mp4 for the input video and output.mp4 for output.
You can convert formats by changing the file extension (ex: input.mp4 output.mkv) but you probably already knew that.
Trim video
Trims input.mp4 starting at 22 seconds ending at 24 seconds. Output saves to a copy named output.mp4.
ffmpeg -i input.mp4 -ss 00:00:22 -to 00:00:24 -c:v copy -c:a copy output.mp4
Remove Black Bars
Removes empty areas/black bars (ex: mobile video "filled" to widescreen)
Run the first command to find the empy areas. The output-temp.mp4 file can be deleted after running it.
ffmpeg -i input.mp4 -vf cropdetect output-temp.mp4
This will give you an output similar to the one below. You need the crop=#:#:#:# value.
[Parsed_cropdetect_0 @ 000002eaf9537640] x1:437 x2:842 y1:0 y2:719 w:400 h:720 x:440 y:0 pts:13465600 t:10.958333 limit:0.094118 crop=400:720:440:0
[Parsed_cropdetect_0 @ 000002eaf9537640] x1:437 x2:842 y1:0 y2:719 w:400 h:720 x:440 y:0 pts:13516800 t:11.000000 limit:0.094118 crop=400:720:440:0
ffmpeg -i input.mp4 -vf "crop=400:720:440:0" output.mp4
Extract Frames
Single Frame
Extract a single frame at 02:37.
ffmpeg -i input.mp4 -ss 00:02:37 -frames:v 1 output.jpg
This gives a warning about using a pattern. You can ignore it or use %03d in the filename.
All Frames
Extracts all frames (filename format output-lt;numbergt;.jpg) from 02:36 to 02:37.
ffmpeg -i input.mp4 -ss 00:02:36 -to 00:02:37 output-%d.jpg
Bulk Convert Script
BulkFFMPEGConvert.ps1
# The example below will convert all .mp4 files in a directory to .mp3. You can change input and output formats if needed.
Get-ChildItem *.mp4 | ForEach-Object {
ffmpeg.exe -i "$($_.Name)" "$($_.BaseName).mp3"
}
yt-dlp extract audio
Extracts audio only from a youtube video downloaded with yt-dlp. Not technically an ffmpeg command but it uses ffmpeg. Close enough.
youtube-dl.exe --extract-audio --audio-format mp3 --audio-quality 0 --ffmpeg-location "ffmpeg\bin" -o %(title)s.%(ext)s <url>
See this post for more output options.