clips frames

This commit is contained in:
j 2007-07-10 20:01:41 +00:00
parent 5a9fd08511
commit b3558df3be
4 changed files with 42 additions and 27 deletions

View file

@ -31,9 +31,8 @@ def saveFile(f_name, data):
def loadStaticFile(fname):
return loadFile(join(dirname(abspath(__file__)), "static", fname))
def loadFrame(afile, position):
position = basename(position)
position = basename(position).replace(':', '.')
frame = join(afile.frameFolder, '%s.%s' % (position, img_extension))
if not exists(frame):
afile.extractFrame(position)
@ -42,7 +41,7 @@ def loadFrame(afile, position):
return ''
def loadClip(afile, position):
position = basename(position)
position = basename(position).replace(':', '.')
flash = join(afile.frameFolder, '%s.%s' % (position, 'flv'))
if not exists(flash):
afile.extractClip(position)

View file

@ -31,16 +31,19 @@ class Root(controllers.RootController):
if action == 'metadata':
return dict(metadata = f)
elif action in ('timeline', 'timeline.png'):
cherrypy.response.headerMap['Content-Type'] = "image/jpeg"
cherrypy.response.headerMap['Content-Type'] = "image/png"
cherrypy.response.headerMap["Expires"] = httpExpires(60*60*24*15)
return f.timeline()
elif position: #clip / frame
cherrypy.response.headerMap['Content-Type'] = "image/jpeg"
cherrypy.response.headerMap["Expires"] = httpExpires(60*60*24*15)
position = position.replace('.png', '').replace('.jpg', '')
position = position.replace('.flv', '')
position = position.replace('-', ':').replace('.',':')
if action == 'clip':
cherrypy.response.headerMap['Content-Type'] = "video/x-flv"
cherrypy.response.headerMap["Expires"] = httpExpires(60*60*24*15)
return f.clip(position)
elif action == 'frame':
cherrypy.response.headerMap['Content-Type'] = "image/jpeg"
cherrypy.response.headerMap["Expires"] = httpExpires(60*60*24*15)
return f.frame(position)
return dict()

View file

@ -8,14 +8,15 @@ import turbogears
import re
from urllib import quote, quote_plus
import os
from os.path import abspath, join, dirname
from os.path import abspath, join, dirname, exists
from datetime import datetime
import time
import math
from glob import glob
import shutil
from scrapeit.utils import read_url
import socket
import cache
import oxdb_import
from oxdb_utils import oxdb_title, oxdb_director, oxdb_id
@ -40,9 +41,12 @@ class Archive(SQLObject):
def notifyFrontend(self, action, md5sum):
if self.baseUrlFrontend:
dto = socket.getdefaulttimeout()
socket.setdefaulttimeout(100)
url = "%s/%s?md5sum=%s" % (self.baseUrlFrontend, action, md5sum)
result = read_url(url)
print "Frontend:", result
socket.setdefaulttimeout(dto)
def _get_files(self):
q = ArchiveFile.select(ArchiveFile.q.archiveID == self.id)
@ -263,7 +267,7 @@ class ArchiveFile(SQLObject):
def updateMeta(self):
self.findSubtitleLink()
if os.path.exists(self.absolutePath):
if exists(self.absolutePath):
info = midentify.identify(self.absolutePath)
self.length = info['length']
self.width = info['width']
@ -338,7 +342,7 @@ class ArchiveFile(SQLObject):
return join(cache.cache_root, 'mini', self.md5sum[:4], "%s.avi" % self.md5sum)
def _get_frameFolder(self):
f = join(cache.cache_root, 'mini', self.md5sum[:4], self.md5sum)
f = join(cache.cache_root, 'frame', self.md5sum[:4], self.md5sum)
if not exists(f):
os.makedirs(f)
return f
@ -347,7 +351,7 @@ class ArchiveFile(SQLObject):
return join(cache.cache_root, 'timeline', self.md5sum[:4], "%s.png" % self.md5sum)
def removeMiniMovie(self):
if os.path.exists(self.mini_movie_file):
if exists(self.mini_movie_file):
os.remove(self.mini_movie_file)
def _findSubtitleByStart(self, start):
@ -365,13 +369,16 @@ class ArchiveFile(SQLObject):
self.extractTimeline()
self.extracted = True
def extractClip(self, inpoint, outpoint=-1, flash_folder=cache.frame_cache_root):
def extractClip(self, inpoint, outpoint=-1, flash_folder=-1):
if flash_folder == -1:
flash_folder = self.frameFolder
movie_file = self.mini_movie_file
position = inpoint.replace(':', '.')
flash_movie = join(self.frameFolder, '%s.%s' % (position, 'flv'))
width = 128
height = int(width / (self.width / self.height))
height = height - height % 2
inpoint = inpoint.replace('.', ':')
if outpoint == -1:
s = self._findSubtitleByStart(inpoint)
if s:
@ -381,21 +388,23 @@ class ArchiveFile(SQLObject):
extract_flash(movie_file, flash_movie, inpoint, outpoint, width, height, offset = 0)
#extract_flash_ng(self.absolutePath, flash_movie, inpoint, outpoint, width, height, offset)
def extractFrame(self, position, img_folder=cache.frame_cache_root):
def extractFrame(self, position, img_folder=-1):
if img_folder == -1:
img_folder = self.frameFolder
if self.movieFile:
return self.movieFile.extractFrame(position, img_folder)
movie_file = self.mini_movie_file
img_folder = join(img_folder, self.oxdb)
if not os.path.exists(img_folder):
if not exists(img_folder):
os.makedirs(img_folder)
position = position.replace('.', ':')
extract_frame(movie_file, position, img_folder, offset = 0, redo = False)
def extractFrames(self, img_folder=cache.frame_cache_root):
if self.movieFile:
return self.movieFile.extractFrames(img_folder)
movie_file = self.absolutePath
img_folder = join(img_folder, self.oxdb)
if not os.path.exists(img_folder):
if not exists(img_folder):
os.makedirs(img_folder)
extract_subtitles(movie_file, self.srt.encode('utf-8'), img_folder, width=100, offset=self.offset)
@ -404,12 +413,12 @@ class ArchiveFile(SQLObject):
return
mini_movie_file = self.mini_movie_file
movie_file = self.absolutePath
if not movie_file or not os.path.exists(movie_file):
if not movie_file or not exists(movie_file):
return
if os.path.exists(mini_movie_file) and not force:
if exists(mini_movie_file) and not force:
print "clip exists, skipping extraction", mini_movie_file
return
if not os.path.exists(dirname(mini_movie_file)):
if not exists(dirname(mini_movie_file)):
os.makedirs(dirname(mini_movie_file))
options = ''
options += " -ovc lavc -lavcopts vcodec=mjpeg"
@ -423,7 +432,7 @@ class ArchiveFile(SQLObject):
def removeTimeline(self):
if os.path.exists(self.timelineFile):
if exists(self.timelineFile):
os.unlink(self.timelineFile)
def extractTimeline(self, force = False):
@ -437,18 +446,20 @@ class ArchiveFile(SQLObject):
return
t = self.timelineFile
if os.path.exists(self.mini_movie_file):
if not os.path.exists(os.path.dirname(t)):
if exists(self.mini_movie_file):
if not exists(os.path.dirname(t)):
os.makedirs(os.path.dirname(t))
#lets only extract the timeline if it does not exist yet
if os.path.exists(t):
if exists(t):
print "skipping, ", self.path
return
extractTimelineScript = abspath(join(dirname(__file__), "tools/extract_timeline.py"))
#this fails in tg-admin shell
#extractTimelineScript = abspath(join(dirname(__file__), "tools/extract_timeline.py"))
extractTimelineScript = "oxdbarchive/tools/extract_timeline.py"
cmd = "python %s %s %s" %(extractTimelineScript, t, self.mini_movie_file)
os.system(cmd)
def loadSubtitleFromFile(self):
def loadSubtitleFromFile(self):
if self.movieFile:
movieFile = self.movieFile
subtitle = self
@ -458,7 +469,7 @@ class ArchiveFile(SQLObject):
if movieFile:
movieFile.srt = ''
if subtitle and movieFile:
if not subtitle.absolutePath or not os.path.exists(subtitle.absolutePath):
if not subtitle.absolutePath or not exists(subtitle.absolutePath):
return
if not subtitle.absolutePath.endswith('.srt'):
print "this is not a subtitle", subtitle.absolutePath

View file

@ -6,6 +6,7 @@ import re
import os
from os.path import abspath, join, dirname
import shutil
import time
import chardet
@ -214,6 +215,7 @@ def extract_frame(movie_file, timestamp, img_folder, width=128, offset = 0, redo
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)