Skip to main content

RPI camera → website → Chromecast → TV: (1) Capture video by RPI

 RPI camera → website → Chromecast → TV: (1) Capture video by RPI



Why am I doing this?

As an unemployed engineer, I need to find interesting things to fill my leisure time. I found there is a thing I can do to make my life more convenient to see the toys under my couch without in the crowing position of bending my knee and waist to find the toys which are “eaten by the couch,” my kids said.

Maybe I can use a camera on RPI to see the area under the couch and project the streaming video onto the TV by Chromecast. That is my initial thought.

Devices

  • An RPI4
  • A V2 camera
  • My computer that I can run a server on.
  • A Chromecast and TV

Goal

  1. Capture video by RPI

libcamera-vid

libcamera-vid is a built-in app for the RPI system. I found that the network streaming functionality can be enabled with libcamera-vid terminal command line, written in the official document. Thus, I can send the streamed video using the app by UDP, TCP, or RTSP.

Benchmark setting

  • The RPI camera captures the computer screen where I open a website showing the time information. I can compare the time from the website and the received video to determine the latency.

UDP

  • In RPI4

    ~ libcamera-vid -t 0 --inline -o udp://$WORKING_COMPUTER_IP:$WORKING_PORT
    
  • In my computer

    ~ ffplay udp://$WORKING_COMPUTER_IP:$WORKING_PORT -fflags nobuffer -flags low_delay -framedrop
    
  • Result

    • The latency is around 0 ~ 660 ms
    • 0ms 


    • 660ms


TCP

  • In RPI4

    ~ libcamera-vid -t 0 --inline --listen -o tcp://0.0.0.0:$WORKING_PORT
    
  • In my computer

    ~ ffplay tcp://$RPI_IP:$WORKING_PORT -vf "setpts=N/30" -fflags nobuffer -flags low_delay -framedrop
    
  • Result

    • The latency is around 0 ~ 300 ms
    • 0ms

    • 300ms

RTSP → RTMP

  • I should start a server first, and I found the below GitHub page, which is a setting about the RTMP server, so I decided to setup an RTMP server instead of an RTSP server

  • https://github.com/twtrubiks/nginx-rtmp-tutorial

    • I followed the instructions from the GitHub page and started an RTSP server.

      • Prepare the docker image and run it (I use all the parameters identical to the GitHub site.)
      docker run \\
          --restart=always \\
          -p "1935:1935" \\  # the RTMP SERVER PORT
          -p "8088:80" \\   
          -v ./nginx_simple.conf:/etc/nginx/nginx.conf \\
          -v ./stat.xsl:/usr/local/nginx/html/stat.xsl \\
          tiangolo/nginx-rtmp-docker-self-build:latest
      
  • In RPI

    • The last string rpicamera can be named as any tag and rpicamera is my chosen name.
    libcamera-vid -t 0 --inline -o - | ffmpeg -re -stream_loop -1 -i /dev/stdin -c:v copy -c:a copy -f flv rtmp://$WORKING_COMPUTER_IP:$RTMP_SERVER_PORT/live/rpicamera
    
  • In my computer

    ffplay -fflags nobuffer rtmp://$WORKING_COMPUTER_IP:$RTMP_SERVER_PORT/live/rpicamera
    
  • Result

    • The latency is around 1.3 ~ 1.6 s




Conclusion

The RTMP has the most latency, but since I know little about this protocol and server setting, it may be improved using the proper config.

I will still put a video into the website for the UTC/ TCP and RTMP methods to see how they will go.
[It will be written as the second part in the other post. maybe tomorrow]

Comments