support media.importFrames for direct uploads
This commit is contained in:
parent
df0c24628c
commit
ac3c84cb9b
3 changed files with 41 additions and 0 deletions
|
@ -351,6 +351,22 @@ def frame(video, frame, position, height=128, redo=False):
|
||||||
'-p', str(position), '-y', str(height)]
|
'-p', str(position), '-y', str(height)]
|
||||||
run_command(cmd)
|
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):
|
def resize_image(image_source, image_output, width=None, size=None):
|
||||||
if exists(image_source):
|
if exists(image_source):
|
||||||
|
|
|
@ -400,6 +400,30 @@ class File(models.Model):
|
||||||
def all_paths(self):
|
def all_paths(self):
|
||||||
return [self.path] + [i.path for i in self.instances.all()]
|
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):
|
def extract_stream(self):
|
||||||
'''
|
'''
|
||||||
extract stream from direct upload
|
extract stream from direct upload
|
||||||
|
|
|
@ -129,6 +129,7 @@ def extract_stream(fileId):
|
||||||
file=file, resolution=resolution, format=config['formats'][0]
|
file=file, resolution=resolution, format=config['formats'][0]
|
||||||
)
|
)
|
||||||
if created:
|
if created:
|
||||||
|
file.extract_frames()
|
||||||
stream.media.name = stream.path(stream.name())
|
stream.media.name = stream.path(stream.name())
|
||||||
stream = stream.encode()
|
stream = stream.encode()
|
||||||
if stream.available:
|
if stream.available:
|
||||||
|
|
Loading…
Reference in a new issue