-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbatchconvert.sh
More file actions
executable file
·47 lines (37 loc) · 954 Bytes
/
Copy pathbatchconvert.sh
File metadata and controls
executable file
·47 lines (37 loc) · 954 Bytes
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
#!/bin/bash
### Mass convert media files with ffmpeg
# Files path
function read_source_files() {
echo "Enter path of files to convert :"
echo "(Ex: /home/user/Videos/*.avi ou ../*.*)"
read -r source_files
source_directory=$(dirname "${source_files}" | sort | uniq )
if [[ ! -d "${source_directory}" ]]; then
echo "No files there. Exiting..."
exit 1
fi
}
# Extension choice
function read_extension() {
echo "Enter format you wish to convert the files to :"
echo "(Ex: mp3, mp4, etc...)"
read -r extension
if [[ -z $extension ]]; then
echo "Non valid extension. Exiting..."
exit 1
fi
}
# Loop to convert all files
function convert() {
for filename in "$source_files"; do
basepath=${filename%.*} # Remove extension
basename=${basepath##*/} # Remove path
ffmpeg -i "${filename}" /home/"$(whoami)"/"${basename}"."${extension}"
done
echo "DONE!"
}
read_source_files
read_extension
convert
ls /home/"$(whoami)"
exit 0