-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathextract-audio
46 lines (40 loc) · 952 Bytes
/
extract-audio
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
#!/bin/bash
# Description: This script extracts audio from video using ffmpeg.
# Dependency: ffmpeg
# Prints an error message to stderr
print_error() {
echo "Error: $1" >&2
exit 1
}
# Prints an help message
print_help() {
echo "extract-audio, It extracts audio from video using ffmpeg"
echo " Usage:"
echo " extract-audio [input-filename] [output-filename]"
}
# Check if ffmpeg is installed
if ! command -v ffmpeg >/dev/null 2>&1; then
echo "Error: 'ffmpeg' is not installed. Please install it using your package manager."
exit 1
fi
case "${1:-}" in
# Exit with code 0 only if help was explicitly requested
-h|--help)
print_help
exit 0
;;
'')
print_help
exit 1
;;
esac
# checks the file exist and extract audio
if [[ -f "$1" ]]; then
if [[ "$2" != "" ]]; then
ffmpeg -i "$1" "$2"
else
print_error "\"$2\": no output file-name given."
fi
else
print_error "\"$1\": no such file."
fi