Miguel Grinberg已經用Python編寫了一個優秀的視頻流教程,它依次發送JPEG幀。這裏檢查他的博客:
http://blog.miguelgrinberg.com/post/video-streaming-with-flask1
每個JPEG可以快速審查,然後播出。 [要考慮所需的延遲]
就獲取輸入視頻饋送而言,您可以使用OPENCV連接攝像頭。 OpenCV使用VideoCapture將原始圖像作爲字節返回。這些字節需要編碼爲JPEG並與Miguel的代碼進行接口。
import cv2
class VideoCamera(object):
def __init__(self):
# Using OpenCV to capture from device
self.video = cv2.VideoCapture(0)
def __del__(self):
self.video.release()
def get_frame(self):
success, image = self.video.read()
# We are using Motion JPEG, but OpenCV defaults to capture raw images,
# so we must encode it into JPEG in order to correctly display the
# video stream.
ret, jpeg = cv2.imencode('.jpg', image)
return jpeg.tobytes()
這種方法將幫助您滿足所有需要的功能:
- 沒有互聯網需要
- 可調延遲 - 您可以輕鬆控制要對每一幀進行延遲和處理
- 良好的質量
- 按需記錄 - 根據需要存儲捕獲的幀
- 有記錄通過只保存以前的24 * x幀(24fps流)