使用 OpenCV 编写视频 +蟒蛇 +苹果
当我尝试将帧写入视频时,我不断收到断言错误。我收到的错误是这样的:
Traceback (most recent call last):
File "VideoMixer.py", line 23, in <module>
cv.WriteFrame(writer, cv.LoadImage(fileName))
cv.error: dst.data == dst0.data
这是我的脚本:
import cv
import sys
files = sys.argv[1:]
for f in files:
capture = cv.CaptureFromFile(f)
height = cv.GetCaptureProperty(capture, cv.CV_CAP_PROP_FRAME_WIDTH)
width = cv.GetCaptureProperty(capture, cv.CV_CAP_PROP_FRAME_HEIGHT)
fps = cv.GetCaptureProperty(capture, cv.CV_CAP_PROP_FPS)
fourcc = cv.GetCaptureProperty(capture, cv.CV_CAP_PROP_FOURCC)
print fourcc
writer = cv.CreateVideoWriter('ok.mov', int(fourcc),fps,(int(width),int(height)),1)
print writer
for i in range(30):
frame = cv.QueryFrame(capture)
print frame
if frame:
cv.WriteFrame(writer, frame)
将帧保存为图像效果很好,所以我知道捕获没有任何问题。我创造作家错了吗? 'print fourcc' 输出 0.0 但我尝试过许多 FOUR_CC 值。
谢谢!
I keep getting an assertion error when I'm trying to write frames to video. The error I'm getting is this:
Traceback (most recent call last):
File "VideoMixer.py", line 23, in <module>
cv.WriteFrame(writer, cv.LoadImage(fileName))
cv.error: dst.data == dst0.data
Here's my script:
import cv
import sys
files = sys.argv[1:]
for f in files:
capture = cv.CaptureFromFile(f)
height = cv.GetCaptureProperty(capture, cv.CV_CAP_PROP_FRAME_WIDTH)
width = cv.GetCaptureProperty(capture, cv.CV_CAP_PROP_FRAME_HEIGHT)
fps = cv.GetCaptureProperty(capture, cv.CV_CAP_PROP_FPS)
fourcc = cv.GetCaptureProperty(capture, cv.CV_CAP_PROP_FOURCC)
print fourcc
writer = cv.CreateVideoWriter('ok.mov', int(fourcc),fps,(int(width),int(height)),1)
print writer
for i in range(30):
frame = cv.QueryFrame(capture)
print frame
if frame:
cv.WriteFrame(writer, frame)
Saving the frames as images works fine so I know there's nothing wrong with the capture. Am I creating the writer wrong? The 'print fourcc' outputs 0.0 but I've tried with many FOUR_CC values.
Thanks!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
OpenCV 源中的此文件< /a> 暗示 #2598 行 - 如果此断言失败:“dst.data == dst0.data”
This file in the OpenCV source implies on line #2598 - if this assert fails: "dst.data == dst0.data"
您的某些框架是否具有不同的色彩空间或深度?一些观察:
fourcc
应该是一个整数 > 0. 请参阅下面我的示例。我个人没有使用 OpenCV 生成 Quicktime 视频,但这对我生成未压缩的 AVI 文件很有用。我使用
cv.CV_FOURCC
函数选择 I420 fourcc:更新:VLC 播放
out.avi
的屏幕截图:在 Quicktime 中:
Do some of your frames have different colorspaces or depths? A few observations:
fourcc
should be an integer > 0. See my example below.I haven't personally generated Quicktime video using OpenCV, but this worked for me generating an uncompressed AVI file. I choose the I420 fourcc using the
cv.CV_FOURCC
function:Update: Screencapture of VLC playing
out.avi
:In Quicktime:
我尝试了各种编解码器,包括“MJPG”和“I420”,但它们都不适用于我的 Mac OpenCV 版本。他们毫无抱怨地生成了微小的无法查看的输出文件。
然后我发现此页面其中列出了一些适合我的编解码器。例如,“mp4v”在我的 Mac 上运行良好,QuickTime 也能够播放它。
I tried various codecs including 'MJPG' and 'I420' and none of them worked on my Mac OpenCV build. They produced tiny unviewable output files without complaining.
Then I found this page which lists some codecs that worked for me. E.g. 'mp4v' works fine on my Mac and QuickTime is able to play it.