Alsa Pulse Audio cannot open audio device pulse (No such file or directory) pulse: Input/output error
Solution 1
(hopefully) IMPROVED CODE AT BOTTOM
Reading the script provided in your own answer, I've reached the following conclusions about your solution. Please correct me on any/all mistakes I might have made.
You append an xwininfo $GAME_WINDOW
-specific dataset to a tmp
file dump after specifying $GAME_WINDOW
's geometry via wmctl
. Before initiating the dump you effectively truncate your tmp
file to 0-bytes with rm -f
which presumably occurs only once per session either because the stream is session-specific or to avoid the tmp
file growing too large, though, again, I'm presuming both. I base the above conclusions on these three lines:
> rm -f twitch_tmp 2> /dev/null
> wmctrl -r "$GAME_WINDOW" -e 0, 411,51,160,144
> xwininfo -name "$GAME_WINDOW" >> twitch_tmp
While I'm not intimately familiar with either wmctl
or xwininfo
I do know that they're common xorg utilities for automating various X window behaviors. I'm assuming you're streaming that dataset just to keep up with any changes as they might occur so ffmpeg
can do the right thing with its transcode rather than actually pumping the actual graphic/sound source data through the following two environment variables as I doubt very seriously the latter behavior would work for any more than a few seconds if at all:
> TOPXY=$(cat twitch_tmp | grep -oEe 'Corners:\s+\+[0-9]+\+[0-9]+' | grep -oEe '[0-9]+\+[0-9]+' | sed -e 's/\+/,/' )
> INRES=$(cat twitch_tmp | grep -oEe 'geometry [0-9]+x[0-9]+' | grep -oEe '[0-9]+x[0-9]+')
Here you:
- Open two
$(command substitution)
subshells, one each for$TOPXY
and$INRES
value assignments.
For $TOPXY
you:
- Con
cat
enate yourtmp
file withstdin
and anonymously|pipe
the results togrep
'sstdin
which then ... -
oEe
Omits any line and any portion of any line not thereby omitted which does not contain the string:- "Corners:" followed by ...
- at
+
least one\s
whitespace character, then ... - a
\+
literal plus sign, then ... - at
+
least one[0-9]
digit ... - another
\+
literal plus ... - and, finally, at least
+
one more[0-9]
digit ...
- The results are anonymously
|piped
to another instance ofgrep
which subsequently-oEe
omits everything before your first captured[0-9]
digit then anonymously|pipe
its results to ... -
sed
whichtr
ansforms all literal\+
pluses it receives to,
commas and dumps to itsstdout
which is ... - finally captured and stored in
$TOPXY
via the$(command substituted)
subshell variable assignment.
The process for $INRES
appears much the same, if a little less complex.
Most noteworthy to me is that the entire tmp
file is concat
enated at least twice for every invocation, which is not to mention all of the |pipes
. Probably there are a lot of ways to do this, but I can't imagine this would be among the better of them.
After this you invoke ffmpeg
referencing the two variables above and various other options including other environment variables you've also specified:
ffmpeg -f x11grab -s "$INRES" -r "$FPS" -i $DISPLAY+$TOPXY \
-f pulse -i default \
-vcodec libx264 -preset $PRESET -crf 30 -x264opts keyint=50:min-keyint=20 -s $INRES \
-acodec libmp3lame -ab $AUDIO_BITRATE -ar $AUDIO_RATE_HZ \
-threads 0 -pix_fmt yuv420p \
-f flv "rtmp://$SERVER.twitch.tv/app/$STREAM_KEY"
PROBABLY MORE DIRECT
What follows involves no tmp
files, a single |pipe
, calls only a single invocation of sed
and a single subshell command substitution
for parsing your geometry settings, and is contained in a single function. All of the environment variables are defined in here-documents
streamed to its stdin
and are therefore effectively locally scoped. They are also defined via parameter-substitution
and are therefore configurable. For instance to alter the value of $FPS
for a single invocation you need only do:
% FPS=28 desk_stream
For what it's worth, though, I still think vlc
would make a much better option.
desk_stream() { sed -rn '\
/.*((Corners:|geometry)\s*\+*([x|+|0-9]*\+)).*/{\
s//\3/;\
/X/s/.*/\
INRES="&";/p;\
s/(.*)\+(.*)\+$/\
DISPLAY='"${DISPLAY}"'"+\1,\2,";/p;\
};$a\. 0<&3 /dev/stdin\n' | . /dev/stdin
} <<FFOPTS 3<<-\FFCMD
${FPS="15"} # target FPS
${PRESET="ultrafast"} # one of the many FFMPEG preset on (k)ubuntu found in /usr/share/ffmpeg
${THREADS="0"} #0 autostarts threads based on cpu cores.
${AUDIO_BITRATE="1k"} #Audio bitrate to 96k
${AUDIO_RATE_HZ ="44100"} #Audio rate 44100 hz
${GAME_WINDOW="MYGAMETEST"}
${STREAM_KEY=live_XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXx}
${SERVER="live-jfk"} # NY server
$(wmctrl -r "$GAME_WINDOW" -e 0, 411,51,160,144 &&\
xwininfo -name "$GAME_WINDOW")
FFOPTS
ffmpeg -f x11grab -s "$INRES" -r "$FPS" -i $DISPLAY \
-f pulse -i default \
-vcodec libx264 -preset $PRESET -crf 30 -x264opts keyint=50:min-keyint=20 -s $INRES \
-acodec libmp3lame -ab $AUDIO_BITRATE -ar $AUDIO_RATE_HZ \
-threads 0 -pix_fmt yuv420p \
-f flv "rtmp://$SERVER.twitch.tv/app/$STREAM_KEY"
FFCMD
Solution 2
So you've definitely got pulseaudio installed, but you are apparently missing the ALSA pulseaudio emulation drivers. Pulseaudio is interfaced by client apps in a lot of different ways, but a common one is for the applications to address ALSA and pulseaudio to intercept. Alsamixer evern works this way on a properly configured system. Here is a very useful page for understanding the way pulseaudio works. In particular, it has this to say on module-alsa-sink:
You should (almost) never have to load this module manually.
You might be interested in the module a couple lines up there, module-pipe-{sink,source}:
Provides a simple test {sink,source} that {writes,reads} the audio data {to,from} a FIFO...
To that end, if you've got VLC, or can get it, you might try streaming with it:
pacmd list-source-outputs
should contain an output address something like what I've pasted in below for your dummy source:
cvlc pulse://alsa_output.pci-0000_01_00.1.hdmi-stereo.monitor \
--sout '#transcode{acodec=mpga,ab=128,channels=2}:\
standard{access=http,dst=0.0.0.0:8080/pc.mp3}' &
Oh, and you might also have some interest in pacat and you've probably already got it. It's the single executable that both parec and paplay link to.
A little more on Pulse/ALSA (though they're documentation is pretty good on this):
Pulseaudio attempts to imitate ALSA for any application that hasn't yet been updated to interface it. Basically the theory goes that if an application isn't equipped to do dbus it with pulse, pulse will middleman ALSA anyway via the module-alsa-sink plugin interface I mentioned before. In fact, the same is true for OSS and Esound and their respective modules if they should be required.
But maybe you're overthinking this - the simplest sound streaming can be accomplished with mkfifo, or even just cat, should you desire. Depending on your bandwidth and latency requirements netcat could be pretty useful here. You could also look in to Sox - it offers an interface similar to pacat.
What is your linux distribution? I understand its in a container, but verifying you've updated all relevant packages is probably called for here, especially if pulse isn't running. Try this:
pulseaudio --start
If it runs, try this for maybe a better hint at what your source might be:
pacmd list-source-outputs | grep 'source:'
Related videos on Youtube
SSpoke
Pro programmer from the russia How to be a programmer in steps? 1). Set a goal what you wish to program.. 2). Make your program just work. (don't worry think much how messy your coding is.) 3). Fix all bugs you can find and do tests on each part to make sure no more bugs exist. 4). Finally start from scratch and re-write your program in a clean matter, this will be fast don't worry because you already did this once ;). 4). And always ask StackOverflow for advise on parts you are unsure.
Updated on September 18, 2022Comments
-
SSpoke almost 2 years
I'm trying to stream my Gnome Desktop I installed on my OpenVZ VPS Server, and I'm not trying to run this from SSH, but the terminal inside the GNOME desktop,
I know it probably doesn't have a sound card, but it's not like i'm trying to play the sound, I just want to route it to the stream.
Inside my PulseAudio Volume Control
Here is how it looks like when I attempt to stream it.
More stuff I tried more errors happened here
Here is when I run the
pacmd list-source-outputs
[removed@removed ~]$ pacmd list-source-outputs Welcome to PulseAudio! Use "help" for usage information. >>> 2 source outputs(s) available. index: 0 driver: <protocol-native.c> flags: DONT_MOVE state: RUNNING source: 0 <auto_null.monitor> current latency: 3.08 ms requested latency: 20.00 ms sample spec: float32le 1ch 25Hz channel map: mono Mono resample method: peaks owner module: 6 client: 4 <PulseAudio Volume Control> properties: media.name = "Peak detect" application.name = "PulseAudio Volume Control" native-protocol.peer = "UNIX socket client" native-protocol.version = "16" application.id = "org.PulseAudio.pavucontrol" application.icon_name = "audio-card" application.version = "0.9.10" application.process.id = "997" application.process.user = "removed_for_stackexchange(wasn't root)" application.process.host = "removed_for_stackexchange" application.process.binary = "pavucontrol" window.x11.display = ":1.0" application.language = "en_US.UTF-8" application.process.machine_id = "27be3273f5d5332051ccdc3100000002" application.process.session_id = "27be3273f5d5332051ccdc3100000002-1394085585.776225-694791372" module-stream-restore.id = "source-output-by-application-id:org.PulseAudio.pavucontrol" index: 1 driver: <protocol-native.c> flags: DONT_MOVE state: RUNNING source: 0 <auto_null.monitor> current latency: 3.11 ms requested latency: 20.00 ms sample spec: float32le 1ch 25Hz channel map: mono Mono resample method: peaks owner module: 6 client: 4 <PulseAudio Volume Control> direct on input: 2 properties: media.name = "Peak detect" application.name = "PulseAudio Volume Control" native-protocol.peer = "UNIX socket client" native-protocol.version = "16" application.id = "org.PulseAudio.pavucontrol" application.icon_name = "audio-card" application.version = "0.9.10" application.process.id = "997" application.process.user = "removed_for_stackexchange(wasn't root)" application.process.host = "removed_for_stackexchange" application.process.binary = "pavucontrol" window.x11.display = ":1.0" application.language = "en_US.UTF-8" application.process.machine_id = "27be3273f5d5332051ccdc3100000002" application.process.session_id = "27be3273f5d5332051ccdc3100000002-1394085585.776225-694791372" module-stream-restore.id = "source-output-by-application-id:org.PulseAudio.pavucontrol"
More information about sink i'm using
[removed@removed ~]$ pacmd list-sinks Welcome to PulseAudio! Use "help" for usage information. >>> 1 sink(s) available. * index: 0 name: <auto_null> driver: <module-null-sink.c> flags: DECIBEL_VOLUME LATENCY FLAT_VOLUME DYNAMIC_LATENCY state: RUNNING suspend cause: priority: 1000 volume: 0: 100% 1: 100% 0: 0.00 dB 1: 0.00 dB balance 0.00 base volume: 100% 0.00 dB volume steps: 65537 muted: no current latency: 3.49 ms max request: 3 KiB max rewind: 3 KiB monitor source: 0 sample spec: s16le 2ch 44100Hz channel map: front-left,front-right Stereo used by: 1 linked by: 3 configured latency: 20.00 ms; range is 0.50 .. 10000.00 ms module: 9 properties: device.description = "Dummy Output" device.class = "abstract" device.icon_name = "audio-card"
-
SSpoke over 10 yearspacat
Connection failure: Connection refused
pacmdNo PulseAudio daemon running, or not running as session daemon.
lol who knows why the sound sliders move. Actually it used to work.. must of crashed, how do I make pulseaudio a service? or i should just restart the server -
SSpoke over 10 yearsDo I need VLC? can I set it up with ffmpeg some how? I been researching for hours now best thing I found was to use jack-capture to dump speakers to file. pacmd idea sounds better if I can link it up with ffmpeg
-
SSpoke over 10 yearsWhat is
ALSA pulseaudio emulation drivers
I can't find these is there a yum command for this? -
SSpoke over 10 yearsadded lots of outputs for
pacmd list-sinks
andpacmd list-source-outputs
in question -
SSpoke over 10 yearsI need from research to add to ffmpeg
-f pulse -i "$INPUT_SINK"
what is the$INPUT_SINK
? I tried just 0 from theindex: 0
above inpacmd list-sinks
I get[pulse @ 0x20a4c00] pa_simple_new failed: Invalid argument
-
SSpoke over 10 years
parec
starts typing crazy letters in the console, I guess thats the sound wave lol? anyway I can just link thatparec
toffmpeg
-
mikeserv over 10 yearsparec records audio - to somehwere. It sounds like you got your stream - those crazy letters were most likely the bits of the audio stream flooding your console. A !! | nc target.domain $PORT is probably all you need, now.
-
SSpoke over 10 yearsI'm trying to stream video and audio as one package over rtmp thats why I have to use ffmpeg.. I almost got it working a few minutes ago, but I broke it again I found a script
ffgrabaudio
but i can't combine it all together.. I don't know where to put thesink name i guess?
in theffmpeg
-
SSpoke over 10 yearsUsing the script
ffgrabaudio.sh -g system
this what happened to my Output Device it changed names.. and still works.. look at screenshot i.imgur.com/0GjpxJz.png the good thing about this script it also hooks up to the game i'm trying to stream not the whole system by window name, it creates a bunch of playback's with combobox's i'll show you screenshot of that soon -
mikeserv over 10 yearsThat's just pavucontrol - it won't do much for you here. It is handy for adjusting volumes on loaded sink/source modules, but it won't set them up for you. paprefs used to work for gui config of pulse modules - but it doesn't any updated system anymore. I forgot what broke it, but maybe it has something to do with this other issue you're having? Have you updated your packages? About ffmpeg - maybe I'm wrong, but I've always considered it to be more of a codec than anything else - are you trying to set pulseaudio to serve its stream? Anything with networking function can handle that.
-
SSpoke over 10 yearsyes i want pulseaudio to be ffmpegs audio stream
pacmd list-source-outputs
Welcome to PulseAudio! Use "help" for usage information. >>> 0 source outputs(s) available.
When I open thepavucontrol
then i get 2 source outputs. -
SSpoke over 10 yearsBut
pacmd list-sinks
even with pavucontrol closed shows 1 sink which is auto_null.. it has state:RUNNING
device.description = "Dummy Output"
device.icon_name ="audio-card"
maybe thats what I need to link somehow -
mikeserv over 10 yearsThe ouputs are not available because you havent configured them. Pulse uses its own, weirdy private udev to automatically detect and configure available resources on load but if there are zero devices available I can't imagine it would be very effective. You need to setup a FIFO or some other target, load the appropriate pulse modules then connect ffmpeg and pulse as necessary.
-
SSpoke over 10 yearsThere is few people who I've seen on random forums that said they managed to achieve this, since I don't have a sound-card on this VPS I need some kind of
Virtual Audio Cable
almost everyone else said nothing you can do to get this to work. -
mikeserv over 10 yearsYeah, on that page I linked you to you'll see that module-source-null is configured to be available by default when nothing else is. Pulse always keeps at least one open, and if nothing else, it's going to be null.
-
mikeserv over 10 yearsA "Virtual Audio Cable" is a pipe - nothing more. It is a buffered connection over which bits flow. cat /dev/audio | remote:/dev/audio is a virtual audio cable. pacat | nc is a virtual audio cable.
-
SSpoke over 10 yearsI don't understand all this module source null,sink stuff at all. How would I begin by setting it up? You mentioned I need those Emulation drivers where do I get them any rpm for them? I couldn't compile the asla_driver kernel_headers were half corrupt. I thought I needed one of those snd_dummy so I could modprobe it.
-
SSpoke over 10 years
cat: /dev/audio: No such file or directory
Guess I don't have that audio haha.. pacat i'll try that out.cat pacat
in ffmpeg somewhere? nvm it's already acat
on it's own, you said it's a recorder so it's recording the current sound then -
mikeserv over 10 yearsYou may need those at that. They're just another module though - like I said, they are what pulse uses to imitate alsa. That webpage with the lists of modules I linked you to has a LOT to say on the subject.
-
mikeserv over 10 yearsNo such file. Exactly - that would be a special device file installed by udev upon detection of audio hardware. Any device file setup without it would need to be something you configure. Besides, I don't even think that's a standard designation - I was just using it as an example.
-
SSpoke over 10 yearsI really don't know what to do next.. reading that documentation probably won't get me anywhere. So far all I got to work with is pacat which probably sends out some unknown audio format which I have to somehow run simultaneously with ffmpeg so probably have to dump it to disk somewhere and load it with ffmpeg. I can't configure anything I don't how and no sound cards on this vps either. I just want the audio to instantly get streamed without processing or anything like direct link game -> to ffmpeg, also I'll probably try vlc.. don't know how good that is.. but it's bulky 100 Megs..
-
SSpoke over 10 yearsOpps, clicked the chat thing by accident, I just wanted to post this link forums.debian.net/viewtopic.php?f=16&t=110440 is that something the documentation says I need to do?
-
mikeserv over 10 yearsWhat documentation? Oh, well, it certainly won't get you anywhere if you don't read it. I did already give you the copy of what I used to pipe sound around as I like - the cvlc command up top. What kind of "unknown audio format?" Of course, if you were curious, you could try pacat --list-audio-formats...
-
SSpoke over 10 yearsThis one freedesktop.org/wiki/Software/PulseAudio/Documentation/User/… Okay I started to read it.. I think I need the
module-tunnel-{sink,source}
-
mikeserv over 10 yearsYou need to turn that off. Just use the simple FIFO one. Or pacat. Seriously. Pacat and your dummy output will work, I think.
-
mikeserv over 10 yearsFor traversing the network just pipe it through a command interface with which you're familiar - do you use ssh? pacat | ssh me@mybox 'paplay'
-
SSpoke over 10 yearsLol how can I play it off ssh, I am using windows on my computer, the server uses centos 6.3
-
mikeserv over 10 yearsI'm on my laptop - I don't even know if it has sound configured either, never checked. BUT it did attempt to send me a file (the pipe-stream) which I cancelled immediately to come here to tell you to turn that off. I'm sorry, man, but I don't have anymore advice.
-
SSpoke over 10 yearsI understand, i'm not a linux guy I'm more of a java/html/jquery guy this is all very complicated to me, but i'll keep trying thanks for all the help.
-
mikeserv over 10 yearsPulseaudio has a lot of windows applications. They have a windows sound server. They have pacat,paplay,parec. Sox will play a pcm stream, or oga or whatever - it is windows and and linux friendly. There are numerous ssh servers and clients for Windows.
-
mikeserv over 10 yearsAnd last, vlc is EASY. It is the video lan client and has been for close to a couple decades now, I think. I run that one command on my box and connect to it from phones, other computers, whatever. Piece of cake.
-
SSpoke over 10 yearsIt's not even broadcasting any sound. Can you just tell me can I do this without a sound card? here are my results alsa-project.org/db/?f=6bc3c5e6cb32f5a959b153324ccb0c81307ab372 my exact question here: superuser.com/questions/718267/…