chop to disk to get index and stream from where instead of loading it all into ram

This commit is contained in:
j 2011-01-01 15:55:13 +05:30
parent 637f3d42a8
commit 7fdae917cf
2 changed files with 24 additions and 14 deletions

View file

@ -392,10 +392,10 @@ def timeline_strip(item, cuts, info, prefix):
print 'writing', timeline_file print 'writing', timeline_file
timeline_image.save(timeline_file) timeline_image.save(timeline_file)
def chop(response, video, start, end): def chop(video, start, end):
if end <= start:
return ''
t = end - start t = end - start
tmp = tempfile.mkdtemp()
choped_video = '%s/tmp.webm' % tmp
cmd = [ cmd = [
'ffmpeg', 'ffmpeg',
'-y', '-y',
@ -405,9 +405,13 @@ def chop(response, video, start, end):
'-vcodec', 'copy', '-vcodec', 'copy',
'-acodec', 'copy', '-acodec', 'copy',
'-f', 'webm', '-f', 'webm',
'/dev/stdout' choped_video
] ]
p = subprocess.Popen(cmd, stdin=subprocess.PIPE, stdout=subprocess.PIPE, stderr=open('/dev/null', 'w')) p = subprocess.Popen(cmd, stdin=subprocess.PIPE,
stdout, stderr = p.communicate() stdout=open('/dev/null', 'w'),
return stdout stderr=open('/dev/null', 'w'))
p.wait()
f = open(choped_video, 'r')
os.unlink(choped_video)
os.rmdir(tmp)
return f

View file

@ -425,13 +425,11 @@ def video(request, id, profile):
path = stream.video.path path = stream.video.path
content_type = path.endswith('.mp4') and 'video/mp4' or 'video/webm' content_type = path.endswith('.mp4') and 'video/mp4' or 'video/webm'
#server side cutting #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) t = request.GET.get('t', None)
if t: if content_type == 'video/webm' and t:
t = map(float, t.split(',')) t = map(float, t.split(','))
if len(t) == 2: if len(t) == 2 and t[1] > t[0] and stream.duration>=t[1]:
response = HttpResponse(content_type=content_type) response = HttpResponse(extract.chop(path, t[0], t[1]), content_type=content_type)
filename = "Clip of %s - %s-%s - %s %s.webm" % ( filename = "Clip of %s - %s-%s - %s %s.webm" % (
item.get('title'), item.get('title'),
ox.formatDuration(t[0] * 1000), ox.formatDuration(t[0] * 1000),
@ -440,7 +438,15 @@ def video(request, id, profile):
item.itemId item.itemId
) )
response['Content-Disposition'] = 'attachment; filename="%s"' % filename response['Content-Disposition'] = 'attachment; filename="%s"' % filename
response.write(extract.chop(response, path, t[0], t[1])) return response
else:
filename = "%s - %s %s.webm" % (
item.get('title'),
settings.SITENAME,
item.itemId
)
response = HttpFileResponse(path, content_type=content_type)
response['Content-Disposition'] = 'attachment; filename="%s"' % filename
return response return response
return HttpFileResponse(path, content_type=content_type) return HttpFileResponse(path, content_type=content_type)