如何使用videoflow从视频URL或USB相机读取?

时间:2019-05-28 22:32:45

标签: python python-3.x videoflow

Videoflow python库中,有examples关于如何从视频文件读取的信息,但是如何从计算机中的USB设备读取视频?

1 个答案:

答案 0 :(得分:0)

它刚刚被添加到其中。你可以做这样的事情。只需确保在代码中正确设置了相机的设备ID。

import videoflow
import videoflow.core.flow as flow
from videoflow.core.constants import REALTIME
from videoflow.producers import VideoDeviceReader
from videoflow.consumers import VideofileWriter

class FrameIndexSplitter(videoflow.core.node.ProcessorNode):
    def __init__(self):
        super(FrameIndexSplitter, self).__init__()

    def process(self, data):
        index, frame = data
        return frame

def main():
    output_file = "output.avi"
    device_id = 0
    reader = VideoDeviceReader(device_id)
    frame = FrameIndexSplitter()(reader)
    writer = VideofileWriter(output_file, fps = 30)(frame)
    fl = flow.Flow([reader], [writer], flow_type = REALTIME)
    fl.run()
    fl.join()

if __name__ == "__main__":
    main()