takanoha
takanoha

Reputation: 353

Running gstreamer on ubuntu sending video through RTSP is too slow

I am trying to stream live video from a webcam attached on my ubuntu machine.

I first checked out the gst-rtsp-server code and followed the steps below:

$ git clone git://anongit.freedesktop.org/gstreamer/gst-rtsp-server
$ cd gst-rtsp-server
$ git checkout 1.4
$ ./autogen.sh
$ make
$ sudo make install

Then I tried to send the test pattern image

./test-launch '( videotestsrc ! x264enc ! rtph264pay name=pay0 pt=96 )'
stream ready at rtsp://127.0.0.1:8554/test

The client side can see the pattern - works.

Then I tried to display the webcam with the following command.

./test-launch '( v4l2src device=/dev/video0 ! video/x-raw,width=640,height=480,framerate=30/1 ! videoconvert ! x264enc ! rtph264pay name=pay0 pt=96 )'

This works fine but the latency is about 3 seconds.

Is there a way to reduce the latency to make it look more like in real time ?

From gst-device-monitor I see the following message:

$ gst-device-monitor-1.0

Probing devices...


Device found:

 Analog Stereo: BUFFALO BSWHD06M USB Camera
    class : Audio/Source
    caps  : audio/x-raw, format=(string){ S16LE, S16BE, F32LE, F32BE, S32LE, S32BE, S24LE, S24BE, S24_32LE, S24_32BE, U8 }, layout=(string)interleaved, rate=(int)[ 1, 384000 ], channels=(int)[ 1, 32 ];
            audio/x-alaw, rate=(int)[ 1, 384000 ], channels=(int)[ 1, 32 ];
            audio/x-mulaw, rate=(int)[ 1, 384000 ], channels=(int)[ 1, 32 ];
    properties:
        alsa.resolution_bits = 16
        device.api = alsa
        device.class = sound
        alsa.class = generic
        alsa.subclass = generic-mix
        alsa.name = "USB\ Audio"
        alsa.id = "USB\ Audio"
        alsa.subdevice = 0
        alsa.subdevice_name = "subdevice\ \#0"
        alsa.device = 0
        alsa.card = 1
        alsa.card_name = "BUFFALO\ BSWHD06M\ USB\ Camera"
        alsa.long_card_name = "KYE\ Systems\ Corp.\ BUFFALO\ BSWHD06M\ USB\ Camera\ at\ usb-0000:00:14.0-10\,\ high\ spee"
        alsa.driver_name = snd_usb_audio
        device.bus_path = pci-0000:00:14.0-usb-0:10:1.2
        sysfs.path = /devices/pci0000:00/0000:00:14.0/usb1/1-10/1-10:1.2/sound/card1
        udev.id = usb-KYE_Systems_Corp._BUFFALO_BSWHD06M_USB_Camera-02
        device.bus = usb
        device.vendor.id = 0411
        device.vendor.name = "BUFFALO\ INC.\ \(formerly\ MelCo.\,\ Inc.\)"
        device.product.id = 0260
        device.product.name = "BUFFALO\ BSWHD06M\ USB\ Camera\015"
        device.serial = KYE_Systems_Corp._BUFFALO_BSWHD06M_USB_Camera
        device.form_factor = webcam
        device.string = front:1
        device.buffering.buffer_size = 352800
        device.buffering.fragment_size = 176400
        device.access_mode = mmap+timer
        device.profile.name = analog-stereo
        device.profile.description = "Analog\ Stereo"
        device.description = "BUFFALO\ BSWHD06M\ USB\ Camera\015\ Analog\ Stereo"
        module-udev-detect.discovered = 1
        device.icon_name = camera-web-usb
        is-default = true
    gst-launch-1.0 pulsesrc device=alsa_input.usb-KYE_Systems_Corp._BUFFALO_BSWHD06M_USB_Camera-02.analog-stereo ! ...


