-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathconvertScript.sh
More file actions
102 lines (80 loc) · 3.28 KB
/
convertScript.sh
File metadata and controls
102 lines (80 loc) · 3.28 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
#!/bin/bash
#source $HOME/.bash_profile
outputDir="./h265vids/"
CRF="22"
FILE_TYPES=("avi" "mp4" "mkv")
PROCESS_PATH="/plex/plex/adult/tv/" #MAKE SURE YOU HAVE / AT END
EXCLUDE_DIRS=("./Greatest Events of WWII in Colour/" "./NewGirl/S03/" "./Outlander/s01/")
cd "$PROCESS_PATH"
SAVEIFS=$IFS
IFS=$(echo -en "\n\b")
[ ! -d "$outputDir" ] && mkdir -p "$outputDir"
#echo "testing " "$outputDir/completed.lock"
if [ -f "$outputDir/completed.lock" ]; then
echo "area already converted. Exiting"
exit 0
fi
FILE_FLAGS=""
len=${#FILE_TYPES[@]}
last=$((len-1))
for ((i=0; i<$len;i++))
do
if [ "$len" -eq "1" ]; then
FILE_FLAGS="${FILE_FLAGS} -name \"*.${FILE_TYPES[i]}\""
continue
fi
if [ "$i" -eq "$last" ]; then
FILE_FLAGS="${FILE_FLAGS} -name \"*.${FILE_TYPES[i]}\""
else
FILE_FLAGS="${FILE_FLAGS} -name \"*.${FILE_TYPES[i]}\" -o"
fi
done
IGNORE_DIR_FLAGS=""
IGNORE_DIR_FLAGS="-not -path \"${outputDir}*\" -prune"
#parse exclude dirs array into find command arguments
for i in "${EXCLUDE_DIRS[@]}"
do
IGNORE_DIR_FLAGS="${IGNORE_DIR_FLAGS} -not -path \"${i}*\" -prune"
done
MY_COMMAND="/usr/bin/find . -type f ${FILE_FLAGS} ${IGNORE_DIR_FLAGS} -print0 | sort"
echo "My command = ${MY_COMMAND}"
#/usr/bin/find . -type f -name "*.avi" -o -name "*.mp4" -o -name "*.mkv" -not -path "./Greatest Events of WWII in Colour/*" -prune -not -path "./h265vids/*" -prune -print0
MY_RESULTS=("")
mapfile -d $'\0' MY_RESULTS < <(eval "$MY_COMMAND")
#for f in `find . -type f -name "*.avi" -o -name "*.mp4" -o -name "*.mkv" -not -path ${PROCESS_PATH}${outputDir} | sort`;
for f in "${MY_RESULTS[@]}"
do
audioformat=$(ffprobe -loglevel error -select_streams a:0 -show_entries stream=codec_name -of default=nw=1:nk=1 "$f")
videoformat=$(ffprobe -loglevel error -select_streams v:0 -show_entries stream=codec_name -of default=nw=1:nk=1 "$f")
if [ "$videoformat" = "hevc" ]; then
echo "${f} is already hevc encoded - skipping."
continue
fi
MYFILE=$(basename "$f")
FILESIZE=$(stat -c%s "$f")
echo "Base filesize: ${FILESIZE}"
if [ "$audioformat" = "aac" ]; then
#/usr/bin/ffmpeg -y -i "$f" -c:v libx265 -x265-params crf="$CRF" -c:a copy "$PROCESS_PATH""$outputDir"/"${MYFILE%.*}.x265.mkv"
/usr/local/bin/ffpb -y -i "$f" -map_chapters 0 -map_metadata 0 -c:s copy -c:v libx265 -x265-params crf="$CRF" -c:a copy "$PROCESS_PATH""$outputDir"/"${MYFILE%.*}.x265.mkv"
else
#/usr/bin/ffmpeg -y -i "$f" -c:v libx265 -x265-params crf="$CRF" -c:a aac "$PROCESS_PATH""$outputDir"/"${MYFILE%.*}.x265.mkv"
/usr/local/bin/ffpb -y -i "$f" -map_chapters 0 -map_metadata 0 -c:s copy -c:v libx265 -x265-params crf="$CRF" -c:a aac "$PROCESS_PATH""$outputDir"/"${MYFILE%.*}.x265.mkv"
fi
#echo "running mv ${outputDir}${MYFILE%.*}.x265.mkv" $(dirname "$f")
myDir=$(dirname "$f")
NEWFILESIZE=$(stat -c%s "${outputDir}${MYFILE%.*}.x265.mkv")
echo "New filesize: ${NEWFILESIZE}"
CMD="mv \"${outputDir}${MYFILE%.*}.x265.mkv\" \"${myDir}\""
echo "Running ${CMD}"
eval "$CMD"
# mv "$PROCESS_PATH""$outputDir/""${MYFILE%.*}.x265.mkv" $(dirname "$f")
CMD="mv \"${f}\" \"${outputDir}\""
echo "Running ${CMD}"
eval "$CMD"
if [ "$FILESIZE" -lt "$NEWFILESIZE" ]; then
echo "WARNING: ${f} is smaller than its converted form." >> CONVERTFILE.WARNINGS.txt
fi
# mv "$f" "$PROCESS_PATH""$outputDir"
done
touch "$outputDir/completed.lock"
IFS=$SAVEIFS