I am using opencv called from gocv to read a video via url which is a http request, and the http response body returns the video whose type is byte array. There is no problems in video file. I could get the video's fps and the totol frames number, but when I try to read the first frame or second frame, in return, I get a unexpected nil。
but when I read the video from a given local file path, I can read the sencond frame as expected.
I am using c++ function to call this interface,however, the c++ function returns nil too. So could I just say that the videocaputure is not supported via a url?
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")
}
I expect the output is:read the frame success
The output is frame is nil, I can't get the frame
[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