Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

After summarizing my question and struggles, here is the answer and solution I've come up with so far. I've posted the question and the solution so others don't have to search through many other posts that don't quite solve the issues I've had, and to share details that I had to figure out which helped me. I am using Visual Studio on MS Windows 7 and 8.1 machines and coding in C++.

The video stream of 2 cameras works with the following minor issues: - I need to figure out how to display them separately instead of alternating on the same window. This is not a problem for my application since I just need to process them together, not display them simultaneously. - About a 1 second delay.

1) It seems clear that FFMPEG library does not work for H264 video streams over RTSP. So I downloaded and installed libVLC along with the VLC Player.

a) libVLC installation: Download the 7zip file (no installer version) so as to get all the library header files, DLL's and source codes. Then link them, almost exactly like you installed and linked OpenCV (I used local method: system paths and environmental variables, after which I had to reboot). - I needed the libvlc.dll, libvlccore.dll, the headers and the .lib files, so you will have to find these and link them.

b) VLC Player: Download and install.
The player is for testing, since sometimes what you have in the code may be wrong. I recommend testing your URL directly in the player when you find errors you cannot explain. This allows you to test the RTSP or HTTP command you should use exactly in your code (go to Media -> Open Network Stream -> Network -> "Please enter a network URL:" -> and then enter "rtsp://username:[email protected]:554" for example).

2) Sample libVLC + OpenCV code to use to test: I used this which is similar to the VLC = VideoLan example.

  • It appears that the "unlock" callback function is one of the places to process the MAT image directly (in libvlc_video_set_callbacks(mediaPlayer, lock, unlock, display, context), for example here)

3) Some troubleshooting I had to do:

a) Undeclared identifiers: This implies missing headers. I needed to include the following for libVLC in addition to OpenCV headers: vlc/libvlc.h vlc/libvlc_media.h vlc/libvlc_media_player.h

b) x86 vs. x64: I kept getting this error since libVLC works for 32 bit and not for 64 bit. You can still use libVLC on a 64 bit machine (which is what I have), but need to change the configuration to 32 bit. I kept getting errors despite changing this in configuration manager, and resolved it by simply creating a new solution from scratch and then copying my code. (See link).

c) Stopped videos: occasionally some errors would show up on the back end, and the first 5 seconds or so were somewhat corrupted for brief periods. After a while, my videos just stopped. I tested the URL in VLC Player and discovered the same thing was happening. Turns out I was using the HTTP port number instead of the RTSP port number after the colon (:) in the URL. For example, I used "rtsp://username:[email protected]:85" instead of "rtsp://username:[email protected]:554")

This is what I have so far, and the video streams are just like what I see through the VLC Player! Yay! I would like to eliminate the ~1 second delay, and make a few other improvements, but this has been a huge progress over where I was a few months ago at integration. Also this and the VLC player seems to crash beyond 20 fps (I'm using Q-See QCN 8023B models) Now I can just focus on coding, for the most part. :)

I will post updates if I have improvements and people are interested, and if I remember.