#!/bin/bash
for file in `find . | grep ".mp4$"`;
do
newname=`basename -s .mp4 $file`
newdirname=`dirname $file`
output=$newdirname"/"$newname"_o.mp4"
size=`ffprobe -v error -show_entries stream=width,height -of default=noprint_wrappers=1 $file`
width=`echo $size | awk -F'[ =]+' '{print $2}'`
height=`echo $size | awk -F'[ =]+' '{print $4}'`
echo $width
echo $height
HandBrakeCLI -i $file -o $output -O -e x264 -q 22 -w $width -l $height -B 48
mv $output $file
done