c++ - 使用 gocv 调用的 opencv 得到一个 nil 帧
问题描述
我正在使用从gocv调用的opencv通过作为 http 请求的 url 读取视频,并且 http 响应正文返回类型为字节数组的视频。视频文件没有问题。我可以得到视频的 fps 和总帧数,但是当我尝试读取第一帧或第二帧时,作为回报,我得到了一个意想不到的nil。</p>
但是当我从给定的本地文件路径读取视频时,我可以按预期读取第二帧。
我用c++函数调用这个接口,但是c++函数也返回nil。那么我可以说不支持通过 url 的 videocaputure 吗?
url := "http://localhost:8080/video"
vc, err := gocv.OpenVideoCapture(url)
if nil != err {
log.Fatal("open video capture failed: ", err)
}
defer vc.Close()
if !vc.IsOpened() {
log.Fatal("vc is not open")
}
frames := 2
vc.Set(gocv.VideoCapturePosFrames, float64(frames))
frame := gocv.NewMat()
defer frame.Close()
// when I read video by srcPath, the vc.Read can read the frame
// when I read video by url, the vc.Read can't read the frame, and the error is the frame is nil
vc.Read(&frame)
if frame.Empty() {
log.Fatal("frame is empty")
}
我期望的输出是:读帧成功
输出是帧为零,我无法得到帧
[mov,mp4,m4a,3gp,3g2,mj2 @ 0x19fd880] stream 1, offset 0xf50: partial file
...
...
[mov,mp4,m4a,3gp,3g2,mj2 @ 0x26ee880] stream 1, offset 0xf50: partial file
[mov,mp4,m4a,3gp,3g2,mj2 @ 0x26ee880] stream 1, offset 0xf50: partial file
[mov,mp4,m4a,3gp,3g2,mj2 @ 0x26ee880] stream 1, offset 0xf50: partial file
[mov,mp4,m4a,3gp,3g2,mj2 @ 0x26ee880] stream 1, offset 0xf50: partial file
[mov,mp4,m4a,3gp,3g2,mj2 @ 0x26ee880] stream 1, offset 0xf50: partial file
[mov,mp4,m4a,3gp,3g2,mj2 @ 0x26ee880] stream 1, offset 0xf50: partial file
[mov,mp4,m4a,3gp,3g2,mj2 @ 0x26ee880] stream 1, offset 0xf50: partial file
2019/07/22 17:06:47 testMyVideo.go:37: frame is empty
exit status 1
解决方案
推荐阅读
- android - 无法在反应原生 android 应用程序中获得 Firebase crashlytics
- javascript - React.js - 是否可以在第一次渲染之前获取元素的大小?
- python - 返回正确日期的函数
- angular - 在没有服务Angular的ngOnInit中创建一个函数
- unified-service-desk - Unified Service Desk 单一登录选项
- powerquery - 电源查询 - 具有动态列数的 List.NonNullCount
- java - 动态报告导出pdf类未找到异常错误
- python - 如何获取来自数组的选定数字的坐标
- php - 递归数组列表类别
- c - C 代码只能在一个项目中工作,不能在任何新项目中工作(不会写 txt 文件)