This repository has been archived by the owner on Mar 16, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 27
/
Copy pathavi2mp4.py
executable file
·96 lines (77 loc) · 2.71 KB
/
avi2mp4.py
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
#!/usr/bin/python
##############################################################################
#
# Copyright (C) 2005 Kevin Deldycke <[email protected]>
#
# This program is Free Software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License
# as published by the Free Software Foundation; either version 2
# of the License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
#
##############################################################################
import os, sys, glob, getopt
from commands import getstatusoutput
INPUT_FILE_PATTERN = '*.avi'
OUTPUT_FILE_EXTENSION = '.mp4'
def usage():
print """Usage : batch.py [options]
** General options
--dry
Don't execute commands, but print them.
--silent
Don't output status messages on screen.
-h, --help
Show this screen.
"""
def main():
# Get all parameters
try:
opts, args = getopt.getopt(sys.argv[1:], "h", ["help", "dry", "silent"])
except getopt.GetoptError:
# print help information and exit:
usage()
sys.exit(2)
# Get all user's options and define internal variables
dry_run = False
silent = False
for o, a in opts:
if o in ("-h", "--help"):
usage()
sys.exit()
if o == "--dry":
dry_run = True
if o == "--silent":
silent = True
# Get the list of files to encode
current_folder_path = os.path.abspath('./')
files = glob.glob(("%s/%s") % (current_folder_path, INPUT_FILE_PATTERN))
if not files:
sys.exit("No file to process.")
input_file_list = []
for file in files:
if os.path.isfile(file):
input_file_list.append(os.path.basename(file))
# Do the command for each file
for input_file in input_file_list:
input_file_elements = input_file.split('.')
output_file = '.'.join(input_file_elements[:-1]) + OUTPUT_FILE_EXTENSION
# Create the shell command string
command = "vlc --sout-all \"%s\" :sout='#transcode{vcodec=h264,acodec=mp3,ab=32,channels=1,audio-sync}:std{access=file,mux=mp4,url=\"%s\"}' vlc:quit -I dummy" % (input_file, output_file)
if not silent:
print """Do "%s"...""" % (command)
# Do the shell command
if not dry_run:
getstatusoutput(command)
if not silent:
print "Done."
if __name__ == "__main__":
main()