[英]Anaconda and Opencv does not open mp4
我試圖在 ubuntu 上使用 Opencv3(安裝在conda
env 中)讀取我的 python 腳本中的 mp4 文件。 但得到以下消息:
Unable to stop the stream: Inappropriate ioctl for device
我發現 Opencv 不支持開箱即用的 mp4。 是否可以在我的機器上安裝額外的庫來使視頻工作而無需重建 Opencv? 可能是一些配置?
代碼如下:
def workOnVideoFile(path) :
print('Reading the video from ' + path )
cap = cv2.VideoCapture(path)
print('Is video opened? ' + str(cap.isOpened()) )
while(cap.isOpened()):
ret, frame = cap.read()
print('Frame has been read ' + str(ret))
workOnFrame(frame)
if cv2.waitKey(1) & 0xFF == ord('q'):
break
print('Releasing the video' + str(cap))
cap.release()
#img = cv2.imread('car.jpg')
if __name__ == "__main__":
if (os.path.isfile(videoFile)) :
workOnVideoFile(videoFile)
else :
print('File ' + videoFile + ' is not found')
cv2.destroyAllWindows()
我認為它可能是 ubuntu 不支持開箱即用的 MP4 - 這是因為 MP4 有一些專利問題。
通常的方法是以標准方式為 Ubuntu 安裝添加對 MP4 的支持,如下所示:
sudo apt-get install ubuntu-restricted-extras
這個名字可能看起來有點奇怪,但它或多或少是標准做法 - 請參閱此處的幫助文章向您保證:
許多只想播放視頻的人只需安裝 VideoLan 即可完成所有這些工作,因此他們不必執行上述步驟。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.