This tutorial details the necessary steps involved in configuring, compiling & finally installing ffmpeg and x264 from source. Many times the packages contained in your distributors repositories are not configured properly for tasks such as screen casting. Compiling and configuring from source will ensure you have the latest version of these packages and that they are configured properly.
x264
- Make sure you don't have ffmpeg or x264 installed:
sudo apt-get remove ffmpeg x264 libx264-dev
- Update your system:
sudo apt-get update
- Install all of the packages required for compilation & Installation:
sudo apt-get install build-essential checkinstall git libfaac-dev libjack-jackd2-dev libmp3lame-dev libopencore-amrnb-dev libopencore-amrwb-dev libsdl1.2-dev libtheora-dev libva-dev libvdpau-dev libvorbis-dev libx11-dev libxfixes-dev texi2html yasm zlib1g-dev
- Now you have to obtain the x264 source code by cloning it's git repository:
git clone git://git.videolan.org/x264
- Now we move on to configuring, compiling and installing:
cd x264
- Configure:
./configure --enable-static --enable-shared
- Compile:
make -j5
*Using the "-J" flag optimizes the compilation process for the number of cores your host system has. The general rule of thumb is to add "1" to the number of cores on your host system in my case I have a quad core system so I would use -J5.
- Install:
sudo checkinstall --pkgname=x264 --pkgversion="3:$(./version.sh | awk -F'[" ]' '/POINT/{print $4"+git"$5}')" --backup=no --deldoc=yes --fstrans=no --default
ffmpeg
cd
- Now you have to obtain the ffmpeg source code by cloning it's git repository:
git clone --depth 1 git://git.videolan.org/ffmpeg
- Now we move on to configuring, compiling and installing:
cd ffmpeg
- Configure:
./configure --enable-gpl --enable-libfaac --enable-libmp3lame --enable-libopencore-amrnb --enable-libopencore-amrwb --enable-libtheora --enable-libvorbis --enable-libx264 --enable-nonfree --enable-postproc --enable-version3 --enable-x11grab
- Compile:
make -j5
- Install:
sudo checkinstall --pkgname=ffmpeg --pkgversion="5:$(date +%Y%m%d%H%M)-git" --backup=no --deldoc=yes --fstrans=no --default
hash x264 ffmpeg ffplay ffprobe
Here's the ffmpeg code I use for screencasting:
# Lou's Screencast script using ffmpeg for desktop use
ffmpeg -f alsa -i pulse -r 30 -s 1600x900 -f x11grab -i :0.0 -vcodec libx264 -
preset ultrafast -crf 0 -y screencast.mp4
okay lou i did everything but still cant get it working when i copy the code i'm getting this
ReplyDeletetrickstar@trickstar ~ $ ffmpeg -f alsa -i pulse -r 30 -s 1600x900 -f x11grab -i :0.0 -vcodec libx264 -
ffmpeg version git-2012-01-12-794006f Copyright (c) 2000-2012 the FFmpeg developers
built on Jan 12 2012 02:19:40 with gcc 4.6.1
configuration: --enable-gpl --enable-libfaac --enable-libmp3lame --enable-libopencore-amrnb --enable-libopencore-amrwb --enable-libtheora --enable-libvorbis --enable-libx264 --enable-nonfree --enable-postproc --enable-version3 --enable-x11grab
libavutil 51. 34.100 / 51. 34.100
libavcodec 53. 55.100 / 53. 55.100
libavformat 53. 29.100 / 53. 29.100
libavdevice 53. 4.100 / 53. 4.100
libavfilter 2. 58.100 / 2. 58.100
libswscale 2. 1.100 / 2. 1.100
libswresample 0. 6.100 / 0. 6.100
libpostproc 51. 2.100 / 51. 2.100
[alsa @ 0x1bfd420] Estimating duration from bitrate, this may be inaccurate
Input #0, alsa, from 'pulse':
Duration: N/A, start: 1326349714.828274, bitrate: N/A
Stream #0:0: Audio: pcm_s16le, 48000 Hz, 2 channels, s16, 1536 kb/s
[x11grab @ 0x1bfdc80] device: :0.0 -> display: :0.0 x: 0 y: 0 width: 1600 height: 900
[x11grab @ 0x1bfdc80] shared memory extension found
X Error of failed request: BadMatch (invalid parameter attributes)
Major opcode of failed request: 139 (MIT-SHM)
Minor opcode of failed request: 4 (X_ShmGetImage)
Serial number of failed request: 11
Current serial number in output stream: 11
trickstar@trickstar ~ $
trickstar@trickstar ~ $ preset ultrafast -crf 0 -y screencast.mp4
Try cloing the git again for ffmpeg and x264 there was some regressions in the git snapshots in Jan I just compiled them both yesterday and all is well using the same code I posted originally.
DeleteIf you get the error "ffmpeg: error while loading shared libraries: libx264.so.80: cannot open shared object file: No such file or directory "
ReplyDeleteThen do sudo ldconfig
Then run your ffmpeg -f alsa -i pulse -r 30 -s 1366x768 -f x11grab -i :0.0 -vcodec libx264 -preset ultrafast -crf 0 -y screencast.mp4
I use the above script that has the 1366x768 resolution set. I would change it to yours.
This comment has been removed by the author.
ReplyDeleteLou,
ReplyDeleteAny idea why I'm getting this error?
[x11grab @ 0x2dfaac0] shared memory extension found
[x11grab @ 0x2dfaac0] Fatal: Can't get shared memory!
:0.0: Cannot allocate memory
Bill