def get_image_from_stream(stream_url: str) -> np.ndarray:
'''
Get last frame from stream using av modul.
'''
container = None
try:
container = av.open(stream_url) # sadad
except Exception:
# quit
raise Exception("ERROR! Stream not working!")
video_stream = next(s for s in container.streams if s.type == 'video')
image_pil = None
for packet in container.demux(video_stream):
for frame in packet.decode():
image_pil = frame.to_image()
if image_pil:
break
if image_pil:
break
image = np.asarray(image_pil)
return image
import matplotlib
matplotlib.use('Agg')
import matplotlib.pyplot as plt
def plot_pic(request):
# делаешь графики
plt.draw()
response = HttpResponse(content_type="image/jpeg")
plt.savefig(response, format="png")
plt.clf()
return response
<img src={% url 'plot_pic' %} width="640" height="auto">
from urllib.request import urlopen
def detail(request):
page = urlopen('https://example.com/1.html')
charset = page.info().get_content_charset()
return render(request, 'detail.html', {'page':page.read().decode(charset)})
{{page|safe}}