1 | initial version |
I found a way to pipe a stream to VideoCapture for windows, because openCV is based on FFmpeg, that supports named pipe.
Here is a quick example:
#!/usr/bin/env python import cv2 import win32pipe, win32file from threading import Thread def runPipe(): p = win32pipe.CreateNamedPipe(r'\\.\pipe\myNamedPipe', win32pipe.PIPE_ACCESS_DUPLEX, win32pipe.PIPE_TYPE_MESSAGE | win32pipe.PIPE_WAIT, 1, 1024, 1024, 0, None) win32pipe.ConnectNamedPipe(p, None) with open("D:\\Streams\\mystream.ts", 'rb') as input: while True: data = input.read(1024) if not data: break win32file.WriteFile(p, data) def extract(): cap = cv2.VideoCapture(r'\\.\pipe\myNamedPipe') fnum = 0 while(True): # Capture frame-by-frame ret, frame = cap.read() print fnum, "pts:", cap.get(cv2.cv.CV_CAP_PROP_POS_MSEC) fnum = fnum + 1 # When everything done, release the capture cap.release() if __name__ == "__main__": thr = Thread(target=extract) thr.start() runPipe() print "bye"