Update of /cvsroot/freevo/freevo/src/util
In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv14316/src/util
Modified Files:
videothumb.py
Log Message:
use secure tmpdir, add extra debugging on error
Index: videothumb.py
===================================================================
RCS file: /cvsroot/freevo/freevo/src/util/videothumb.py,v
retrieving revision 1.26
retrieving revision 1.27
diff -C2 -d -r1.26 -r1.27
*** videothumb.py 1 Jan 2005 18:45:46 -0000 1.26
--- videothumb.py 8 Jan 2005 13:46:46 -0000 1.27
***************
*** 43,59 ****
import popen2
import mevas
from stat import *
! _runqueue = []
! import logging
log = logging.getLogger()
# do not import freevo stuff when running this file
if __name__ != "__main__":
from util.popen import Process
import config
- import vfs
class MplayerThumbnail(Process):
--- 43,64 ----
import popen2
import mevas
+ import tempfile
+ import logging
from stat import *
! # freevo imports
! import vfs
! # get logging object
log = logging.getLogger()
+ # internal thumbnail queue
+ _runqueue = []
+
# do not import freevo stuff when running this file
if __name__ != "__main__":
from util.popen import Process
import config
class MplayerThumbnail(Process):
***************
*** 65,79 ****
Process.__init__(self, app)
def stdout_cb(self, line):
line.strip(' \t\n')
if line:
! log.info('>> %s' % line)
def stderr_cb(self, line):
line.strip(' \t\n')
if line:
! log.info('>> %s' % line)
def finished(self):
global _runqueue
_runqueue = _runqueue[1:]
--- 70,96 ----
Process.__init__(self, app)
+
def stdout_cb(self, line):
+ """
+ print debug from child as warning
+ """
line.strip(' \t\n')
if line:
! log.warning('>> %s' % line)
!
def stderr_cb(self, line):
+ """
+ print debug from child as warning
+ """
line.strip(' \t\n')
if line:
! log.warning('>> %s' % line)
!
def finished(self):
+ """
+ Job finished, run next if there is more
+ """
global _runqueue
_runqueue = _runqueue[1:]
***************
*** 86,122 ****
! def snapshot(videofile, imagefile=None, pos=None, update=True):
! """
! make a snapshot of the videofile at position pos to imagefile
! """
! global _runqueue
! if not imagefile:
! imagefile = os.path.splitext(videofile)[0] + '.jpg'
!
! if not update and os.path.isfile(imagefile) and \
! os.stat(videofile)[ST_MTIME] <= os.stat(imagefile)[ST_MTIME]:
! return
!
! if imagefile.endswith('.raw'):
! imagefile += '.tmp'
!
! for r, r_image in _runqueue:
! if r_image == imagefile:
return
-
- log.info('generate %s' % imagefile)
- args = [ config.MPLAYER_CMD, videofile, imagefile ]
! if pos != None:
! args.append(str(pos))
! job = (([os.environ['FREEVO_SCRIPT'], 'execute',
! os.path.abspath(__file__) ] + args), imagefile)
! _runqueue.append(job)
! if len(_runqueue) == 1:
! MplayerThumbnail(*_runqueue[0])
--- 103,133 ----
+ def snapshot(videofile, imagefile=None, pos=None, update=True):
+ """
+ make a snapshot of the videofile at position pos to imagefile
+ """
+ global _runqueue
+ if not imagefile:
+ imagefile = os.path.splitext(videofile)[0] + '.jpg'
! if not update and os.path.isfile(imagefile) and \
! os.stat(videofile)[ST_MTIME] <= os.stat(imagefile)[ST_MTIME]:
return
! for r, r_image in _runqueue:
! if r_image == imagefile:
! return
! log.info('generate %s' % imagefile)
! args = [ config.MPLAYER_CMD, videofile, imagefile ]
+ if pos != None:
+ args.append(str(pos))
+ job = (([os.environ['FREEVO_SCRIPT'], 'execute',
+ os.path.abspath(__file__) ] + args), imagefile)
+ _runqueue.append(job)
+ if len(_runqueue) == 1:
+ MplayerThumbnail(*_runqueue[0])
***************
*** 150,162 ****
# chdir to tmp so we have write access
! os.chdir('/tmp')
# call mplayer to get the image
child = popen2.Popen3((mplayer, '-nosound', '-vo', 'png', '-frames', '8',
'-ss', position, '-zoom', filename), 1, 100)
while(1):
data = child.fromchild.readline()
if not data:
break
child.wait()
child.fromchild.close()
--- 161,179 ----
# chdir to tmp so we have write access
! tmpdir = tempfile.mkdtemp('tmp', 'videothumb', '/tmp/')
! os.chdir(tmpdir)
# call mplayer to get the image
child = popen2.Popen3((mplayer, '-nosound', '-vo', 'png', '-frames', '8',
'-ss', position, '-zoom', filename), 1, 100)
+ child_output = ''
while(1):
data = child.fromchild.readline()
if not data:
break
+ child_output += data
+ for line in child.childerr.readlines():
+ child_output += line
+
child.wait()
child.fromchild.close()
***************
*** 167,171 ****
--- 184,192 ----
captures = glob.glob('000000??.png')
if not captures:
+ # strange, print debug to find the problem
print "error creating capture for %s" % filename
+ print child_output
+ os.chdir('/')
+ os.rmdir(tmpdir)
sys.exit(1)
***************
*** 189,203 ****
image.save(imagefile)
except:
try:
- import config
- import vfs
if not os.path.isdir(os.path.dirname(imagefile)):
os.makedirs(os.path.dirname(imagefile))
image.save(imagefile)
except Exception, e:
print 'unable to write file %s: %s' % \
(vfs.getoverlay(imagefile), e)
except (OSError, IOError), e:
! print 'saving image', e
for capture in captures:
--- 210,227 ----
image.save(imagefile)
except:
+ # unable to save image, try vfs dir
+ imagefile = vfs.getoverlay(imagefile)
try:
if not os.path.isdir(os.path.dirname(imagefile)):
os.makedirs(os.path.dirname(imagefile))
image.save(imagefile)
except Exception, e:
+ # strange, print debug to find the problem
print 'unable to write file %s: %s' % \
(vfs.getoverlay(imagefile), e)
+
except (OSError, IOError), e:
! # strange, print debug to find the problem
! print 'error saving image %s: %s' % (imagefile, e)
for capture in captures:
***************
*** 206,207 ****
--- 230,235 ----
except:
print "error removing temporary captures for %s" % filename
+
+ os.chdir('/')
+ os.rmdir(tmpdir)
+ sys.exit(0)
-------------------------------------------------------
The SF.Net email is sponsored by: Beat the post-holiday blues
Get a FREE limited edition SourceForge.net t-shirt from ThinkGeek.
It's fun and FREE -- well, almost....http://www.thinkgeek.com/sfshirt
_______________________________________________
Freevo-cvslog mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/freevo-cvslog