Pavel Železný
Pavel Železný

Reputation: 310

How to stream wpesrc audio to rtmp using gstreamer

I'm trying to put together an html overlay over a video to stream using gstreamer. I'd like to capture an html page with Twitch alerts that generates audio in addition to video.

I found a sample on the internet https://www.youtube.com/watch?v=QNZJYOuVGiE , which presents the html overlay but only the video part.

However, according to the documentation for gstreamer wpesrc https://gstreamer.freedesktop.org/documentation/wpe/wpesrc.html?gi-language=c#audio-u it looks like it should be able to do the audio component as well.

I compose the following command

GST_DEBUG="*:3" LIBGL_ALWAYS_SOFTWARE=true gst-launch-1.0 -f \
    flvmux name=mux streamable=true ! rtmp2sink location="rtmp://localhost:1935/app/test"\
    wpesrc location="https://dashboard.twitch.tv/widgets/alertbox#[STREAMER_KEY]" draw-background=0 name=wpesrc \
    wpesrc. ! audioconvert ! avenc_aac ! mux. \
    wpesrc. ! queue ! videoconvert ! x264enc speed-preset=1 bitrate=1000 tune=zerolatency ! video/x-h264 ! mux.

But when the website render any audiopart, it generates the following log:

0:00:05.461786294  2000 0xaaaad1bea810 WARN                   pulse pulsesink.c:615:gst_pulseringbuffer_open_device:<autoaudiosink0-actual-sink-pulse> error: Failed to connect: Connection refused
0:00:05.465120711  2000 0xaaaad1bea810 ERROR             jackclient gstjackaudioclient.c:35:jack_log_error: Cannot connect to server socket err = No such file or directory
0:00:05.465142294  2000 0xaaaad1bea810 ERROR             jackclient gstjackaudioclient.c:35:jack_log_error: Cannot connect to server request channel
0:00:05.468177378  2000 0xaaaad1bea810 ERROR             jackclient gstjackaudioclient.c:35:jack_log_error: jack server is not running or cannot be started
0:00:05.468436836  2000 0xaaaad1bea810 ERROR             jackclient gstjackaudioclient.c:35:jack_log_error: JackShmReadWritePtr::~JackShmReadWritePtr - Init not done for -1, skipping unlock
0:00:05.468469628  2000 0xaaaad1bea810 ERROR             jackclient gstjackaudioclient.c:35:jack_log_error: JackShmReadWritePtr::~JackShmReadWritePtr - Init not done for -1, skipping unlock
0:00:05.468474003  2000 0xaaaad1bea810 WARN              jackclient gstjackaudioclient.c:381:gst_jack_audio_get_connection: could not create connection
0:00:05.468481586  2000 0xaaaad1bea810 WARN                jacksink gstjackaudiosink.c:358:gst_jack_ring_buffer_open_device:<autoaudiosink0-actual-sink-jackaudio> error: Jack server not found
0:00:05.468486086  2000 0xaaaad1bea810 WARN                jacksink gstjackaudiosink.c:358:gst_jack_ring_buffer_open_device:<autoaudiosink0-actual-sink-jackaudio> error: Cannot connect to the Jack server (status 17)
0:00:05.468853253  2000 0xaaaad1bea810 WARN                 default oss4-property-probe.c:302:gst_oss4_property_probe_get_values:<autoaudiosink0-actual-sink-oss4> Can't open file descriptor to probe available devices: No such file or directory

(WPEWebProcess:2000): GStreamer-CRITICAL **: 10:17:11.475: gst_debug_log_valist: assertion 'category != NULL' failed

