gpt4 book ai didi

python - Vidgear 写视频打不开

转载 作者:行者123 更新时间:2023-12-04 23:22:39 27 4
gpt4 key购买 nike

Source code

命令:( https://drive.google.com/file/d/14YGKIhftAidQVvR_nMWY3oIhcWFzLERE/view?usp=sharing )

没有发生错误。我一直在试图弄清楚如何用 Vidgear 写视频。我正在使用 Windows 和网络摄像头。

错误:“Output.mp4”打开的是黑色。 (https://drive.google.com/file/d/11x-q_w59gdaAECtRIqi0MNGIOZ-Vuati/view?usp=sharing)

# import required libraries
from vidgear.gears import CamGear
from vidgear.gears import WriteGear
import cv2

# Open live video stream on webcam at first index(i.e. 0) device
stream = CamGear(source=0).start()

# retrieve framerate from CamGear Stream and pass it as `-input_framerate` parameter
output_params = {"-input_framerate":stream.framerate}

# Define writer with defined parameters and suitable output filename for e.g. `Output.mp4`
writer = WriteGear(output_filename = 'Output.mp4', **output_params)

# loop over
while True:

# read frames from stream
frame = stream.read()

# check for frame if None-type
if frame is None:
break


# {do something with the frame here}


# write frame to writer
writer.write(frame)

# Show output window
cv2.imshow("Output Frame", frame)

# check for 'q' key if pressed
key = cv2.waitKey(1) & 0xFF
if key == ord("q"):
break

# close output window
cv2.destroyAllWindows()

# safely close video stream
stream.stop()

# safely close writer
writer.close()

最佳答案

我是VidGear的作者图书馆。 WriteGear API 工作得很好。你的相机才是这个问题的真正罪魁祸首。
在您的屏幕截图中看到此错误:
enter image description here
此错误是由于您的 Windows 机器上的后端不正确造成的。 请尝试使用此代码来修复此错误:

# import required libraries
from vidgear.gears import CamGear
from vidgear.gears import WriteGear
import cv2

# Open live video stream on webcam at first index(i.e. 0) device
stream = CamGear(source=0, backend=cv2.CAP_DSHOW).start()

# retrieve framerate from CamGear Stream and pass it as `-input_framerate` parameter
output_params = {"-input_framerate":stream.framerate}

# Define writer with defined parameters and suitable output filename for e.g. `Output.mp4`
writer = WriteGear(output_filename = 'Output.mp4', **output_params)

# loop over
while True:

# read frames from stream
frame = stream.read()

# check for frame if None-type
if frame is None:
break


# {do something with the frame here}


# write frame to writer
writer.write(frame)

# Show output window
cv2.imshow("Output Frame", frame)

# check for 'q' key if pressed
key = cv2.waitKey(1) & 0xFF
if key == ord("q"):
break

# close output window
cv2.destroyAllWindows()

# safely close video stream
stream.stop()

# safely close writer
writer.close()

关于python - Vidgear 写视频打不开,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/62367452/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com