Last active
December 12, 2015 06:58
-
-
Save dgrant/4732921 to your computer and use it in GitHub Desktop.
This script builds the latest stable versions of x264 and ffmpeg and/or libav and builds deb packages for them (which do not replace the existing deb packages. Mine place binaries in /usr/local/bin, not /usr/bin). Limitations:
-Meant for ubuntu systems. Probably works on debian just fine but I have not tested.
-Builds static libraries and puts t…
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python3 | |
import os | |
import subprocess | |
import shutil | |
from os.path import join | |
from subprocess import call | |
X264 = 'x264' | |
X264_VER = 'stable' | |
LIBAV = 'libav' | |
LIBAV_VER = 'v9.3' | |
FFMPEG = 'ffmpeg' | |
FFMPEG_VER = 'n2.4.3' | |
YASM_VER = '1.3.0' | |
MPLAYER = 'mplayer' | |
GIT_DIR = '.git' | |
GIT_BIN = 'git' | |
SVN_BIN = 'svn' | |
SUDO = '/usr/bin/sudo' | |
APTITUDE = '/usr/bin/aptitude' | |
FDK_DIR = 'fdk-aac' | |
X264_GIT = 'git://git.videolan.org/x264' | |
FFMPEG_GIT = 'git://source.ffmpeg.org/ffmpeg.git' | |
LIBAV_GIT = 'git://git.libav.org/libav.git' | |
FDK_GIT = 'git://github.com/mstorsjo/fdk-aac.git' | |
YASM_TARBALL = 'yasm-%s.tar.gz' % (YASM_VER,) | |
VID_STAB_GIT = 'git://github.com/georgmartius/vid.stab.git' | |
DEPS = ('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', 'libxvidcore-dev', 'texi2html', \ | |
'yasm', 'zlib1g-dev',) | |
def run(args, check_retcode=True): | |
print("***** Running:", args) | |
try: | |
retcode = call(args) | |
if retcode != 0 and check_retcode: | |
print("ERROR: the following command failed: ", " ".join(args), "with error code ", retcode) | |
raise Exception("Got a bad return code") | |
else: | |
print("***** Command succeeded (retcode=%d)" % (retcode)) | |
except OSError as e : | |
print("Execution failed of command: ", " ".join(args)) | |
raise | |
def sudo(args): | |
run((SUDO,) + args) | |
def apt_update(): | |
sudo((APTITUDE, 'update')) | |
class cd: | |
def __init__(self, path): | |
self.path = path | |
def __call__(self, f): | |
def wrapped_f(*args, **kwargs): | |
olddir = os.getcwd() | |
os.chdir(self.path) | |
try: | |
f(*args, **kwargs) | |
finally: | |
os.chdir(olddir) | |
return wrapped_f | |
def checkout_x264(): | |
run((GIT_BIN, 'clone', X264_GIT)) | |
@cd(X264) | |
def build_x264(clean=False): | |
run((GIT_BIN, 'checkout', X264_VER)) | |
run((GIT_BIN, 'pull')) | |
if clean: | |
run((GIT_BIN, 'clean', '-f', '-d', '-x')) | |
run(('make', 'distclean')) | |
run(('./configure', '--enable-static', '--disable-opencl')) | |
run(('make',)) | |
sudo(('checkinstall', | |
'--pkgname=libx264-local', | |
"--pkgversion=\"3:$(./version.sh | awk -F'[\" ]' '/POINT/{print $4\"+git\"$5}')\"", | |
'--backup=no', | |
'--deldoc=yes', | |
'--fstrans=no', | |
'--default')) | |
def checkout_ffmpeg(): | |
if os.path.exists(FFMPEG): | |
raise Exception(FFMPEG + " path already exists.") | |
run((GIT_BIN, 'clone', FFMPEG_GIT)) | |
@cd(FFMPEG) | |
def build_ffmpeg(clean=False): | |
run((GIT_BIN, 'fetch')) | |
run((GIT_BIN, 'checkout', FFMPEG_VER)) | |
if clean: | |
run((GIT_BIN, 'clean', '-f', '-d', '-x')) | |
run(('make', 'clean'), check_retcode=False) | |
run(('./configure', | |
'--enable-gpl', | |
'--enable-libfaac', | |
'--enable-libfdk_aac', | |
'--enable-libmp3lame', | |
'--enable-libopencore-amrnb', | |
'--enable-libopencore-amrwb', | |
'--enable-libtheora', | |
# '--enable-libvidstab', | |
'--enable-libvorbis', | |
'--enable-libx264', | |
'--enable-libxvid', | |
'--enable-nonfree', | |
'--enable-postproc', | |
'--enable-version3', | |
'--enable-x11grab')) | |
run(('make',)) | |
sudo(('checkinstall', | |
'--pkgname=ffmpeg-local', | |
'--pkgversion="5:$(date +%Y%m%d%H%M)-git"', | |
'--backup=no', | |
'--deldoc=yes', | |
'--fstrans=no', | |
'--default')) | |
def checkout_libav(): | |
if os.path.exists(LIBAV): | |
raise Exception(LIBAV + " path already exists.") | |
run((GIT_BIN, 'clone', LIBAV_GIT)) | |
@cd(LIBAV) | |
def build_libav(clean=False): | |
run((GIT_BIN, 'fetch')) | |
run((GIT_BIN, 'checkout', LIBAV_VER)) | |
if clean: | |
run(('make', 'clean'), check_retcode=False) | |
run(('./configure', | |
'--enable-gpl', | |
'--enable-libfaac', | |
'--enable-libmp3lame', | |
'--enable-libopencore-amrnb', | |
'--enable-libopencore-amrwb', | |
'--enable-libtheora', | |
'--enable-libvorbis', | |
'--enable-libx264', | |
'--enable-libxvid', | |
'--enable-nonfree', | |
'--enable-postproc', | |
'--enable-version3', | |
'--enable-x11grab')) | |
run(('make',)) | |
sudo(('checkinstall', | |
'--pkgname=libav-local', | |
'--pkgversion="5:$(date +%Y%m%d%H%M)-git"', | |
'--backup=no', | |
'--deldoc=yes', | |
'--fstrans=no', | |
'--default')) | |
def download_yasm(): | |
if os.path.exists(YASM_TARBALL): | |
raise Exception(YASM_TARBALL + ' already exists.') | |
run(('wget', 'http://www.tortall.net/projects/yasm/releases/%s' % (YASM_TARBALL,))) | |
run(('tar', 'zxvf', YASM_TARBALL)) | |
@cd('yasm-%s' % (YASM_VER,)) | |
def build_yasm(clean=False): | |
if clean: | |
run(('make', 'clean'), check_retcode=False) | |
run(('./configure',)) | |
run(('make',)) | |
sudo(('checkinstall', | |
'--pkgname=yasm-local', | |
'--pkgversion="2:$(date +%Y%m%d%H%M)-git"', | |
'--backup=no', | |
'--deldoc=yes', | |
'--fstrans=no', | |
'--default')) | |
def download_fdk(): | |
run((GIT_BIN, 'clone', FDK_GIT)) | |
@cd(FDK_DIR) | |
def build_fdk(clean=False): | |
run((GIT_BIN, 'checkout', 'master')) | |
run((GIT_BIN, 'pull')) | |
if clean: | |
run((GIT_BIN, 'clean', '-f', '-d', '-x')) | |
run(('make', 'clean'), check_retcode=False) | |
run(('autoreconf', '-fiv',)) | |
run(('./configure', '--disable-shared',)) | |
run(('make',)) | |
sudo(('checkinstall', | |
'--pkgname=fdk-aac-local', | |
'--pkgversion="1:$(date +%Y%m%d%H%M)-git"', | |
'--backup=no', | |
'--deldoc=yes', | |
'--fstrans=no', | |
'--default')) | |
if __name__ == "__main__": | |
sudo((APTITUDE, '-y', 'purge', 'ffmpeg-local', 'libx264-local', 'libav-local', 'yasm-local') ) | |
# apt_update() | |
# sudo((APTITUDE, 'install') + DEPS) | |
if not os.path.exists(YASM_TARBALL): | |
download_yasm() | |
build_yasm(clean=True) | |
if not os.path.exists(X264): | |
checkout_x264() | |
build_x264(clean=True) | |
if not os.path.exists(FDK_DIR): | |
download_fdk() | |
build_fdk(clean=True) | |
if not os.path.exists(FFMPEG): | |
checkout_ffmpeg() | |
build_ffmpeg(clean=True) | |
# if os.path.exists(LIBAV): | |
# print('Deleting dir', LIBAV) | |
# shutil.rmtree(LIBAV) | |
# checkout_libav() | |
# build_libav() | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment