ffmpeg4.3.1 iOS初体验
xcode12.2,FFmpeg4.3.1
1. 下载FFmpeg
git clone https://git.ffmpeg.org/ffmpeg.git
也可以点击下载压缩包,我下的 .bz2
2. 编译FFmpeg
下载gas-preprocessor:https://github.com/libav/gas-preprocessor,亲测可用
sudo cp gas-preprocessor.pl /usr/local/bin
chmod +x gas-preprocessor.pl
github下载FFmpeg-iOS-build-script,将build-ffmpeg.sh拖入ffmpeg的跟目录。./build-ffmpeg.sh
完成之后删掉i386,armv7。留下x86和arm64,重新./build-ffmpeg.sh lipo,得到真机和模拟器的库
3. 使用FFmpeg
建立xcode工程,FFmpeg-iOS加入
4. 拖入视频文件
[[NSBundle mainBundle]pathForResource..取值为空
设置Bundle Resource, 选中工程->Build Phases->Copy Bundle Resources,拖入资源文件
5. 代码
#import "ViewController.h"
#import <libavutil/log.h>
#import <libavformat/avformat.h>
@interface ViewController ()
@end
@implementation ViewController
- (void)viewDidLoad {
[super viewDidLoad];
// Do any additional setup after loading the view.
int ret;
AVFormatContext *fmt_ctx = NULL;
av_log_set_level(AV_LOG_DEBUG);
av_log(NULL, AV_LOG_DEBUG, "av log");
NSString *filepath = [[NSBundle mainBundle]pathForResource:@"fm-decoder" ofType:@"mp4"];
const char *fpath = [filepath cStringUsingEncoding:NSASCIIStringEncoding];
ret = avformat_open_input(&fmt_ctx, fpath, NULL, NULL);
if (ret < 0) {
av_log(NULL, AV_LOG_ERROR, "cannot open file:%s\n", av_err2str(ret));
return;
}
av_dump_format(fmt_ctx, 0, fpath, 0);
avformat_close_input(&fmt_ctx);
}
@end
5. 测试
Metadata:
major_brand : isom
minor_version : 512
compatible_brands: isomiso2mp41
encoder : Lavf56.15.100
Duration: 00:20:48.26, bitrate: N/A
Stream #0:0(und), 0, 1/12288: Video: mpeg4, 1 reference frame (mp4v / 0x7634706D), none, 1476 kb/s, 9.38 fps, 24 tbr, 12288 tbn (default)
Metadata:
handler_name : VideoHandler
Stream #0:1(und), 0, 1/44100: Audio: mp3 (mp4a / 0x6134706D), 44100 Hz, 2 channels, 235 kb/s (default)
Metadata:
handler_name : SoundHandler
[AVIOContext @ 0x7f9914c073c0] Statistics: 533002 bytes read, 1 seeks
上一篇: CentOS 7配置静态ip
下一篇: 电子商务B2C网站很全面的数据分析方法