首页 > 解决方案 > 使用 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


标签: c++opencvgovideo-streaming

解决方案


推荐阅读