ffmpeg结构体以及函数介绍(三)

1 AVPacket

typedef
struct AVPacket {

    /**

     * Presentation timestamp in AVStream->time_base units; the time at which

     * the decompressed packet will be presented to the user.

     * Can be AV_NOPTS_VALUE if it is not stored in the 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 be converted to true pts/dts before they are stored in AVPacket.

     */

    int64_t pts;

    /**

     * Decompression timestamp in AVStream->time_base units; the time at which

     * the packet is decompressed.

     * Can be AV_NOPTS_VALUE if it is not stored in the file.

     */

    int64_t dts;

    uint8_t *data;

    int   size;

    int   stream_index;

    int   flags;

 

int   duration;

.

.

.

} AVPacket

// AVPacket是个很重要的结构,该结构在读媒体源文件和写输出文件时都需要用到

// int64_t pts; 显示时间戳

// int64_t dts; 解码时间戳

// uint8_t *data; 包数据

// int   size; 包数据长度

// int   stream_index; 包所属流序号

// int   duration; 时长

// 以上信息,如果是在读媒体源文件那么avcodec会初始化,如果是输出文件,用户需要对以上信息赋值

 

2
av_init_packet()

/**

 * Initialize optional fields of a packet with default values.

 *

 * @param pkt packet

 */

void av_init_packet(AVPacket *pkt);

// 使用默认值初始化AVPacket

// 定义AVPacket对象后,请使用av_init_packet进行初始化

 

3
av_free_packet()

/**

 * Free a packet.

 *

 * @param pkt packet to free

 */

void av_free_packet(AVPacket *pkt);

// 释放AVPacket对象

 

4
av_read_frame()

/**

 * Return the next frame of a stream.

 * This function returns what is stored in the file, and does not validate

 * that what is there are valid frames for the decoder. It will split what is

 * stored in the file into frames and return one for each call. It will not

 * omit invalid data between valid frames so as to give the decoder the maximum

 * information possible for decoding.

 *

 * The returned packet is valid

 * until the next av_read_frame() or until av_close_input_file() and

 * must be freed with av_free_packet. For video, the packet contains

 * exactly one frame. For audio, it contains an integer number of

 * frames if each frame has a known fixed size (e.g. PCM or ADPCM

 * data). If the audio frames have a variable size (e.g. MPEG audio),

 * then it contains one frame.

 *

 * pkt->pts, pkt->dts and pkt->duration are always set to correct

 * values in AVStream.time_base units (and guessed if the format cannot

 * provide them). pkt->pts can be AV_NOPTS_VALUE if the video format

 * has B-frames, so it is better to rely on pkt->dts if you do not

 * decompress the payload.

 *

 * @return 0 if OK, < 0 on error or end of file

 */

int av_read_frame(AVFormatContext *s, AVPacket *pkt);

// 从输入源文件容器中读取一个AVPacket数据包

// 该函数读出的包并不每次都是有效的,对于读出的包我们都应该进行相应的解码(视频解码/音频解码),

// 在返回值>=0时,循环调用该函数进行读取,循环调用之前请调用av_free_packet函数清理AVPacket

 

5
avcodec_decode_video2()

/**

 * Decode the video frame of size avpkt->size from avpkt->data into picture.

 * Some decoders may support multiple frames in a single AVPacket, such

 * decoders would then just decode the first frame.

 *

 * @warning The input buffer must be FF_INPUT_BUFFER_PADDING_SIZE larger than

 * the actual read bytes because some optimized bitstream readers read 32 or 64

 * bits at once and could read over the end.

 *

 * @warning The end of the input buffer buf should be set to 0 to ensure that

 * no overreading happens for damaged MPEG streams.

 *

 * @note You might have to align the input buffer avpkt->data.

 * The alignment requirements depend on the CPU: on some CPUs it isn't

 * necessary at all, on others it won't work at all if not aligned and on others

 * it will work but it will have an impact on performance.

 *

 * In practice, avpkt->data should have 4 byte alignment at minimum.

 *

 * @note Some codecs have a delay between input and output, these need to be

 * fed with avpkt->data=NULL, avpkt->size=0 at the end to return the remaining frames.

 *

 * @param avctx the codec context

 * @param[out] picture The AVFrame in which the decoded video frame will be stored.

 *             Use avcodec_alloc_frame to get an AVFrame, the codec will

 *             allocate memory for the actual bitmap.

 *             with default get/release_buffer(), the decoder frees/reuses the bitmap as it sees fit.

 *             with overridden get/release_buffer() (needs CODEC_CAP_DR1) the user decides into what buffer the decoder

 *                   decodes and the decoder tells the user once it does not need the data anymore,

 *                   the user app can at this point free/reuse/keep the memory as it sees fit.

 *

 * @param[in] avpkt The input AVpacket containing the input buffer.

 *            You can create such packet with av_init_packet() and by then setting

 *            data and size, some decoders might in addition need other fields like

 *            flags&AV_PKT_FLAG_KEY. All decoders are designed to use the least

 *            fields possible.

 * @param[in,out] got_picture_ptr Zero if no frame could be decompressed, otherwise, it is nonzero.

 * @return On error a negative value is returned, otherwise the number of bytes

 * used or zero if no frame could be decompressed.

 */

