- Timestamp:
- 03/11/07 23:54:01 (2 years ago)
- git-parent:
- Files:
-
- plugins/video/transcode.py (modified) (7 diffs)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
plugins/video/transcode.py
r22c71e0 rcafe669 1 import subprocess, shutil, os, re, sys, ConfigParser 1 import subprocess, shutil, os, re, sys, ConfigParser, time, lrucache 2 2 3 3 from Config import config 4 5 info_cache = lrucache.LRUCache(1000) 4 6 5 7 FFMPEG = config.get('Server', 'ffmpeg') … … 31 33 32 34 def transcode(inFile, outFile): 33 cmd = [FFMPEG, '-i', inFile, '-vcodec', 'mpeg2video', '-r', '29.97', '-b', '4096K'] + select_aspect(inFile) + ['-comment', 'pyTivo.py', '-ac', '2', '-ab', '192', '-f', 'vob', '-' ]35 cmd = [FFMPEG, '-i', inFile, '-vcodec', 'mpeg2video', '-r', '29.97', '-b', '4096K'] + select_aspect(inFile) + ['-comment', 'pyTivo.py', '-ac', '2', '-ab', '192','-ar', '44100', '-f', 'vob', '-' ] 34 36 ffmpeg = subprocess.Popen(cmd, stdout=subprocess.PIPE) 35 37 try: 36 38 shutil.copyfileobj(ffmpeg.stdout, outFile) 37 39 except: 38 if mswindows: 39 win32kill(ffmpeg.pid) 40 else: 41 import os, signal 42 os.kill(ffmpeg.pid, signal.SIGKILL) 43 40 kill(ffmpeg.pid) 41 44 42 def select_aspect(inFile): 45 43 type, width, height, fps, millisecs = video_info(inFile) … … 127 125 128 126 def video_info(inFile): 127 print inFile 128 if inFile in info_cache: 129 return info_cache[inFile] 130 129 131 if (inFile[-5:]).lower() == '.tivo': 132 info_cache[inFile] = (True, True, True, True, True) 130 133 return True, True, True, True, True 134 131 135 cmd = [FFMPEG, '-i', inFile ] 132 136 ffmpeg = subprocess.Popen(cmd, stderr=subprocess.PIPE, stdout=subprocess.PIPE, stdin=subprocess.PIPE) 137 138 # wait 4 sec if ffmpeg is not back give up 139 for i in range(80): 140 time.sleep(.05) 141 if not ffmpeg.poll() == None: 142 break 143 144 if ffmpeg.poll() == None: 145 kill(ffmpeg.pid) 146 info_cache[inFile] = (None, None, None, None, None) 147 return None, None, None, None, None 148 133 149 output = ffmpeg.stderr.read() 150 134 151 durre = re.compile(r'.*Duration: (.{2}):(.{2}):(.{2})\.(.),') 135 152 d = durre.search(output) … … 140 157 codec = x.group(1) 141 158 else: 159 info_cache[inFile] = (None, None, None, None, None) 142 160 return None, None, None, None, None 143 161 … … 148 166 height = int(x.group(2)) 149 167 else: 168 info_cache[inFile] = (None, None, None, None, None) 150 169 return None, None, None, None, None 151 170 … … 155 174 fps = x.group(1) 156 175 else: 157 return None, None, None, None, None 176 info_cache[inFile] = (None, None, None, None, None) 177 return None, None, None, None, None 178 179 rezre = re.compile(r'.*film source: (\d+).*') 180 x = rezre.search(output.lower()) 181 if x: 182 fps = x.group(1) 158 183 159 184 millisecs = ((int(d.group(1))*3600) + (int(d.group(2))*60) + int(d.group(3)))*1000 + (int(d.group(4))*100) 185 info_cache[inFile] = (codec, width, height, fps, millisecs) 160 186 return codec, width, height, fps, millisecs 161 187 … … 166 192 return False 167 193 194 def kill(pid): 195 if mswindows: 196 win32kill(pid) 197 else: 198 import os, signal 199 os.kill(pid, signal.SIGKILL) 200 168 201 def win32kill(pid): 169 202 import ctypes
