2

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). I am using a Logitech C920 camera for this. If I record a very short video (~30 seconds) I can watch the video and open it in opencv with no issues. 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. The last 4 minutes is fine. What am I doing wrong?

2
  • where did you store the data?, are trying to create a temp or maybe will store to specific database. Are you referring to this link for your reference? - opencv-python-tutroals.readthedocs.org/en/latest/py_tutorials/… Commented Dec 23, 2015 at 2:25
  • I'm saving it into my Videos folder. I have also tried recording using the default recording software installed on my computer. In that case, the recording is fine, but I cannot open the video in OpenCV. Is that a codec issue? Commented Dec 23, 2015 at 2:31

1 Answer 1

2

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()
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.