my python mp4 convert stripts(for psp)
It's easy but useful.
Convert .rmvb and avi file to mp4 file.
Convert .rmvb and avi file to mp4 file.
#!/usr/bin/env python
#coding=utf-8
import os,sys
'''
psp转换脚本
2007-12-31
qinchuan
'''
_filelist = []
def quote(name):
name = name.replace(" ","\ ")
name = name.replace("[","\[")
name = name.replace("(","\(")
name = name.replace("]","\]")
name = name.replace(")","\)")
return name
def getFile(path):
global _filelist
for item in os.listdir(path):
if os.path.isdir(os.path.join(path,item)):
getFile(os.path.join(path,item))
elif os.path.isfile(os.path.join(path,item)):
t = item.split(".")[-1].lower()
if t == "rmvb" or t =="rm" or t =="avi" or t =="mpg":
path = quote(path)
item = quote(item)
_filelist.append([path,item])
def change(str1,str2):
convert = "mencoder -oac lavc -ovc lavc -of lavf -lavcopts aglobal=1:vglobal=1:vcodec=mpeg4:acodec=libfaac -af lavcresample=24000 -vf harddup,scale -zoom -xy 320 -ofps 30000/1001 %s -o %s" % (str1,str2)
print convert
os.system(convert)
if __name__ == '__main__':
if len(sys.argv) > 3:
print "cpsp filepath outputpath"
exit(0)
elif len(sys.argv) == 3:
change(sys.argv[1],sys.argv[2])
elif len(sys.argv) == 2:
print "change all media file"
getFile(sys.argv[1])
for item in _filelist:
print os.path.join(item[0],item[1]),"/melo/mp4/"+item[1]+".mp4"
change(os.path.join(item[0],item[1]),"/melo/mp4/"+item[1]+".mp4")
#coding=utf-8
import os,sys
'''
psp转换脚本
2007-12-31
qinchuan
'''
_filelist = []
def quote(name):
name = name.replace(" ","\ ")
name = name.replace("[","\[")
name = name.replace("(","\(")
name = name.replace("]","\]")
name = name.replace(")","\)")
return name
def getFile(path):
global _filelist
for item in os.listdir(path):
if os.path.isdir(os.path.join(path,item)):
getFile(os.path.join(path,item))
elif os.path.isfile(os.path.join(path,item)):
t = item.split(".")[-1].lower()
if t == "rmvb" or t =="rm" or t =="avi" or t =="mpg":
path = quote(path)
item = quote(item)
_filelist.append([path,item])
def change(str1,str2):
convert = "mencoder -oac lavc -ovc lavc -of lavf -lavcopts aglobal=1:vglobal=1:vcodec=mpeg4:acodec=libfaac -af lavcresample=24000 -vf harddup,scale -zoom -xy 320 -ofps 30000/1001 %s -o %s" % (str1,str2)
print convert
os.system(convert)
if __name__ == '__main__':
if len(sys.argv) > 3:
print "cpsp filepath outputpath"
exit(0)
elif len(sys.argv) == 3:
change(sys.argv[1],sys.argv[2])
elif len(sys.argv) == 2:
print "change all media file"
getFile(sys.argv[1])
for item in _filelist:
print os.path.join(item[0],item[1]),"/melo/mp4/"+item[1]+".mp4"
change(os.path.join(item[0],item[1]),"/melo/mp4/"+item[1]+".mp4")
浙公网安备 33010602011771号