pyinstaller:不保存来自网络摄像头的视频

问题描述 投票:0回答:0

我有一个 python 脚本,它使用 cv2.VideoWriter 记录网络摄像头并保存视频。当我直接运行代码时,代码没有问题。使用 pyinstaller 在 Windows 上创建 exe 文件后,它会打开网络摄像头并创建 output.avi,但文件不会打开。这是我的 sample.py 脚本:

import cv2

# Set up video capture
video_capture = cv2.VideoCapture(1)
fourcc = cv2.VideoWriter_fourcc(*'XVID')
video_out = cv2.VideoWriter('output.avi', fourcc, 12.0, (640, 480))

# Record video and audio
while True:
    ret, frame = video_capture.read()
    video_out.write(frame)
    cv2.imshow('Video', frame)
    if cv2.waitKey(1) & 0xFF == ord('q'):
        break

# Release resources
video_out.release()
video_capture.release()
cv2.destroyAllWindows()

然后我在终端中运行以下命令:

pyinstaller --onefile sample.py

我还按照其他人的建议将 opencv_videoio_ffmpeg412_64.dll 添加到 sample.exe 旁边的文件夹中,但仍然存在同样的问题。我什至试过这个命令:

pyinstaller --onefile sample2.py --add-binary opencv_videoio_ffmpeg412_64.dll;.

仍然没有运气。有什么建议吗?

python opencv pyinstaller cv2
© www.soinside.com 2019 - 2024. All rights reserved.