-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmts2mp4.bash
125 lines (107 loc) · 3.69 KB
/
mts2mp4.bash
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
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
#!/bin/bash
shopt -s extglob
function func_help()
{
echo " --help or -h: this help"
echo " --in=<input file name> or -i=<>"
#echo " --insuffix=<filename> where filename must match this input suffix ex: MTS of name.MTS files -s=<>"
echo " --donothing or --testrun or -d Dont actuall do anything, just output commands"
echo " --dir=<dir>rectory in which to perform action"
#echo " --verbose|-v Verbose output"
}
CMD="ffmpeg.exe"
out_suffix="mp4"
in_suffix="MTS"
start_dir=`pwd`
for arg in "$@" ; do
#echo "DELME0: Argument: ${arg}"
case $arg in
--help|-h)
func_help
exit
;;
--in=*|-i=*)
if [[ "" != "$basename" ]] ; then
echo "Warning: Basename was already set to ${basename}. Resetting to new value."
fi
basename=`echo ${arg} | awk -F'=' '{print $2}'`
;;
#--insuffix=*|-s=*)
#
#if [[ "" != "$in_suffix" ]] ; then
#echo "Warning: Suffix was already set to ${in_suffix}. Resetting to new value."
#fi
#
#in_suffix=`echo ${arg} | awk -F'=' '{print $2}'`
#;;
--dono*|--testrun|-d)
test_run="true"
;;
--dir=*)
newdir=`echo ${arg} | awk -F'=' '{print $2}'`
;;
--verbose|-v)
verb="true"
;;
*)
echo "Not sure what to do with: $arg .. Ignoring..."
func_help
exit
;;
esac
done
if [[ "" != ${verb} ]] ; then echo "newdir=${newdir}" ; fi
cd "$newdir"
cwd=`pwd`
if [[ "" != ${verb} ]] ; then echo "inputfile=${basename}" ; fi
if [[ "" != ${verb} ]] ; then echo "CMD=${CMD}" ; fi
if [[ "" != ${verb} ]] ; then echo "test_run=${test_run}" ; fi
if [[ "" != ${verb} ]] ; then echo "start_dir=${start_dir}" ; fi
if [[ "" != ${verb} ]] ; then echo "working dir=${cwd}" ; fi
#ffmpeg.exe -i "E:\Video\TKD\2011 friendship\2011 friendship_00060.mts" -acodec copy -vcodec copy "E:\Video\TKD\2011 friendship\2011 friendship_00060.mp4
if [[ "" == "${basename}" && "" == "${newdir}" ]] ; then
echo -e "\e[31mError:\e[0m One of inputfile or directory must be set."
func_help
exit 1
elif [[ "" != "${basename}" && "" != "${newdir}" ]] ; then
echo -e "\e[31mError:\e[0m Only one of inputfile or directory is allowed to be set."
func_help
exit 1
elif [[ "" == "${basename}" ]] ; then
basename="$newdir"
fi
if [[ ! -e ${basename} ]] ; then
echo "File: ${basename} does not exist"
elif [[ -f ${basename} ]] ; then
file_bad_basename=`echo ${basename} | awk -F'.' '{$NF="";print $0}'`
file_basename=`echo ${file_bad_basename} | sed 's/ $//'`
if [[ "" != "$test_run" ]] ; then
echo -e "\e[36mtestrun:\e[0m ${CMD} -i ${basename} -acodec copy -vcodec copy ${file_basename}.${out_suffix}"
else
echo ${CMD} -i "${basename} -acodec copy -vcodec copy ${file_basename}.${out_suffix}"
${CMD} -i "${basename}" -acodec copy -vcodec copy "${file_basename}.${out_suffix}"
fi
elif [[ -d ${newdir} ]] ; then
for file in * ; do
echo DELME: file: ${file}
file_suf=`echo ${file} | awk -F'.' '{print $NF}'`
file_bad_basename=`echo ${file} | awk -F'.' '{$NF="";print $0}'`
#HACK ALERT: every file has a space placed at the end making the tests fail
file_basename=`echo ${file_bad_basename} | sed 's/ $//'`
if [[ ! -f $file ]] ; then
if [[ "" != ${verb} ]] ; then echo -e "\e[33mskipping\e[0m \"${file}\" (not a file after all)" ; fi
elif [[ "${file_suf}" == "${in_suffix}" ]] ; then
newname=${basename}_${file}
if [[ "" != "$test_run" ]] ; then
echo -e "\e[36mtestrun:\e[0m ${CMD} -i ${file} -acodec copy -vcodec copy ${file_basename}.${out_suffix}"
else
echo ${CMD} -i "${file} -acodec copy -vcodec copy ${file_basename}.${out_suffix}"
${CMD} -i "${file}" -acodec copy -vcodec copy "${file_basename}.${out_suffix}"
fi
else
echo -e "\e[33mskipping\e[0m \"${file}\" (no input suffix match)"
fi
done
else
echo "I'm confused about File: ${file}."
fi