(WPEWebProcess:2000): GStreamer-CRITICAL **: 10:17:11.475: gst_debug_log_valist: assertion 'category != NULL' failed
ALSA lib confmisc.c:855:(parse_card) cannot find card '0'
ALSA lib conf.c:5178:(_snd_config_evaluate) function snd_func_card_inum returned error: No such file or directory
ALSA lib confmisc.c:422:(snd_func_concat) error evaluating strings
ALSA lib conf.c:5178:(_snd_config_evaluate) function snd_func_concat returned error: No such file or directory
ALSA lib confmisc.c:1334:(snd_func_refer) error evaluating name
ALSA lib conf.c:5178:(_snd_config_evaluate) function snd_func_refer returned error: No such file or directory
ALSA lib conf.c:5701:(snd_config_expand) Evaluate error: No such file or directory
ALSA lib pcm.c:2664:(snd_pcm_open_noupdate) Unknown PCM default
AL lib: (EE) ALCplaybackAlsa_open: Could not open playback device 'default': No such file or directory
0:00:05.477473169  2000 0xaaaad1bea810 WARN                  openal gstopenalsink.c:637:gst_openal_sink_open:<autoaudiosink0-actual-sink-openal> error: Could not open device.
0:00:05.477485544  2000 0xaaaad1bea810 WARN                  openal gstopenalsink.c:637:gst_openal_sink_open:<autoaudiosink0-actual-sink-openal> error: ALC error: Out of Memory
0:00:05.477749836  2000 0xaaaad1bea810 WARN                     oss gstosssink.c:401:gst_oss_sink_open:<autoaudiosink0-actual-sink-oss> error: Could not open audio device for playback.
0:00:05.477767544  2000 0xaaaad1bea810 WARN                     oss gstosssink.c:401:gst_oss_sink_open:<autoaudiosink0-actual-sink-oss> error: system error: No such file or directory
0:00:05.663318086  2000 0xaaaad1bea810 WARN                   pulse pulsesink.c:615:gst_pulseringbuffer_open_device:<autoaudiosink1-actual-sink-pulse> error: Failed to connect: Connection refused
Cannot connect to server socket err = No such file or directory
Cannot connect to server request channel
jack server is not running or cannot be started
JackShmReadWritePtr::~JackShmReadWritePtr - Init not done for -1, skipping unlock
JackShmReadWritePtr::~JackShmReadWritePtr - Init not done for -1, skipping unlock
0:00:05.669305711  2000 0xaaaad1bea810 WARN              jackclient gstjackaudioclient.c:381:gst_jack_audio_get_connection: could not create connection
0:00:05.669318711  2000 0xaaaad1bea810 WARN                jacksink gstjackaudiosink.c:358:gst_jack_ring_buffer_open_device:<autoaudiosink1-actual-sink-jackaudio> error: Jack server not found
0:00:05.669323211  2000 0xaaaad1bea810 WARN                jacksink gstjackaudiosink.c:358:gst_jack_ring_buffer_open_device:<autoaudiosink1-actual-sink-jackaudio> error: Cannot connect to the Jack server (status 17)
0:00:05.669445295  2000 0xaaaad1bea810 WARN                 default oss4-property-probe.c:302:gst_oss4_property_probe_get_values:<autoaudiosink1-actual-sink-oss4> Can't open file descriptor to probe available devices: No such file or directory

(WPEWebProcess:2000): GStreamer-CRITICAL **: 10:17:11.676: gst_debug_log_valist: assertion 'category != NULL' failed

