Move video thumbnailing code to helpers.
This commit is contained in:
parent
5bc2bbdacb
commit
97e1f881d0
2 changed files with 39 additions and 26 deletions
|
@ -178,6 +178,36 @@ def generate_image_thumbnail(filepath, width, height):
|
||||||
image = image.convert('RGB')
|
image = image.convert('RGB')
|
||||||
return image
|
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):
|
def get_mimetype(filepath):
|
||||||
'''
|
'''
|
||||||
Extension to mimetypes.guess_type which uses my
|
Extension to mimetypes.guess_type which uses my
|
||||||
|
|
|
@ -802,37 +802,20 @@ class Photo(ObjectBase):
|
||||||
return_filepath = hopeful_filepath
|
return_filepath = hopeful_filepath
|
||||||
|
|
||||||
elif self.simple_mimetype == 'video' and constants.ffmpeg:
|
elif self.simple_mimetype == 'video' and constants.ffmpeg:
|
||||||
#print('video')
|
|
||||||
self.photodb.log.debug('Thumbnailing %s', self.real_path.absolute_path)
|
self.photodb.log.debug('Thumbnailing %s', self.real_path.absolute_path)
|
||||||
probe = constants.ffmpeg.probe(self.real_path.absolute_path)
|
|
||||||
try:
|
try:
|
||||||
if probe.video:
|
success = helpers.generate_video_thumbnail(
|
||||||
size = helpers.fit_into_bounds(
|
self.real_path.absolute_path,
|
||||||
image_width=probe.video.video_width,
|
outfile=hopeful_filepath.absolute_path,
|
||||||
image_height=probe.video.video_height,
|
width=self.photodb.config['thumbnail_width'],
|
||||||
frame_width=self.photodb.config['thumbnail_width'],
|
height=self.photodb.config['thumbnail_height'],
|
||||||
frame_height=self.photodb.config['thumbnail_height'],
|
**special
|
||||||
)
|
)
|
||||||
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,
|
|
||||||
)
|
|
||||||
except Exception:
|
except Exception:
|
||||||
traceback.print_exc()
|
traceback.print_exc()
|
||||||
else:
|
else:
|
||||||
return_filepath = hopeful_filepath
|
if success:
|
||||||
|
return_filepath = hopeful_filepath
|
||||||
|
|
||||||
if return_filepath != self.thumbnail:
|
if return_filepath != self.thumbnail:
|
||||||
data = {
|
data = {
|
||||||
|
|
Loading…
Reference in a new issue