From d0158aa0c5f13ce55f64fa7c3029171d6bfe304f Mon Sep 17 00:00:00 2001 From: Yves Fischer Date: Thu, 31 Dec 2015 00:07:40 +0100 Subject: encode only UNTIL the next keyframe not INCLUDING fix handling of last segment (end of file) in m3u8 playlist remove assumedly unneeded -async 1 --- mediabrowser/__init__.py | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) (limited to 'mediabrowser/__init__.py') diff --git a/mediabrowser/__init__.py b/mediabrowser/__init__.py index 0bdc21d..855c3e0 100644 --- a/mediabrowser/__init__.py +++ b/mediabrowser/__init__.py @@ -93,10 +93,21 @@ def build(root_directory, cache): def stream(ss, t, path): path = os.path.normpath(path) ospath = os.path.join(root_directory, path) + data = ffprobe(ospath) + duration = float(data['format']['duration']) # cut at next key frame after given time 'ss' - new_ss = ffmpeg.find_next_keyframe(ospath, ss, t / 2) - # find next key frame after given time 't' - new_t = ffmpeg.find_next_keyframe(ospath, ss + t, t / 2) - new_ss + _, new_ss = ffmpeg.find_next_keyframe(ospath, ss, t / 2) + + if ss + t * 2 > duration: + # encode all remain frames at once + new_t = duration - new_ss + else: + # find next key frame after given time 't' + new_t_prev_duration, new_t = ffmpeg.find_next_keyframe(ospath, ss + t, t / 2) + new_t -= new_ss + # minus one frame + new_t -= new_t_prev_duration + process = ffmpeg.stream(ospath, new_ss, new_t) return Response(process.stdout, mimetype='video/MP2T') -- cgit v1.2.1