Move video thumbnailing code to helpers.

master
voussoir 2018-04-28 20:36:33 -07:00
parent 5bc2bbdacb
commit 97e1f881d0
2 changed files with 39 additions and 26 deletions

View File

@ -178,6 +178,36 @@ def generate_image_thumbnail(filepath, width, height):
image = image.convert('RGB')
return image
def generate_video_thumbnail(filepath, outfile, width, height, **special):
probe = constants.ffmpeg.probe(filepath)
if not probe.video:
return False
size = fit_into_bounds(
image_width=probe.video.video_width,
image_height=probe.video.video_height,
frame_width=width,
frame_height=height,
)
size = '%dx%d' % size
duration = probe.video.duration
if 'timestamp' in special:
timestamp = special['timestamp']
elif duration < 3:
timestamp = 0
else:
timestamp = 2
constants.ffmpeg.thumbnail(
filepath,
outfile=outfile,
quality=2,
size=size,
time=timestamp,
)
return True
def get_mimetype(filepath):
'''
Extension to mimetypes.guess_type which uses my

View File

@ -802,37 +802,20 @@ class Photo(ObjectBase):
return_filepath = hopeful_filepath
elif self.simple_mimetype == 'video' and constants.ffmpeg:
#print('video')
self.photodb.log.debug('Thumbnailing %s', self.real_path.absolute_path)
probe = constants.ffmpeg.probe(self.real_path.absolute_path)
try:
if probe.video:
size = helpers.fit_into_bounds(
image_width=probe.video.video_width,
image_height=probe.video.video_height,
frame_width=self.photodb.config['thumbnail_width'],
frame_height=self.photodb.config['thumbnail_height'],
)
size = '%dx%d' % size
duration = probe.video.duration
if 'timestamp' in special:
timestamp = special['timestamp']
else:
if duration < 3:
timestamp = 0
else:
timestamp = 2
constants.ffmpeg.thumbnail(
self.real_path.absolute_path,
outfile=hopeful_filepath.absolute_path,
quality=2,
size=size,
time=timestamp,
)
success = helpers.generate_video_thumbnail(
self.real_path.absolute_path,
outfile=hopeful_filepath.absolute_path,
width=self.photodb.config['thumbnail_width'],
height=self.photodb.config['thumbnail_height'],
**special
)
except Exception:
traceback.print_exc()
else:
return_filepath = hopeful_filepath
if success:
return_filepath = hopeful_filepath
if return_filepath != self.thumbnail:
data = {