Skip to content

Instantly share code, notes, and snippets.

@Psycojoker
Last active July 16, 2018 19:41
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Psycojoker/f1b0fa6c720c72298bf417ed232eeea8 to your computer and use it in GitHub Desktop.
Save Psycojoker/f1b0fa6c720c72298bf417ed232eeea8 to your computer and use it in GitHub Desktop.
Display possible video compressed size
possible_sizes() {
local video_path=$1
if [ ! "$video_path" ]
then
echo "Usage: possible_size video_path"
return
fi
local width=$(mediainfo $1 | grep Width | cut -d ":" -f 2 | sed 's/[^0-9]//g')
local height=$(mediainfo $1 | grep Height | cut -d ":" -f 2 | sed 's/[^0-9]//g')
for i in $(seq 9 | sort -r)
do
((x=$width * .$i))
((y=$height * .$i))
local x_remainer=$(echo $x | cut -d '.' -f 2 | sed 's/0//g')
local y_remainer=$(echo $y | cut -d '.' -f 2 | sed 's/0//g')
if [ ! "$x_remainer" ] && [ ! "$y_remainer" ]
then
local possible_size=$(echo $x | cut -d '.' -f 1)x$(echo $y | cut -d '.' -f 1)
echo $possible_size
echo ffmpeg -i $video_path -s $possible_size -pix_fmt yuv420p -profile main -y ${video_path:r}-compressed.${video_path:e}
fi
done
}
Example output:
$ possible_sizes video.mp4
1728x972
ffmpeg -i video.mp4 -s 1728x972 -pix_fmt yuv420p -profile main -y video-compressed.mp4
1536x864
ffmpeg -i video.mp4 -s 1536x864 -pix_fmt yuv420p -profile main -y video-compressed.mp4
1344x756
ffmpeg -i video.mp4 -s 1344x756 -pix_fmt yuv420p -profile main -y video-compressed.mp4
1152x648
ffmpeg -i video.mp4 -s 1152x648 -pix_fmt yuv420p -profile main -y video-compressed.mp4
960x540
ffmpeg -i video.mp4 -s 960x540 -pix_fmt yuv420p -profile main -y video-compressed.mp4
768x432
ffmpeg -i video.mp4 -s 768x432 -pix_fmt yuv420p -profile main -y video-compressed.mp4
576x324
ffmpeg -i video.mp4 -s 576x324 -pix_fmt yuv420p -profile main -y video-compressed.mp4
384x216
ffmpeg -i video.mp4 -s 384x216 -pix_fmt yuv420p -profile main -y video-compressed.mp4
192x108
ffmpeg -i video.mp4 -s 192x108 -pix_fmt yuv420p -profile main -y video-compressed.mp4
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment