You are not logged in.

#1 2012-03-06 21:25:39

zacariaz
Member
From: Denmark
Registered: 2012-01-18
Posts: 539

[solved]ffmpeg x11grab fail (screencast/streaming)

So I decided to try and do some live streaming and quickly found a couple of not too complicated guides using ffmpeg, but I get an error and can't seem to find an explanation.

Command (one of many I've tried):

ffmpeg -f x11grab -s 1920x1080 -r 30 -i :0.0  -f alsa -ac 2 -i pulse -vcodec libx264 -vpre fast -s 1280x720  -acodec libmp3lame -ab 96k -vol 4096 -ar 22050 -threads 0 -f flv "rtmp://live.justin.tv/app/live_blablablablabla" 

Output:

ffmpeg version N-37208-g01fcbdf Copyright (c) 2000-2012 the FFmpeg developers
  built on Feb  7 2012 10:34:18 with gcc 4.6.2 20120120 (prerelease)
  configuration: --prefix=/usr --enable-libmp3lame --enable-libvorbis --enable-libxvid --enable-libx264 --enable-libvpx --enable-libtheora --enable-libgsm --enable-libspeex --enable-postproc --enable-shared --enable-x11grab --enable-libopencore_amrnb --enable-libopencore_amrwb --enable-libschroedinger --enable-libopenjpeg --enable-librtmp --enable-libpulse --enable-gpl --enable-version3 --enable-runtime-cpudetect --disable-debug --disable-static
  libavutil      51. 34.101 / 51. 34.101
  libavcodec     53. 60.100 / 53. 60.100
  libavformat    53. 31.100 / 53. 31.100
  libavdevice    53.  4.100 / 53.  4.100
  libavfilter     2. 60.100 /  2. 60.100
  libswscale      2.  1.100 /  2.  1.100
  libswresample   0.  6.100 /  0.  6.100
  libpostproc    52.  0.100 / 52.  0.100
[x11grab @ 0x92b5e0] device: :0.0 -> display: :0.0 x: 0 y: 0 width: 1920 height: 1080
[x11grab @ 0x92b5e0] shared memory extension found
X Error of failed request:  BadMatch (invalid parameter attributes)
  Major opcode of failed request:  142 (MIT-SHM)
  Minor opcode of failed request:  4 (X_ShmGetImage)
  Serial number of failed request:  11
  Current serial number in output stream:  11

I've tried doing this in a multitude of ways, but the error is always the same:

[x11grab @ 0x92b5e0] shared memory extension found
X Error of failed request:  BadMatch (invalid parameter attributes)
  Major opcode of failed request:  142 (MIT-SHM)
  Minor opcode of failed request:  4 (X_ShmGetImage)
  Serial number of failed request:  11
  Current serial number in output stream:  11[

Quite frankly I haven't got a clue, so please let me know if you've got an explanation.

So far the only idea I've been able to come up with is that the fact that I run openbox instead of gnome/kde, may have something to do with it. Possibly the proprietary nvidia drivers I'm using could have something to do with it as well I suppose, though I should think it rather odd.


Best regards.

Last edited by zacariaz (2012-03-10 04:45:19)


I am a philosopher, of sorts, not a troll or an imbecile.
My apologies that this is not always obvious, despite my best efforts.

Offline

#2 2012-03-07 00:41:22

zacariaz
Member
From: Denmark
Registered: 2012-01-18
Posts: 539

Re: [solved]ffmpeg x11grab fail (screencast/streaming)

by switching around -f and -s, the x11grab problem seem to be solved.

now however there's another problem:

ALSA lib pcm.c:2217:(snd_pcm_open_noupdate) Unknown PCM pulse
[alsa @ 0x139fb60] cannot open audio device pulse (No such file or directory)
pulse: Input/output error

I suppose I'll figure it out eventually, but please do assist if you can.


I am a philosopher, of sorts, not a troll or an imbecile.
My apologies that this is not always obvious, despite my best efforts.

Offline

#3 2012-03-07 01:31:19

zacariaz
Member
From: Denmark
Registered: 2012-01-18
Posts: 539

Re: [solved]ffmpeg x11grab fail (screencast/streaming)

Okay, I'm quite tired now. Been at it for hours. I've gotten video to work and stream fine, but audio is a mystery.

It's quite clear that pulse audio is a problem, but I suppose I may not actually be using it, thus I removed that option and it worked, though no audio was apparently sent along with the stream.

I must say that I have a hard time understanding why this has to be so complicated. Someone must have written a tutorial or something that actually works out...


I am a philosopher, of sorts, not a troll or an imbecile.
My apologies that this is not always obvious, despite my best efforts.

Offline

#4 2012-03-07 10:52:21

graysky
Wiki Maintainer
From: :wq
Registered: 2008-12-01
Posts: 10,595
Website

Re: [solved]ffmpeg x11grab fail (screencast/streaming)


CPU-optimized Linux-ck packages @ Repo-ck  • AUR packagesZsh and other configs

Offline

#5 2012-03-07 17:00:18

zacariaz
Member
From: Denmark
Registered: 2012-01-18
Posts: 539

Re: [solved]ffmpeg x11grab fail (screencast/streaming)

That's for the link. It's actually a good one, but it don't solve my problem. I still don't get any audio and I have no idea why.


I am a philosopher, of sorts, not a troll or an imbecile.
My apologies that this is not always obvious, despite my best efforts.

Offline

#6 2012-03-08 18:22:17

DrZaius
Member
Registered: 2008-01-02
Posts: 193

Re: [solved]ffmpeg x11grab fail (screencast/streaming)

zacariaz wrote:
[x11grab @ 0x92b5e0] shared memory extension found
X Error of failed request:  BadMatch (invalid parameter attributes)
  Major opcode of failed request:  142 (MIT-SHM)
  Minor opcode of failed request:  4 (X_ShmGetImage)
  Serial number of failed request:  11
  Current serial number in output stream:  11[

I believe this occurs when you use an input -s that is larger than your actual screen size.

zacariaz wrote:
ALSA lib pcm.c:2217:(snd_pcm_open_noupdate) Unknown PCM pulse
[alsa @ 0x139fb60] cannot open audio device pulse (No such file or directory)
pulse: Input/output error

Do you even use pulse? You probably have to replace pulse with your desired alsa device, such as hw:0,0. See arecord -l for a list of devices. If you want to grab audio output instead of recording from sound card then I believe alsa can do that too if your sound card supports recording from output mix.

Your next error will be:

File for preset 'fast' not found

Presets are now used with the -preset option, so simply replace -vpre with -preset. See a list of available presets with x264--help (and ignore "placebo" as it's a joke).

Last edited by DrZaius (2012-03-08 18:22:53)

Offline

#7 2012-03-08 20:38:01

rhasti
Member
From: Frankfurt am Main / Germany
Registered: 2009-02-18
Posts: 9

Re: [solved]ffmpeg x11grab fail (screencast/streaming)

A while ago I tried streaming to Justin TV.
Following bash function worked ~2 month ago.
Found it in JustinTV Wiki or Forum and tweaked it a little bit so the presets match.

streaming() {
INRES="1920x1080" # input resolution
OUTRES="1280x720"
FPS="20" # target FPS
QUAL="lossless_max"  # one of the many FFMPEG preset
STREAM_KEY="live_xxxxxxxxxxx"

ffmpeg -f x11grab -s "$INRES" -r "$FPS" -i :0.0 \
 -f alsa -ac 2 -i pulse -vcodec libx264  -s "$OUTRES"  \
 -acodec libmp3lame -ab 128k -ar 44100 -threads 0 \
 -f flv "rtmp://live.justin.tv/app/$STREAM_KEY"  
}

Offline

#8 2012-03-08 20:43:43

DrZaius
Member
Registered: 2008-01-02
Posts: 193

Re: [solved]ffmpeg x11grab fail (screencast/streaming)

There is no longer a lossless_max preset. Lossless is now achieved with "-preset ultrafast -crf 0" or "-preset veryslow -crf 0" depending on your situation (fastest capture vs smallest file for archive or whatever), and do you really want to send a lossless output to justin.tv?

Offline

#9 2012-03-08 21:00:54

rhasti
Member
From: Frankfurt am Main / Germany
Registered: 2009-02-18
Posts: 9

Re: [solved]ffmpeg x11grab fail (screencast/streaming)

This one work for me.
Needs around 700kbit/s upload.

streaming() {
INRES="1920x1080" 
OUTRES="1280x720"
FPS="20" 
STREAM_KEY="live_xxxxx

ffmpeg -f x11grab -s "$INRES" -r "$FPS" -i :0.0 \
 -f alsa -ac 2 -i pulse -vcodec libx264  -s "$OUTRES"  \
 -acodec libmp3lame -ab 128k -ar 44100 -threads 0 \
 -f flv "rtmp://live.justin.tv/app/$STREAM_KEY"  
}

Offline

#10 2012-03-09 02:08:50

zacariaz
Member
From: Denmark
Registered: 2012-01-18
Posts: 539

Re: [solved]ffmpeg x11grab fail (screencast/streaming)

Wow, a lot of help and I just now got a notice on my email. How is that? Is it only send out once a day or something?


Anyway, thanks a bunch. I figured out by my self that I didn't have pulseaudio, but whether I want it or need it... Well, I haven't got a clue. I did assume that I could do it without pulse, but I'm still somewhat confused. Worst case scenario I could probably just get pulseaudio up and running, but of course it's confusing as always, messing around with openbox.


The badmatch error do not imply that the resolution is wrong (at least in my case) and is sorted out by putting the params in the proper order. It's odd but it works.

Also thanks for the preset tip. I assumed it was something like that, but the manpages are confusing at best, at least for me, so thanks again.

An no,l do not want lossless video, but my resources are limited. I suppose I misinterpreted the the option.


So to wrap it all up, it will properly be a few days before I have time to mess around with this again, but I will return whether it goes well or not.

For those who may wish to offer further advise, here's a few pointers.

I'm running on a machine with an aging core2 duo (E7400), 4GB RAM, SSD, no swap and a somewhat limited upload (1-1.5 Mbit), so there are a few issues to consider.

Any advice will be very much appreciated, but for now I'll assume that I can at least get it to work, albeit maybe not great.

Also would it be wise to encode mp3 instead of aac and how would it be done?


Best regards.

Last edited by zacariaz (2012-03-09 10:05:49)


I am a philosopher, of sorts, not a troll or an imbecile.
My apologies that this is not always obvious, despite my best efforts.

Offline

#11 2012-03-09 09:16:48

ChemBro
Member
Registered: 2008-10-22
Posts: 703

Re: [solved]ffmpeg x11grab fail (screencast/streaming)

zacariaz wrote:

Also would it be wise to encode aac instead of aac and how would it be done?

AAC instead of AAC? Um, dunno,

Also: I got sound for my recording only with pulse audio (or using GLC, but I don't think, that is an option you, because other use case). I saw a video with one, who got recording working with alsa, but I think, he had a much better sound card then me (I have only my onboard sound card). If your sound card is able to do hardware mixing, you might want to look into alsamixer and play a little bit around, maybe you can get it to work.

Offline

#12 2012-03-09 10:07:06

zacariaz
Member
From: Denmark
Registered: 2012-01-18
Posts: 539

Re: [solved]ffmpeg x11grab fail (screencast/streaming)

ChemBro wrote:
zacariaz wrote:

Also would it be wise to encode aac instead of aac and how would it be done?

AAC instead of AAC? Um, dunno,

Also: I got sound for my recording only with pulse audio (or using GLC, but I don't think, that is an option you, because other use case). I saw a video with one, who got recording working with alsa, but I think, he had a much better sound card then me (I have only my onboard sound card). If your sound card is able to do hardware mixing, you might want to look into alsamixer and play a little bit around, maybe you can get it to work.

stupid aac error has been corrected wink


I am a philosopher, of sorts, not a troll or an imbecile.
My apologies that this is not always obvious, despite my best efforts.

Offline

#13 2012-03-10 04:45:01

zacariaz
Member
From: Denmark
Registered: 2012-01-18
Posts: 539

Re: [solved]ffmpeg x11grab fail (screencast/streaming)

So I've gotten pulse audio up and running and after that it was simply a matter of putting the input resolution param before the x11grab and change vpre to preset.

Thanks a bunch for the help.


I am a philosopher, of sorts, not a troll or an imbecile.
My apologies that this is not always obvious, despite my best efforts.

Offline

#14 2012-10-09 16:25:47

nehaljwani
Member
Registered: 2012-10-09
Posts: 6

Re: [solved]ffmpeg x11grab fail (screencast/streaming)

You can see a tutorial on how to use ffmeg to do screencast in linux here: https://www.youtube.com/watch?v=B-ry-f3Mpx4

Offline

#15 2012-10-09 20:50:49

DrZaius
Member
Registered: 2008-01-02
Posts: 193

Re: [solved]ffmpeg x11grab fail (screencast/streaming)

nehaljwani wrote:

You can see a tutorial on how to use ffmeg to do screencast in linux here: https://www.youtube.com/watch?v=B-ry-f3Mpx4

It is nice to see a video demonstrating ffmpeg usage for screencasts, but the video suggests usage of the -sameq option. This is the most misused ffmpeg option and the video contributes to the confusion by including it. See sameq does not mean "same quality".  The video then states:

To join combine the audio and video in a single file, just type:
$ ffmpeg -i output.wav -i output.mp4 -sameq output.mp4

Again, the improper usage of the -sameq option, and the command will re-encode the audio and video with lossy encoders, and therefore degrade the output quality instead of simply muxing them:

ffmpeg -i input.wav -i input.mp4 -c copy -map 0 output.mkv

Of course users may want to re-encode to reduce the file size of a lossless screencast. See the CRF section of the FFmpeg and x264 Encoding Guide.

Offline

Board footer

Powered by FluxBB