server side chopping of webm, resulting files have broken index, to get seeking to work they need to be run through mkvmerge once.

This commit is contained in:
j 2010-12-31 17:34:33 +05:30
parent a0db8b77ad
commit 0b71fa1ef1
2 changed files with 37 additions and 0 deletions

View file

@ -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

View file

@ -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)