Opened 3 months ago

Last modified 3 months ago

#15581 assigned Question/How do I...?

Streaming my desktop, to show a jitsi conference to a broad audience.

Reported by: Enrique Rosas Owned by: Enrique Rosas
Priority: Urgent Component: Tech
Keywords: ffmpeg icecast Cc:
Sensitive: no

Description (last modified by Enrique Rosas)

Hi again Jamie

In order to do that, I consider using an extra "robot user" in the jitsi room with a dedicated laptop for capturing the desktop as a video source (including the audio too), encoding and packaging to the icecast server by using ffmpeg.

I found this guide in our wiki:Streaming what is on your desktop and I have tried to follow it, but found some errors. As explained below.

Attachments (2)

config-stream-desktop (1.0 KB) - added by Enrique Rosas 3 months ago.
bin-stream-desktop (701 bytes) - added by Enrique Rosas 3 months ago.

Download all attachments as: .zip

Change History (16)

Changed 3 months ago by Enrique Rosas

Attachment: config-stream-desktop added

Changed 3 months ago by Enrique Rosas

Attachment: bin-stream-desktop added

comment:1 Changed 3 months ago by Enrique Rosas

Description: modified (diff)
Owner: set to Jamie McClelland
Status: newassigned

Once I created the two files suggested in the guide (uploaded in this ticket), I ran the ~/bin/stream-desktop with the error message:

...
Opening an input file: :0.0.
:0.0: Invalid argument

Then I found in this forum the suggestion to change the frame size '-s' reducing in -1 height and weidht and use the '$DISPLAY' variable. So I modify the command like that:

-f x11grab -s 1365x767 -show_region 1 -thread_queue_size 32 -video_size "$dimensions" -framerate 30 -i $DISPLAY \

And apparently worked as expected. But then I found a second error I'm not able to solve:

...
Successfully parsed a group of options.
Opening an input file: :0.
[x11grab @ 0x55dad8963d00] Probe buffer size limit of 5000000 bytes reached
[x11grab @ 0x55dad8963d00] Stream #0: not enough frames to estimate rate; consider increasing probesize
Input #0, x11grab, from ':0':
  Duration: N/A, start: 1586917336.845138, bitrate: N/A
    Stream #0:0, 2, 1/1000000: Video: rawvideo, 1 reference frame (BGR[0] / 0x524742), bgr0, 1365x767, 0/1, 30 fps, 1000k tbr, 1000k tbn, 1000k tbc
Successfully opened the file.
Parsing a group of options: input url .
Applying option f (force format) with argument pulse.
Successfully parsed a group of options.
Opening an input file: .
[pulse @ 0x55dad896e400] All info found
Guessed Channel Layout for Input Stream #1.0 : stereo
Input #1, pulse, from '':
  Duration: N/A, start: 1586917336.885347, bitrate: 1536 kb/s
    Stream #1:0, 1, 1/1000000: Audio: pcm_s16le, 48000 Hz, stereo, s16, 1536 kb/s
Successfully opened the file.
Parsing a group of options: output url .
Applying option f (force format) with argument webm.
Applying option af (set audio filters) with argument aresample=async=1.
Applying option c:a (codec name) with argument libvorbis.
Applying option b:a (video bitrate (please use -b:v)) with argument 96K.
Applying option c:v (codec name) with argument libvpx.
Applying option b:v (video bitrate (please use -b:v)) with argument .
Successfully parsed a group of options.
Opening an output file: .
[file @ 0x55dad898f140] Setting default whitelist 'file,crypto'
: No such file or directory

I don't know if the inscription 'file,crypto' (and then having the command failed), has to do somenthing with the SSL connection to the server, or from where it comes from such attempt.

Would you mind give a hand? It is quite urgent this request as the event is tonight.

Thanks a lot in advance

Enrique

comment:2 Changed 3 months ago by Enrique Rosas

Sensitive: unset

comment:3 Changed 3 months ago by Enrique Rosas

