Yes that title is a question not an answer. A short amount of scouring the internet turned up nothing. We recently purchased a Canon S1 camera that takes pretty good mjpeg videos. Our DVD player, the Philips 642 will play divx video, yet I can't seem to convert the mjpeg videos correctly. If anyone has any clues feel free to pipe in. In the meantime here's a script to spider a directory and create a shell script to convert all videos found to SVCD (since my player will play those). It also renames the files to include their date in the name.
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 | #!/usr/bin/python
import sys
import os
import stat
import time
class DirectoryWalker:
"""from http://aspn.activestate.com/ASPN/Mail/Message/541112"""
def __init__(self, directory):
self.stack = [directory]
self.files = []
self.index = 0
def __getitem__(self, index):
while 1:
try:
file = self.files[self.index]
self.index = self.index + 1
except IndexError:
# pop next directory from stack. this raises
# an IndexError if there's nothing more to do
self.directory = self.stack.pop()
if os.access(self.directory, os.R_OK):
try:
#windows might not really have "read" permissions
#see http://mail.python.org/pipermail/python-bugs-list/2004-August/024493.html
self.files = os.listdir(self.directory)
self.index = 0
except Exception, e:
#print e
continue
else:
# got a filename
if file.startswith("."):
#skip hidden files
continue
fullname = os.path.join(self.directory, file)
if os.path.isdir(fullname) and not os.path.islink(fullname):
# it's a directory; save it for later
self.stack.append(fullname)
return fullname
class Date:
def __init__(self, secs):
self.gtime = time.localtime(secs)
def getYear(self):
return str(self.gtime[0])
def getMonth(self):
months = {1:"January",2:"February",3:"March",4:"April",
5:"May",6:"June",7:"July",8:"August",9:"September",
10:"October",11:"November",12:"December"}
return str(months[self.gtime[1]])
def getPaddedMonth(self):
return self.pad(self.gtime[1])+self.getMonth()
def pad(self, num, totalWidth=2):
"""pad upto total with on left side with zeros
"""
zeros = "0"*(totalWidth-len(str(num)))
return zeros+str(num)
def getDay(self):
day = str(self.gtime[2])
#pad with leading zeros
return self.pad(day)
def strftime(self, fmt):
return time.strftime(fmt, self.gtime)
def getMDY(self):
return self.getMonth()+self.getDay()+self.getYear()
def cpDir(indir, outdir):
for filename in DirectoryWalker(indir):
if filename.endswith("avi"):
filestat = os.stat(filename)
mtime = filestat[stat.ST_MTIME]
gtime = time.gmtime(mtime)
date = Date(mtime)
basename = os.path.basename(filename)
outname = date.strftime("%y%m%d") + basename[:basename.index(".avi")] + ".mpg"
outpath = os.path.join(outdir, outname)
#change this command as desired
print """ffmpeg -i %s -target ntsc-svcd -s 640x480 %s"""%(filename,outpath)
if __name__=="__main__":
#crawl arg1 and write a command to output it as SVCD in arg2
cpDir(sys.argv[1], sys.argv[2])
|