为什么我的输出视频加速了 - v4l2 python罗技C920

时间:2018-06-08 22:41:09

标签: python camera usb v4l2 logitech

我正在尝试使用python和python v4l2的可移植库开发捕获程序。有时,当我运行代码时,输​​出视频有15秒(视频必须有30秒,如下面的代码所示)。

以下是代码:

class captureThread (threading.Thread):

   def __init__(self, threadID, name):
        threading.Thread.__init__(self)
        self.threadID = threadID
        self.name = name

   def run(self):
        patientPath = 'Testes/' + patient
        if not os.path.exists(patientPath):
            os.makedirs(patientPath)

        video = v4l2capture.Video_device("/dev/video0")

        video.set_format(640, 480, fourcc='H264')
        video.create_buffers(30)
        video.queue_all_buffers()
        video.start()

        rawPath = 'video.raw'
        stop_time = time.time() + 30.0
        with open(rawPath, 'wb') as f:
            while stop_time >= time.time():
                select.select((video,), (), ())

                image_data = video.read_and_queue()
                f.write(image_data)

        video.close()

        outPath = 'video.mp4'
        osPath = 'ffmpeg -f h264 -i {0} -vcodec copy {1} -y'.format(rawPath, outPath)
        os.system(osPath)
        os.remove(rawPath)
        os.rename(outPath, "Testes/" + patient + "/video.mp4")

随机地,有时候,我运行代码,视频应该有正确的30秒。

感谢您的任何提示!

0 个答案:

没有答案