【问题标题】:OpenCV: FFMPEG: tag 0xffffffff/'����' is not found (format 'mp4 / MP4 (MPEG-4 Part 14)')'OpenCV:FFMPEG:未找到标签 0xffffffff/'����'(格式 'mp4 / MP4(MPEG-4 Part 14)')'
【发布时间】:2017-06-08 16:09:31
【问题描述】:

我正在尝试在 python 中保存减去背景的视频,以下是我的代码。

import cv2
import numpy as np

capture = cv2.VideoCapture('MAH00119.mp4')
size = (int(capture.get(cv2.CAP_PROP_FRAME_WIDTH)),
int(capture.get(cv2.CAP_PROP_FRAME_HEIGHT)))
fourcc = cv2.VideoWriter_fourcc(*'X264')
out = cv2.VideoWriter('output.mp4', -1 , 20.0 , size)
fgbg= cv2.createBackgroundSubtractorMOG2()

while True:
    ret, img = capture.read()
    if ret==True:
        fgmask = fgbg.apply(img)
        out.write(fgmask)
        cv2.imshow('img',fgmask)

    if(cv2.waitKey(27)!=-1):
        break

capture.release()
out.release()
cv2.destroyAllWindows()

但是,这会不断抛出以下错误:“OpenCV: FFMPEG: tag 0xffffffff/'����' is not found (format 'mp4 / MP4 (MPEG-4 Part 14)')'”

我已安装 FFMPEG 并将其添加到环境变量中。我的背景减法代码无需保存到文件就可以正常工作,所以我知道 openCV 安装没有问题。我被困在这个地方。我知道我的 python 似乎无法识别 FFMPEG,但除了将 FFMPEG 添加到环境变量之外,我不知道还能做什么。 我在 Windows 10 和 Python 2.7 上使用 OpenCV 3.2 版。

任何帮助将不胜感激!

【问题讨论】:

  • 看起来你的文件不是真正的 mp4。
  • @furas:我认为它是真正的 mp4。当我在 .avi 文件上运行代码时,它会抛出相同的错误“OpenCV: FFMPEG: tag 0xffffffff/'����' is not found (format 'avi / AVI (Audio Video Interleaved)')'”
  • 谷歌这条消息,你会发现:stackoverflow.com/questions/34024041/…
  • 顺便说一句:总是提出问题 FULL 错误消息(回溯)。还有其他有用的信息。

标签: python opencv video ffmpeg


【解决方案1】:

稍微修改了代码。它可以在我的 PC 上使用 OpenCV 3.2 for Python 2.7 在 Windows 10 64 位上运行。

import cv2
import numpy as np

capture = cv2.VideoCapture('./videos/001.mp4')
size = (int(capture.get(cv2.CAP_PROP_FRAME_WIDTH)), int(capture.get(cv2.CAP_PROP_FRAME_HEIGHT)))
fourcc = cv2.VideoWriter_fourcc(*'DIVX')  # 'x264' doesn't work
out = cv2.VideoWriter('./videos/001_output.mp4',fourcc, 29.0, size, False)  # 'False' for 1-ch instead of 3-ch for color
fgbg= cv2.createBackgroundSubtractorMOG2()

while (capture.isOpened()):  #while Ture:
    ret, img = capture.read()
    if ret==True:
        fgmask = fgbg.apply(img)
        out.write(fgmask)
        cv2.imshow('img',fgmask)

    #if(cv2.waitKey(27)!=-1):  # observed it will close the imshow window immediately
    #    break                 # so change to below
    if cv2.waitKey(1) & 0xFF == ord('q'):
        break

capture.release()
out.release()
cv2.destroyAllWindows()

检查 this 以获取 cv2.VideoWriter() 上的参数设置。

希望对您有所帮助。

【讨论】:

    猜你喜欢
    • 2020-08-28
    • 2020-01-07
    • 2022-11-30
    • 1970-01-01
    • 2013-08-13
    • 2018-05-08
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多