import cv2, sys
import time
if sys.platform == 'win32':
    import os, msvcrt
msvcrt.setmode(sys.stdout.fileno(), os.O_BINARY)
cap = cv2.VideoCapture(0)
while True:
    ret, frm = cap.read()
sys.stdout.write(frm.tostring())
Pipe raw OpenCV images to FFmpeg