From 55289adf78990957aa80ee1ba02f5a69f41af78d Mon Sep 17 00:00:00 2001 From: bai Date: Tue, 26 Nov 2019 16:47:37 -0300 Subject: Agregado soporte para video/mp4 --- cgi/img.py | 26 +++++++++++++++----------- 1 file changed, 15 insertions(+), 11 deletions(-) diff --git a/cgi/img.py b/cgi/img.py index 21f326a..3561672 100644 --- a/cgi/img.py +++ b/cgi/img.py @@ -24,7 +24,7 @@ def processImage(post, data, t, originalname, spoiler=False): Returns updated with file and thumb values """ board = Settings._.BOARD - + used_filetype = None # get image information @@ -90,7 +90,6 @@ def processImage(post, data, t, originalname, spoiler=False): logTime("Generating thumbnail") if used_filetype['mime'][:5] == 'video': - #duration_half = str(int(extra['duration'] / 2)) retcode = subprocess.call([ Settings.FFMPEG_PATH, '-strict', '-2', '-ss', '0', '-i', file_path, '-v', 'quiet', '-an', '-vframes', '1', '-f', 'mjpeg', '-vf', 'scale=%d:%d' % (file_thumb_width, file_thumb_height), @@ -179,7 +178,7 @@ def processImage(post, data, t, originalname, spoiler=False): def extraInfo(mime, file_name, file_path): board = Settings._.BOARD - if mime in ['audio/ogg', 'audio/opus', 'audio/mpeg', 'video/webm']: + if mime in ['audio/ogg', 'audio/opus', 'audio/mpeg', 'video/webm', 'video/mp4']: info = ffprobe_f(file_path) extra = {} credit_str = "" @@ -278,14 +277,10 @@ def getImageInfo(data): elif (size >= 4) and data.startswith("\x1A\x45\xDF\xA3"): content_type = "video/webm" info = ffprobe(data) - - for stream in info['streams']: - if 'width' in stream: - width = stream['width'] - height = stream['height'] - break - - extra['duration'] = float(info['format']['duration']) + + # handle mp4 + elif (size >= 8) and data[4:12] in ["ftypmp42", "ftypisom"]: + content_type = "video/mp4" # handle ogg formats (vorbis/opus) elif (size >= 64) and data[:4] == "OggS": @@ -326,6 +321,15 @@ def getImageInfo(data): elif (size >= 2) and data[:2] == "PK": content_type = "application/epub+zip" + if content_type.startswith("video"): + info = ffprobe(data) + for stream in info['streams']: + if 'width' in stream: + width = stream['width'] + height = stream['height'] + break + + return content_type, width, height, size, extra def ffprobe(data): -- cgit v1.2.1-18-gbd029