[iOS]FFmpeg框架在iOS平台上的编译和使用

使用环境

  • Mac OS Yosemite 10.10.5

开发工具

  • Xcode 7.0

  • Terminal

需要的文件链接

编译适用于iOS平台的FFmpeg静态库

  • 打开终端Terminal进入下载后的gas-preprocessor文件夹

    • 将文件夹内的gas-preprocessor.pl文件拷贝到/usr/sbin/目录下

    • 修改/usr/sbin/gas-preprocessor.pl的文件权限为可执行权限

        chmod 777 /usr/sbin/gas-preprocessor.pl
  • 执行FFmpeg-iOS-build-script-master文件夹内的build-ffmpeg.sh

    • 编译所有的版本arm64armv7x86_64的静态库

      ./build-ffmpeg.sh
    • 编译支持arm64架构的静态库

      ./build-ffmpeg.sh arm64
    • 编译适用于armv7x86_64(64-bit simulator)的静态库

      ./build-ffmpeg.sh armv7 x86_64
    • 编译合并的版本

      ./build-ffmpeg.sh lipo

编译静态库遇到的问题

  • yasm没有安装的情况

    • 解决方案1

      • 进入下载后的yasm文件夹,通过编译安装命令yasm

          ./configure && make -j 4 && sudo make install
    • 解决方案2

      • 使用Homebrew包管理器,进行安装

          brew install yasm
    • 测试是否安装成功

        yasm --verision
  • c test failed的情况

    • xcode环境安装过多,使用xcode-select选择默认的工具路径/Applications/Xcode-beta.app

        sudo xcode-select -s /Applications/Xcode-beta.app

使用编译完成的FFmpeg静态库

  • 编译成功后,即可将FFmpeg-iOS文件夹(包含include和lib)引入到Xcode内

  • 加入依赖库libz.lib

  • 加入依赖库libbz2.lib

  • 加入依赖库libiconv.lib

  • 如有编译错误,链接文件不存在

      修改Build Setting 
      Header Search Paths = $(SRCROOT)/LOFFmpegSample/FFmpeg-iOS/include

使用框架kxmovie播放视频

    NSString *path = @"";
    NSMutableDictionary *parameters = [NSMutableDictionary dictionary];

    // increase buffering for .wmv, it solves problem with delaying audio frames
    if ([path.pathExtension isEqualToString:@"wmv"])
        parameters[KxMovieParameterMinBufferedDuration] = @(5.0);

    // disable deinterlacing for iPhone, because it's complex operation can cause stuttering
    if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPhone)
        parameters[KxMovieParameterDisableDeinterlacing] = @(YES);

    KxMovieViewController *vc = [KxMovieViewController movieViewControllerWithContentPath:path
                                                                               parameters:parameters];
    [self presentViewController:vc animated:YES completion:nil];

实例工程:
LOFFmpeg

原文地址:https://www.cnblogs.com/Ghosgt/p/7090170.html