Type: Bug/Something is brokenQuestion/How do I...?

comment:4 Changed 3 months ago by Jamie McClelland

I'm not sure Enrique what is going wrong. I followed the directions exactly as is and did not get either of the errors you reported. But my stream craps out after a few seconds:

0 jamie@liberace:~$ stream-desktop 
ffmpeg version 4.2.2-1+b1 Copyright (c) 2000-2019 the FFmpeg developers
  built with gcc 9 (Debian 9.2.1-28)
  configuration: --prefix=/usr --extra-version=1+b1 --toolchain=hardened --libdir=/usr/lib/x86_64-linux-gnu --incdir=/usr/include/x86_64-linux-gnu --arch=amd64 --enable-gpl --disable-stripping --enable-avresample --disable-filter=resample --enable-avisynth --enable-gnutls --enable-ladspa --enable-libaom --enable-libass --enable-libbluray --enable-libbs2b --enable-libcaca --enable-libcdio --enable-libcodec2 --enable-libflite --enable-libfontconfig --enable-libfreetype --enable-libfribidi --enable-libgme --enable-libgsm --enable-libjack --enable-libmp3lame --enable-libmysofa --enable-libopenjpeg --enable-libopenmpt --enable-libopus --enable-libpulse --enable-librsvg --enable-librubberband --enable-libshine --enable-libsnappy --enable-libsoxr --enable-libspeex --enable-libssh --enable-libtheora --enable-libtwolame --enable-libvidstab --enable-libvorbis --enable-libvpx --enable-libwavpack --enable-libwebp --enable-libx265 --enable-libxml2 --enable-libxvid --enable-libzmq --enable-libzvbi --enable-lv2 --enable-omx --enable-openal --enable-opencl --enable-opengl --enable-sdl2 --enable-libdc1394 --enable-libdrm --enable-libiec61883 --enable-chromaprint --enable-frei0r --enable-libx264 --enable-shared
  libavutil      56. 31.100 / 56. 31.100
  libavcodec     58. 54.100 / 58. 54.100
  libavformat    58. 29.100 / 58. 29.100
  libavdevice    58.  8.100 / 58.  8.100
  libavfilter     7. 57.100 /  7. 57.100
  libavresample   4.  0.  0 /  4.  0.  0
  libswscale      5.  5.100 /  5.  5.100
  libswresample   3.  5.100 /  3.  5.100
  libpostproc    55.  5.100 / 55.  5.100
Input #0, x11grab, from ':0.0':
  Duration: N/A, start: 1586961860.921655, bitrate: N/A
    Stream #0:0: Video: rawvideo (BGR[0] / 0x524742), bgr0, 640x480, 30 fps, 30 tbr, 1000k tbn, 1000k tbc
Guessed Channel Layout for Input Stream #1.0 : stereo
Input #1, pulse, from 'alsa_output.pci-0000_00_1f.3.analog-stereo.monitor':
  Duration: N/A, start: 1586961863.689007, bitrate: 1536 kb/s
    Stream #1:0: Audio: pcm_s16le, 48000 Hz, stereo, s16, 1536 kb/s
Stream mapping:
  Stream #0:0 -> #0:0 (rawvideo (native) -> vp8 (libvpx))
  Stream #1:0 -> #0:1 (pcm_s16le (native) -> vorbis (libvorbis))
Press [q] to stop, [?] for help
[libvpx @ 0x55d39ced32c0] v1.8.2
Output #0, webm, to 'icecast://frente:aloquehayquecambiar@a.stream.mayfirst.org:8000/pulso.webm':
  Metadata:
    encoder         : Lavf58.29.100
    Stream #0:0: Video: vp8 (libvpx), yuv420p(progressive), 640x480, q=-1--1, 150 kb/s, 30 fps, 1k tbn, 30 tbc
    Metadata:
      encoder         : Lavc58.54.100 libvpx
    Side data:
      cpb: bitrate max/min/avg: 0/0/0 buffer size: 0 vbv_delay: -1
    Stream #0:1: Audio: vorbis (libvorbis), 48000 Hz, stereo, fltp, 96 kb/s
    Metadata:
      encoder         : Lavc58.54.100 libvorbis
