I'm using Python2.7, Django==1.7
and uwsgi
.
I need to stream a mp4 file using HttpResponse
for rendering in html (e.g. video
tag) as below:
def test(request):
return render(request,
'shared/test.html',
{'video_url': BASE_URL + '/stream_video/'})
def stream_video(request):
path = '/var/www/test/video_file.mp4'
video_file = open(path, 'r')
response = HttpResponse(video_file, content_type='video/mp4')
response['Content-Length'] = os.path.getsize(path)
return response
And I run my Django app via uwsgi with this parameters:
uwsgi --http :8000 --chdir /var/www/test --module test.wsgi --chunked-input-timeout 40000 --post-buffering 12829000 --buffer-size 12829000 --post-buffering-bufsize 12829000 --fastrouter-buffer-size 12829000 --http-buffer-size 12829000
In small videos (less than 1MB) it works correctly, but in other case i have uwsgi error as below:
uwsgi_response_write_body_do(): Connection reset by peer [core/writer.c line 331] during GET /stream_video/ (192.168.0.224) IOError: write error
As you see, I set all buffer-size parameters to solve this problem. But it doesn't work for me.
What's your idea?