Screencasting with JACK [SOLVED!]

Post fully complete "how to" guides and tutorials here. This is a great place to get feedback on stuff you might put in the wiki.

Moderators: MattKingUSA, khz

Post Reply
male
Established Member
Posts: 232
Joined: Tue May 22, 2012 5:45 pm

Screencasting with JACK [SOLVED!]

Post by male »

As some of you may recall, every time I've posted a demo video to LAD, I've had to include a disclaimer excusing the poor quality due to a lack of functional screencasting tools.

Well, it took a couple of weeks of hair pulling and many, many hours of testing, but I finally arrived at a solution.

Anyone who wants to create a screencast and record audio via JACK *in perfect sync* must do the following:

Get ffmpeg. Apply this patch to it:

https://github.com/original-male/FFmpeg ... 6130.patch

Build it with vorbis and h264 support.

Then, start your favorite desktop environment. I use Xephyr for this.

Have jack running (at -r 48000)

Then run the following command:

ffmpeg -fflags +genpts+igndts -f x11grab -vsync 0 -r 30 -s 1920x1080 -i :${DISPLAY}.+0,0 -vcodec h264 -f jack -ac 2 -r:a 48000 -i screencast -acodec pcm_s16le -r:v 30 -vsync 2 -async 1 -map 0:0,1,0 -map 1:0 -preset ultrafast -qp 0 "$FILE"

Where DISPLAY is the number of your X11 display and FILE is the filename for the screencast. I use a .mkv extension for the matroska container.

Remember to connect the streams you want recorded to the 'screencast' JACK inputs!

With this setup I'm able to record a full 30 FPS @ 1080P with audio in perfect sync. Please share your results too. With some more evidence I might have a good case to get ffmpeg to accept my patch.

Enjoy!
Image
User avatar
AnthonyCFox
Established Member
Posts: 393
Joined: Mon Apr 22, 2013 3:50 pm
Been thanked: 1 time

Re: Screencasting with JACK [SOLVED!]

Post by AnthonyCFox »

Oh, good! I haven't needed this yet but I expect I will one day.
War, crime, disease, starvation, extreme poverty; these are serious things.
Music? Not so serious. Have some fun! :D
male
Established Member
Posts: 232
Joined: Tue May 22, 2012 5:45 pm

Re: Screencasting with JACK [SOLVED!]

Post by male »

falkTX wrote:Nice, thanks very much!

I can do some testing. Which version of ffmpeg does this apply to? could it perhaps work with libav source as well?
You can see the exact commit I based it on in the github repo. I posted it as a patch though because I figure it'll apply to most versions as the jack driver hasn't been touched that often. I don't know about libav conv. And, of course, even if the patch applies, ffmpeg/avconv is a complex and fragile beast. Who knows you won't run into some new/different problem.
Image
zth
Established Member
Posts: 94
Joined: Mon Jan 16, 2012 9:06 pm

Re: Screencasting with JACK [SOLVED!]

Post by zth »

Using it with the scripts in KXstudio, works like a charm. Thanks all involved, great work!
ssj71
Established Member
Posts: 1294
Joined: Tue Sep 25, 2012 6:36 pm
Has thanked: 1 time

Re: Screencasting with JACK [SOLVED!]

Post by ssj71 »

I'm now in the habit of digging up old threads I guess, but it makes sense when this thread is what google brings up first.

I've adapted the patch for ffmpg release 2.4.2. They had changed a few minor things but never applied male's patch. I'm not sure if he ever got to submitting it. I also found male's patch segfaulted if there isn't a system:input_1 port. This fixes that. So if you want to screencast on kxstudio 14.04 (though the patch should apply to any distro) do this in a terminal:

Code: Select all

#get tools and source
sudo apt-get install yasm libvorbis-dev libx263-dev libxfixes-dev libmp3lame-dev 
wget http://ffmpeg.org/releases/ffmpeg-2.4.2.tar.bz2
tar -xvf ffmpeg-2.4.2.tar.bz2

#patch the source
cd ffmpeg-2.4.2/libavdevice/
wget http://sourceforge.net/p/infamousplugins/code/ci/2c97af07ea6fb54eca55f6bcdd707a3ad60c0325/tree/test/ffmpeg-2.4.2-jack.patch?format=raw
mv ffmpeg-2.4.2-jack.patch?format=raw ffmpeg-2.4.2-jack.patch
patch < ffmpeg-2.4.2-jack.patch

#build ffmpeg
cd ..
./configure --enable-x11grab --enable-libvorbis --enable-libx264 --enable-indev=jack --enable-gpl --enable-libmp3lame
make
sudo make install
sudo ln -s /usr/local/bin/ffmpeg /usr/local/bin/ffmpeg_harvid

#record a screencast using the current screen
ffmpeg -fflags +genpts+igndts -f x11grab -vsync 0 -r 30 -s 1440x900 -i :0 -vcodec h264 -f jack -ac 2 -r:a 48000 -i screencast -acodec pcm_s16le -r:v 30 -vsync 2 -async 1 -map 0:0,1,0 -map 1:0 -preset ultrafast -qp 0 "thisisonlyatest.mkv"

#compress it for youtube
ffmpeg -i "thisisonlyatest.mkv" -acodec mp3 -ab 160000 -vcodec h264 "thisisonlyatest-final.mkv"
The nice thing is that 14.04 uses avconv so installing an ffmpeg binary shouldn't get in the way of anything.
Alternatively to the last 2 commands to record and compress use the kxstudio scripts as falk described here.

**EDIT** I found tonight that if you don't compress it the audio sounds terrible on youtube. AND I didn't configure ffmpeg for mp3 encoding so I've added that to the above instructions so the kxstudio-scripts should work perfectly now. Should.
_ssj71

music: https://soundcloud.com/ssj71
My plugins are Infamous! http://ssj71.github.io/infamousPlugins
I just want to get back to making music!
Post Reply