int avcodec_decode_video2(AVCodecContext *avctx, AVFrame *picture,

                         int *got_picture_ptr,

                         AVPacket *avpkt);

// 解码视频流AVPacket

// 使用av_read_frame读取媒体流后需要进行判断,如果为视频流则调用该函数解码

// 返回结果<0时失败,此时程序应该退出检查原因

// 返回>=0时正常,假设 读取包为:AVPacket vPacket 返回值为 int vLen; 每次解码正常时,对vPacket做

// 如下处理:

//   vPacket.size -= vLen;
//   vPacket.data += vLen;

// 如果 vPacket.size==0,则继续读下一流包,否则继续调度该方法进行解码,直到vPacket.size==0

// 返回 got_picture_ptr > 0 时,表示解码到了AVFrame *picture,其后可以对picture进程处理

 

6
avcodec_decode_audio3()

/**

 * Decode the audio frame of size avpkt->size from avpkt->data into samples.

 * Some decoders may support multiple frames in a single AVPacket, such

 * decoders would then just decode the first frame. In this case,

 * avcodec_decode_audio3 has to be called again with an AVPacket that contains

 * the remaining data in order to decode the second frame etc.

 * If no frame

 * could be outputted, frame_size_ptr is zero. Otherwise, it is the

 * decompressed frame size in bytes.

 *

 * @warning You must set frame_size_ptr to the allocated size of the

 * output buffer before calling avcodec_decode_audio3().

 *

 * @warning The input buffer must be FF_INPUT_BUFFER_PADDING_SIZE larger than

 * the actual read bytes because some optimized bitstream readers read 32 or 64

 * bits at once and could read over the end.

 *

 * @warning The end of the input buffer avpkt->data should be set to 0 to ensure that

 * no overreading happens for damaged MPEG streams.

 *

 * @note You might have to align the input buffer avpkt->data and output buffer

 * samples. The alignment requirements depend on the CPU: On some CPUs it isn't

 * necessary at all, on others it won't work at all if not aligned and on others

 * it will work but it will have an impact on performance.

 *

 * In practice, avpkt->data should have 4 byte alignment at minimum and

 * samples should be 16 byte aligned unless the CPU doesn't need it

 * (AltiVec and SSE do).

 *

 * @param avctx the codec context

 * @param[out] samples the output buffer, sample type in avctx->sample_fmt

 * @param[in,out] frame_size_ptr the output buffer size in bytes

 * @param[in] avpkt The input AVPacket containing the input buffer.

 *            You can create such packet with av_init_packet() and by then setting

 *            data and size, some decoders might in addition need other fields.

 *            All decoders are designed to use the least fields possible though.

 * @return On error a negative value is returned, otherwise the number of bytes

 * used or zero if no frame data was decompressed (used) from the input AVPacket.

 */

int avcodec_decode_audio3(AVCodecContext *avctx, int16_t *samples,

                         int *frame_size_ptr,

                         AVPacket *avpkt);

// 解码音频流AVPacket

// 使用av_read_frame读取媒体流后需要进行判断,如果为音频流则调用该函数解码

// 返回结果<0时失败,此时程序应该退出检查原因

// 返回>=0时正常,假设 读取包为:AVPacket vPacket 返回值为 int vLen; 每次解码正常时,对vPacket做

// 如下处理:

//   vPacket.size -= vLen;
//   vPacket.data += vLen;

