I daily drive this FFMPEG wrapper to compress videos and, at least in my experience, is very effective but not perfect. In most cases it should be able to compress from 98% to 70% of the video file size, maybe less, maybe more. I guess it all depends on the video itself and/or how powerful your CPU is. For my use case, it's enough, but I still keep modifying every now and then trying to achieve the best balance between: compression time, file size and perceived quality. If you found any improvements in those aspects, feel free to share them in the comments. I wanna clarify I'm not an expert on this topic, I just started testing out stuff with help of AI and eventually got to this point.
minify-video.fish:
function _show_help
echo 'Usage: minify-video [OPTIONS] [FILES...]'
echo 'Options:'
echo ' -h, --help Show this help message'
echo ' -y, --yes Don\'t ask for confirmations'
echo ' -p, --preset Set the encoding preset (default: veryfast)'
echo ' -c, --crf Set the constant rate factor (default: 28)'
echo ' -vc Set the video codec (default: libx265)'
echo ' -vf Set the video filter (default: none)'
echo ' -ac Set the audio codec (default: libopus)'
echo ' -e, --extension Set the output file extension (default: mp4)'
echo ' -pixfmt Set the pixel format (default: yuv420p10le)'
echo ' -profile Set the encoding profile (default: main10)'
end
function minify-video
argparse -n minify-video 'h/help' 'y/yes' 'p/preset=' 'c/crf=' 'vc=' 'vf=' 'ac=' 'e/extension=' 'pixfmt=' 'profile=' -- $argv
or return
set -q _flag_p; or set -l _flag_p 'veryfast'
set -q _flag_c; or set -l _flag_c '28'
set -q _flag_vc; or set -l _flag_vc 'libx265'
set -q _flag_ac; or set -l _flag_ac 'libopus'
set -q _flag_e; or set -l _flag_e 'mp4'
set -q _flag_pixfmt; or set -l _flag_pixfmt 'yuv420p10le'
set -q _flag_profile; or set -l _flag_profile 'main10'
set -l _x265params "log-level=warning:aq-mode=3:aq-strength=1.0:psy-rd=1.0:psy-rdoq=1.0"
if set -q _flag_h
_show_help
return
end
set -l _flags \
-preset $_flag_p \
-crf $_flag_c \
-c:v $_flag_vc \
-profile:v $_flag_profile \
-pix_fmt $_flag_pixfmt \
(if set -q _flag_vf; echo "-vf $_flag_vf" | string split -n ' '; end) \
-c:a $_flag_ac \
-b:a 96k \
-movflags +faststart \
-map_metadata 0 \
-hide_banner \
-loglevel warning \
-x265-params $_x265params
set -q _flag_y; and set _flags '-y' $_flags
for file in $argv
set -l name (path basename -E "$file")
echo "Running: ffmpeg -i \"$file\" $_flags \"$name-MIN.$_flag_e\""
ffmpeg -i "$file" $_flags "$name-MIN.$_flag_e"
end
end