2017-03-10 5 views
0

python을 사용하여 openCv에서 videocapture 객체를 사용하여 비디오를 저장하려고합니다. 그러나 'q'를 누르면 동영상은 'output.avi'로 저장되지만 크기는 0KB로 표시됩니다. 도움이 필요하고 오류를 찾을 수 없습니다. 여기동영상이 저장 중이지만 0KB 만 표시합니다. OpenCv의 이러한 코드에서 발생할 수있는 오류는 무엇입니까

import numpy as np 
import cv2 
cap = cv2.VideoCapture(0) 
#1.2. Gui Features in OpenCV 25 
#OpenCV-Python Tutorials Documentation, Release 1 
# Define the codec and create VideoWriter object 
fourcc = cv2.VideoWriter_fourcc(*'XVID') 
out = cv2.VideoWriter('output.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() 
+0

그 type.you 어떤 codics를 확인해야 Codics에 문제가 주어진 미디어 타입이 제대로 작동 –

답변

1

는 * ('J', 'P', 'G', 'M') 또는 cv2.VideoWriter_fourcc (

FOURCC 코드 cv2.VideoWriter_fourcc로 전달 FOURCC 코드와 재생해야 'MJPG를위한 MJPG). 더 읽기

import numpy as np 
import cv2 

cap = cv2.VideoCapture(0) 

# Define the codec and create VideoWriter object 
#fourcc = cv2.cv.CV_FOURCC(*'DIVX') 
#out = cv2.VideoWriter('output.avi',fourcc, 20.0, (640,480)) 
out = cv2.VideoWriter('output.avi', -1, 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() 

, OpenCV saving docFourCC doc

+0

당신은 나에게 조금, 무엇을 설명 할 수 '-1' 의미? 그리고 왜 내 첫 진술서에 대해 논평 한거야? –

+0

@AjayKhetan FourCC는 비디오 코덱을 지정하는 데 사용되는 4 바이트 코드입니다. 여기 코덱을 보내지 않았다. 다른 형식을 시도하고 결과를 볼 수 있습니다. –