[x11grab @ 0x55d39ceac7c0] Thread message queue blocking; consider raising the thread_queue_size option (current value: 32)
av_interleaved_write_frame(): Connection reset by peer9.12 bitrate= 118.7kbits/s dup=0 drop=151 speed= 1.2x    
Error writing trailer of icecast://frente:aloquehayquecambiar@a.stream.mayfirst.org:8000/pulso.webm: Connection reset by peer
frame=   91 fps= 10 q=0.0 Lsize=     132kB time=00:00:09.18 bitrate= 117.8kbits/s dup=0 drop=153 speed=1.03x    
video:179kB audio:0kB subtitle:0kB other streams:0kB global headers:4kB muxing overhead: unknown
Conversion failed!
1 jamie@liberace:~$

comment:5 Changed 3 months ago by Jamie McClelland

Sensitive: set

comment:6 Changed 3 months ago by Jamie McClelland

I just made this ticket private because I accidentally exposed the password (since it's you, I used the existing frente user account and mount point). In any event, if you are using a different user, pass and mountpoint, maybe you should try this one?

comment:7 Changed 3 months ago by Enrique Rosas

Hi Jamie. It is not my personal account, nor one created in the Control Panel. It is one set up in the Icecast config file, just for streaming purposes. Once we finish testing, I could change it.

I made this a public ticket in order to ask other members for support, in case they would have ideas. Is it ok if we make it public again?

Would you mind sharing your config file and the script, as you have use them, for comparison?

comment:8 Changed 3 months ago by Jamie McClelland

Here's the config file:

0 jamie@liberace:~$ cat ~/.config/stream-desktop 
# This file is sourced by the stream-desktop script

# Set output device. Use the command: `pactl list sources | grep alsa_output` to find the
# right one. If you have a USB headset or some other device, it might not be the alsa device
# that is the active one.
#output=alsa_output.usb-SADES_Electronics_Inc._SADES_Snuk-00.analog-stereo.monitor
output=alsa_output.pci-0000_00_1f.3.analog-stereo.monitor

# Set the icecast server URL, including password. 
server="icecast://frente:aloquehayquecambiar@a.stream.mayfirst.org:8000/pulso.webm"

# Set your screen dimensions. For performance reasons I am keeping it very low.
# If you want to set it to your maximum resolution for your monitor, you can
# find your dimensions with: `xdpyinfo | awk '/dimensions:/ { print $2; exit }'`
dimensions=640x480

# video bits is the main quality marker. .15M seems the lowest you can go without
# sacrificing too much quality. 1.5M gives really good video quality, but doesn't
# play too well.
video_bits=.15M

name="May First"
description="Meeting"
0 jamie@liberace:~$ 

And here is the script:

0 jamie@liberace:~$ cat ~/bin/stream-desktop 
#!/bin/bash

config_file=~/.config/stream-desktop
if [ ! -f "$config_file" ]; then
  printf "Please create the file %s and set all configuration parameters.\n" "$config_file"
  exit 1
fi
source "$config_file"

ffmpeg -loglevel info \
  -f x11grab -show_region 1 -thread_queue_size 32 -video_size "$dimensions" -framerate 30 -i :0.0  \
  -f pulse  -i "$output" \
  -f webm -af aresample=async=1 -cluster_size_limit 2M -cluster_time_limit 5100 -content_type video/webm \
  -c:a libvorbis -b:a 96K \
  -c:v libvpx -b:v "$video_bits" -crf 30 -g 30 -deadline good -threads 3 \
  "$server"

0 jamie@liberace:~$

The frente username and password is exposed in this ticket - so we could make it public again but we should change that password on the server first. Let me know if that is ok - I don't want to break anything you might have setup that uses that username/password.

comment:9 Changed 3 months ago by Enrique Rosas

Sensitive: unset

Thanks Jamie, I have done the change in the icecast config file, and put the ticket back to public.

comment:10 Changed 3 months ago by https://id.mayfirst.org/kosa

Hi there erq and Jamie!

if other workflows are welcome I would like to suggest you giving obs + gstrearmer a look. I've tried many different things and I can tell that is my favorite and more reliable and versatile combo.

I can write a larger guide to make it publicly avalbale for other people, but I can keep it short in this ticket.

1.- apt install obs-studio gstreamer1.0-x wmctrl xdotool (good, bad and/or ugly gstreamer plugins might need to installed as well)

2.- add whatever windows(s) you would like to stream as source to obs. You can just add one scence per source or be creative and play with all kinds of layouts/canvas/effects/mixes. Just put special atention on sound sources.

2.1 (protip) if you are using an internet browser as one of the sources, say for a jitsi videoconference room, you can resize that source within obs or set xy margin for it so the menu and/or tabs are not displayed. You can do that with any source to make it look better.

3.- set obs on Studio mode so you have separete "live" and "preview" views

4.- right click on the "live" view and detach as "program" (not the full screen mode)

5.- (optional) resize of the window you would like to stream (as you would resize any other window or using xdotool for specific sizes).

6.- run wmctrl -l in a shell to get the ID of the detached window you will stream using gstreamer; it's the first column

7.- run this gstreamer command on a shell replacing XXXXXXXXX the with whatever you got on previous step.

gst-launch-1.0 ximagesrc use-damage=false xid='XXXXXXXXXXXX' ! videoconvert ! vp8enc end-usage=cq target-bitrate=384000 buffer-size=1000 keyframe-max-dist=8 threads=4 ! queue ! mezcla. pulsesrc ! audio/x-raw,channels=2,rate=48000 ! audioconvert ! vorbisenc ! queue max-size-buffers=0 max-size-time=0 max-size-bytes=0 ! mezcla. webmmux name=mezcla streamable=true ! tee name=doble doble. ! queue ! shout2send ip=a.stream.mayfirst.org port=8000 mount=mountpoint.webm password= streamname="StreamName" description="Descripción"

If you have enough resources and bandwith on your cumputer you can detach more than one window from obs, and set, for instance, different sizes, then stream them at the same time.

caveats: don't resize the detached window once the gstreamer has been launched. it will break the stream and you would need to restart it.

Sorry I was unable to keep it short, he.

Please receive my best wishes. Hope you and all your people are doing as well as possible these days.

~/k054

comment:11 Changed 3 months ago by Jamie McClelland

Thanks k054 for adding the commment about obs. I realize I created a how to with obs as well that is here: https://support.mayfirst.org/wiki/free-video-streaming-technology

I'm not sure it still works - but it seems it's possible to go straight from obs to icecast

comment:12 Changed 3 months ago by https://id.mayfirst.org/kosa

Hi Jamie,

I was not aware of that how to, and you are correct about it being possible, but there are two things to consider when going that way.

1.- Since you are using the recording function to stream, you can't actually keep a copy of whatever you stream unless you do it on the icecast side, which could not be done for everyone, I think,

2.- Even if you do it that way and store it on the icecast server, you would be storing a somehow low-res copy of it instead of a better quality local one.

I mean, the how to you wrote can be very helpfull in many circumstances, but going the other way is not that much harder and offeres some advantages.

does it make sense?

comment:13 Changed 3 months ago by Enrique Rosas

Owner: changed from Jamie McClelland to Enrique Rosas

Thanks k054 for jumping in.

Additionaly Jacobo pointed me to streamdesktop.git from Rubén Rodríguez. I post it here to share the love.

Now I need to spend so time testing and will come back later.

comment:14 Changed 3 months ago by https://id.mayfirst.org/kosa

hi erq!

I was actually aware of that set up, but still like the obs + gstreamer more. It is way more versatile.

Abrazo.

Please login to add comments to this ticket.

Note: See TracTickets for help on using tickets.