1
0
mirror of https://github.com/haiwen/seahub.git synced 2025-09-16 15:19:06 +00:00

Remove moviepy dependency, use ffmpeg for all video thumbnails

This commit is contained in:
Jonathan Beaudoin
2020-10-01 05:05:35 -04:00
committed by GitHub
parent 0bff0c1104
commit 09c0a9ff29

View File

@@ -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)))