FFmpeg解封装

解封装解析:
将输入的封装格式的数据,分离成为音频流压缩编码数据和视频流压缩编码数据。封装格式种类很多,例如 MP4,MKV,RMVB,TS,FLV,AVI 等等,它的作用就是将已经压缩编码的视频数据和音频数据按照一定的格式放到一起。例如,FLV 格式的数据,经过解封装操作后,输出 H.264 编码的视频码流和 AAC 编码的音频码流。

基本概念图
在这里插入图片描述
解封装流程:

1.分配解复用器上下文avformat_alloc_context
2.根据url打开本地文件或网络流avformat_open_input
3.读取媒体的部分数据包以获取码流信息avformat_find_stream_info
4.读取码流信息:循环处理
  4.1 从文件中读取数据包av_read_frame
  4.2 定位文件avformat_seek_file或av_seek_frame
5.关闭解复用器avformat_close_input

相关函数:

  1. AVFormatContext * qFormatCtx = avformat_alloc_context();
    是描述一个媒体文件或媒体流的构成和基本信息的结构体
  2. avformat_network_init();
  3. avformat_open_input
  4. avformat_find_stream_info
  5. av_find_best_stream
  6. AVStream
  7. AVPacket *pkt = av_packet_alloc();
    
  8. av_read_frame
-(void)action_jfz{
   
    AVFormatContext *qFormatCtx = NULL;      //封装格式上下文  是描述一个媒体文件或媒体流的构成和基本信息的结构体
    //获取文件路径
    const char *filePath = [[[NSBundle mainBundle] pathForResource:@"output" ofType:@"mp4"] UTF8String];
    if (filePath == nil) {
   
        NSLog(@"文件路径无效");
        return;
    }
    
    //注册FFmpeg组件
    avformat_network_init();
    
    qFormatCtx = avformat_alloc_context();


    //打开音视频文件
    if (avformat_open_input(&qFormatCtx, filePath, NULL, NULL) != 0) {
   
        NSLog(@"FFmpeg打开视频文件失败");
        return;
    }
    //获取音视频文件流信息
    if (avformat_find_stream_info(qFormatCtx, NULL) < 0) {
   
        NSLog(@"找不到流信息");
        return;
    }
    
    // 3.打印总体信息
    printf("\n==== av_dump_format in_filename:%s ===\n", filePath);
        av_dump_format(qFormatCtx, 0, filePath, 0);
    printf
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值