chop to disk to get index and stream from where instead of loading it all into ram
This commit is contained in:
parent
637f3d42a8
commit
7fdae917cf
2 changed files with 24 additions and 14 deletions
|
@ -392,10 +392,10 @@ 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 ''
|
||||
def chop(video, start, end):
|
||||
t = end - start
|
||||
tmp = tempfile.mkdtemp()
|
||||
choped_video = '%s/tmp.webm' % tmp
|
||||
cmd = [
|
||||
'ffmpeg',
|
||||
'-y',
|
||||
|
@ -405,9 +405,13 @@ def chop(response, video, start, end):
|
|||
'-vcodec', 'copy',
|
||||
'-acodec', 'copy',
|
||||
'-f', 'webm',
|
||||
'/dev/stdout'
|
||||
choped_video
|
||||
]
|
||||
p = subprocess.Popen(cmd, stdin=subprocess.PIPE, stdout=subprocess.PIPE, stderr=open('/dev/null', 'w'))
|
||||
stdout, stderr = p.communicate()
|
||||
return stdout
|
||||
|
||||
p = subprocess.Popen(cmd, stdin=subprocess.PIPE,
|
||||
stdout=open('/dev/null', 'w'),
|
||||
stderr=open('/dev/null', 'w'))
|
||||
p.wait()
|
||||
f = open(choped_video, 'r')
|
||||
os.unlink(choped_video)
|
||||
os.rmdir(tmp)
|
||||
return f
|
||||
|
|
|
@ -425,13 +425,11 @@ def video(request, id, 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:
|
||||
if content_type == 'video/webm' and t:
|
||||
t = map(float, t.split(','))
|
||||
if len(t) == 2:
|
||||
response = HttpResponse(content_type=content_type)
|
||||
if len(t) == 2 and t[1] > t[0] and stream.duration>=t[1]:
|
||||
response = HttpResponse(extract.chop(path, t[0], t[1]), content_type=content_type)
|
||||
filename = "Clip of %s - %s-%s - %s %s.webm" % (
|
||||
item.get('title'),
|
||||
ox.formatDuration(t[0] * 1000),
|
||||
|
@ -440,7 +438,15 @@ def video(request, id, profile):
|
|||
item.itemId
|
||||
)
|
||||
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 HttpFileResponse(path, content_type=content_type)
|
||||
|
||||
|
|
Loading…
Reference in a new issue