由于项目中需要播放一段服务器返回的视频,群内大神推荐了kxmovie,初步了解了下,在使用的过程中,遇到很多错误,查阅了一些资料,最后总算完成了一个Demo,现将学习过程记录下来,以备以后使用:
期间,参阅了一些资料,最终找到这篇博文讲的比较详细,一些问题按照其中的方法都得到了解决,在此感谢作者!
之所以又写一篇文章,一是对自己学习的总结,对相关问题的整理;二是每个人都有自己的使用习惯,整理成符合自己习惯的文章,对以后使用也是有很大的好处的;
因为使用了kxmovie开源库,就需要先下载它:github地址,官方demo是无法通过编译的,需要自己编译FFmpeg的相关静态库;
$ cd /Users/mac/Desktop/FFmpeg-iOS-build-script-master
$ ./build-ffmpeg.sh
Yasm not found Homebrew not found. Trying to install... ==> This script will install: /usr/local/bin/brew /usr/local/Library/... /usr/local/share/doc/homebrew /usr/local/share/man/man1/brew.1 /usr/local/share/zsh/site-functions/_brew /usr/local/etc/bash_completion.d/brew ==> The following directories will be made group writable: /usr/local/. /usr/local/bin ==> The following directories will have their owner set to Artron_LQQ: /usr/local/. /usr/local/bin ==> The following directories will have their group set to admin: /usr/local/. /usr/local/bin Press RETURN to continue or any other key to abort ==> /usr/bin/sudo /bin/chmod g+rwx /usr/local/. /usr/local/bin
WARNING: Improper use of the sudo command could lead to data loss or the deletion of important system files. Please double-check your typing when using sudo. Type "man sudo" for more information. To proceed, enter your password, or type Ctrl-C to abort. Password:
==> /usr/bin/sudo /usr/sbin/chown Artron_LQQ /usr/local/. /usr/local/bin ==> /usr/bin/sudo /usr/bin/chgrp admin /usr/local/. /usr/local/bin ==> /usr/bin/sudo /bin/mkdir /Library/Caches/Homebrew ==> /usr/bin/sudo /bin/chmod g+rwx /Library/Caches/Homebrew ==> /usr/bin/sudo /usr/sbin/chown Artron_LQQ /Library/Caches/Homebrew ==> Downloading and installing Homebrew... remote: Counting objects: 464, done. remote: Compressing objects: 100% (421/421), done. remote: Total 464 (delta 26), reused 270 (delta 17), pack-reused 0 Receiving objects: 100% (464/464), 753.13 KiB | 155.00 KiB/s, done. Resolving deltas: 100% (26/26), done. From https://github.com/Homebrew/brew 以下省略N行...
上面省略N行 lipo -create /Users/mac/Desktop/FFmpeg-iOS-build-script-master/thin/arm64/lib/libavutil.a /Users/mac/Desktop/FFmpeg-iOS-build-script-master/thin/armv7/lib/libavutil.a /Users/mac/Desktop/FFmpeg-iOS-build-script-master/thin/i386/lib/libavutil.a /Users/mac/Desktop/FFmpeg-iOS-build-script-master/thin/x86_64/lib/libavutil.a -output FFmpeg-iOS/lib/libavutil.a lipo -create /Users/mac/Desktop/FFmpeg-iOS-build-script-master/thin/arm64/lib/libswresample.a /Users/mac/Desktop/FFmpeg-iOS-build-script-master/thin/armv7/lib/libswresample.a /Users/mac/Desktop/FFmpeg-iOS-build-script-master/thin/i386/lib/libswresample.a /Users/mac/Desktop/FFmpeg-iOS-build-script-master/thin/x86_64/lib/libswresample.a -output FFmpeg-iOS/lib/libswresample.a lipo -create /Users/mac/Desktop/FFmpeg-iOS-build-script-master/thin/arm64/lib/libswscale.a /Users/mac/Desktop/FFmpeg-iOS-build-script-master/thin/armv7/lib/libswscale.a /Users/mac/Desktop/FFmpeg-iOS-build-script-master/thin/i386/lib/libswscale.a /Users/mac/Desktop/FFmpeg-iOS-build-script-master/thin/x86_64/lib/libswscale.a -output FFmpeg-iOS/lib/libswscale.a Done
'libavutil/avconfig.h' file not found
FFmpeg-iOS/include即:
Use of undeclared identifier 'PIX_FMT_RGB24'; did you mean 'AV_PIX_FMT_RGB24'?
1.Expected a type 2.Use of undeclared identifier 'UIImage'
Undefined symbols for architecture armv7: "_avpicture_deinterlace", referenced from: -[KxMovieDecoder decodeFrames:] in KxMovieDecoder.o ld: symbol(s) not found for architecture armv7 clang: error: linker command failed with exit code 1 (use -v to see invocation)大概的意思是说在KxMovieDecoder文件里面,有一个方法“decodeFrames: ”,在这个方法里面的"_avpicture_deinterlace"这个方法不能用,armv7结构里面没有这种方法。因此需要找到这个方法直接注释掉即可。
// avpicture_deinterlace((AVPicture*)_videoFrame, // (AVPicture*)_videoFrame, // _videoCodecCtx->pix_fmt, // _videoCodecCtx->width, // _videoCodecCtx->height);
Implicit declaration of function 'avpicture_deinterlace' is invalid in C99
// avpicture_deinterlace((AVPicture*)_videoFrame, // (AVPicture*)_videoFrame, // _videoCodecCtx->pix_fmt, // _videoCodecCtx->width, // _videoCodecCtx->height);
#import "ViewController.h" #import "KxMovieViewController.h" @interface ViewController () @end @implementation ViewController - (void)viewDidAppear:(BOOL)animated { NSString *path = @"http://v.jxvdy.com/sendfile/w5bgP3A8JgiQQo5l0hvoNGE2H16WbN09X-ONHPq3P3C1BISgf7C-qVs6_c8oaw3zKScO78I--b0BGFBRxlpw13sf2e54QA"; 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]; }