(WPEWebProcess:2000): GStreamer-CRITICAL **: 10:17:11.676: gst_debug_log_valist: assertion 'category != NULL' failed
ALSA lib confmisc.c:855:(parse_card) cannot find card '0'
ALSA lib conf.c:5178:(_snd_config_evaluate) function snd_func_card_inum returned error: No such file or directory
ALSA lib confmisc.c:422:(snd_func_concat) error evaluating strings
ALSA lib conf.c:5178:(_snd_config_evaluate) function snd_func_concat returned error: No such file or directory
ALSA lib confmisc.c:1334:(snd_func_refer) error evaluating name
ALSA lib conf.c:5178:(_snd_config_evaluate) function snd_func_refer returned error: No such file or directory
ALSA lib conf.c:5701:(snd_config_expand) Evaluate error: No such file or directory
ALSA lib pcm.c:2664:(snd_pcm_open_noupdate) Unknown PCM default
AL lib: (EE) ALCplaybackAlsa_open: Could not open playback device 'default': No such file or directory
0:00:05.669878378  2000 0xaaaad1bea810 WARN                  openal gstopenalsink.c:637:gst_openal_sink_open:<autoaudiosink1-actual-sink-openal> error: Could not open device.
0:00:05.670036211  2000 0xaaaad1bea810 WARN                  openal gstopenalsink.c:637:gst_openal_sink_open:<autoaudiosink1-actual-sink-openal> error: ALC error: Out of Memory
0:00:05.670111211  2000 0xaaaad1bea810 WARN                     oss gstosssink.c:401:gst_oss_sink_open:<autoaudiosink1-actual-sink-oss> error: Could not open audio device for playback.
0:00:05.670129753  2000 0xaaaad1bea810 WARN                     oss gstosssink.c:401:gst_oss_sink_open:<autoaudiosink1-actual-sink-oss> error: system error: No such file or directory
0:00:05.893481378  2000 0xaaaad1bea810 WARN                   pulse pulsesink.c:615:gst_pulseringbuffer_open_device:<autoaudiosink2-actual-sink-pulse> error: Failed to connect: Connection refused
Cannot connect to server socket err = No such file or directory
Cannot connect to server request channel
jack server is not running or cannot be started
JackShmReadWritePtr::~JackShmReadWritePtr - Init not done for -1, skipping unlock
JackShmReadWritePtr::~JackShmReadWritePtr - Init not done for -1, skipping unlock
0:00:05.899286170  2000 0xaaaad1bea810 WARN              jackclient gstjackaudioclient.c:381:gst_jack_audio_get_connection: could not create connection
0:00:05.899297711  2000 0xaaaad1bea810 WARN                jacksink gstjackaudiosink.c:358:gst_jack_ring_buffer_open_device:<autoaudiosink2-actual-sink-jackaudio> error: Jack server not found
0:00:05.899343628  2000 0xaaaad1bea810 WARN                jacksink gstjackaudiosink.c:358:gst_jack_ring_buffer_open_device:<autoaudiosink2-actual-sink-jackaudio> error: Cannot connect to the Jack server (status 17)
0:00:05.899428045  2000 0xaaaad1bea810 WARN                 default oss4-property-probe.c:302:gst_oss4_property_probe_get_values:<autoaudiosink2-actual-sink-oss4> Can't open file descriptor to probe available devices: No such file or directory

(WPEWebProcess:2000): GStreamer-CRITICAL **: 10:17:11.906: gst_debug_log_valist: assertion 'category != NULL' failed

(WPEWebProcess:2000): GStreamer-CRITICAL **: 10:17:11.906: gst_debug_log_valist: assertion 'category != NULL' failed
ALSA lib confmisc.c:855:(parse_card) cannot find card '0'
ALSA lib conf.c:5178:(_snd_config_evaluate) function snd_func_card_inum returned error: No such file or directory
ALSA lib confmisc.c:422:(snd_func_concat) error evaluating strings
ALSA lib conf.c:5178:(_snd_config_evaluate) function snd_func_concat returned error: No such file or directory
ALSA lib confmisc.c:1334:(snd_func_refer) error evaluating name
ALSA lib conf.c:5178:(_snd_config_evaluate) function snd_func_refer returned error: No such file or directory
ALSA lib conf.c:5701:(snd_config_expand) Evaluate error: No such file or directory
ALSA lib pcm.c:2664:(snd_pcm_open_noupdate) Unknown PCM default
AL lib: (EE) ALCplaybackAlsa_open: Could not open playback device 'default': No such file or directory
0:00:05.899792461  2000 0xaaaad1bea810 WARN                  openal gstopenalsink.c:637:gst_openal_sink_open:<autoaudiosink2-actual-sink-openal> error: Could not open device.
0:00:05.899798253  2000 0xaaaad1bea810 WARN                  openal gstopenalsink.c:637:gst_openal_sink_open:<autoaudiosink2-actual-sink-openal> error: ALC error: Out of Memory
0:00:05.899841378  2000 0xaaaad1bea810 WARN                     oss gstosssink.c:401:gst_oss_sink_open:<autoaudiosink2-actual-sink-oss> error: Could not open audio device for playback.
0:00:05.899845336  2000 0xaaaad1bea810 WARN                     oss gstosssink.c:401:gst_oss_sink_open:<autoaudiosink2-actual-sink-oss> error: system error: No such file or directory
0:00:09.797177088  2000 0xaaaad1bea810 WARN          downloadbuffer gstdownloadbuffer.c:973:gst_download_buffer_close_temp_location_file:<downloadbuffer2> Failed to remove temporary file /var/tmp/WebKit-Media-QJC0Y2: No such file or directory

