Ask Your Question

Gabriel Barreras's profile - activity

2020-11-04 00:40:02 -0600 received badge  Notable Question (source)
2019-10-21 07:32:05 -0600 received badge  Popular Question (source)
2015-05-12 04:07:10 -0600 received badge  Enthusiast
2015-05-07 12:56:03 -0600 commented question OpenCV won't capture frames from a RTMP source, while FFmpeg does

Yes, I'm in Windows 8.1. I've tried what you suggested and the result was the same. However, since I was running it from Eclipse PyDev, this time I run it from cmd instead, and I'm getting the following warning:

warning: Error opening file (../../modules/highgui/src/cap_ffmpeg_impl.hpp:545)

This warning means, as far as I could read, that either the file-path is wrong, or either the codec is not supported. Now, the question is the same. Is OpenCV not capable of getting the frames from this source?

2015-05-07 11:18:28 -0600 asked a question OpenCV won't capture frames from a RTMP source, while FFmpeg does

My goal is to capture a frame from a rtmp stream every second, and process it using OpenCV. I'm using FFmpeg version N-71899-g6ef3426 and OpenCV 2.4.9 with the Java interface (but I'm first experimenting with Python). For the moment, I can only take the simple and dirty solution, which is to capture images using FFmpeg, store them in disk, and then read those images from my OpenCV program. This is the FFmpeg command I'm using:

ffmpeg -i "rtmp://antena3fms35livefs.fplive.net:1935/antena3fms35live-live/stream-lasexta_1 live=1" -r 1 capImage%03d.jpg

This is currently working for me, at least with this concrete rtmp source. Then I would need to read those images from my OpenCV program in a proper way. I have not actually implemented this part, because I'm trying to find a better solution.

I think the ideal way would be to capture the rtmp frames directly from OpenCV, but I cannot find the way to do it. This is the code in Python I'm using:

cv2.namedWindow("camCapture", cv2.CV_WINDOW_AUTOSIZE)
cap = cv2.VideoCapture()
cap.open('"rtmp://antena3fms35livefs.fplive.net:1935/antena3fms35live-live/stream-lasexta_1 live=1"')
if not cap.open:
    print "Not open"
while (True):
    err,img = cap.read()
    if img and img.shape != (0,0):
        cv2.imwrite("img1", img)
        cv2.imshow("camCapture", img)
    if err:
        print err
        break
    cv2.waitKey(30)

Instead of read() function, I'm also trying with grab() and retrieve() functions without any good result. The read() function is being executed every time, but no "img" or "err" is received. Is there any other way to do it? or maybe there is no way to get frames directly from OpenCV 2.4.9 from a stream like this?

I've read OpenCV uses FFmpeg to do this kind of tasks, but as you can see, in my case FFmpeg is able to get frames from the stream while OpenCV is not.

In the case I could not find the way to get the frames directly from OpenCV, my next idea is to pipe somehow, FFmpeg output to OpenCV, which seems harder to implement.

Any idea? Thank you!