ios使用ffmpeg错误收集

本文提供了一种在iOS上编译FFmpeg的方法,通过使用一个强大的脚本简化了整个过程,并解决了链接器错误的问题。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

  1. 编译ffmpeg.
    1. 下载源码后可以自己手动编译 ,反正是通过各种命令 配置configure 
    2. 通过一个很牛逼的脚本:git@github.com:kewlbear/FFmpeg-iOS-build-script.git     下载之后,检查ffmpeg的版本号,替换成最新的 然后运行脚本就行了
      1
      2
      3
      4
      5
      6
      7
      8
      9
      10
      11
      12
      13
      14
      15
      16
      17
      18
      19
      20
      21
      22
      23
      24
      25
      26
      27
      28
      29
      30
      31
      32
      33
      34
      35
      36
      37
      38
      39
      40
      41
      42
      43
      44
      45
      46
      47
      48
      49
      50
      51
      52
      53
      54
      55
      56
      57
      58
      59
      60
      61
      62
      63
      64
      65
      66
      67
      68
      69
      70
      71
      72
      73
      74
      75
      76
      77
      78
      79
      80
      81
      82
      83
      84
      85
      86
      87
      88
      89
      90
      91
      92
      93
      94
      95
      96
      97
      98
      99
      100
      101
      102
      103
      104
      105
      106
      107
      108
      109
      110
      111
      112
      113
      114
      115
      116
      117
      118
      119
      120
      121
      122
      123
      124
      125
      126
      127
      128
      129
      130
      131
      132
      133
      134
      135
      136
      137
      138
      139
      140
      141
      142
      143
      144
      145
      146
      147
      148
      149
      150
      151
      152
      153
      154
      155
      #!/bin/sh
       
      # directories
      SOURCE= "ffmpeg-2.6.1"
      FAT= "FFmpeg-iOS"
       
      SCRATCH= "scratch"
      # must be an absolute path
      THIN=`pwd`/ "thin"
       
      # absolute path to x264 library
      #X264=`pwd`/fat-x264
       
      #FDK_AAC=`pwd`/fdk-aac/fdk-aac-ios
       
      CONFIGURE_FLAGS="--enable-cross-compile --disable-debug --disable-programs \
                        --disable-doc --enable-pic"
       
      if  "$X264"  ]
      then
           CONFIGURE_FLAGS= "$CONFIGURE_FLAGS --enable-gpl --enable-libx264"
      fi
       
      if  "$FDK_AAC"  ]
      then
           CONFIGURE_FLAGS= "$CONFIGURE_FLAGS --enable-libfdk-aac"
      fi
       
      # avresample
      #CONFIGURE_FLAGS="$CONFIGURE_FLAGS --enable-avresample"
       
      ARCHS= "arm64 armv7s armv7 x86_64 i386"
       
      COMPILE= "y"
      LIPO= "y"
       
      DEPLOYMENT_TARGET= "6.0"
       
      if  "$*"  ]
      then
           if  "$*"  "lipo"  ]
           then
               # skip compile
               COMPILE=
           else
               ARCHS= "$*"
               if  [ $# -eq 1 ]
               then
                   # skip lipo
                   LIPO=
               fi
           fi
      fi
       
      if  "$COMPILE"  ]
      then
           if  [ ! `which yasm` ]
           then
               echo  'Yasm not found'
               if  [ ! `which brew` ]
               then
                   echo  'Homebrew not found. Trying to install...'
                   ruby -e  "$(curl -fsSL https://raw.github.com/Homebrew/homebrew/go/install)"  \
                       ||  exit  1
               fi
               echo  'Trying to install Yasm...'
               brew install yasm ||  exit  1
           fi
           if  [ ! `which gas-preprocessor.pl` ]
           then
               echo  'gas-preprocessor.pl not found. Trying to install...'
               (curl -L https: //github.com/libav/gas-preprocessor/raw/master/gas-preprocessor.pl \
                   -o /usr/local/bin/gas-preprocessor.pl \
                   && chmod +x /usr/local/bin/gas-preprocessor.pl) \
                   ||  exit  1
           fi
       
           if  [ ! -r $SOURCE ]
           then
               echo  'FFmpeg source not found. Trying to download...'
               curl http: //www.ffmpeg.org/releases/$SOURCE.tar.bz2 | tar xj \
                   ||  exit  1
           fi
       
           CWD=`pwd`
           for  ARCH in $ARCHS
           do
               echo  "building $ARCH..."
               mkdir -p  "$SCRATCH/$ARCH"
               cd  "$SCRATCH/$ARCH"
       
               CFLAGS= "-arch $ARCH"
               if  "$ARCH"  "i386"  -o  "$ARCH"  "x86_64"  ]
               then
                   PLATFORM= "iPhoneSimulator"
                   CFLAGS= "$CFLAGS -mios-simulator-version-min=$DEPLOYMENT_TARGET"
               else
                   PLATFORM= "iPhoneOS"
                   CFLAGS= "$CFLAGS -mios-version-min=$DEPLOYMENT_TARGET"
                   if  "$ARCH"  "arm64"  ]
                   then
                       EXPORT= "GASPP_FIX_XCODE5=1"
                   fi
               fi
       
               XCRUN_SDK=`echo $PLATFORM | tr  '[:upper:]'  '[:lower:]' `
               CC= "xcrun -sdk $XCRUN_SDK clang"
               CXXFLAGS= "$CFLAGS"
               LDFLAGS= "$CFLAGS"
               if  "$X264"  ]
               then
                   CFLAGS= "$CFLAGS -I$X264/include"
                   LDFLAGS= "$LDFLAGS -L$X264/lib"
               fi
               if  "$FDK_AAC"  ]
               then
                   CFLAGS= "$CFLAGS -I$FDK_AAC/include"
                   LDFLAGS= "$LDFLAGS -L$FDK_AAC/lib"
               fi
       
               TMPDIR=${TMPDIR/%\/} $CWD/$SOURCE/configure \
                   --target-os=darwin \
                   --arch=$ARCH \
                   --cc= "$CC"  \
                   $CONFIGURE_FLAGS \
                   --extra-cflags= "$CFLAGS"  \
                   --extra-cxxflags= "$CXXFLAGS"  \
                   --extra-ldflags= "$LDFLAGS"  \
                   --prefix= "$THIN/$ARCH"  \
               ||  exit  1
       
               make -j3 install $EXPORT ||  exit  1
               cd $CWD
           done
      fi
       
      if  "$LIPO"  ]
      then
           echo  "building fat binaries..."
           mkdir -p $FAT/lib
           set - $ARCHS
           CWD=`pwd`
           cd $THIN/$1/lib
           for  LIB in *.a
           do
               cd $CWD
               echo lipo -create `find $THIN -name $LIB` -output $FAT/lib/$LIB 1>&2
               lipo -create `find $THIN -name $LIB` -output $FAT/lib/$LIB ||  exit  1
           done
       
           cd $CWD
           cp -rf $THIN/$1/include $FAT
      fi
       
      echo Done
  2. 导入项目,有静态包经验的就就不用看了,这个对于我这个半路出家的和尚还是处理了老半天才解决.
    .a文件直接导入 .h文件要导入文件夹结构   配置header search 环境变量  使用的时候导入文件 结构:#import "文件夹/文件.h"
  3. 编译.
    1. 首次编译.
      复制代码
      Undefined symbols for architecture armv7:
        "_deflateInit2_", referenced from:
            _encode_frame in libavcodec.a(pngenc.o)
        "_crc32", referenced from:
            _encode_frame in libavcodec.a(pngenc.o)
        "_deflateReset", referenced from:
            _encode_frame in libavcodec.a(lclenc.o)
            _encode_frame in libavcodec.a(zmbvenc.o)
        "_compress", referenced from:
            _encode_strip in libavcodec.a(tiffenc.o)
        "_deflateBound", referenced from:
            _flashsv_decode_frame in libavcodec.a(flashsv.o)
            _encode_frame in libavcodec.a(pngenc.o)
            _encode_frame in libavcodec.a(lclenc.o)
        "_inflateSync", referenced from:
            _flashsv_decode_frame in libavcodec.a(flashsv.o)
        "_inflateReset", referenced from:
            _flashsv_decode_frame in libavcodec.a(flashsv.o)
            _zlib_decomp in libavcodec.a(lcldec.o)
            _decode_frame in libavcodec.a(tscc.o)
            _zerocodec_decode_frame in libavcodec.a(zerocodec.o)
            _decode_frame in libavcodec.a(zmbv.o)
        "_iconv_open", referenced from:
            _avcodec_open2 in libavcodec.a(utils.o)
            _avcodec_decode_subtitle2 in libavcodec.a(utils.o)
        "_BZ2_bzDecompress", referenced from:
            _matroska_decode_buffer in libavformat.a(matroskadec.o)
        "_inflate", referenced from:
            _http_read_stream in libavformat.a(http.o)
            _matroska_decode_buffer in libavformat.a(matroskadec.o)
            _rtmp_open in libavformat.a(rtmpproto.o)
            _zlib_refill in libavformat.a(swfdec.o)
            _decode_frame_common in libavcodec.a(pngdec.o)
            _decode_text_chunk in libavcodec.a(pngdec.o)
            _flashsv_decode_frame in libavcodec.a(flashsv.o)
            ...
        "_inflateInit_", referenced from:
            _matroska_decode_buffer in libavformat.a(matroskadec.o)
            _rtmp_open in libavformat.a(rtmpproto.o)
            _swf_read_header in libavformat.a(swfdec.o)
            _decode_frame_apng in libavcodec.a(pngdec.o)
            _decode_frame_png in libavcodec.a(pngdec.o)
            _decode_text_chunk in libavcodec.a(pngdec.o)
            _flashsv_decode_init in libavcodec.a(flashsv.o)
            ...
        "_iconv", referenced from:
            _avcodec_decode_subtitle2 in libavcodec.a(utils.o)
        "_BZ2_bzDecompressEnd", referenced from:
            _matroska_decode_buffer in libavformat.a(matroskadec.o)
        "_inflateInit2_", referenced from:
            _http_read_header in libavformat.a(http.o)
        "_deflateEnd", referenced from:
            _flashsv_decode_frame in libavcodec.a(flashsv.o)
            _flashsv2_encode_frame in libavcodec.a(flashsv2enc.o)
            _flashsv_encode_init in libavcodec.a(flashsvenc.o)
            _flashsv_encode_end in libavcodec.a(flashsvenc.o)
            _encode_frame in libavcodec.a(pngenc.o)
            _encode_end in libavcodec.a(lclenc.o)
            _encode_init in libavcodec.a(zmbvenc.o)
            ...
        "_BZ2_bzDecompressInit", referenced from:
            _matroska_decode_buffer in libavformat.a(matroskadec.o)
        "_deflateInit_", referenced from:
            _flashsv_decode_frame in libavcodec.a(flashsv.o)
            _flashsv2_encode_frame in libavcodec.a(flashsv2enc.o)
            _encode_init in libavcodec.a(lclenc.o)
            _encode_init in libavcodec.a(zmbvenc.o)
        "_zlibCompileFlags", referenced from:
            _http_read_header in libavformat.a(http.o)
        "_compress2", referenced from:
            _flashsv2_encode_frame in libavcodec.a(flashsv2enc.o)
            _flashsv_encode_frame in libavcodec.a(flashsvenc.o)
        "_deflate", referenced from:
            _flashsv_decode_frame in libavcodec.a(flashsv.o)
            _flashsv2_encode_frame in libavcodec.a(flashsv2enc.o)
            _encode_frame in libavcodec.a(pngenc.o)
            _encode_frame in libavcodec.a(lclenc.o)
            _encode_frame in libavcodec.a(zmbvenc.o)
        "_inflateEnd", referenced from:
            _http_close in libavformat.a(http.o)
            _http_read_header in libavformat.a(http.o)
            _matroska_decode_buffer in libavformat.a(matroskadec.o)
            _rtmp_open in libavformat.a(rtmpproto.o)
            _swf_read_close in libavformat.a(swfdec.o)
            _decode_frame_apng in libavcodec.a(pngdec.o)
            _decode_frame_png in libavcodec.a(pngdec.o)
            ...
        "_uncompress", referenced from:
            _id3v2_read_internal in libavformat.a(id3v2.o)
            _mov_read_cmov in libavformat.a(mov.o)
            _swf_read_packet in libavformat.a(swfdec.o)
            _decode_frame in libavcodec.a(cscd.o)
            _decode_frame in libavcodec.a(dxa.o)
            _decode_block in libavcodec.a(exr.o)
            _g2m_decode_frame in libavcodec.a(g2meet.o)
            ...
        "_iconv_close", referenced from:
            _avcodec_open2 in libavcodec.a(utils.o)
            _avcodec_decode_subtitle2 in libavcodec.a(utils.o)
      ld: symbol(s) not found for architecture armv7
      clang: error: linker command failed with exit code 1 (use -v to see invocation)
      复制代码

      导入 libz.1.2.5.dylib ,再次编译

      复制代码
      Undefined symbols for architecture armv7:
        "_BZ2_bzDecompressInit", referenced from:
            _matroska_decode_buffer in libavformat.a(matroskadec.o)
        "_iconv", referenced from:
            _avcodec_decode_subtitle2 in libavcodec.a(utils.o)
        "_BZ2_bzDecompress", referenced from:
            _matroska_decode_buffer in libavformat.a(matroskadec.o)
        "_BZ2_bzDecompressEnd", referenced from:
            _matroska_decode_buffer in libavformat.a(matroskadec.o)
        "_iconv_open", referenced from:
            _avcodec_open2 in libavcodec.a(utils.o)
            _avcodec_decode_subtitle2 in libavcodec.a(utils.o)
        "_iconv_close", referenced from:
            _avcodec_open2 in libavcodec.a(utils.o)
            _avcodec_decode_subtitle2 in libavcodec.a(utils.o)
      ld: symbol(s) not found for architecture armv7
      clang: error: linker command failed with exit code 1 (use -v to see invocation)
      复制代码

      导入 libbz2.1.0.dylib ,再次编译

      复制代码
      Undefined symbols for architecture armv7:
        "_iconv", referenced from:
            _avcodec_decode_subtitle2 in libavcodec.a(utils.o)
        "_iconv_open", referenced from:
            _avcodec_open2 in libavcodec.a(utils.o)
            _avcodec_decode_subtitle2 in libavcodec.a(utils.o)
        "_iconv_close", referenced from:
            _avcodec_open2 in libavcodec.a(utils.o)
            _avcodec_decode_subtitle2 in libavcodec.a(utils.o)
      ld: symbol(s) not found for architecture armv7
      clang: error: linker command failed with exit code 1 (use -v to see invocation)
      复制代码

      导入  libiconv.2.4.0.dylib  编译通过

转载于:https://www.cnblogs.com/kelejiabing/p/4398430.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值