zoukankan      html  css  js  c++  java
  • 转:ffmpeg编译iOS 静态库教程

    本文大部分内容参考于此篇文章:How to Prepare Your Mac for iOS Development with FFmpeg Libraries , 然后针对最新情况做了一些修改。

    1. 首先,准备编译环境

    1. 安装Xcode和Command Line Tools
    2. 下载和安装 gas-preprocessor
    3. 安装 pkg-config
    

    关于gas-preprocessor,安装方式是直接copy文件 gas-preprocessor.pl 到 /usr/bin ,记得修改权限可执行.

    原文给出的下载地址是 gas-preprocessor , 不过这里的版本比较老 , 因为在编译ffmpeg的时候,gas-preprocessor版本必须和ffmpeg配合,所以如果你下载的ffmpeg源码是最新的,那么建议去 libav网站 下载最新的 gas-preprocessor.

    如果之后在编译时候遇到类似这样的错误

    unknown register alias 'TCOS_D0_HEAD'
    

    那么可以尝试更换 gas-preprocessor版本来解决.

    然后 pkg-config, 可以直接通过MacPorts来安装

    sudo port install pkgconfig
    

    2. 下载ffmpeg的源码

    git clone git://source.ffmpeg.org/ffmpeg.git
    

    3. 编译armv7的支持

    configure参数如下

    1
    
    ./configure --prefix=armv7 --disable-ffmpeg --disable-ffplay --disable-ffprobe --disable-ffserver --enable-avresample --enable-cross-compile --sysroot="/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS6.1.sdk" --target-os=darwin --cc="/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/usr/bin/gcc" --extra-cflags="-arch armv7 -mfpu=neon -miphoneos-version-min=5.1" --extra-ldflags="-arch armv7 -isysroot /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS6.1.sdk -miphoneos-version-min=5.1" --arch=arm --cpu=cortex-a9 --enable-pic

    编译和安装到armv7目录下

    1
    
    make clean && make && make install

    4. 编译armv7s的支持

    configure参数如下

    1
    
    ./configure --prefix=armv7s --disable-ffmpeg --disable-ffplay --disable-ffprobe --disable-ffserver --enable-avresample --enable-cross-compile --sysroot="/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS6.1.sdk" --target-os=darwin --cc="/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/usr/bin/gcc" --extra-cflags="-arch armv7s -mfpu=neon -miphoneos-version-min=5.1" --extra-ldflags="-arch armv7s -isysroot /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS6.1.sdk -miphoneos-version-min=5.1" --arch=arm --cpu=cortex-a9 --enable-pic

    编译和安装到armv7s目录下

    1
    
    make clean && make && make install

    5. 编译i386的支持

    configure参数如下

    1
    
    ./configure --prefix=i386 --disable-ffmpeg --disable-ffplay --disable-ffprobe --disable-ffserver --enable-avresample --enable-cross-compile --sysroot="/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator6.1.sdk" --target-os=darwin --cc="/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/usr/bin/gcc" --extra-cflags="-arch i386" --extra-ldflags="-arch i386 -isysroot /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator6.1.sdk" --arch=i386 --cpu=i386 --enable-pic --disable-asm

    编译和安装到i386目录下

    1
    
    make clean && make && make install

    如果一切顺利,那么ffmpeg目录下会分别生成 armv7、armv7s、i386几个目录,里面lib文件下就是我们需要的静态库了.

    6. 最后,我们合并armv7、armv7s、i386库在一起.

    1.建立universal/lib/目录.

    2.新建bash脚本,内容如下:

    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    
    #! /bin/sh
    cd armv7/lib
    for file in *.a
    do
    cd ../..
    xcrun -sdk iphoneos lipo -output universal/lib/$file  -create -arch armv7 armv7/lib/$file -arch armv7s armv7s/lib/$file -arch i386 i386/lib/$file
    echo "Universal $file created."
    cd -
    done
    cd ../..
    

    3.执行这个脚本,稍等完成后在universal/lib/下就是我们需要的静态库了。

    以上这么简单的步骤就是编译ffmpeg为iOS静态库的方法,其他各种库编译方式也都大同小异.是不是很简单呢?

    然后关于configure的参数,大家可以参考ffmepg官网解释。

     

    转自:http://cdbit.com/read/how-to-build-ffmpeg-libraries-for-ios.html

  • 相关阅读:
    Java & PHP RSA 互通密钥、签名、验签、加密、解密
    Spring Cloud:Security OAuth2 自定义异常响应
    Spring Cloud:统一异常处理
    Spring Cloud:多环境配置、eureka 安全认证、容器宿主机IP注册
    Hexo + GitEE 搭建、备份、恢复、多终端
    Spring:AOP面向切面编程
    如何找到适合自己的文档工具?
    比较好玩的工具类合集推荐!!!
    C++11 如何使代码仅执行一次?
    CMake 常用操作有哪些?
  • 原文地址:https://www.cnblogs.com/haveadream/p/3390886.html
Copyright © 2011-2022 走看看