【发布时间】:2018-10-06 19:17:09
【问题描述】:
我正在尝试将视频保存为 .avi 格式,但我不断收到错误 "could not demultiplex stream"。我主要想保存灰度视频。
我需要使用任何特定的codec 吗?
现在我尝试使用XVID, DIVX
import imutils
import cv2
import numpy as np
interval = 30
outfilename = 'output.avi'
threshold=100.
fps = 10
cap = cv2.VideoCapture("video.mp4")
ret, frame = cap.read()
height, width, nchannels = frame.shape
fourcc = cv2.cv.CV_FOURCC(*'DIVX')
out = cv2.VideoWriter( outfilename,fourcc, fps, (width,height))
ret, frame = cap.read()
frame = imutils.resize(frame, width=500)
frame = cv2.cvtColor(frame, cv2.COLOR_RGB2GRAY)
while(True):
frame0 = frame
ret, frame = cap.read()
frame = imutils.resize(frame, width=500)
frame = cv2.cvtColor(frame, cv2.COLOR_RGB2GRAY)
if not ret:
deletedcount +=1
break
if np.sum( np.absolute(frame-frame0) )/np.size(frame) > threshold:
out.write(frame)
else:
print "Deleted"
cv2.imshow('Feed - Press "q" to exit',frame)
key = cv2.waitKey(interval) & 0xFF
if key == ord('q'):
print('received key q' )
break
cap.release()
out.release()
print('Successfully completed')
【问题讨论】:
-
请提供minimal, complete code您的问题。
-
我更新了代码,你能帮我弄清楚吗
-
当我插入
print语句时,视频编译和运行正常,并给出正确的控制台 o/p,但我得到的 o/p 无法读取,它给出了"Could not demultiplex stream."