ofVideoPlayer rtsp video streaming

Found a minor bug and a minor solution. The solution seems to work for me, and I haven’t had any problems so far. Just wanted to share.

in ofVideoPlayer loadMovie there is this if statement::

if( name.substr(0, 7) == "[http://"){](http://"){)  
			if(! createMovieFromURL(name, moviePtr) ) return false;  
			name 					= ofToDataPath(name);  
			if( !createMovieFromPath((char *)name.c_str(), moviePtr) ) return false;  

I changed it to this:

if( name.substr(0, 7) == "[http://"){](http://"){)  
			if(! createMovieFromURL(name, moviePtr) ) return false;  
		}else if ( name.substr(0,7) == "rtsp://"){  
			if(! createMovieFromURL(name, moviePtr) ) return false;  
			name 					= ofToDataPath(name);  
			if( !createMovieFromPath((char *)name.c_str(), moviePtr) ) return false;  

So now video streaming from a rtsp url works!


sweet, nice fix !!

  • zach

So I finally got around to continuing work with QT video streaming in openframeworks. Turns out if the stream loads too slowly QT will say the stream is 160x120 resolution, and unless you set ofVideoplayer to 160x120 the app will crash. However I found the solution in Apples QT docs.


Before any movie is played, QuickTime needs to allocate buffers and open appropriate media handlers. This process is called prerolling the movie. Before a streaming movie can be played, additional steps need to be taken, such as establishing RTP streams between the client and the server. This setup process is called pre-prerolling.

if( name.substr(0, 7) == "[http://"](http://") || name.substr(0,7) == "rtsp://" ){  
			if(! createMovieFromURL(name, moviePtr) ) return false;  
			SetMoviePlayHints(moviePtr, hintsAllowDynamicResize,hintsAllowDynamicResize);  
			PrePrerollMovie(moviePtr, 0, GetMoviePreferredRate(moviePtr),NULL,NULL);  

Oh yeah, and you have to tell QT that its ok to resize the movie if the stream resizes…which basically means, change from the default 160x120 when the stream video size info becomes available.

Anyway, streaming works much better now. Before it was kind of hit or miss. I didn’t use asynchronous callback for loading completion as they suggested, so the OF app wont load until the video stream loads.


Hello Noah,
Thanks for all your hard work on this, do you by any chance have an example I can look at of your rtsp code working? I am trying to get a simple example running using your code but just keep getting a quicktime window with a connecting animation. I am running OF using CodeBlocks and the latest build.


can we use apple philosophy in video streaming in linux or windows? how? what is the tool we need???

in linux you should be able to do just the same as on mac:

ofVideoPlayer video;  

even with flash video, ogg… and anything that totem or vlc can open.

sorry but can this work on LAN?
thank you

yes, of course, just use the ip of the computer instead of the server name

thank you i will chack that :smiley:


has anybody got a good idea how to prevent my app from freezing for about a minute when calling .loadMovie() and the RTSP-Service isn’t answering?

It all works like a charm when everything is properly set up. But we’re working on an installation with various cameras spread over the town. So I really can’t guarantee the availability. :?

My first thought was loading the video in a seperate thread. There’s a post on that already:
I just don’t know any better than that.

Another thing I’ve tried is using ofxTCPClient to establish a quick connection and calling loadMovie only when everything looks good. However same thing here – long wait…

Is there some place I can chose a shorter time to wait for a reply?

We are working on Mac and Windows btw.

I have gotten my rtsp streaming video coming into OF nicely now, by following whats been written in this thread. the next step is trying to reduce latency.

I notice that Quicktime adds about a 3 second buffer to any streaming file it tries to open. If open my stream in quicktime i notice about 4 second latency. If I open the same stream in VLC i get about 1 second latency. In OF (on mac) i get the same 4 second latency.

So, anyone have any idea how to adjust latency/buffering in OF?


@coraceJQ and others with the same problem in win:
what worked for me was replacing the line

PrePrerollMovie(moviePtr, 0, GetMoviePreferredRate(moviePtr),NULL,NULL);  

with line

PrePrerollMovie(moviePtr, 0, 25,NULL,NULL);  

I guess there’s some kind of problem with some cameras, or in Windows, that blocks Quicktime when trying to access the MoviePreferredRate, so hardcoding it avoids the problem of the “Connecting…” animation to be blocked.

I solved the delay in the streaming just by calling nextFrame() function once the streaming is playing, like:


I don’t understand why, but it works, at least in Windows. Maybe it does also in Mac?

My question now is related with the size of the ofVideoPlayer. As Noah said before in this thread (thanks a lot for the help Noah!), apparently Quicktime function GetMovieBox() thinks the streaming is 160x120 at the beginning, even if its resolution changes later dinamically calling SetMoviePlayHints(…).

But unluckily the ofVideoPlayer can’t change its size as easy as the Quicktime container. So I managed to change my ofVideoPlayer object to 640x480 changing the width and height in the loadMovie() in ofVideoPlayer.cpp. But this an awful way of solving the problem.

My question: is there a way to change the size of an ofVideoPlayer object (and its Texture!) in an elegant way (e.g. without changing openFrameworks core code?). I tried changing the width and height attributes but I get an error because the texture remains the same size. I also tried to clear and reallocate the texture after loading the streaming, but I get a segmentation fault… Any clue of what would be the nice way of doing this? I think if the ofVideoPlayer is supposed to reproduce a streaming that can change its size, these “resize()” function should belong to the ofVideoPlayer class…maybe? Thanks a lot!


in OSX, after following Noah’s suggestions the video automatically re-sizes to the actual size of the stream. So, if you are having that problem, it may be Windows specific. I’ll be checking it out when i do some windows tests. I will try the nextFrame() thing as well on OSX.

Right now, I’m more hopeful about switching over to gstreamer for windows, because I have a lot more faith in it’s streaming abilities.

also, if you are doing streaming in only windows, what are you using for your broadcasting software? On OSX, I use quicktime broadcaster + darwin streaming server.


I’m not configuring any server actually. There were at work 4 IP cameras that stream straight away in rtsp, so I was told to find if it was possible to make them work with oF.

About gstreamer, I have no idea if it’s better or worse, i’ve never used it. But I’m interested on it if you find out any results :slight_smile:

interesting, I have some cheap IP cameras lying around, I should check if they do rtsp.

So, I tried the nextFrame() thing, and it worked just great. almost no delay in streaming now. I wonder why that works?

all this is good with mac but on linux does’nt work

i have this error:

OF_ERROR: Gstreamer: cannot query width and height OF_WARNING: Gstreamer: cannot query time duration

on windows instead doesn’t works also inside quicktime i suppose that it is a quicktime bug

is the video that you are trying to play in some public url? i’ve done some changes for 007 to the videoplayer and perhaps it’s already solved if not i’ll try to solve it

how can try ofvideoplayer 0.07 version?

the 007 branch is super unstable right now so better to stay with 0062 by now. is there any way i can try a rtsp stream that is giving you errors? is difficult to help you without the problematic resource

I could set up a publicly accessible RTSP stream if it would be of help to anybody in debugging. I can’t promise great bandwidth though.

edit 1:

also, I get a similar error on a local rtsp stream in windows via Gstreamer:

gstvideo: failed to get caps of pad appsink0:sink
OF_ERROR:GStreamer: cannot querry width and height
OF_WARNING: GStreamer: cannot querry time duration

this is on windows 0.61 with GStreamer installed.

edit 2:
I can confirm now that I get identical errors in OF 0062 linux/ ubuntu 10.10

if you want some streams to test with:
[stream removed] (out my window)
also apple keynote speeches seem to get me the same errors:

Both of these should be visible using VLC.
they can both be seen in OSX with ofvideoplayer, although the stream I am sending is pretty flaky due to my low upload bandwidth.

I can confirm that if a stream isn’t received at all, (i.e. incorrect address) gives a different set of errors.

conversely, does anyone have an example of a streaming video that does load properly with GStreamer?