vmware虚拟机下ubuntu 13.04使用zeranoe脚本交叉编译ffmpeg
2013-07-01今天是建党节,习总书记指出,党的建设要以“照镜子、正衣冠、洗洗澡、治治病”为总要求。希望我们的党越来越纯洁,为人民谋福利。
言归正传,每次项目中需要编译相应的ffmpeg,都很费时费力。这次记录下全过程,以便下次使用。
windows下使用msys编译比较麻烦,而且由于安装了很多开源库,导致系统变量很复杂,容易出错。
本次选择在ubuntu下使用zeranoe的脚本交叉编译,windows下使用的ffmpeg动态库。
环境:ubuntu 13.04,vmware 8.0.2 build-591240
ubuntu是在官网下载了镜像文件,通过vmware虚拟机安装后,没有更新直接使用。
主要工具以及版本号:
gcc 3.7.4
make 3.8.1
cmake 2.8.10.1
automake 1.11.6
yasm 1.2.0
makeinfo 4.13
curl 7.29.0
pkg-config 0.26
audoconf 2.69
libtool 2.4.2
flex 2.5.35
bison 2.5
明确需求:本次项目中需要ffmpeg帮助编解码,要求编译第三方的libaacplus和libx264.生成动态库,尽可能小,以便于软件打包。
1. 首先下载 cross_compile_ffmpeg.sh ,本次下载的git上一个月以前更新的。
地址在 https://github.com/rdp/ffmpeg-windows-build-helpers
如果网络允许的话,可以直接运行
a> $ wget https://raw.github.com/rdp/ffmpeg-windows-build-helpers/master/cross_compile_ffmpeg.sh -O cross_compile_ffmpeg.sh
b> $ chmod u+x cross_compile_ffmpeg.sh
c> $ ./cross_compile_ffmpeg.sh
但是这种方法,往往会提示https……失败,换http或者git都失败。还是老老实实地下载了吧。
2. 下载下来的 cross_compile_ffmpeg.sh 放到主目录下cross_compile_ffmpeg文件夹里。
我的目录结构是这样的 /home/gong/cross_compile_ffmpeg/cross_compile_ffmpeg.sh
3. 更改 cross_compile_ffmpeg.sh 的属性,使其可以执行。并执行它。
$ chmod u+x cross_compile_ffmpeg.sh
$ ./cross_compile_ffmpeg.sh
如果提示某些命令没有安装,例如 'curl' 'pkg-config' 'make' 'git' 'svn' 'cmake' 'gcc' 'autoconf' 'libtool' 'automake' 'yasm' 'cvs' 'flex' 'bison' 'makeinfo'
中的某一个。直接 sudo apt-get install xxx 对应安装即可。
4. 一般来说上一步执行肯定会出错,但是会在 cross_compile_ffmpeg文件夹里生成一个sandbox的文件夹,这个文件夹里面有一个名为 mingw-w64-build-3.2.0 的文件(cross_compile_ffmpeg.sh里有下载该文件的语句)。
会在脚本里被执行,下载安装我们本次编译需要的工具。我看到官网http://ffmpeg.zeranoe.com/blog/ 已经更新到 mingw-w64-build-3.2.3 了。但是 cross_compile_ffmpeg.sh 脚本里还是指定的是3.2.0版本。
工具编译完成后,生成在路径/home/gong/cross_compile_ffmpeg/sandbox/mingw-w64-i686/i686-w64-mingw32/bin 下。
5. 按照本次项目需求,更改脚本,中间会经历千万曲折,反复修改编译选项。最终脚本如下
#!/usr/bin/env bash
################################################################################
# ffmpeg windows cross compile helper/downloader script
################################################################################
# Copyright (C) 2012 Roger Pack
#
# This program is free software: you can redistribute it and/or modify it under
# the terms of the GNU General Public License as published by the Free Software
# Foundation, either version 3 of the License, or (at your option) any later
# version.
#
# This program is distributed in the hope that it will be useful, but WITHOUT
# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
# FOR A PARTICULAR PURPOSE.See the GNU General Public License for more
# details.
#
# You should have received a copy of the GNU General Public License along with
# this program.If not, see .
#
# The GNU General Public License can be found in the LICENSE file.
yes_no_sel () {
unset user_input
local question="$1"
shift
while [[ "$user_input" != ]]; do
echo -n "$question"
read user_input
if [[ "$user_input" != ]]; then
clear; echo 'Your selection was not vaild, please try again.'; echo
fi
done
# downcase it
user_input=$(echo $user_input | tr '' '')
}
check_missing_packages () {
local check_packages=('curl' 'pkg-config' 'make' 'git' 'svn' 'cmake' 'gcc' 'autoconf' 'libtool' 'automake' 'yasm' 'cvs' 'flex' 'bison' 'makeinfo')
for package in "${check_packages[@]}"; do
type -P "$package" >/dev/null || missing_packages=("$package" "${missing_packages[@]}")
done
if [[ -n "${missing_packages[@]}" ]]; then
clear
echo "Could not find the following execs: ${missing_packages[@]}"
echo 'Install the missing packages before running this script.'
exit 1
fi
local out=`cmake --version` # like cmake version 2.8.7
local version_have=`echo "$out" | cut -d " " -f 3`
function version { echo "$@" | awk -F. '{ printf("%d%03d%03d%03d\n", $1,$2,$3,$4); }'; }
if [[ $(version $version_have)< $(version '2.8.10') ]]; then
echo "your cmake version is too old $version_have wanted 2.8.10"
exit 1
fi
}
cur_dir="$(pwd)/sandbox"
cpu_count="$(grep -c processor /proc/cpuinfo)" # linux only
if [ -z "$cpu_count" ]; then
cpu_count=`sysctl -n hw.ncpu | tr -d '\n'` # OS X
if [ -z "$cpu_count" ]; then
echo "warning, unable to determine cpu count, defaulting to 1"
cpu_count=1 # boxes where we don't know how to determine cpu count , default to just 1, instead of blank, which means infinite
fi
fi
original_cpu_count=$cpu_count # save it away for some that revert it temporarily
intro() {
cat
页:
[1]