===== ffmpeg cheatsheet =====
not linking that man page good lord
[[https://cheat-sheets.org/project/tldr/command/ffmpeg/|ffmpeg TLDR]], [[http://cheat.sh/ffmpeg|ffmpeg cheat.sh]]
==== audio ====
=== FLAC to MP3 ===
one-off:
ffmpeg -i "$FILE.flac" -ab 320k -map_metadata 0 -id3v2_version 3 "$FILE.mp3"
bash loop:
for f in *.flac; do ffmpeg -i "$f" -ab 320k -map_metadata 0 -id3v2_version 3 "${f%.*}.mp3"; done
==== video to frames ====
see ''~/.local/bin/vidtools'' ([[https://bytes.4-walls.net/kat/dotfiles/src/commit/73e1380fd1dd186ce5925ab20b4529b4928e91cf/config/.local/bin/vidtools#L11|dotfiles]]) for the default/most used option (every frame including duplicates).
=== 1/1 frames ===
ffmpeg -i "$FILE" -filter:v fps=fps=1/1 %04d.jpg
=== 1/2 frames ===
ffmpeg -i "$FILE" -filter:v fps=fps=1/2 %04d.jpg
==== re-encode ====
now mostly consolidated in ''vidtools'' (linked above), but copied here just in case.
=== x264 (AVC), no GPU ===
ffmpeg -i "$FILE.mp4" -c:v libx264 -crf 18 -c:a copy -c:s copy "$FILE.mkv"
=== x265 (HEVC), no GPU ===
ffmpeg -i "$FILE.mp4" -c:v libx265 -vtag hvc1 -crf 18 -c:a copy -c:s copy "$FILE.mkv"
=== x265 (HEVC), GPU, bash loop ===
for f in *.mkv; do ffmpeg -hwaccel cuda -hwaccel_output_format cuda -i "$f" -c:v hevc_nvenc -vtag hvc1 -profile main -preset slow -rc vbr_hq -c:a copy -c:s copy -map 0 "${f%.*} HEVC.mkv"; done
=== AVI/DivX/XviD to MKV, bash loop ===
for f in *.avi; do ffmpeg -fflags +genpts -i "$f" -c:v copy -c:a copy -c:s copy "${f%.*} AVI2MKV.mkv"; done
=== copy video, remove audio, bash loop ===
for f in *.mp4; do ffmpeg -i "$f" -vcodec copy -an "${f%.mp4}_noaudio.mp4"; done
=== camcorder sources ===
GPU accelerated camcorder source MPEG+AC3+VOBSUB to x264+AC3+VOBSUB (little to no file size reduction, for web uploads)
ffmpeg -y -vsync 0 -hwaccel cuda -hwaccel_output_format cuda -extra_hw_frames 10 -i "input.mkv" -c:a copy -c:v h264_nvenc -c:s copy -b:v 5M "output.mkv"