这篇文章主要介绍了python实现实时视频流播放代码实例,文中通过示例代码介绍的非常详细,对大家的学习或者工作具有一定的参考学习价值,需要的朋友可以参考下
@action(methods=['GET'], detail=True)
def video(self, request, pk=None):
"""
获取设备实时视频流
:param request:
:param pk:
:return:
"""
device_obj = self.get_object()
# if device_obj.status == 0:
# return Response({'error': '设备离线'})
if not device_obj.rtsp_address:
return Response({'error': '缺少rtsp地址'})
cache_id = '_video_stream_{}'.format(device_obj.hash)
cache_status = cache.get(cache_id, None)
if cache_status is None: # 任务初始化,设置初始时间
cache.set(cache_id, time.time(), timeout=60)
elif isinstance(cache_status, float) and time.time() - cache_status > 30: # 任务已超时, 返回错误信息, 一段时间内不再入队
return Response({&