Device found:

    name  : Monitor of Built-in Audio Digital Stereo (HDMI 3)
    class : Audio/Source
    caps  : audio/x-raw, format=(string){ S16LE, S16BE, F32LE, F32BE, S32LE, S32BE, S24LE, S24BE, S24_32LE, S24_32BE, U8 }, layout=(string)interleaved, rate=(int)[ 1, 384000 ], channels=(int)[ 1, 32 ];
            audio/x-alaw, rate=(int)[ 1, 384000 ], channels=(int)[ 1, 32 ];
            audio/x-mulaw, rate=(int)[ 1, 384000 ], channels=(int)[ 1, 32 ];
    properties:
        device.description = "Monitor\ of\ Built-in\ Audio\ Digital\ Stereo\ \(HDMI\ 3\)"
        device.class = monitor
        alsa.card = 0
        alsa.card_name = "HDA\ Intel\ PCH"
        alsa.long_card_name = "HDA\ Intel\ PCH\ at\ 0x51130000\ irq\ 136"
        alsa.driver_name = snd_hda_intel
        device.bus_path = pci-0000:00:1f.3
        sysfs.path = /devices/pci0000:00/0000:00:1f.3/sound/card0
        device.bus = pci
        device.vendor.id = 8086
        device.vendor.name = "Intel\ Corporation"
        device.product.id = a348
        device.product.name = "Cannon\ Lake\ PCH\ cAVS"
        device.form_factor = internal
        device.string = 0
        module-udev-detect.discovered = 1
        device.icon_name = audio-card-pci
        is-default = false
    gst-launch-1.0 pulsesrc device=alsa_output.pci-0000_00_1f.3.hdmi-stereo-extra2.monitor ! ...


Device found:

    name  : Built-in Audio Digital Stereo (HDMI 3)
    class : Audio/Sink
    caps  : audio/x-raw, format=(string){ S16LE, S16BE, F32LE, F32BE, S32LE, S32BE, S24LE, S24BE, S24_32LE, S24_32BE, U8 }, layout=(string)interleaved, rate=(int)[ 1, 384000 ], channels=(int)[ 1, 32 ];
            audio/x-alaw, rate=(int)[ 1, 384000 ], channels=(int)[ 1, 32 ];
            audio/x-mulaw, rate=(int)[ 1, 384000 ], channels=(int)[ 1, 32 ];
    properties:
        alsa.resolution_bits = 16
        device.api = alsa
        device.class = sound
        alsa.class = generic
        alsa.subclass = generic-mix
        alsa.name = "HDMI\ 2"
        alsa.id = "HDMI\ 2"
        alsa.subdevice = 0
        alsa.subdevice_name = "subdevice\ \#0"
        alsa.device = 8
        alsa.card = 0
        alsa.card_name = "HDA\ Intel\ PCH"
        alsa.long_card_name = "HDA\ Intel\ PCH\ at\ 0x51130000\ irq\ 136"
        alsa.driver_name = snd_hda_intel
        device.bus_path = pci-0000:00:1f.3
        sysfs.path = /devices/pci0000:00/0000:00:1f.3/sound/card0
        device.bus = pci
        device.vendor.id = 8086
        device.vendor.name = "Intel\ Corporation"
        device.product.id = a348
        device.product.name = "Cannon\ Lake\ PCH\ cAVS"
        device.form_factor = internal
        device.string = "hdmi:0\,2"
        device.buffering.buffer_size = 352800
        device.buffering.fragment_size = 176400
        device.access_mode = mmap+timer
        device.profile.name = hdmi-stereo-extra2
        device.profile.description = "Digital\ Stereo\ \(HDMI\ 3\)"
        device.description = "Built-in\ Audio\ Digital\ Stereo\ \(HDMI\ 3\)"
        module-udev-detect.discovered = 1
        device.icon_name = audio-card-pci
        is-default = true
    gst-launch-1.0 ... ! pulsesink device=alsa_output.pci-0000_00_1f.3.hdmi-stereo-extra2


