25
25
26
26
# USAGE
27
27
#
28
- # $ ./trimvid.sh <FILE> <START> [END]
28
+ # $ ./trimvid.sh <FILE> <START> [END] [OUTPUT-FILE]
29
29
30
30
# EXAMPLES
31
31
#
36
36
# number (in seconds), in which case it acts as a duration, OR a timecode in the
37
37
# form of HH:MM:SS, in which case it acts as a stop position.
38
38
#
39
+ # OUTPUT-FILE is optional. If no value is provided, it creates a video with
40
+ # "-trim" appended to the original filename.
41
+ #
39
42
# Trim video.mp4 beginning at 1 minute, 29 seconds to the end of the video:
40
43
# $ ./trimvid.sh video.mp4 00:01:29
41
44
#
44
47
# $ ./trimvid.sh video.mp4 00:01:29 90
45
48
#
46
49
# Trim video.mp4 beginning at 1 minute, 29 seconds and ending at 1 hour, 52
47
- # minutes, 56 seconds:
48
- # $ ./trimvid.sh video.mp4 00:01:29 01:52:56
50
+ # minutes, 56 seconds; name the video "final.mp4" :
51
+ # $ ./trimvid.sh video.mp4 00:01:29 01:52:56 final.mp4
49
52
50
53
# Revision history:
54
+ # 2021-12-30 Adding output filename option (1.3)
51
55
# 2021-11-29 Updating license (1.2)
52
56
# 2021-10-15 Adding help, dependency checks, and other standardization (1.1)
53
57
# 2021-10-11 Initial release (1.0)
54
58
# ---------------------------------------------------------------------------
55
59
56
60
# Standard variables
57
61
PROGNAME=${0##*/ }
58
- VERSION=" 1.2 "
62
+ VERSION=" 1.3 "
59
63
red=$( tput setaf 1)
60
64
green=$( tput setaf 2)
61
65
yellow=$( tput setaf 3)
@@ -95,7 +99,7 @@ signal_exit() {
95
99
# Usage: Separate lines for mutually exclusive options.
96
100
usage () {
97
101
printf " %s\n" \
98
- " ${bold} Usage:${reset} ${PROGNAME} <FILE> <START> [END]"
102
+ " ${bold} Usage:${reset} ${PROGNAME} <FILE> <START> [END] [OUTPUT-FILE] "
99
103
printf " %s\n" \
100
104
" ${PROGNAME} [-h|--help]"
101
105
}
@@ -123,6 +127,9 @@ the end of the video. If a value is provided, it can be either a decimal number
123
127
(in seconds), in which case it acts as a duration, OR a timecode in the form of
124
128
HH:MM:SS, in which case it acts as a stop position.
125
129
130
+ OUTPUT-FILE is optional. If no value is provided, it creates a video with
131
+ "-trim" appended to the original filename.
132
+
126
133
Trim video.mp4 beginning at 1 minute, 29 seconds to the end of the video:
127
134
128
135
${green} $ ${PROGNAME} video.mp4 00:01:29${reset}
@@ -133,9 +140,9 @@ and a half minutes):
133
140
${green} $ ${PROGNAME} video.mp4 00:01:29 90${reset}
134
141
135
142
Trim video.mp4 beginning at 1 minute, 29 seconds and ending at 1 hour, 52
136
- minutes, 56 seconds:
143
+ minutes, 56 seconds; name the video "final.mp4" :
137
144
138
- ${green} $ ${PROGNAME} video.mp4 00:01:29 01:52:56${reset}
145
+ ${green} $ ${PROGNAME} video.mp4 00:01:29 01:52:56 final.mp4 ${reset}
139
146
140
147
_EOF_
141
148
}
@@ -170,14 +177,18 @@ name="${1%.*}"
170
177
ext=" ${1##* .} "
171
178
start=$2
172
179
end=$3
180
+ output=$4
173
181
if [[ ! $file ]]; then
174
182
usage >&2
175
- error_exit " Filename must be provided."
183
+ error_exit " Input filename must be provided."
176
184
fi
177
185
if [[ ! $start ]]; then
178
186
usage >&2
179
187
error_exit " Start timecode must be provided."
180
188
fi
189
+ if [[ ! $output ]]; then
190
+ output=" ${name} -trim.${ext} "
191
+ fi
181
192
182
193
# Dependencies
183
194
ffmpeg=$( command -v ffmpeg)
205
216
fi
206
217
207
218
if [ -f " ${file} " ]; then # Make sure video file exists
208
- " $ffmpeg " -v quiet -stats -ss " $start " -i " $file " -t " $end " -c copy -map_metadata -1 -map_chapters -1 " $name " -trim. " $ext "
219
+ " $ffmpeg " -v quiet -stats -ss " $start " -i " $file " -t " $end " -c copy -map_metadata -1 -map_chapters -1 " $output "
209
220
210
- printf " %s\n" " ${green} Video trimmed. File: ${reset}${bold}${name} -trim. ${ext}${reset }"
221
+ printf " %s\n" " ${green} Video trimmed. File: ${reset}${bold}${output } "
211
222
else
212
223
error_exit " Video file '${file} ' not found."
213
224
fi
0 commit comments