CYFFmpeg
用于iOS的FFmpeg动态库
基于FFmpeg 3.4版本构建
集成FFmpeg、x264、fdk-acc、FFmpeg-cmdctl、sambclient(samba)、openssl于一体
前言
之前的代码仓库已经删除,因为不想使用LFS了
当时为了支持armv7和armv7s架构,有的静态库超过了100MB,必须存储在GLFS中
要想减少已使用GLFS仓库的存储使用量,GitHub官方建议直接删除仓库
借此机会,索性引入目前最新的xcode14进行开发,取消对armv7、armv7s的支持,并关闭Bitcode
版本号将从1.0.0开始,不继续使用0.3.3
接下来也会逐步更新对FFmpeg的支持
安装方法
使用CocoaPods将ffmpeg动态库安装到项目中
pod 'CYFFmpeg'
基本特性
-
CYFFmpeg支持通过CocoaPods安装;
-
构建为动态库版本;
-
支持Samba协议,多线程优化;
-
支持Http、Https协议;
-
支持RTMP、HLS、RTSP协议;
-
基于ffmpeg 3.4.2;
-
支持ffmpeg命令行方式调用;
-
OpenSSL;
-
libX264;
-
libSmbClient;
-
libFdkAAC
//ffmpeg -i Downloads.mp4 -r 1 -ss 00:20 -vframes 1 %3d.jpg
char* a[] = {
"ffmpeg",
"-ss",
timeInterval,
"-i",
movie,
"-f",
"image2",
"-r",
"25",
"-vframes",
"1",
outPic
};
//加锁
dispatch_semaphore_wait([CYGCDManager sharedManager].av_read_frame_lock, DISPATCH_TIME_FOREVER);
int result = ffmpeg_main(sizeof(a)/sizeof(*a), a);
dispatch_semaphore_signal([CYGCDManager sharedManager].av_read_frame_lock);
-
支持x86_64模拟器和armv7/arm64真机运行;
-
启用Bitcode=YES;
Xcode14放弃了从Xcode7引入的该特性
-
即装即用。
示例
- 关于samba库相关函数的使用
#import <CYFFmpeg/CYFFmpeg.h>
+ (void)testSMB
{
SMBCCTX * ctx = smbc_new_context();
if (!ctx) {
NSLog(@"smbc_new_context failed");
}
if (!smbc_init_context(ctx))
{
NSLog(@"smbc_init_context failed");
}
smbc_set_context(ctx);
smbc_setOptionUserData(ctx, @"work");
smbc_setTimeout(ctx,3000);
smbc_setFunctionAuthDataWithContext(ctx, my_smbc_get_auth_data_with_context_fn);
// smbc_setOptionUserData(ctx, h);
// smbc_setFunctionAuthDataWithContext(libsmbc->ctx, libsmbc_get_auth_data);
if (smbc_init(NULL, 0) < 0) {
NSLog(@"smbc_init failed");
}
// smbc_get_auth_data_fn fn;
// int debug;
// smbc_init(fn, debug);
//当制定了密码,不会走
// | O_WRONLY 注意权限问题my_smbc_get_auth_data_with_context_fn
if ((smbc_open("smb://workgroup;mobile:[email protected]/video/test.mp4", O_RDONLY, 0666)) < 0) {
NSLog(@"File open failed");
}
else
{
NSLog(@"File open successed");
}
//
// x264_encoder_encode(NULL, NULL, NULL, NULL, NULL);
// avcodec_open2(NULL, NULL, NULL);
}
- 使用ffmpeg相关函数,直接调用即可
// 快进到指定时间播放
av_seek_frame(_formatCtx, -1, (seconds)*AV_TIME_BASE + (double)_formatCtx->start_time, AVSEEK_FLAG_BACKWARD);//不指定stream进行seek
// 打开流
NSString *path = @“rtmp://xxxxx”;
AVFormatContext *formatCtx = avformat_alloc_context();
AVDictionary *_options;
av_dict_set(&_options, "rtsp_transport", "udp", 0);
int ret;
if (( ret = formatCtx->io_open(formatCtx, &formatCtx->pb, [path UTF8String], AVIO_FLAG_READ | formatCtx->avio_flags, &_options)) < 0){
return;//打开失败
}
// 打开成功之后的逻辑
// xxxxx
- 关于OpenSSL、Fdk-aac的使用,请参考网上文章,此处不再一一示例