如何使用videoflow从视频url或usb摄像头读取?

2024-10-01 07:51:31 发布

您现在位置:Python中文网/ 问答频道 /正文

Videoflowpython库中有examples关于如何从视频文件中读取视频,但是如何从计算机的usb设备中读取视频呢?你知道吗


Tags: 视频计算机examplesusb视频文件videoflowpython
1条回答
网友
1楼 · 发布于 2024-10-01 07:51:31

只是加进去了。你可以这样做。只需确保在代码中正确设置相机的设备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() 

相关问题 更多 >