summaryrefslogtreecommitdiff
path: root/mediabrowser/__init__.py
diff options
context:
space:
mode:
authorYves Fischer <yvesf-git@xapek.org>2015-12-31 00:07:40 +0100
committerYves Fischer <yvesf-git@xapek.org>2016-01-08 20:38:18 +0100
commitd0158aa0c5f13ce55f64fa7c3029171d6bfe304f (patch)
tree5bf2a988dba6e3f87b864d384d9a87213fe23cf1 /mediabrowser/__init__.py
parent48f917e478ed365e58f6880a90dd00be120fcc83 (diff)
downloadflask-mediabrowser-d0158aa0c5f13ce55f64fa7c3029171d6bfe304f.tar.gz
flask-mediabrowser-d0158aa0c5f13ce55f64fa7c3029171d6bfe304f.zip
encode only UNTIL the next keyframe not INCLUDING
fix handling of last segment (end of file) in m3u8 playlist remove assumedly unneeded -async 1
Diffstat (limited to 'mediabrowser/__init__.py')
-rw-r--r--mediabrowser/__init__.py17
1 files changed, 14 insertions, 3 deletions
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')