简体   繁体   English

无法查看 Python OpenCV 录制的视频

[英]Cannot view Python OpenCV recorded video

I am doing a minor research project for my Master's Degree and don't have much experience with programming, but I need to record myself juggling and then track the balls.我正在为我的硕士学位做一个小型研究项目,并且没有太多编程经验,但我需要记录自己的杂耍然后跟踪球。 Unfortunately, I am having trouble at the first stage.不幸的是,我在第一阶段遇到了麻烦。 This is the code I am using to record这是我用来记录的代码

import numpy as np
import cv2

cap = cv2.VideoCapture(1)

# Define the codec and create VideoWriter object
out = cv2.VideoWriter('C:/Users/Sean/Videos/output1.avi', -1, 30.0, (640,480))

while(cap.isOpened()):
    ret, frame = cap.read()
    if ret==True:
        out.write(frame)

        cv2.imshow('frame',frame)
        if cv2.waitKey(1) & 0xFF == ord('q'):
            break
    else:
        break

# Release everything if job is finished
cap.release()
out.release()
cv2.destroyAllWindows()

I am using -1 for the fourcc to choose my own codec (Intel IYUV).我使用 -1 for thefourcc 来选择我自己的编解码器(Intel IYUV)。 I am using a Logitech C920 camera for this.为此,我使用了罗技 C920 相机。 If I record a very short video (~30 seconds) I can watch the video and open it in opencv with no issues.如果我录制了一个很短的视频(约 30 秒),我可以观看视频并在 opencv 中打开它,没有任何问题。 When I record longer videos, I cannot open the file.当我录制更长的视频时,我无法打开文件。 I have tried watching it in Windows Media Player which shows me that the first ~6 minutes of a 10 minute video is a multi-colored screen with shadows of me juggling in the background.我曾尝试在 Windows Media Player 中观看它,它显示 10 分钟视频的前 6 分钟是一个多色屏幕,背景中有我在玩杂耍的阴影。 The last 4 minutes is fine.最后4分钟还好。 What am I doing wrong?我究竟做错了什么?

If you have time try to explore this, hope it would help..如果你有时间尝试探索这个,希望它会有所帮助..

import numpy as np
import cv2

cap = cv2.VideoCapture(0)

# Define the codec and create VideoWriter object
fourcc = cv2.VideoWriter_fourcc(*'XVID')
out = cv2.VideoWriter('C:/Users/Sean/Video/soutput.avi',fourcc, 20.0, (640,480))

while(cap.isOpened()):
    ret, frame = cap.read()
    if ret==True:
        frame = cv2.flip(frame,0)

        # write the flipped frame
        out.write(frame)

        cv2.imshow('frame',frame)
        if cv2.waitKey(1) & 0xFF == ord('q'):
            break
    else:
        break

# Release everything if job is finished
cap.release()
out.release()
cv2.destroyAllWindows()

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM