diff --git a/pandora/archive/extract.py b/pandora/archive/extract.py index 20477e83f..fd8472df3 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 08f1943a0..8b2826cf2 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)