Streaming your RaspberryPi Camera

To start streaming camera video, we simply combine raspivid and ffmpeg by piping one into another.

Prequisites

  • raspivid
  • ffmpeg
raspivid -t 0 -w 1280 -h 720 -fps 25 -g 75 -fl -o - | ffmpeg -f lavfi -i anullsrc=channel_layout=stereo:sample_rate=44100 -i pipe:0 -c:v copy -c:a aac -strict experimental -f flv -f flv rtmp://ip:port/app/stream  
  • -t 0: Continuously pull video from the camera
  • -w 1280 -h 720 -fps 25: Video stream of 720p25
  • -g 75: I-frame interval at 1/s
  • -o -: Pipe video to stdout
  • -f lavfi -i anullsrc=channel_layout=stereo:sample_rate=44100 and -c:a aac -strict experimental: Since the RaspberryPi doesn't have a microphone, we can pipe some silence instead. This is very optional and depends on your use case.
  • -i pipe:0 -c:v copy: Read the video stream from stdin . The video stream from raspivid is already encoded in h264, so we skip re-encoding by using copy.
  • -f flv rtmp://ip:port/app/stream: The destination.

References:
* adding-silent-audio-to-mov-in-ffmpeg