From 8378a89bbd5b54d8efb064581725a765fb54740a Mon Sep 17 00:00:00 2001 From: Yves Fischer Date: Thu, 31 Dec 2015 15:20:27 +0100 Subject: replace ffmpegthumbnailer with call to ffmpeg directly set resolution to x480 instead of x360 --- README.md | 1 - mediabrowser/__init__.py | 4 ++-- mediabrowser/ffmpeg.py | 19 ++++++++----------- 3 files changed, 10 insertions(+), 14 deletions(-) diff --git a/README.md b/README.md index c67a24b..071e48d 100644 --- a/README.md +++ b/README.md @@ -20,7 +20,6 @@ The video stream is encoded as h.264 + AAC stream. Tested with * python3, flask * `ffmpeg` command -* `ffmpegthumbnailer` command # Run tests diff --git a/mediabrowser/__init__.py b/mediabrowser/__init__.py index 855c3e0..6927205 100644 --- a/mediabrowser/__init__.py +++ b/mediabrowser/__init__.py @@ -140,8 +140,8 @@ def build(root_directory, cache): if client_mtime is not None and mtime <= client_mtime: return Response(status=304) else: - process = ffmpeg.thumbnail_png(ospath, 64) - r = Response(process.stdout, mimetype="image/png") + process = ffmpeg.thumbnail(ospath, 90, 50) + r = Response(process.stdout, mimetype="image/jpeg") r.last_modified = mtime return r diff --git a/mediabrowser/ffmpeg.py b/mediabrowser/ffmpeg.py index 1f7fb18..ea589d6 100644 --- a/mediabrowser/ffmpeg.py +++ b/mediabrowser/ffmpeg.py @@ -35,7 +35,7 @@ def stream(ospath, ss, t): [ospath] + shlex.split("-c:a aac -strict experimental -ac 2 -b:a 64k" " -c:v libx264 -pix_fmt yuv420p -profile:v high -level 4.0 -preset ultrafast -trellis 0" - " -crf 31 -vf scale=w=trunc(oh*a/2)*2:h=360" + " -crf 31 -vf scale=w=trunc(oh*a/2)*2:h=480" " -f mpegts" " -output_ts_offset {output_ts_offset:.6f} -t {t:.6f} pipe:%d.ts".format(**locals())), stdout=PIPE, stderr=DEVNULL) @@ -110,17 +110,14 @@ def calculate_splittimes(ospath, chunk_duration): duration = float(ffprobe_data(ospath)['format']['duration']) points = list(calculate_points(duration)) - adj_points = points - # for point in points: - # adj_points += [find_next_iframe(ospath, point, chunk_duration / 2.0)] - # - for (point, nextPoint) in zip([0.0] + adj_points, adj_points + [duration]): + for (point, nextPoint) in zip([0.0] + points, points + [duration]): yield ("{:0.6f}".format(point), "{:0.6f}".format(nextPoint - point)) -def thumbnail_png(path, size): - logging.debug("thumbnail %s", path) - process = LoggedPopen(['ffmpegthumbnailer', '-i', path, - '-o', '-', '-s', str(size), '-c', 'png'], - stdout=PIPE, stderr=DEVNULL) +def thumbnail(ospath, width, height): + process = LoggedPopen(shlex.split("ffmpeg -noaccurate_seek -ss 25.0 -i") + [ospath] + + shlex.split("-frames:v 10 -map 0:0" + " -filter:v 'scale=w=oh*a:h={}, crop=(min(iw\,{})):(min(ih\,{}))'" + " -f singlejpeg pipe:".format(height+(height/10), width, height)), + stdout=PIPE) return process -- cgit v1.2.1