av_parser_parse2分析

ffmpeg av_parser_parse2分析


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 
)

Parse a packet.
Parameters
    s               parser context.
    avctx           codec context.
    poutbuf         set to pointer to parsed buffer or NULL if not yet finished.
    poutbuf_size    set to size of parsed buffer or zero if not yet finished.
    buf             input buffer.
    buf_size        input length, to signal EOF, this should be 0 (so that the last frame can be output).
    pts             input presentation timestamp.
    dts             input decoding timestamp.
    pos             input byte position in stream.
Returns
    the number of bytes of the input bitstream used.

Example:
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);
}
Definition at line 136 of file parser.c.
Referenced by decode(), flac_read_timestamp(), old_flac_header(), and parse_packet().

av_parser_parse2分析_第1张图片


用法:
av_parser_parse2分析_第2张图片


**我的发现:**av_parser_parse2 好像会一个一个NALU往里面放,若packet.data不能与tmpPkt.data中的数据构成一帧,则说明前面的数据为一帧的内容,于是此时tmpPkt.size为前面若干NALU的总和,即一帧,于是解码出来,但要注意,此时的packet.data不会放入tmpPkt.data中,因此需要将文件指针回退packet.size个字节,为了下次再读取该packet,否则便会跳过该packet。
(不知是否正确,恳请大神给予指正)

你可能感兴趣的:(Qt+ffmpeg)