首页 技术 正文
技术 2022年11月17日
0 收藏 303 点赞 2,559 浏览 1984 个字

主要是通过av_parser_parse2拿到AVPaket数据,跟av_read_frame类似。输入必须是只包含视频编码数据“裸流”(例如H.264、HEVC码流文件),而不能是包含封装格式的媒体数据(例如AVI、MKV、MP4)。FFmpeg纯净版解码 av_parser_parse2av_parser_init():初始化AVCodecParserContext。其参数是codec_id,所以同时只能解析一种AVCodecParser用于解析输入的数据流并把它们分成一帧一帧的压缩编码数据。比较形象的说法就是把长长的一段连续的数据“切割”成一段段的数据。核心函数是av_parser_parse2():av_parser_parse2():解析数据获得一个Packet, 从输入的数据流中分离出一帧一帧的压缩编码数据。

  1. /**
  2. * Parse a packet.
  3. *
  4. * @param s             parser context.
  5. * @param avctx         codec context.
  6. * @param poutbuf       set to pointer to parsed buffer or NULL if not yet finished.
  7. * @param poutbuf_size  set to size of parsed buffer or zero if not yet finished.
  8. * @param buf           input buffer.
  9. * @param buf_size      input length, to signal EOF, this should be 0 (so that the last frame can be output).
  10. * @param pts           input presentation timestamp.
  11. * @param dts           input decoding timestamp.
  12. * @param pos           input byte position in stream.
  13. * @return the number of bytes of the input bitstream used.
  14. *
  15. * Example:
  16. * @code
  17. *   while(in_len){
  18. *       len = av_parser_parse2(myparser, AVCodecContext, &data, &size,
  19. *                                        in_data, in_len,
  20. *                                        pts, dts, pos);
  21. *       in_data += len;
  22. *       in_len  -= len;
  23. *
  24. *       if(size)
  25. *          decode_frame(data, size);
  26. *   }
  27. * @endcode
  28. */
  29. int av_parser_parse2(AVCodecParserContext *s,
  30. AVCodecContext *avctx,
  31. uint8_t **poutbuf, int *poutbuf_size,
  32. const uint8_t *buf, int buf_size,
  33. int64_t pts, int64_t dts,
  34. int64_t pos);

其中poutbuf指向解析后输出的压缩编码数据帧,buf指向输入的压缩编码数据。如果函数执行完后输出数据为空(poutbuf_size为0),则代表解析还没有完成,还需要再次调用av_parser_parse2()解析一部分数据才可以得到解析后的数据帧。当函数执行完后输出数据不为空的时候,代表解析完成,可以将poutbuf中的这帧数据取出来做后续处理。avformat_open_input()会调用avformat_new_stream()创建AVStreamavformat_new_stream()中又会调用avcodec_alloc_context3()创建AVCodecContextav_read_frame():获取媒体的一帧压缩编码数据。其中调用了av_parser_parse2()。“纯净”的解码器中,通过avcodec_decode_video2()成功解码第一帧之后,才能获取到宽高等信息解析出来的数据,可通过下面的方法判断帧类型:AVCodecParserContext->pict_type  :AV_PICTURE_TYPE_I,AV_PICTURE_TYPE_P参考:解码器-纯净版(不包含libavformat)

相关推荐
python开发_常用的python模块及安装方法
adodb:我们领导推荐的数据库连接组件bsddb3:BerkeleyDB的连接组件Cheetah-1.0:我比较喜欢这个版本的cheeta…
日期:2022-11-24 点赞:878 阅读:9,088
Educational Codeforces Round 11 C. Hard Process 二分
C. Hard Process题目连接:http://www.codeforces.com/contest/660/problem/CDes…
日期:2022-11-24 点赞:807 阅读:5,565
下载Ubuntn 17.04 内核源代码
zengkefu@server1:/usr/src$ uname -aLinux server1 4.10.0-19-generic #21…
日期:2022-11-24 点赞:569 阅读:6,413
可用Active Desktop Calendar V7.86 注册码序列号
可用Active Desktop Calendar V7.86 注册码序列号Name: www.greendown.cn Code: &nb…
日期:2022-11-24 点赞:733 阅读:6,186
Android调用系统相机、自定义相机、处理大图片
Android调用系统相机和自定义相机实例本博文主要是介绍了android上使用相机进行拍照并显示的两种方式,并且由于涉及到要把拍到的照片显…
日期:2022-11-24 点赞:512 阅读:7,822
Struts的使用
一、Struts2的获取  Struts的官方网站为:http://struts.apache.org/  下载完Struts2的jar包,…
日期:2022-11-24 点赞:671 阅读:4,905