#!/bin/bash
eval $(ffprobe -v error -show_entries stream=width,height -of default=noprint_wrappers=1 "$1")
#results in e.g.
#width=300
#height=1200
echo "height=$height"$'\n'"width=$width"
newenv=$(bc <<< "width=$width; height=$height;"$'\nscale=3; aspect=width / height;\nprint "aspect=", aspect;
    print "''\n'$'";\n\nif (aspect>3) { r=(height) * (aspect/3); print "height=";}
    if (aspect<(1/3)) {r=(width) / (aspect/(1/3)); print "width=";}\nscale=0
    if (r) { print r/1 }')
[ ! -z "$newenv" ] && echo "$newenv" && export $newenv
echo "aspect=""$(bc <<< "scale=3; $width/$height")"
