-
Notifications
You must be signed in to change notification settings - Fork 0
/
converter
executable file
·293 lines (245 loc) · 6.17 KB
/
converter
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
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
#! /bin/bash
#lets write a video mp3 converter
#we are going to use ffmpeg as the library
#tasks:convert video to mp3,convert video to different video formats,create a video from an audio and an image,slow down the speed of the media
#Author:peter macharia
#declare the required variables
dpkg -l | grep -qw ffmpeg || sudo apt install ffmpeg
dpkg -l | grep -qw less || sudo apt install less
convert(){
echo "basic video to mp3 conversion"
#ffmpeg -i input.mp4 output.mp3
#we need input file,output file from the user if no output given use default
echo "enter the filename to convert(remember to put the extension)"
read inputFile
if [ -z "$inputFile" ]
then
echo "you must provide a file name to convert"
exit
else
if [ -f "$inputFile" ]
then
echo "enter the output filename or press enter for default"
read outPutFile
if [ -z "$outPutFile" ]
then
outPutFile="$inputFile"
else
outPutFile="$outPutFile".mp3
fi
else
echo "file $inputFile does not exist"
exit
fi
fi
echo "------------------------------"
echo "wait as your file is converted"
echo "------------------------------"
sleep 4
ffmpeg -y -i $inputFile -vn $outPutFile
if [ "$?" == "0" ]
then
echo "successfully saved your file as $outPutFile"
else
echo "something went wrong"
rm -i $outPutFile &> /dev/null
exit 1
fi
}
pic2Video(){
#we need to get picture ,audio and output file from use
echo "----------------------------------------"
echo "use an image and audio to create a video"
echo "----------------------------------------"
echo "enter the name of the image"
read imageFile
if [ -z "$imageFile" ]
then
echo "image must be provided"
exit
else
if [ -f "$imageFile" ]
then
#echo "we have an image"
echo "name of the audio file"
read audioFile
if [ -z "$audioFile" ]
then
echo "you have to provide an audio file"
exit 1
else
if [ -f "$audioFile" ]
then
echo "how do you want to save your file"
read pic2vidOut
if [ -z "$pic2vidOut" ]
then
pic2vidOut="$audioFile".mkv
else
pic2vidOut="$pic2vidOut".mkv
fi
else
echo "the file $audioFile does not exist"
exit 1
fi
echo "---------------------------------------"
echo "---combining your image and audio------"
echo "---------------------------------------"
sleep 3
#call ffmpeg to do the task
ffmpeg -loop 1 -y -i "$imageFile" -i "$audioFile" -acodec flac -vcodec libx264 -shortest -preset fast -vf scale=1280:-2 "$pic2vidOut"
if [ "$?" == "0" ]
then
echo "---------------------------"
echo "done:file saved as $pic2vidOut"
else
rm $pic2vidOut &> /dev/null
echo "something went wrong, try again"
exit 1
fi
fi
fi
fi
}
formatConvert(){
echo "basic video format conversion"
#convert any video file to a differnet format
echo "enter the video to convert"
read video
if [ -z "$video" ]
then
echo "you must provide a filename"
exit
else
if [ ! -f "$video" ]
then
echo "the file $video does not exist"
exit
fi
echo "enter the format you want"
read vidFormat
echo "how do you want to save the new file"
read videoName
if [ -z $videoName ]
then
$videoName="output"
fi
echo "----------------------------------"
echo "------This might take long--------"
echo "----------------------------------"
sleep 4
case "$vidFormat" in
avi)
echo "the format is avi"
ffmpeg -i $video -q:a 0 -q:v 0 -f avi -preset veryslow "$videoName".avi
exit
;;
webm)
echo "the format is webm"
ffmpeg -i $video -q:a 0 -q:v 0 -f webm "$videoName".webm
exit
;;
mp4)
echo "mp4 video format"
ffmpeg -i $video -q:a 0 -q:v 0 -f mp4 "$videoName".mp4
exit
;;
flv)
echo "flv video format"
ffmpeg -i $video -q:a 1 -q:v 1 -f flv "$videoName".flv
exit
;;
mpeg)
echo "mpeg format"
ffmpeg -i $video -q:a 1 -q:v 1 -f mpeg "$videoName".mpeg
exit
;;
ogg)
echo "ogg video fomat"
ffmpeg -i $video -q:a 1 -q:v 1 -f ogg "$videoName".ogg
exit
;;
m3u8)
echo "m3u8 video format-output inside $vidoeName.output directory"
mkdir "$videoName".output
ffmpeg -i $video -b:v 1M -g 60 -hls_time 2 -hls_list_size 0 -hls_segment_size 500000 "$videoName.output/$videoName".m3u8
exit
;;
*)
echo "check your format/may not be supported"
exit 1
;;
esac
fi
}
completed(){
echo "-------------------------------"
echo "proceess completed successfully"
echo "----------goodbye--------------"
echo "-------------------------------"
}
usage_help(){
less << _EOF_
converter version 1.0
Name:
converter
SYNOPSIS:
converter [options]
DESCRIPTION:
converter is a unix program that can be used to do various media
tasks.it can be used to convert video files to audio files,it
can also be used to create a video from audio and image and
other basic media conversions.
-This program uses ffmpeg video converter
USAGE:
converter -option
That simple,The program will guide you afterwords
OPTIONS:
-c : This option is used for basic video to audio conversion
if audio input is in a different directory provide
the full path to it
The output can also be directed to a different directory
by providing the absolute path
Note: if output name already exists they will be overwritten
-p : This option is used to create a video from a raw image
file and audio file.
-b : To convert your videos or audio from one format to another
say video from mkv to avi,audio from mp3 to mp4
--help: used to display this help page
-----------------------------------------------------------
AUTHOR: PETER MACHARIA
ADIOS
-----------------------------------------------------
_EOF_
}
#execution
#check the correct parameter usage first
if [ -z "$1" ]
then
# usage_help
echo "usage:check converter --help"
exit 0
fi
if [ "$1" == "-c" ]
then
convert
completed
# exit 0
elif [ "$1" == "-p" ]
then
pic2Video
completed
exit 0
elif [ "$1" == "--help" ]
then
usage_help
exit 0
elif [ "$1" == "-b" ]
then
formatConvert
completed
exit 0
else
echo "unrecoginzed option ,type: converter --help to learn more"
exit 1
fi