Got black screen when recording screen from xvfb by ffmpeg x11grab device
I'm trying to record video from a firefox run by xvfb-run
but it always output nothing in the video file except black screen.
Here's what I did:
start a firefox, open google.com:
$ xvfb-run firefox https://google.com
Then it will use the default display server number 99. I can see the display information by command xdpyinfo -display :99
.
A screenshot works very well by command:
$ xwd -root -silent -display :99.0 | xwdtopnm |pnmtojpeg > screen.jpg
Start using ffmpeg to record a video:
$ ffmpeg -f x11grab -i :99.0 out.mpg
When I play the video file out.mpg
, there's black screen all the time.
Is there any parameter I missed?
Updates
I made progress that the video works instead of black screen only by this command:
$ ffmpeg -y -r 30 -g 300 -f x11grab -s 1024x768 -i :99 -vcodec qtrle out.mov
Notice it requires the screen resolution matches by specify more options to xvfb-run
:
$ xvfb-run -s "-screen 0 1224x768x16" -a firefox http://google.com
But I still want to get more feedbacks and answers here.
Solution 1:
I happened to have the same problem and found out: you have to specify the depth (16 in this case) so ffmpeg won't produce the black screen.
e.g.
Xvnc -geometry 1024x768 -depth 16 :10 <<---WORKS
Xvnc -geometry 1024x768 :10 <<---does NOT work, produce black screen.
Solution 2:
I had the same issue. Seems like it had something to do with the version of ffmpeg available in the official Ubuntu packages (Kubuntu 15.04 in my case to be precise).
I downloaded the ffmpeg sources and with a bit of help of the docs I managed to get something running.
The build process takes a long time! And by default many features (x11grab among others) are disabled. I ended up with the following:
./configure \
--prefix=/home/exhuma/.local \
--enable-x11grab \
--enable-gpl \
--enable-libx264 \
--enable-libmp3lame \
--enable-nonfree
I now have both video and sound.