-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathbmm-converter_mp4
executable file
·83 lines (67 loc) · 2.59 KB
/
bmm-converter_mp4
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
#!/bin/bash
## load enviroment variables
if [ -f $HOME/bmm/.env ]; then
. $HOME/bmm/.env
else
echo -e "FATAL ERROR: .env not found.$\n
Use bmm-setup_enviroment to create one.\nAborting...";
exit 1;
fi
HB_PRESETS=("Very Fast 1080p30" "Very Fast 720p30" "Very Fast 480p30")
FF_OPTIONS=()
FORMATS=("mp4" "avi" "mkv" "rm")
##temp for test
PRESET="Very Fast 720p30"
FORMAT="avi"
convert_ffmpeg (){
dep_check ffmpeg;
}
convert_handbrake () {
dep_check handbrake-cli;
while IFS= read -d '' -r ITEM
do
echo -e "Target: ${OK}$ITEM${NC}" # full path of item.
## MOVE ORIGINAL to junk
FILE=${ITEM##*/} # individual file name.
echo "Moving original file: $FILE"
mv "$ITEM" "$VIDEOSJUNK"
## SET SOURCE
SOURCE="$VIDEOSJUNK$FILE"
echo -e "Processing source: ${WARN}$SOURCE${NC}"
## SET DEST
EXT=${ITEM##*.} # get file extension
EXT=$(echo $EXT | tr "[:upper:]" "[:lower:]") # normalize extension
TARGET="${ITEM%.*}.$EXT" # normalize target destination ext
DEST="${TARGET/."${FORMAT}"}.mp4" #set destination path.ext
echo -e "Destination: ${WARN}$DEST${NC}"
## DO STUFF
eval $(echo -e "handbrake-cli -i \"$SOURCE\" -o \"$DEST\" --preset \"$PRESET\" --optimize")
done< <(find "$MEDIAROOT" -iname "*.$FORMAT" -print0)
}
## HANDBRAKE args
if [ "$1" == '-hb' ] || [ "$1" == '--handbrake' ]; then
MEDIAROOT=$2
FORMAT=$3
PRESET=$4
convert_handbrake;
elif [ "$1" == '-hp' ] || [ "$1" == '--handbrake-presets' ]; then
for preset in "${HB_PRESETS[@]}"
do
((i++))
echo -e "Handbrake preset $i: ${OK}\"$preset\"${NC}"
done
## FFMPEG args (todo)
## HELP
elif [ "$1" == '-h' ] || [ "$1" == '--help' ]; then
if ! command -v $BANNER >> /dev/null; then echo -e "${WARN}BASH MEDIA MANAGER${NC}"; else eval $BANNER; fi
echo -e "${HEAD}Converter MP4"
echo -e "${OK}Converts VIDEO files to ${WARN}\"H.264 AAC-2.0 Web-Optimized .mp4\"${OK} for streaming.${NC}\n"
echo -e "Use with no arguements to enter the GUI."
echo -e "Usage: bmm-converter_mp4 [-arg] [--arg] [args]\n"
echo -e " -hp [--handbrake-presets] -> List optimal handbrake presets for streaming."
echo -e " -hb [--handbrake] -> Convert 'format' files from 'target folder' using \"preset\"."
echo -e " (Ex: bmm-converter_mp4 --handbrake \"/mnt/videos/\" \"avi\" \"Very Fast 720p30\")"
echo -e " -h [--help] -> Shows this screen."
else
echo 'dialog menu will be called here soon... try --help'
fi