encode input file to hevc
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
set -euo pipefail | |
infile="$1" | |
preset=veryfast | |
audiobitrateperchannel=64 | |
ffmpeg_docker='lloesche/nginx-fatpack' | |
originfile=$infile | |
[ ! -f "$infile" ] && \ | |
echo "file $infile not found" && \ | |
exit 1 | |
if type ffmpeg > /dev/null 2>&1 && type ffprobe > /dev/null 2>&1 | |
then | |
ffmpeg=ffmpeg | |
ffprobe=ffprobe | |
else | |
ffmpeg="docker run -it -v /:/host $ffmpeg_docker ffmpeg" | |
ffprobe="docker run -i -v /:/host $ffmpeg_docker ffprobe" | |
pwd=$(pwd) | |
if [ ${infile:0:1} == '/' ] | |
then | |
infile="/host${infile}" | |
else | |
infile="/host${pwd}/${infile}" | |
fi | |
fi | |
if ! codec=$($ffprobe -i "$infile" -show_streams -select_streams v:0 2> /dev/null | grep codec_name= | cut -d = -f 2) | |
then | |
echo "can't determin codec" | |
exit 1 | |
fi | |
if [ "$codec" == "hevc" ] | |
then | |
echo "$infile is already h.265" | |
exit 1 | |
fi | |
outdir="$(dirname "$infile")" | |
origoutdir="$(dirname "$originfile")" | |
outfile="$(basename "$infile").x265.mkv" | |
audiochannels=$($ffprobe -i "$infile" -show_streams -select_streams a:0 2> /dev/null | grep ^channels= | cut -d = -f 2) | |
audiobitrate=$(($audiochannels*$audiobitrateperchannel))k | |
$ffmpeg -i "$infile" -c:v libx265 -x265-params crf=23 -preset $preset -c:a libfdk_aac -b:a $audiobitrate "$outdir/.$outfile" && \ | |
mv -f "$origoutdir/.$outfile" "$origoutdir/$outfile" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment