support media.importFrames for direct uploads

This commit is contained in:
j 2014-07-29 19:07:50 +02:00
parent df0c24628c
commit ac3c84cb9b
3 changed files with 41 additions and 0 deletions

View File

@ -351,6 +351,22 @@ def frame(video, frame, position, height=128, redo=False):
'-p', str(position), '-y', str(height)]
run_command(cmd)
def frame_direct(video, target, position):
fdir = os.path.dirname(target)
if fdir and not os.path.exists(fdir):
os.makedirs(fdir)
pre = position - 2
if pre < 0:
pre = 0
else:
position = 2
cmd = [ox.file.cmd('ffmpeg'), '-y', '-ss', str(pre), '-i', video, '-ss', str(position),
'-vf', 'scale=iw*sar:ih',
'-an', '-vframes', '1', target]
r = run_command(cmd)
return r == 0
def resize_image(image_source, image_output, width=None, size=None):
if exists(image_source):

View File

@ -400,6 +400,30 @@ class File(models.Model):
def all_paths(self):
return [self.path] + [i.path for i in self.instances.all()]
def extract_frames(self):
def video_frame_positions(duration):
pos = duration / 2
return map(int, [pos/2, pos, pos+pos/2])
if settings.CONFIG['media'].get('importFrames') and self.data:
filename = self.data.path
prefix = os.path.dirname(filename)
info = self.info
oshash = info['oshash']
for pos in video_frame_positions(info['duration']):
position = float(pos)
name = "%s.png" % position
fr, created = Frame.objects.get_or_create(file=self, position=position)
if fr.frame:
fr.frame.delete()
fr.frame.name = self.get_path(name)
if not os.path.exists(fr.frame.path):
extract.frame_direct(filename, fr.frame.path, pos)
if os.path.exists(fr.frame.path):
fr.save()
os.chmod(fr.frame.path, 0644)
self.item.select_frame()
def extract_stream(self):
'''
extract stream from direct upload

View File

@ -129,6 +129,7 @@ def extract_stream(fileId):
file=file, resolution=resolution, format=config['formats'][0]
)
if created:
file.extract_frames()
stream.media.name = stream.path(stream.name())
stream = stream.encode()
if stream.available: