-
Notifications
You must be signed in to change notification settings - Fork 0
/
cpv
executable file
·99 lines (88 loc) · 2.8 KB
/
cpv
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
#!/usr/bin/env bash
#==================================================================================================
# NAME: Convert & Proxy Video - CPV
# USAGE: cpv.sh [-i filename.xxx] convert file, or [-a] convert all .xxx files in directory
#
# DESCRIPTION: Converts video files to .mkv with additional lower resolution proxy files
# WEBSITE: https://www.elsewebdevelopment.com/
#
# REQUIREMENTS: FFmpeg installed in the $PATH
# AUTHOR: David Else
# COMPANY: Else Web Development
# VERSION: 1.0
# add -vf drawtext="fontfile=/usr/share/fonts/cantarell/Cantarell-Regular.otf: text='Test Text'"
#==================================================================================================
set -eu
normal=$(tput sgr0)
red=$(tput setaf 1)
green=$(tput setaf 2)
suffix=".MTS" # tested .mp4
log="-loglevel warning"
strip_subs="-sn"
prompt_user() {
clear
echo -e "The following will be stream copied to .mkv into the current directory:\n${green}$1${normal}\n"
read -p "Create additional proxy video files? (y/N) " -n 1
echo
}
create_stream_copy() {
local new_filename="${original_file%"$suffix"}.mkv"
local command=(ffmpeg $log -i "$original_file"
-c copy "$strip_subs"
"$new_filename")
"${command[@]}"
echo "Created file ${green}$new_filename${normal}"
}
create_proxy_copy() {
local video_settings="libx264 -preset ultrafast -crf 0 -vf scale=480:-1"
local new_filename="${original_file%"$suffix"}-proxy.mkv"
local command=(ffmpeg $log -i "$original_file"
-c:v $video_settings
-c:a copy "$strip_subs"
"$new_filename")
"${command[@]}"
echo "Created file ${green}$new_filename${normal}"
}
create_files() {
original_file="$1"
create_stream_copy
if [[ $REPLY =~ ^[Yy]$ ]]; then
create_proxy_copy
fi
}
while getopts c:i:a opt; do
case $opt in
c)
suffix="${OPTARG}"
;;
i)
# now we can't use different extensions for this option
if [[ $OPTARG == *"$suffix" ]]; then
prompt_user "\n$OPTARG"
create_files "$OPTARG"
else
echo "${red}Invalid file extension, must be $suffix${normal}" && exit 1
fi
;;
a)
files_preview=()
for file_preview in *"$suffix"; do
[ -f "$file_preview" ] || break
files_preview+=("\n$file_preview")
done
: "${files_preview:="empty"}"
if [ "$files_preview" == "empty" ]; then
echo "${red}There are no files with the container $suffix${normal}" && exit 1
fi
prompt_user "${files_preview[*]}"
for file in *"$suffix"; do
[ -f "$file" ] || break
create_files "$file"
done
;;
?)
exit
;;
esac
done
shift $((OPTIND - 1))