matthiasbock / gstreamer-phone

gstreamer based SIP console videophone, designed especially for the Raspberry Pi
54 stars 9 forks source link

High bandwidth consumption #1

Closed matthiasbock closed 11 years ago

matthiasbock commented 11 years ago

The network bandwidth consumption of a Logitech C920 streaming H.264 captured and packed by cvlc to the network via RTSP lies constantly around 400 KBytes per second. This is extraordinary much and a lot more, than an average DSL internet connection can upstream (512 kbps). Surprisingly the bandwidth consumption does not significantly reduce when reducing the capture resolution. It's almost the same for 640x480 and 1920x1080.

I guess this counterintuitive finding explains itself from the C920 trying to encode/stream at a constant bitrate. In fact, I found several articles concerning the alteration of the C920's H.264 stream bitrate:

In case it turns out, it's not possible or too difficult to control the bitrate of the C920's internal video compression, there still is the option of using the Raspberry's OpenMAX encoding capabilities.

However, as of may 14th, there is a problem with setting the bitrate, too, as the libraries for the Broadcom SoC are closed source:

matthiasbock commented 11 years ago

The Raspberry encoding solution looks like a lot of work and does not ensure bitrate control. The capture script was developed, when there was no native H.264 support available yet. Now it is, so I will try to go for the uvch264 gstreamer source solution. Apparently people already got bitrate control to work with it.

matthiasbock commented 11 years ago

According to http://kakaroto.homelinux.net/2012/09/uvc-h264-encoding-cameras-support-in-gstreamer/, the UVC H.264 source is only available for gstreamer 0.10 (not 0.11 or higher). It's in the bad plugins package.

The following source parameters are interesting for bitrate control:

Static:

Dynamic:

UVC H.264 dependencies:

matthiasbock commented 11 years ago

Example:

gst-launch uvch264_src device=/dev/video1 name=src auto-start=true src.vfsrc ! \
queue ! \
“video/x-raw-yuv,width=320,height=240,framerate=30/1″ ! \
xvimagesink src.vidsrc !  \
queue ! \
video/x-h264,width=1920,height=1080,framerate=30/1,profile=constrained-baseline ! \
h264parse ! ffdec_h264 ! xvimagesink

Another example, with RTMP streaming:

gst-launch -v uvch264_src device=/dev/video1 name=src auto-start=true \
average-bitrate=512000 initial-bitrate=512000 peak-bitrate=512000 \
\
src.vidsrc ! queue ! video/x-h264,width=800,height=448,framerate=30/1,\
profile=constrained-baseline,stream-format=byte-stream ! h264parse !  \
muxout. \
\
src.vfsrc ! queue ! "video/x-raw-yuv,width=320,height=240,framerate=30/1"  ! fakesink \
\
pulsesrc device="alsa_input.usb-046d_HD_Pro_Webcam_C920_E69194FF-02-C920.analog-stereo" \
! queue ! audioconvert ! voaacenc bitrate=65536 ! \
muxout. \
\
flvmux name=muxout streamable=true ! \
rtmpsink location='rmtp://wowza-live:1935/live/myStream'
matthiasbock commented 11 years ago

In order to have a uvc h264 source, I need to compile gstreamer-0.10's bad plugins from the source.

He did that, too: http://groakat.wordpress.com/2012/12/05/gstreamer-stream-h264-webcam-data-to-series-of-files/

matthiasbock commented 11 years ago

The uvch264_src plugin has been successfully compiled. See Issue 2 for details.

matthiasbock commented 11 years ago

Now it should be possible, to launch a gstreamer pipeline with the camera, streaming video via RTP, where the H.264 bitrate can be set according to the available bandwidth.

matthiasbock commented 11 years ago
$ gst-inspect-0.10 uvch264_src
...
      video/x-h264
                  width: [ 1, 2147483647 ]
                 height: [ 1, 2147483647 ]
              framerate: [ 0/1, 2147483647/1 ]
          stream-format: { byte-stream, avc }
              alignment: { au }
                profile: { high, main, baseline, constrained-baseline }
...
matthiasbock commented 11 years ago

Experimenting with gstreamer to gstreamer H.264 streaming via RTP ... see Wiki ...

matthiasbock commented 11 years ago

The bandwidth is now adjustable using uvch264_src initial_bitrate=400000 which should work on an average DSL 6000 internet connection.