2

I'm trying to live stream the Raspberry Pi camera feed using rtp to a Janus gateway running on the same Raspberry Pi. The Janus and the demo pages are working so far, e.g. the streaming page streams both sample audios to a browser on a different computer.

What I need is a working ffmpeg one-liner to take the camera at /dev/video0 as input and output an rtp stream to Janus, maybe also with a corresponding /opt/janus/etc/janus/janus.plugin.streaming.jcfg

What I've found so far is a working one-liner using raspivid piped into gstreamer but that laggs hard:

raspivid --verbose --nopreview -hf -vf --width 640 --height 480 --framerate 30 --bitrate 1000000 --profile baseline --timeout 0 -o - | gst-launch-1.0 -v fdsrc ! h264parse ! rtph264pay config-interval=1 pt=126 ! udpsink host=127.0.0.1 port=8004

I'm looking for something similar to this (which apparently is not working/playing on the demo page):

ffmpeg -f v4l2 -framerate 30 -video_size 640x480 -codec:v h264 -i /dev/video0 -codec:v libx264 -profile:v baseline -preset ultrafast -tune zerolatency -s 640x480 -b:v 1000k -f rtp rtp://localhost:8004

My /opt/janus/etc/janus/janus.plugin.streaming.jcfg looks like this (tried with and without commenting out the single line):

h264-sample: {
    type = "rtp"
    id = 10
    description = "H.264 live stream"
    audio = false
    video = true
    videoport = 8004
    videopt = 96
    videortpmap = "H264/90000"
    #videofmtp = "profile-level-id=42e01f;packetization-mode=1"
    videofmtp = "packetization-mode=1"
}

Any help is greatly appreciated!

2 Answers 2

3

So after a lot of research and trial/error I've finally found a solution using gstreamer. You can use something like this which plays perfectly fine via Janus while also being able to adjust the resolution, bitrate and the port of the stream:

gst-launch-1.0 -v v4l2src device=/dev/video0 ! video/x-raw,width=1280,height=720,framerate=30/1 ! omxh264enc target-bitrate=1000000 control-rate=variable ! h264parse ! rtph264pay config-interval=1 pt=96 ! udpsink host=127.0.0.1 port=8004

To embed the current time and date (in this case the format is 14:55:03 01.08.2019) directly in the stream, you can use:

gst-launch-1.0 -v v4l2src device=/dev/video0 ! video/x-raw,width=1280,height=720,framerate=30/1 ! clockoverlay time-format="%H:%M:%S %d.%m.%Y" outline-color=-16777216 color=-1 draw-shadow=false font-desc="myriad pro bold expanded 16" ! omxh264enc target-bitrate=1000000 control-rate=variable ! h264parse ! rtph264pay config-interval=1 pt=96 ! udpsink host=127.0.0.1 port=8004

For a nightly live stream (using IR Leds) I use the following one which is brighter but has less contrast (e.g. it's almost black and white) as you can't see colors anyway. Also you can stream to two different ports simultaneously:

gst-launch-1.0 -v v4l2src extra-controls="c,brightness=65,saturation=-60" device=/dev/video0 ! video/x-raw,width=1280,height=720,framerate=30/1 ! clockoverlay time-format="%H:%M:%S %d.%m.%Y" outline-color=-16777216 color=-1 draw-shadow=false font-desc="myriad pro bold expanded 16" ! omxh264enc target-bitrate=3000000 control-rate=variable ! h264parse ! rtph264pay config-interval=1 pt=96 ! udpsink clients=127.0.0.1:8004,127.0.0.1:8040

To save a stream using the matroska container (e.g. after a movement detection/timer) you can use this:

gst-launch-1.0 -e udpsrc port=8040 ! application/x-rtp ! rtph264depay ! h264parse ! matroskamux ! filesink location=livecamera2.mp4

And to stream the same file:

gst-launch-1.0 -v filesrc location=livecamera2.mp4 ! matroskademux ! video/x-h264 ! rtph264pay config-interval=1 pt=96 ! udpsink host=127.0.0.1 port=8004

I hope this will be helpful for someone :)

2

I could use ffmpeg to stream my webcam video like this.

$ ffmpeg \
    -f v4l2 -thread_queue_size 8192 -input_format yuyv422 \
    -video_size 1280x720 -framerate 10 -i /dev/video0 \
    -c:v h264_omx -profile:v baseline -b:v 1M -bf 0 \
    -flags:v +global_header -bsf:v "dump_extra=freq=keyframe" \
    -max_delay 0 -an -bufsize 1M -vsync 1 -g 10 \
    -f rtp rtp://127.0.0.1:8004/

There may be more better ffmpeg option settings though.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .