2016-12-31 59 views
1

我在讀取視頻文件(.mp4格式)時運行一個簡單的程序,並在翻轉每一幀後寫回。我收到錯誤和錯誤警告。使用Python在OpenCV3中編寫視頻時出錯

Error in CoreDragRemoveTrackingHandler: -1856

我使用船長巨巖OSX,我已經安裝了Python虛擬環境使用Python 3.5的OpenCV 3.2.0-RC。有人可以幫我解決這個問題嗎?

由於

import numpy as np 
import cv2 
cap = cv2.VideoCapture('Root.mp4') 
# Define the codec and create VideoWriter object 
#fourcc = cv2.VideoWriter_fourcc(*'AVRN') 
#out = cv2.VideoWriter('Root1.mp4',fourcc, 20.0, (640,360)) 
fourcc = cv2.VideoWriter_fourcc(*'MJPG') 
out = cv2.VideoWriter('Root1.avi',fourcc, 20.0, (640,360)) 
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

總是放置文本而不是截圖 - 現在沒有人可以複製粘貼代碼來測試它並進行修改。 – furas

+0

好的。謝謝。我會改變它 –

+0

也許問[OpenCV問題](https://github.com/opencv/opencv/issues) – furas

回答

0

有一件事我可以告訴你,有你上面提到的腳本沒有問題:對,這是我的系統上運行良好。在新的虛擬環境中重新安裝opencv和python。

0

試試這個:

cap = cv2.VideoCapture(0) 
fps = 15 
capSize = (1280, 720) 
#print cap.get(3) 
#print cap.get(4) 
fourcc = cv2.VideoWriter_fourcc('m', 'p', '4', 'v') 
out = cv2.VideoWriter('output.mov',fourcc, fps, capSize, True) 

它爲我,所以我希望它可以幫助你!