From 0b71fa1ef1f133c359ffdbb4f0d9bf5b369fddf0 Mon Sep 17 00:00:00 2001 From: j <0x006A@0x2620.org> Date: Fri, 31 Dec 2010 17:34:33 +0530 Subject: [PATCH] server side chopping of webm, resulting files have broken index, to get seeking to work they need to be run through mkvmerge once. --- pandora/archive/extract.py | 19 +++++++++++++++++++ pandora/item/views.py | 18 ++++++++++++++++++ 2 files changed, 37 insertions(+) diff --git a/pandora/archive/extract.py b/pandora/archive/extract.py index 20477e83..fd8472df 100644 --- a/pandora/archive/extract.py +++ b/pandora/archive/extract.py @@ -392,3 +392,22 @@ def timeline_strip(item, cuts, info, prefix): print 'writing', timeline_file timeline_image.save(timeline_file) +def chop(response, video, start, end): + if end <= start: + return '' + t = end - start + cmd = [ + 'ffmpeg', + '-y', + '-i', video, + '-ss', '%.3f'%start, + '-t','%.3f'%t, + '-vcodec', 'copy', + '-acodec', 'copy', + '-f', 'webm', + '/dev/stdout' + ] + p = subprocess.Popen(cmd, stdin=subprocess.PIPE, stdout=subprocess.PIPE, stderr=open('/dev/null', 'w')) + stdout, stderr = p.communicate() + return stdout + diff --git a/pandora/item/views.py b/pandora/item/views.py index 08f1943a..8b2826cf 100644 --- a/pandora/item/views.py +++ b/pandora/item/views.py @@ -424,5 +424,23 @@ def video(request, id, profile): stream = get_object_or_404(item.streams, profile=profile) path = stream.video.path content_type = path.endswith('.mp4') and 'video/mp4' or 'video/webm' + #server side cutting + #FIXME: find way to not load video into ram, + # this can easily get to much for the server + t = request.GET.get('t', None) + if t: + t = map(float, t.split(',')) + if len(t) == 2: + response = HttpResponse(content_type=content_type) + filename = "Clip of %s - %s-%s - %s %s.webm" % ( + item.get('title'), + ox.formatDuration(t[0] * 1000), + ox.formatDuration(t[1] * 1000), + settings.SITENAME, + item.itemId + ) + response['Content-Disposition'] = 'attachment; filename="%s"' % filename + response.write(extract.chop(response, path, t[0], t[1])) + return response return HttpFileResponse(path, content_type=content_type)