-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathmain.sh
54 lines (45 loc) · 1.15 KB
/
main.sh
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
#!/bin/sh
function help(){
echo "Use : sh main.sh [-r][-h] -p <path/to/parent/directory>"
echo -e "\t -h \t shows this help utility"
echo -e "\t -r \t removes source files after conversion"
}
PWD=$(pwd)
DELETE="false"
#Check for flags
while getopts :p:rh aflag
do
case $aflag in
r) DELETE="true";;
p) PARENT_DIR=$OPTARG;;
h) help;exit 0;;
?) echo "Illegal flag : $aflag, terminating";exit -1;;
esac
done
cd "$PARENT_DIR"
FILE_LIST=$(find -type f -exec file -N -i -- {} + | sed -n 's!: video/[^:]*$!!p')
DEL_LIST=$FILE_LIST
echo "$FILE_LIST"
echo "Do you want to convert these files?"
read y
if [ $y == 'y' ]
then
while read -r FILE_LIST
do
echo "$FILE_LIST"
ffmpeg -loglevel 2 -i "$FILE_LIST" -c:v libx265 -preset ultrafast -x265-params lossless=0 "${FILE_LIST%.*}".hevc.mkv < /dev/null
echo "complete"
done <<< "$FILE_LIST"
fi
echo $FILE_LIST
#block to remove converted files
if [ $DELETE == 'true' ]
then
while read -r DEL_LIST
do
echo "$DEL_LIST"
rm "$DEL_LIST"
echo "Successfully removed $DEL_LIST"
done <<< "$DEL_LIST"
fi
cd "$PWD"