use mplayer gst is to slow

This commit is contained in:
j 2008-07-03 19:04:17 +02:00
commit a6d52af083
2 changed files with 46 additions and 12 deletions

View file

@ -141,7 +141,9 @@ def extract_frame(movie_file, timestamp, img_folder, width=128, offset = 0, redo
mplayer_options = '' mplayer_options = ''
mplayer_options += " '%s'" % movie_file mplayer_options += " '%s'" % movie_file
mplayer_options += " -ss '%s' -frames 2" % (timestamp_in_file) mplayer_options += " -ss '%s' -frames 2" % (timestamp_in_file)
mplayer_options += " -vo jpeg:quality=90 -vf scale -zoom -xy %d " % width mplayer_options += " -vo jpeg:quality=90 "
if width > 0:
mplayer_options += " -vf scale -zoom -xy %d " % width
mplayer_options += " -ao null" mplayer_options += " -ao null"
mplayer = "mplayer %s >/dev/null 2>&1" % mplayer_options mplayer = "mplayer %s >/dev/null 2>&1" % mplayer_options
frame = os.path.join(img_folder, "%s.%s" % (timestamp.replace(':', '.'), img_extension)) frame = os.path.join(img_folder, "%s.%s" % (timestamp.replace(':', '.'), img_extension))
@ -161,15 +163,46 @@ def extract_frame(movie_file, timestamp, img_folder, width=128, offset = 0, redo
print "update the cache %s missing" % movie_file print "update the cache %s missing" % movie_file
shutil.rmtree(framedir) shutil.rmtree(framedir)
def extract_still(movie_file, png_file, inpoint): def extract_still(movie_file, timestamp, img_folder, width=128, offset = 0, redo = False):
import warnings
warnings.filterwarnings("ignore", "tempnam")
ext = movie_file.split('.')[-1] ext = movie_file.split('.')[-1]
if ext in ('sub', 'srt'): if ext in ('sub', 'srt'):
print "this is not a movie file, will not try to extract frames" print "this is not a movie file, will not try to extract frames"
return return
inpoint = time2ms(inpoint) framedir = os.tempnam()
extractClipScript = abspath(join(dirname(__file__), "tools/extract_frame.py"))
cmd = '''%s "%s" "%s" %s 0 -1''' % (extractClipScript, movie_file, png_file, inpoint) os.mkdir(framedir)
run_command(cmd.encode('utf-8'), 100) os.chdir(framedir)
if offset:
timestamp_in_file = shift_time(-offset, timestamp)
else:
timestamp_in_file = timestamp
if os.path.exists(movie_file):
mplayer_options = ''
mplayer_options += " '%s'" % movie_file
mplayer_options += " -ss '%s' -frames 2" % (timestamp_in_file)
mplayer_options += " -vo png "
if width > 0:
mplayer_options += " -vf scale -zoom -xy %d " % width
mplayer_options += " -ao null"
mplayer = "mplayer %s >/dev/null 2>&1" % mplayer_options
frame = os.path.join(img_folder, "%s.%s" % (timestamp.replace(':', '.'), 'png'))
if redo or not os.path.exists(frame):
print mplayer.encode('utf-8')
os.system (mplayer.encode('utf-8'))
files = os.listdir(framedir)
if files:
print "creating frame ", frame
shutil.move(os.path.join(framedir,files[-1]), frame)
if len(files)>1:
for f in files[:-2]:
print "unlink", f
os.unlink(f)
time.sleep(0.1)
else:
print "update the cache %s missing" % movie_file
shutil.rmtree(framedir)
def extract_poster_still(movie_file, png_file, inpoint): def extract_poster_still(movie_file, png_file, inpoint):
ext = movie_file.split('.')[-1] ext = movie_file.split('.')[-1]

View file

@ -431,6 +431,11 @@ class ArchiveFile(SQLObject):
f = join(cache.cache_root, 'frame', self.md5sum[:4], self.md5sum) f = join(cache.cache_root, 'frame', self.md5sum[:4], self.md5sum)
oxdb_makedir(f) oxdb_makedir(f)
return f return f
def _get_stillFolder(self):
f = join(cache.cache_root, 'still', self.md5sum[:4], self.md5sum)
oxdb_makedir(f)
return f
def _get_timelineFile(self): def _get_timelineFile(self):
return join(cache.cache_root, 'timeline', self.md5sum[:4], "%s.png" % self.md5sum) return join(cache.cache_root, 'timeline', self.md5sum[:4], "%s.png" % self.md5sum)
@ -438,10 +443,6 @@ class ArchiveFile(SQLObject):
def _get_posterStillFile(self): def _get_posterStillFile(self):
return join(cache.cache_root, 'posterStill', self.md5sum[:4], "%s.png" % self.md5sum) return join(cache.cache_root, 'posterStill', self.md5sum[:4], "%s.png" % self.md5sum)
def stillFile(self, position):
position = oxlib.getValidFilename(position)
return join(cache.cache_root, 'still', self.md5sum[:4], "%s_%s.png" % (self.md5sum, position))
def removeMiniMovie(self): def removeMiniMovie(self):
if exists(self.mini_movie_file): if exists(self.mini_movie_file):
os.remove(self.mini_movie_file) os.remove(self.mini_movie_file)
@ -740,13 +741,13 @@ class ArchiveFile(SQLObject):
return cache.loadPosterStill(self, position) return cache.loadPosterStill(self, position)
def still(self, position): def still(self, position):
still = self.stillFile(position) still = os.path.join(self.stillFolder, "%s.%s" % (position.replace(':', '.'), 'png'))
if not exists(still): if not exists(still):
oxdb_makedir(dirname(still)) oxdb_makedir(dirname(still))
movieFile = self.absolutePath movieFile = self.absolutePath
if os.path.splitext(movieFile)[-1] in ('.mov', '.mpg', '.mpeg'): if os.path.splitext(movieFile)[-1] in ('.mov', '.mpg', '.mpeg'):
movieFile = self.mini_movie_file movieFile = self.mini_movie_file
extract_still(movieFile, still, position) extract_still(movieFile, position, self.stillFolder, -1)
if exists(still): if exists(still):
return cache.loadFile(still) return cache.loadFile(still)
return '' return ''