Mac平台上编译FFMpeg4.1版本

前言

本文介绍Mac平台上编译FFMpeg4.1版本;

编译流程

  1. 下载源代码
    FFMpeg官网下载
    github上FFmpeg的下载

  2. 编译工具安装
    FFMpeg编译需要安装相关的编译环境跟工具链

    • 安装 Xcode 和 Command Line Tools
      从 App Store 上安装 Xcode,并确保在 Xcode 的 Preferences -> Downloads -> Components 下安装好 Command Line Tools。
      当然你也可以从 https://developer.apple.com/ 下载 Xcode 和 Command Line Tools。

    • 安装brew&相关依赖库
      Homebrew 是 Mac 上的一个很好用的包管理工具,安装方法即允许下列命令:

     # 安装brew
     $ ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"
     # 安装依赖库
     $ brew install automake fdk-aac git libtool libvorbis libvpx opus sdl shtool yasm texi2html theora wget       x264 xvid lame libass
    
    • 安装编译ffplay依赖
      查找configure发现ffplay依赖sdl2,配置文件:fplay_deps="avcodec avformat swscale swresample sdl2"
      通过brew安装sdl2
     $ brew install sdl2
    
  3. 编译FFMpeg

  • 在根目录创建build_mac.sh编译脚本

    #!/bin/bash
    # 显示执行该指令及所下的参数。
    set -x
    # clean 整个工程
    make clean
    OUTPUT=$(pwd)/mac
    # 编译函数
    function build_mac
    {
    ./configure  \
    --prefix=$OUTPUT \
    --enable-gpl \
    --enable-nonfree --enable-libass \
    --enable-libfdk-aac \
    --enable-libfreetype \
    --enable-libmp3lame \
    --enable-libopus \
    --enable-libtheora \
    --enable-libvorbis \
    --enable-libvpx \
    --enable-libx264 \
    --enable-libxvid \
    --enable-ffplay \
    --extra-ldflags=-L/usr/local/lib
    # 编译前清理数据
    make clean
    # 设置8线程编译,可以提高编译速度,具体看机器配置
    make -j8
    # 编译安装,它也从Makefile中读取指令,安装到指定的位置。
    make install
    echo -e "\033[32m build successful \033[0m"
    }
    #执行编译命令
    build_mac
    
  • 执行编译脚本

    $ chmod 777 build_mac.sh
    $ ./build_mac.sh
    

编译结果

19_21_07__05_07_2019.jpg
1557212415286.jpg

测试

  • 使用ffplay播放流媒体
    #  执行./ffplay的命令可打开ffplay,把ffplay加到环境变量后,不需要加./
    $ ./ffplay http://devimages.apple.com.edgekey.net/streaming/examples/bipbop_16x9/gear5/prog_index.m3u8
    
最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容