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

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值