Sunday, May 10, 2015

Video Streaming Speeds as Compared to original Raspberry Pi and Raspberry Pi 2

Having managed to get reasonable video streaming working on a Raspberry Pi with minimal lag I thought it would be a good idea to test it on a Raspberry PI 2.

Using the Original Raspberry Pi

Using UV4L and its built in MJPEG streaming server I was able to get a pretty reasonable solution together with a lag of about 0.5 seconds. However, I had to use a video size of 320x240 at 15 FPS which is pretty low res. See video below.
I pointed the camera at a stopwatch on a phone which was put up against my tablet which is running the video app developed for the robot (see earlier post). If you pause the video at any time you can see the lag between the two clocks of roughly 0.5 secs. If I set the video to the default 1920x1024 at 30 FPS the lag is 3-4 seconds.

Using the Raspberry Pi 2

The Pi 2 being 6 times faster you'd hope that video rendering would be much faster and you'd be right!
The video below show video streaming using MJPEG at 1920x1024 at 30 FPS and we're getting about 0.4 to 0.5 seconds lag which is pretty good.
I wasn't able to improve on the speed by very much by dropping the frame rate and resolution. Even at 320x240 15 FPS I was still getting a lag of 0.3 seconds. I think there is a certain amount of lag that cannot be overcome. The speed of the wifi and the rendering on the tablet will all add to the delay.


Using WebRTC

UV4L on a Raspberry Pi 2 supports WebRTC which is not available on the original Pi due to API's not bundled in Wheezy for the original Pi. WebRTC is a new protocol and API for supporting real time communication in browsers. Media streaming is just one of the many uses.
Although it works very nicely the speed was very similar to MJPEG.

So, near real time streaming video at full resolution is possible with the Raspberry Pi 2 and UV4L. 

17 comments:

  1. How do you call up and launch the server, i have it installed but i cant figure out how im supposed to embed the video into a script.

    ReplyDelete
    Replies
    1. After you install (see earlier blog post) it install u4vl as a service which launches on startup. You can also start/stop/restart using:

      sudo /etc/init.d/uv4l_raspicam start

      The config file is stored in: /etc/uv4l/uv4l-raspicam.conf

      The main part in the conf file to alter is width, height and framerate. For the raspberry pi 1 it has to be set quite low:

      width = 320
      height = 240
      framerate = 10

      For the raspberry pi 2 you can up it a bit to a frame rate of 15. You should be able to go higher with the Pi 3 but I've not tried it.

      If you change the config you need to restart the server using:

      sudo /etc/init.d/uv4l_raspicam restart

      To access the control panel and links to the streams just point a web browser to it:

      http://:8080

      My android app just embeds the web page in a WebView component. See other blog post and code on github.

      Delete
    2. For the Pi2 I was able to get it up to 1920x1024 at 30 FPS with only a small lag.

      Delete
  2. Nice video, very impressive. I also agree with Demios - a little example code would be very welcome.

    ReplyDelete
  3. Excellent work. You may get even less lag with a Wifi adapter with a better aerial than the one you are using like this one. http://www.ebay.co.uk/itm/181448830743 I've tried both and while both are fully compatible with Pi, the one with the external aerial has far better signal strength/perfomance.

    ReplyDelete
    Replies
    1. Signal strength was not an issue for this test but generally that's a good idea.

      Delete
    2. Signal strength was not an issue for this test but generally that's a good idea.

      Delete
  4. This comment has been removed by the author.

    ReplyDelete
  5. I couldn't see it documented here, but have you tried overclocking the Pi? You might get even less lag (at the expense of battery life of course). I've had good results running it at 1ghz, 500, 500, 2 with zero crashes. Depends on your power supply of course.

    ReplyDelete
    Replies
    1. I haven't tried that but I agree that's likely to improve it.

      Delete
    2. I haven't tried that but I agree that's likely to improve it.

      Delete
  6. Hey Paul,
    thank's for the original post that helped me a lot when trying to get video streaming to work on my pi2. I've put most of the ressources I've found on streaming and video+audio recording (including your post) into a blog post here.
    I've achieved almost latency-free streaming with GStreamer (see post above) but also came up with about 300-500 ms of lag when using the Picam option i settled with.
    Cheers, Daniel

    ReplyDelete
    Replies
    1. Anyone clicking on this link: if it doesn't work, remove the speechmark from the end of the URL.

      Delete
    2. Hi Dan
      Thanks for your post. It looks like the options for streaming are improving. You're right to observe that my choices are restricted by wanting to stream onto an Android device which is why I settled on an mpeg based solution.
      Thanks

      Delete
    3. Hi Dan
      Thanks for your post. It looks like the options for streaming are improving. You're right to observe that my choices are restricted by wanting to stream onto an Android device which is why I settled on an mpeg based solution.
      Thanks

      Delete
  7. Hey Paul,
    your Blog is great!
    But please can you exlain this video streaming with 1920x1024 at 30 FPS step by step until the html code ?
    Yours tom.

    ReplyDelete