@Ritwick. I did this by changing the gen and index function below
def gen (camera):
while True:
frame = camera.get_frame ()
yield (b '- frame \ r \ n'
b'Content-Type: image / jpeg \ r \ n \ r \ n '+ frame + b' \ r \ n \ r \ n ')
@ gzip.gzip_page
def index (request):
try:
return StreamingHttpResponse (gen (VideoCamera ()), content_type = "multipart / x-mixed-replace; boundary = frame")
except HttpResponseServerError as e:
print ("aborted")
I use a python generator to generate each frame of the camera and using StreamingHttpResponse to replace multipart / x-mixed-replace , which is marked as a frame
In django there is a gzip decorator function.
from django.views.decorators import gzip
To increase the speed of streaming. I used the dzango gzip decorator method for the gzip frame.
source share