Last active
May 17, 2021 09:23
-
-
Save eric-vader/129119e2825a2bd2e2b8cc00e79a27cd to your computer and use it in GitHub Desktop.
Converts all mov files to mp4 using handbrake
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 | |
# Make sure globstar is enabled | |
if [[ $# -ne 2 ]] ; then | |
echo 'Must have 2 arguments!' | |
exit 1 | |
fi | |
shopt -s globstar | |
for EXT in mov MOV | |
do | |
for i in $1/**/*.$EXT; do # Whitespace-safe and recursive | |
NO_EXT="${i%.*}" | |
# Sanitize the input so it doesnt mess with bash commands | |
NO_EXT_ESC=$(printf '%q' "$NO_EXT") | |
MOV_ESC=$NO_EXT_ESC.$EXT | |
MP4_ESC=$NO_EXT_ESC.mp4 | |
OUT_ESC=$NO_EXT_ESC.out | |
MOV=$NO_EXT.$EXT | |
MP4=$NO_EXT.mp4 | |
OUT=$NO_EXT.out | |
EXE="numactl --cpunodebind $2 HandBrakeCLI --preset-import-file /data/il_temp/ILVT.json -Z 'ILVT' -i $MOV_ESC -o $MP4_ESC > $OUT_ESC 2>&1" | |
if [ -f "$MP4" ]; then | |
echo "Skip: $MP4 already exist." | |
if grep -q 'Encode done!' "$OUT"; then | |
rm "$OUT" | |
rm "$MOV" | |
fi | |
else | |
echo "Render: $MP4, executing $EXE" | |
eval $EXE | |
fi | |
if grep -q 'Encode done!' "$OUT"; then | |
if grep -q 'removing audio' "$OUT"; then | |
echo "Audio Missing, skip deleting $OUT and $MOV" | |
else | |
rm "$OUT" | |
rm "$MOV" | |
fi | |
fi | |
done | |
done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment