Data packet Avpacket analysis of ffmpeg in C/C + + audio and video library

Source: Internet
Author: User

FFmpeg http://www.ffmpeg.club/

Avpacket is ffmpeg used to store encoded video frame data, we analyze this structure, first put out the source code of Avpacket declaration in ffmpeg3.2:
typedef struct AVPACKET {/*** A reference to the reference-counted buffer where the packet data is* stored.* could be NULL, Then the packet data isn't reference-counted.*/avbufferref *buf;/*** Presentation timestamp in avstream->time_base Uni Ts The time at which* the decompressed packet'll be a presented to the user.* Can be av_nopts_value if it's not stored in th E file.* pts must be larger or equal to DTS as presentation cannot happen before* decompression, unless one wants to view Hex dumps. Some formats misuse* The terms DTS and pts/cts to mean something different. Such timestamps* must is converted to true Pts/dts before they is stored in avpacket.*/int64_t pts;/*** decompression Tim Estamp in avstream->time_base units; The time at which* the packet are decompressed.* Can be av_nopts_value if it's not stored in the file.*/int64_t dts;uint8_  T *data;int size;int stream_index;/*** A combination of Av_pkt_flag values*/int flags;/*** Additional packet data that can be provided by The container.* Packet can contain several types of side information.*/avpacketsidedata *side_data;int side_data_elems;/* * * Duration of this packet in avstream->time_base units, 0 if unknown.* Equals next_pts-this_pts in presentation Orde r.*/int64_t duration;int64_t POS; < byte position in stream, 1 if unknown#if ff_api_convergence_duration/*** @deprecated same as the DURATION field, But as int64_t. This is required* for Matroska subtitles, whose duration values could overflow when the* duration field is still an int. */attribute_deprecatedint64_t convergence_duration; #endif} avpacket;

We analyze in turn

avbufferref *buf;The data used to hold the reference count, if no reference count is used, the value is null, which is used when multiple packet objects refer to the same frame data.int64_t pts;This frame data display time, compares the key data, in does the seek and the play progress the time to use it, the PTS is only a quantity, corresponds to the avstream->time_base, must according to the Time_base can convert to the concrete time, Audio and video generally have different time_base, so in doing audio and video synchronization must do the conversion, can not directly take PTS to do. Conversion mode, such as to milliseconds avformatcontext *ic = null;static double r2d (avrational R) {return r.num = = 0 | | r.den = = 0? 0.: (double) r.num/(double) R.den;} 。。。 int pts = (pkt->pts *r2d (ic->streams[pkt->stream_index]->time_base)) * 1000;int64_t DTS;The basic attribute is equivalent to pts, the difference is that DTS corresponds to the decoding time is not the display time, decoding will be put into a buffer, such as h264, if there is a B-frame, you must first decode the back of the B-frame, and then decode the previous frame.uint8_t *data; int size;frame data and data sizeint stream_index;the index of the stream to which the frame data belongs, to distinguish between audio, video, and subtitle data. int flags;Flag, where 1 indicates that the data is a keyframe av_pkt_flag_key 0x0001 keyframe AVpacketsidedata *side_data;int side_data_elems;Some additional data provided by the containerint64_t duration;Next Frame pts-the current frame, Pts, also represents a two-frame interval. int64_t Pos;The position of the current frame data in the file (in bytes), if the file shift is used, if RTSP does not have this data. More information can also follow my video courseXia Chaojun Teacher Course column http://edu.csdn.net/lecturer/961teach you how to develop a video player

http://edu.csdn.net/course/detail/3300

Data packet Avpacket analysis of ffmpeg in C/C + + audio and video library

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.