前言
开发中遇到使用了多个ffmpeg库的不同版本,为了兼容都能正常使用,从而需要将ffmpeg编译成动态库
编译动态库
1.创建一个动态库工程
2.将编译好的ffmpeg静态库放入工程中,可以看我以前的编译ffmpeg文章
3.搜索
search,填入引用路径
4.搜索
other link,填入-all_load
5.将静态库文件拖入目录中
6.添加如下库
7.设置只支持arm64
8.编写测试代码
#import "test.h"
#import "libavformat/avformat.h"
@implementation test
- (void)test{
av_register_all();
}
@end
9.提供头文件
10.编译运行,会生成一个framework
11.进入framework目录检查,动态库已经编译成功了
项目运行动态库
1.创建一个普通项目,将动态库拖入项目中
2.再将动态库拖入目标位置
3.引入头文件
4.编写测试代码
#import "ViewController.h"
#import "libavformat/avformat.h"
#import "libswscale/swscale.h"
#import "libavcodec/avcodec.h"
#import "libavutil/avutil.h"
#import "libswresample/swresample.h"
#import "libavfilter/avfilter.h"
#import "libavdevice/avdevice.h"
@interface ViewController ()
@end
@implementation ViewController
- (void)viewDidLoad {
[super viewDidLoad];
av_register_all();
AVCodec * codec_dec = avcodec_find_decoder(AV_CODEC_ID_H264);
if(codec_dec == NULL){
NSLog(@"222");
}else {
NSLog(@"%s",codec_dec->name);
}
}
@end
5.动态库运行成功