Skip to content

Instantly share code, notes, and snippets.

@xykong
Last active December 31, 2017 06:46
Show Gist options
  • Save xykong/c115854fc3acb305b3363fac3d56c8d3 to your computer and use it in GitHub Desktop.
Save xykong/c115854fc3acb305b3363fac3d56c8d3 to your computer and use it in GitHub Desktop.
Convert all videos in the given folder to h265 format.
#!/bin/sh
path=`pwd`
dry=0
while test $# -gt 0
do
case "$1" in
--dry)
dry=1
;;
--*) echo "bad option $1"
;;
*) echo "argument $1"
path=$1
;;
esac
shift
done
echo dry:$dry
echo path:$path
if ! command -v ffmpeg >/dev/null 2>&1; then
echo 'ffmpeg no exists, please install with: brew install ffmpeg --with-x265'
return
fi
for f in $path/* $path/**/* ; do
# echo $f
ffmpeg -i "$f" 2>&1 | grep fps > /dev/null
rc=$?
if [[ $rc != 0 ]]; then
continue;
fi
# echo "this is video:" $f
ffmpeg -i "$f" 2>&1 | grep hevc > /dev/null
rc=$?
if [[ $rc == 0 ]]; then
continue;
fi
# echo "this video is not h265:" $f
newFile=${f%%.*}.h265.mp4
# echo "new h265 file:" $newFile
if [ -f "$newFile" ]; then
echo "skip: h265 file exist:" $newFile
continue;
fi
echo "convert: h265 file:" $newFile
if [ $dry == 1 ]; then
continue;
fi
ffmpeg -y -i "$f" -c:v libx265 -c:a copy "$newFile"
done;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment