Low latency (0.4s) H.264 livestreaming from Theta V WiFi to html5 clients with RTSP plug-in, ffmpeg and Janus Gateway on raspberry Pi

Hello,

After many tries on Theta V, I achieved to get a H.264 livestreaming on a Raspberry Pi for multiples html5 clients with a 0.4s latency.
It uses almost all realtime protocols available and powerfull softwares just to bypass USB livestreaming witch is not available on linux !

How it works:

  • Theta V with RTSP plug-in connected in client mode (should work in AP mode too, 5GHz WiFi for better bandwith). RTSP with Device WebAPI Plug-in also works.
  • ffmpeg (running on a Raspberry Pi) gets the RTSP stream and send it in rtp to Janus Gateway.
  • Janus Gateway (running on a Raspberry Pi) transforms rtp stream and distributes it to html5 clients (tested on both FireFox and Chrome) with webRTC.

How to do it:

theta-rpi: {
    type = "rtp"
    id = 1
    description = "Theta"
    audio = false
    video = true
    videoport = 8080
    videopt = 96
    videortpmap = "H264/90000"
    videofmtp = "profile-level-id=42e028;packetization-mode=1"
} 

Debug level to 0 in janus.jcfg for better Cpu usage

  • Install fmpeg on the Pi (already installed with full raspbian) and run it:

ffmpeg -i rtsp://192.168.1.48:8554/live?resolution=1920x960 -an -c:v copy -flags global_header -bsf dump_extra -f rtp rtp://192.168.1.28:8080

192.168.1.48 is the Theta IP address,192.168.1.28 is the Raspberry Pi address
You can use vlc instead but it add latency and when i change the buffer size (1000ms by defauft) it is not stable.

vlc -vvv rtsp://192.168.1.48:8554/live?resolution=3840x1920 --network-caching=1000 --sout “#rtp{dst=192.168.1.28,port=8080}”

  • Install RTSP plug-in and Theta V, start Theta V, wait for Wifi connection, start the plug-in

Pros:

  • It works !
  • low latency => 330 ms
    My solution to test latency: screen capture with chronometer
  • Multiple clients
  • low cpu usage (it works on a Pi Zero W), example in 1920x960 with 2 clients
  • 4K available
  • Endless streaming if theta V is connected with external power (tested in fullHD)
  • Bonus : after the plug-in is started, you can connect theta in USB and download files from it at the same time

Cons:

  • Low bitrate, 30fps/2Mbps in 1920x960, 18 fps/3Mbps in 4K
    => more powerfull Pi needed for 4K
  • Equirectangular format (need three.js for better view)
    => use RTSP with Device WebAPI Plug-in for a standard view or VR view
  • Some freezing

Next:

  • Add audio (not needed for my goal)
  • Rebuild my three.js implementation (it consumes lot of cpu on the client side)
  • See if gophoto2 works (I need powerOff function only available in USB mode) and how to start the plug-in even if the theta is connected in USB (for now i need to disconnect Theta from USB and start the plug-in with the wifi API)
  • Use ffmpeg to get both streaming and record on the Pi (easy task)
  • Help needed for a new plug-in with all Theta functionnalities and better bitrate

All this work to see wonderfull images from space, NO just sewer pipes :slight_smile:

Hugues

1 Like

Hugues, this is fantastic. Thanks for sharing it. Your project is really advancing. Are you selling your product globally? It seems like there’s a need for a low-cost way to assess different types of pipelines and sewer systems.

Under cons, you list RTSP. I don’t know too much about RTSP and I’m curious as to the downside. Why is it a con?

You also indicate that you need to disconnect the THETA from USB and start the plug-in with the Wi-Fi API.

Just an FYI, I’ve seen a demo of a usermode Linux streaming driver that allows the THETA to livestream on Linux. I believe the developer is planning to release it as open source in the next few months. When the driver is released, it could be another possible strategy for you.

Update: Nov 13, 2019

@Hugues, can you confirm that this diagram is accurate?