// 如果 vPacket.size==0,则继续读下一流包,否则继续调度该方法进行解码,直到vPacket.size==0

//

时间: 2024-12-09 09:03:05

ffmpeg结构体以及函数介绍(三)的相关文章

ffmpeg结构体以及函数介绍(一)

本文对在使用ffmpeg进行音视频编解码时使用到的一些函数做一个简单介绍,我当前使用的ffmpeg版本为:0.8.5,因为本人发现在不同的版本中,有些函数名称会有点小改动,所以在此有必要说明下ffmpeg的版本号.     ffmpeg本人也是刚接触,本文将采用累加的方法逐个介绍我使用到的函数,如有不妥之处,还望谅解!     头文件引入方法: extern "C" { #include "libavcodec/avcodec.h" #include "l

ffmpeg结构体以及函数介绍(二)

1 avcodec_find_decoder() /**  * Find a registered decoder with a matching codec ID.  *  * @param id CodecID of the requested decoder  * @return A decoder if one was found, NULL otherwise.  */ AVCodec *avcodec_find_decoder(enum CodecID id); // 通过code

c++初学者求解一道结构体,函数题

问题描述 c++初学者求解一道结构体,函数题 声明一个结构体类型Date,包括年月日,即一个日期类型的结构体. 设计一个程序,完成以下对日期的操作,包括以下函数: Date AddDay(Date d, int days):对日期增加days天数,然后返回得到的日期 Date AddMonth(Date d, int months):对日期增加months月数,然后返回得到的日期 Date AddYear(Date d, int years):对日期增加years年数,然后返回得到的日期 int

编程-c/c++关于结构体的函数中调用时如何存储数据并实现排序

问题描述 c/c++关于结构体的函数中调用时如何存储数据并实现排序 template struct acc_med { inline acc_med(int poolHeight, int poolWidth, type derOutput = 0) : value(-std::numeric_limits::infinity()), derOutput(derOutput), derDataActivePt(NULL) { } int i; type* array; inline void a

结构体的函数指针-结构体的函数的指针问题

问题描述 结构体的函数的指针问题 我在a.h中定义了结构体 typedef struct link_t{ int data; struct link_t* prior; struct link_t* next; }Node_t,Link_t; typedef struct{ void (*destory_link)(Link_t head); link_t (*creat_link)(int length); Node_t* (*delete_node)(Node_t node); Node_t

关于返回结构体的函数

[前言]写作本文,源于最近回复的 <汇编中函数返回结构体的方法> 一文.在网络上也已经有一些相关文章和相关问题,有的文章已经给出了一部分结果,但总体而言还缺少比较重要的结论.本文以分析 VC6 编译器,32 位架构为主来重复性分析这个话题.   (一)不超过 8 bytes 的小结构体可以通过 EDX:EAX 返回. 本文的范例代码取材于 <汇编中函数返回结构体的方法>一文,并在此基础上进行修改和试验.要研究的第一份代码如下,定义一个不超过 8 bytes 的小结构体,不超过 8

[MySQL学习] Innodb锁系统(3)关键结构体及函数

1.锁对象的定义: 关键结构体: UNIV_INTERN lock_sys_t* lock_sys = NULL; lock_sys是一个全局变量,用于控制整个Innodb锁系统的全部锁结构,其对应的结构体为lock_sys_t,该结构体只包含两个成员: struct lock_sys_struct{     hash_table_t* rec_hash;     ulint rec_num; }; 从函数lock_rec_create可以很容易看出这两个变量的作用: quoted code:

结构体作为函数返回值??

问题描述 typedefstructLFlight{//构造航班信息类,用于存放航班信息chardestination[20];intyear;structLFlight*next;}LFlight,*FlightPointer;然后定义下面的函数怎么不行??LFlightFindFlight(FlightPointerf){chardes[20];printf("请输入查询航班的目的地:");scanf("%s",des);while(f->next){if

C# 多个结构体作为函数参数传入,怎样访问结构体中的数据?

问题描述 structHeader1{PubliccharPointFormateID=1;}structHeader2{PubliccharPointFormateID=2;}structPointFormate1{PublicintX=1;PublicintY=2;}structPointFormate2{PublicintX=3;PublicintY=4;}privateintGetAtrribute<THeader,TFormate>(THeaderH,TFormateF,intN){