gocv
gocv copied to clipboard
Error opening video capture device
Description
Recently,i wanna do some ai with the livestream, and i installed gocv and Opencv as https://github.com/hybridgroup/gocv shows step by step on my centOS VM, but wen i tried to open the stream in my code which is shown bleow
func (c *Client) StartOpencvStream() {
var err error
c.OpenCv, err = gocv.VideoCaptureFile(c.Url)
i got the error
OpenCV(4.5.3) /tmp/opencv/opencv-4.5.3/modules/videoio/src/cap_images.cpp:253: error: (-5:Bad argument) CAP_IMAGES: can't find starting number (in the name of file): rtmp://192.168.137.160:1935/myapp/rus in function 'icvExtractPattern'
Error opening video capture device: rtmp://192.168.137.160:1935/myapp/rus
but the vidoe stream can be opened by the VLC, i cannot find the problem.
Steps to Reproduce
- prepare a video live stream by the FFmpeg,push the stream to the server
ffmpeg -re -i "/home/rus.mp4" -vcodec libx264 -vprofile baseline -acodec aac -ar 44100 -strict -2 -ac 1 -f flv -s 1280x720 -q 10 rtmp://192.168.137.160:1935/myapp/rus
- Try to open the stream with gocv code:
func (c *Client) StartOpencvStream() {
var err error
c.OpenCv, err = gocv.VideoCaptureFile(c.Url) // failed at this line
if err != nil {
log.Errorf("open stream url error:%v", err)
return
}
//defer webcam.Close()
defer func() {
c.OpenCv.Close()
close(c.BaseImg)
close(c.WarnData)
}()
- got the error shows below:
[ERROR:0] global /tmp/opencv/opencv-4.5.3/modules/videoio/src/cap.cpp (162) open VIDEOIO(CV_IMAGES): raised OpenCV exception:
OpenCV(4.5.3) /tmp/opencv/opencv-4.5.3/modules/videoio/src/cap_images.cpp:253: error: (-5:Bad argument) CAP_IMAGES: can't find starting number (in the name of file): rtmp://192.168.137.160:1935/myapp/rus in function 'icvExtractPattern'
Error opening video capture device: rtmp://192.168.137.160:1935/myapp/rus
- i try to change the livestream type to the HLS, but still got the error(but this time it didn‘t show the “can‘t ’find starting numer...error” as rtmp stream shows above):
Error opening video capture device: http://192.168.137.160:8080/live/russ.m3u8
Your Environment
- Operating System and version:
Linux version 3.10.0-957.el7.x86_64 ([email protected]) (gcc version 4.8.5 20150623 (Red Hat 4.8.5-36) (GCC) )
- OpenCV version used:opencv lib version: 4.5.3
- How did you install OpenCV? Follow the goCV project steps https://github.com/hybridgroup/gocv
- GoCV version used:gocv version: 0.28.0
- Go version: go version go1.16.3 linux/amd64
- Did you run the
env.sh
orenv.cmd
script before trying togo run
orgo build
? No
@deadprogram @drnic @mattn @lstep can somebody help me witht this, really in hurry
I'd check the syntax you are using, it is known to work with various streams.
I'd check the syntax you are using, it is known to work with various streams.
You mean the stream's URI? but even with the local video file, still got the same error :
[root@master1 gocv]# pwd
/root/gocv/gocv
[root@master1 gocv]# go run ./cmd/capwindow/main.go /home/rus.mp4
Error opening video capture device: /home/rus.mp4
The correct syntax for that command is go run ./cmd/capwindow/main.go 0
where 0
is the ID of the connected camera device e.g. webcam that you want to use. Not a file, which is why error says Error opening video capture device
The correct syntax for that command is
go run ./cmd/capwindow/main.go 0
where0
is the ID of the connected camera device e.g. webcam that you want to use. Not a file, which is why error saysError opening video capture device
thanks, my bad! But the code "gocv.VideoCaptureFile("rtmp://192.168.137.160:1935/myapp/rus.mp4")" got the same error, is this also needed to pass the Device Number ?
I think what you want to use is https://pkg.go.dev/gocv.io/x/gocv#OpenVideoCapture but your URL may or may not be correct. That part you will have to figure out yourself, since is also based on server you are trying to use.
I think what you want to use is https://pkg.go.dev/gocv.io/x/gocv#OpenVideoCapture but your URL may or may not be correct. That part you will have to figure out yourself, since is also based on server you are trying to use.
Yes, since i wanna open the Live Stream through RTMP Protocol,so the Function OpenVideoCapture will call the Function VideoCaptureFile any way. Just now I tried to Call the OpenVideoCapture Function First in my code ,but it didn't work . Now the URL may not be correct, but what else can I do with the strem URI o(╥﹏╥)o ,can gocv read the RTMP live stream?
If OpenCV can do it, GoCV can do it, but that all depends on the installed libs on your system, the server, syntax, etc.
If OpenCV can do it, GoCV can do it, but that all depends on the installed libs on your system, the server, syntax, etc.
since my opencv was installed by the makefile under gocv repository, and as the tutorial shows, i can run the command:
[root@master1 gocv]# go run ./cmd/version/main.go
gocv version: 0.28.0
opencv lib version: 4.5.3
does this mean my opencv and libs is correctly installed?
That does not mean that you have any particular libs used internally to OpenCV that may require separate installation, such as gstreamer or FFMPEG. Sorry I cannot be more specific. GoCV is a wrapper so OpenCV docs are where to look for those kinds of details.
That does not mean that you have any particular libs used internally to OpenCV that may require separate installation, such as gstreamer or FFMPEG. Sorry I cannot be more specific. GoCV is a wrapper so OpenCV docs are where to look for those kinds of details.
Really thanks for your help, i think it should be the server OpenCV env miss the FFMPEG libs , i will try to install this lib then try again! Really thanks for your patience!
No problem! It you get it figured out for your situation and have time to submit a PR for docs update someplace with what you have learned, I am sure others will find it very helpful.
edit win_build_opencv.cmd try: line 41(building opencv): add -DWITH_FFMPEG=ON