The current Dockerfile look like this:

FROM ubuntu:jammy

ENV DEBIAN_FRONTEND noninteractive
ENV LIBGL_ALWAYS_SOFTWARE=true
ENV TERM xterm-color
ENV XDG_RUNTIME_DIR=/tmp

RUN apt-get update -qq && apt-get install --no-install-recommends -qq -y \
        ca-certificates \
        gstreamer1.0-gl \
        gstreamer1.0-gtk3 \
        gstreamer1.0-libav \
        gstreamer1.0-plugins-bad \
        gstreamer1.0-plugins-good \
        gstreamer1.0-plugins-ugly \
        gstreamer1.0-tools \
        gstreamer1.0-wpe \
        libcairo-dev \
        libgles2-mesa-dev \
        libnginx-mod-rtmp \
        libnvidia-compute-535-server \
        libnvidia-decode-535-server \
        libnvidia-encode-535-server \
        libsndfile1 \
        libsndfile1-dev \
        mc \
        nginx \
    && apt-get clean all \
    && apt-get purge -y --auto-remove -o APT::AutoRemove::RecommendsImportant=false \
    && rm -rf /var/lib/apt/lists/* \
    && mkdir /var/www/rtmp \
    && rm -rf /etc/nginx/sites-available \
    && rm -rf /etc/nginx/sites-enabled

COPY ./config/nginx.conf /etc/nginx/nginx.conf

WORKDIR /var/www

VOLUME ["/etc/nginx"]
VOLUME ["/var/www"]
VOLUME ["/var/log/nginx"]

RUN chown -R www-data:www-data /var/www

#USER user
#ENV XDG_RUNTIME_DIR=/run/user/"${UID}"

EXPOSE 1935
CMD ["nginx", "-g", "daemon off;"]

And the nginx.conf is

user www-data;
worker_processes auto;
pid /run/nginx.pid;
error_log /dev/stdout;
include /etc/nginx/modules-enabled/*.conf;

rtmp_auto_push on;

events {
    worker_connections 768;
    # multi_accept on;
}

http {
    ##
    # Basic Settings
    ##
    sendfile on;
    tcp_nopush on;
    types_hash_max_size 2048;
    server_tokens off;

    # server_names_hash_bucket_size 64;
    # server_name_in_redirect off;

    include /etc/nginx/mime.types;
    default_type application/octet-stream;

    ##
    # SSL Settings
    ##
    ssl_protocols TLSv1 TLSv1.1 TLSv1.2 TLSv1.3; # Dropping SSLv3, ref: POODLE
    ssl_prefer_server_ciphers on;

    ##
    # Logging Settings
    ##
    access_log  /dev/stdout;

    ##
    # Gzip Settings
    ##
    gzip on;

    # gzip_vary on;
    # gzip_proxied any;
    # gzip_comp_level 6;
    # gzip_buffers 16 8k;
    # gzip_http_version 1.1;
    # gzip_types text/plain text/css application/json application/javascript text/xml application/xml application/xml+rss text/javascript;

    ##
    # Virtual Host Configs
    ##
    include /etc/nginx/conf.d/*.conf;
    #include /etc/nginx/sites-enabled/*;
}

rtmp {
    server {
        listen 1935;

        allow publish 127.0.0.0/16;
        allow publish 192.168.0.0/16;
        allow publish 10.0.0.0/16;
        allow publish 172.18.0.0/16;
        deny publish all;
        allow play all;

        ack_window 2500000;
        buflen 1s;
        chunk_size 4096;
        notify_method get;

        application app {
            live on;
            record off;

            push "rtmp://localhost/publish/";
        }

        application publish {
            live off;
            record off;
            
            allow publish 127.0.0.0/16;
            deny publish all;

            allow play all;

            push "rtmp://live.twitch.tv/app/";
        }
    }
}

I have tried all my best but I'm still not able to catch the audio part and send it to RTMP.

The ALSA/PULSE/... have no hardware, because it is inside the docker. I have also tried to use snd_aloop or something similar, but have not found the working way to install it.

Upvotes: 0

Views: 36

Answers (0)

Related Questions