av_parser_parse2:
源码定义:
/**
* Parse a packet.
*
* @param s parser context.
* @param avctx codec context.
* @param poutbuf set to pointer to parsed buffer or NULL if not yet finished.
* @param poutbuf_size set to size of parsed buffer or zero if not yet finished.
* @param buf input buffer.
* @param buf_size input length, to signal EOF, this should be 0 (so that the last frame can be output).
* @param pts input presentation timestamp.
* @param dts input decoding timestamp.
* @param pos input byte position in stream.
* @return the number of bytes of the input bitstream used.
*
* Example:
* @code
* while(in_len){
* len = av_parser_parse2(myparser, AVCodecContext, &data, &size,
* in_data, in_len,
* pts, dts, pos);
* in_data += len;
* in_len -= len;
*
* if(size)
* decode_frame(data, size);
* }
* @endcode
*/
<pre name="code" class="cpp">int av_parser_parse2(AVCodecParserContext *s,
AVCodecContext *avctx,
uint8_t **poutbuf, int *poutbuf_size,
const uint8_t *buf, int buf_size,
int64_t pts, int64_t dts,
int64_t pos);
第一个参数:
eg:
AVCodecParserContext *parser = NULL;
if (avcodec_open(c, codec) < 0) { fprintf(stderr, "could not open codec\n"); exit(1); } /* the codec gives us the frame size, in samples */ parser = av_parser_init(c->codec_id); parser->flags |= PARSER_FLAG_ONCE;//在打开解码器后初始化parase
另一种用法:
AVStream *st = s->streams[stream_index];
len = av_parser_parse2(st->parser, st->codec, &out_pkt.data, &out_pkt.size, data, size, pkt->pts, pkt->dts, pkt->pos);第二个参数:正常的 AVCodecContext
第三个参数:初始化后的avpkt的avpkt.data
第四个参数:初始化后的avpkt的avpkt.size
第五个参数:一次接收的数据包
第六个参数:本次接收数据包的长度
第七个参数:pts,没有的话,可以在声明后直接用int pts,单单h264的话直接挂上pts即可
第八个参数:dts,同上
第九个参数:接收数据