#-----[ffmpeg]------#
# ffmpegthumbnailer
# create thumbnail:
    ffmpeg -i input.mp4 -ss 00:00:25 -frames:v 1 output.jpg
# remove audio:
    ffmpeg -i input.mp4 -c copy -an output.mp4
# transcode to webm:
    ffmpeg -i input.mp4 -c:v libvpx-vp9 -crf 31 -b:v 0 -an output.webm

ffmpeg -i "$@" -vf "select='gte(t,9)',scale=320:-1" -frames:v 1

ffmpeg -i "$@" -r 10 -vf scale=200:-1 -frames:v 1 -y
# extract a single thumbnail at a specific timestamp
ffmpeg -i "$@" -ss 00:00:15 -vf scale=200:-1 -frames:v 1 -y

ffmpeg -i "$@" -vf "thumbnail" -frames:v 1
ffmpeg -i "$@" -vframes 1 -s 640x360 -aspect 16:9 -q:v 2
ffmpeg -i "$@" -vframes 1 -s 640x360 -q:v 2

# extract a multiple thumbnails at regular intervals
ffmpeg -i input_video.mp4 -vf "fps=1,scale=320:-1" -vsync vfr -q:v 2 thumb%04d.png

# video recording settings:
#   recording format = mp4
#   encoder          = x264
#   crf rate control = 23   (try lower values to increase quality)

# both make a gif
ffmpeg -i who.webm -vf "fps=10,scale=320:-1:flags=lanczos" -c:v pam \
  -ss 00:01:05  -t 00:00:05.0 \
  -f image2pipe - \
  | convert -delay 10 - -loop 0 -layers optimize output2.gif

ffmpeg -i output.webm -vf "fps=10,scale=540:-1:flags=lanczos" -c:v pam \
  -ss 1 -f image2pipe - \
  | convert -delay 0 -  -loop 0 -layers optimize whoo.gif

# losslessly convert the video you can use ffmpeg bitstream filters
#
# note:
#   easily be adjusted to other framerates by changing the -r and -bsf:v values
#
# -c don't transcode, remain lossless
# -r output framerate, mostly informational for the whole-video metadata
# -fps_mode don't drop frames to match expected framerate, just preserve all input frames
# -bsf:v update the presentation time to 1/2 the previous one (play twice as fast)
#
# ---
# source: https://kevincox.ca/2025/08/05/losslessly-change-video-framerate/
# also see: https://trac.ffmpeg.org/wiki/How%20to%20speed%20up%20/%20slow%20down%20a%20video
# also see: https://trac.ffmpeg.org/wiki/How%20to%20speed%20up%20/%20slow%20down%20a%20video#rawbitstreammethod

ffmpeg -i "$1".mp4 -c copy -r 60 -fps_mode vfr -bsf:v "setts=ts=PTS/2" output.mp4

# compress a video
ffmpeg -i input.mp4 -vcodec libx265 -crf 28 output.mp4

# make a vid smaller
ffmpeg -y -i 'vid.mp4' -c:v libx264 -preset slow -b:v 1000k \
  -c:a aac -b:a 96k -pass 1 -f null /dev/null \
  && ffmpeg -y -i 'vid.mp4' -c:v libx264 -preset slow -b:v 1000k \
  -c:a aac -b:a 96k -pass 2  mixtape.mp4

# and if you are embedding it in HTML to make it more compatible,

# you can use this to make a vp9 / webm version that will work on all
# computers/phones that cant read h264 mp4s:

ffmpeg -y -i "vid.mp4" -c:v libvpx-vp9 -b:v 1000k -tile-columns 2 -g 240 \
  -threads 8 -quality good -crf 31 -c:a libopus -b:a 96k \
  -pass 1 -speed 4 -f null /dev/null \
  && ffmpeg -y -i "vid.mp4" -c:v libvpx-vp9 -b:v 1000k -tile-columns 3 -g 240 \
  -threads 8 -quality good -crf 31 -c:a libopus -b:a 96k \
  -pass 2 -speed 4 "mixtape.webm"

# trim
ffmpeg -ss 01:19:27 -i input.mp4 -to 02:18:51 -c:v copy -c:a copy output.mp4

# fade in/out
ffmpeg -y -i voctest_v2.mp4 \
    -ss 00:01 -to 00:35 \
    -vf "fade=t=in:st=1:d=3,fade=t=out:st=33:d=2" \
    out.mp4