Device found:

    name  : BUFFALO BSWHD06M USB Camera
    class : Video/Source
    caps  : video/x-raw, format=(string)YUY2, width=(int)1280, height=(int)720, pixel-aspect-ratio=(fraction)1/1, framerate=(fraction)8/1;
            video/x-raw, format=(string)YUY2, width=(int)800, height=(int)600, pixel-aspect-ratio=(fraction)1/1, framerate=(fraction){ 15/1, 8/1 };
            video/x-raw, format=(string)YUY2, width=(int)640, height=(int)480, pixel-aspect-ratio=(fraction)1/1, framerate=(fraction){ 30/1, 20/1, 15/1, 8/1 };
            video/x-raw, format=(string)YUY2, width=(int)640, height=(int)360, pixel-aspect-ratio=(fraction)1/1, framerate=(fraction){ 30/1, 20/1, 15/1, 8/1 };
            video/x-raw, format=(string)YUY2, width=(int)352, height=(int)288, pixel-aspect-ratio=(fraction)1/1, framerate=(fraction){ 30/1, 20/1, 15/1, 8/1 };
            video/x-raw, format=(string)YUY2, width=(int)320, height=(int)240, pixel-aspect-ratio=(fraction)1/1, framerate=(fraction){ 30/1, 20/1, 15/1, 8/1 };
            video/x-raw, format=(string)YUY2, width=(int)176, height=(int)144, pixel-aspect-ratio=(fraction)1/1, framerate=(fraction){ 30/1, 20/1, 15/1, 8/1 };
            video/x-raw, format=(string)YUY2, width=(int)160, height=(int)120, pixel-aspect-ratio=(fraction)1/1, framerate=(fraction){ 30/1, 20/1, 15/1, 8/1 };
            image/jpeg, width=(int)1280, height=(int)960, pixel-aspect-ratio=(fraction)1/1, framerate=(fraction)12/1;
            image/jpeg, width=(int)1280, height=(int)720, pixel-aspect-ratio=(fraction)1/1, framerate=(fraction){ 30/1, 24/1, 20/1, 16/1 };
            image/jpeg, width=(int)800, height=(int)600, pixel-aspect-ratio=(fraction)1/1, framerate=(fraction){ 30/1, 24/1, 20/1, 16/1 };
            image/jpeg, width=(int)640, height=(int)480, pixel-aspect-ratio=(fraction)1/1, framerate=(fraction){ 30/1, 24/1, 20/1, 16/1 };
            image/jpeg, width=(int)640, height=(int)360, pixel-aspect-ratio=(fraction)1/1, framerate=(fraction){ 30/1, 20/1, 15/1, 8/1 };
            image/jpeg, width=(int)352, height=(int)288, pixel-aspect-ratio=(fraction)1/1, framerate=(fraction){ 30/1, 24/1, 20/1, 15/1 };
            image/jpeg, width=(int)320, height=(int)240, pixel-aspect-ratio=(fraction)1/1, framerate=(fraction){ 30/1, 20/1, 15/1, 8/1 };
            image/jpeg, width=(int)176, height=(int)144, pixel-aspect-ratio=(fraction)1/1, framerate=(fraction){ 30/1, 20/1, 15/1, 8/1 };
            image/jpeg, width=(int)160, height=(int)120, pixel-aspect-ratio=(fraction)1/1, framerate=(fraction){ 30/1, 24/1, 20/1, 16/1 };
    properties:
        udev-probed = true
        device.bus_path = pci-0000:00:14.0-usb-0:10:1.0
        sysfs.path = /sys/devices/pci0000:00/0000:00:14.0/usb1/1-10/1-10:1.0/video4linux/video0
        device.bus = usb
        device.subsystem = video4linux
        device.vendor.id = 0411
        device.vendor.name = "KYE\\x20Systems\\x20Corp."
        device.product.id = 0260
        device.product.name = "BUFFALO\ BSWHD06M\ USB\ Camera"
        device.serial = KYE_Systems_Corp._BUFFALO_BSWHD06M_USB_Camera
        device.capabilities = :capture:
        device.api = v4l2
        device.path = /dev/video0
        v4l2.device.driver = uvcvideo
        v4l2.device.card = "BUFFALO\ BSWHD06M\ USB\ Camera\015\012:\ "
        v4l2.device.bus_info = usb-0000:00:14.0-10
        v4l2.device.version = 329746 (0x00050812)
        v4l2.device.capabilities = 2225078273 (0x84a00001)
        v4l2.device.device_caps = 69206017 (0x04200001)
    gst-launch-1.0 v4l2src ! ...

Upvotes: 1

Views: 1640

Answers (1)

Florian Zwoch
Florian Zwoch

Reputation: 7373

You are not just playing the stream, you are actually re-encoding the data. This encoding introduces latency. For the x264enc element use the tune=zerolatency option to reduce the delay. It comes at a cost of video quality though.

Upvotes: 1

Related Questions