iOS编译ffmpeg1.2.1,使用kxmovie播放视频文件

今天完成了,iOS上面播放视频的功能,特写此日记,以便以后用到

 

我的环境是xcode5.0.1+iOS6.0SDK(喜欢的话可以直接使用7.0的SDK,不过为了兼容,我选择了6.0的),ffmpeg的版本是1.2.1,系统版本是10.8.5

 

1、先来看编译模拟器的ffmpeg库:

使用脚本compile.sh,内容如下:

 

  1. SRCDIR=`pwd`  
  2. SDKVERSION="6.0"  
  3.   
  4. make clean  
  5.   
  6. CC=/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/usr/bin/gcc \  
  7. ./configure \  
  8. --as='/usr/local/bin/gas-preprocessor.pl /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/usr/bin/gcc' \  
  9. --sysroot=/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator5.1.sdk \  
  10. --target-os=darwin \  
  11. --arch=i386 \  
  12. --cpu=i386 \  
  13. --extra-cflags='-arch i386' \  
  14. --extra-ldflags='-arch i386 -isysroot /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator5.1.sdk' \  
  15. --prefix=compiled/i386 \  
  16. --enable-cross-compile \  
  17. --enable-nonfree \  
  18. --enable-gpl \  
  19. --disable-armv5te \  
  20. --disable-swscale-alpha \  
  21. --disable-doc \  
  22. --disable-ffmpeg \  
  23. --disable-ffplay \  
  24. --disable-ffprobe \  
  25. --disable-ffserver \  
  26. --disable-asm \  
  27. --disable-debug  
  28.   
  29. make && make install  


 

 

 


 

 

然后执行sh compile.sh,一段时间后,就可以在当前目录的compiled文件夹下面,找到i386的子目录,里面的lib自文件夹中存放的就是模拟器版本的ffmpeg解码库

 

下面打开kxmovie工程,把刚才生成的lib文件夹,拷贝到工程目录中:

 

 

用xcode打开这个工程,把刚才加入的lib文件夹导入到当前工程中:

 

 

找到MainViewController.m文件,因为我在内网部署了对应的http和rtsp服务器,rtmp的也部署了,但是这里似乎没能访问(所以rtmp部分还是使用原来的那些链接)。

command+R打开模拟器,看看效果(使用6.0的一个模拟器,因为我的手机是6.1.4的系统):

 

 

2、下面是真机库的编译:

使用compile-armv7s.sh,内容如下:

 

  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/iPhoneOS7.0.sdk" --target-os=darwin --cc="/Applications/XCode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/clang" --extra-cflags="-arch armv7s -mfpu=neon -miphoneos-version-min=6.0" --extra-ldflags="-arch armv7s -isysroot /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS7.0.sdk -miphoneos-version-min=6.0" --arch=arm --cpu=cortex-a9 --enable-pic  

同样的因为我这里,真机的iOS版本是6.1.4的,所以这里选择min=6.0,表示支持的系统最低是6.0的
 
运行上面的sh compile-armv7s.sh,在使用make,make install。

编译之后在当前文件夹下出现armv7s的文件夹,里面有和上面我们需要的同一样的lib文件夹:

 

同样和上面,拷贝到工程中,然后用kxmovie打开,在引入到工程中。

 

选择我们的真机,然后commond+R,执行一下App,可以在手机上边看到效果:

 

好了 到此为止,想要什么效果,我们只需要按照kxmovie里面的例子进行修改即可。

posted @ 2015-12-01 15:34  golfy  阅读(330)  评论(0)    收藏  举报