Skip to content

Instantly share code, notes, and snippets.

@yutahaga
Last active January 25, 2018 05:35
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 yutahaga/82eb936f34fdf1ed05bae2331827a08a to your computer and use it in GitHub Desktop.
Save yutahaga/82eb936f34fdf1ed05bae2331827a08a to your computer and use it in GitHub Desktop.
#!/bin/bash
POSITIONAL=()
while [[ $# -gt 0 ]]
do
key="$1"
case $key in
-c|--crf)
CRF="$2"
shift # past argument
shift # past value
;;
*) # unknown option
POSITIONAL+=("$1") # save it in an array for later
shift # past argument
;;
esac
done
set -- "${POSITIONAL[@]}" # restore positional parameters
if [ -z "${CRF}" ]; then
CRF=16
fi
readonly FILE_PATH=$1
readonly FILE_BASENAME=$(basename "${FILE_PATH}")
readonly FILE_NAME="${FILE_BASENAME%.*}"
readonly DIR_PATH=$(dirname "${FILE_PATH}")
ffmpeg -i "$FILE_PATH" -crf $CRF -preset slower -pix_fmt yuv420p -f hevc "/var/tmp/${FILE_NAME}.bitstream.265"
echo "{\"general\":{\"output\":{\"file_path\":\"${DIR_PATH}/${FILE_NAME}.heic\"},\"brands\":{\"major\":\"mif1\",\"other\":[\"mif1\", \"heic\", \"hevc\"]}},\"content\":[{\"master\":{\"file_path\":\"/var/tmp/${FILE_NAME}.bitstream.265\",\"hdlr_type\":\"pict\",\"code_type\":\"hvc1\",\"encp_type\":\"meta\"}}]}" > "/var/tmp/${FILE_NAME}.config.json"
heifw "/var/tmp/${FILE_NAME}.config.json"
rm "/var/tmp/${FILE_NAME}.bitstream.265" "/var/tmp/${FILE_NAME}.config.json"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment