From 09c0a9ff29b95e24acbc7cc8ce38487e1f772b37 Mon Sep 17 00:00:00 2001 From: Jonathan Beaudoin Date: Thu, 1 Oct 2020 05:05:35 -0400 Subject: [PATCH] Remove moviepy dependency, use ffmpeg for all video thumbnails --- seahub/thumbnail/utils.py | 18 +++++++----------- 1 file changed, 7 insertions(+), 11 deletions(-) diff --git a/seahub/thumbnail/utils.py b/seahub/thumbnail/utils.py index 85afe631fc..9c37be5e2c 100644 --- a/seahub/thumbnail/utils.py +++ b/seahub/thumbnail/utils.py @@ -5,6 +5,7 @@ import timeit import tempfile import urllib.request, urllib.error, urllib.parse import logging +import subprocess from io import BytesIO import zipfile try: # Py2 and Py3 compatibility @@ -26,15 +27,6 @@ logger = logging.getLogger(__name__) XMIND_IMAGE_SIZE = 1024 -if ENABLE_VIDEO_THUMBNAIL: - try: - from moviepy.editor import VideoFileClip - logger.debug('Video thumbnail is enabled.') - except ImportError: - logger.error("Could not find moviepy installed.") -else: - logger.debug('Video thumbnail is disabled.') - def get_thumbnail_src(repo_id, size, path): return posixpath.join("thumbnail", repo_id, str(size), path.lstrip('/')) @@ -196,10 +188,14 @@ def create_video_thumbnails(repo, file_id, path, size, thumbnail_file, file_size return (False, 500) inner_path = gen_inner_file_get_url(token, os.path.basename(path)) - clip = VideoFileClip(inner_path) tmp_path = str(os.path.join(tempfile.gettempdir(), '%s.png' % file_id[:8])) - clip.save_frame(tmp_path, t=THUMBNAIL_VIDEO_FRAME_TIME) + try: + subprocess.check_output(['ffmpeg', '-ss', '00:00:01', '-vframes', '1', tmp_path, '-i', inner_path]) + except Exception as e: + logger.error(e) + return (False, 500) + t2 = timeit.default_timer() logger.debug('Create thumbnail of [%s](size: %s) takes: %s' % (path, file_size, (t2 - t1)))