首先看一下FFmpeg关于该packet函数的注释:

int avcodec_send_packet ( AVCodecContext *  avctx,
    const AVPacket *  avpkt 
  )    

Supply raw packet data as input to a decoder.

Internally, this call will copy relevant AVCodecContext fields, which can influence decoding per-packet, and apply them when the packet is actually decoded. (For example AVCodecContext.skip_frame, which might direct the decoder to drop the frame contained by the packet sent with this function.)

Warning
The input buffer, avpkt->data must be AV_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.
Do not mix this API with the legacy API (like avcodec_decode_video2()) on the same AVCodecContext. It will return unexpected results now or in future libavcodec versions.
Note
The AVCodecContext MUST have been opened with avcodec_open2() before packets may be fed to the decoder.
Parameters
  avctx codec context
[in] avpkt The input AVPacket. Usually, this will be a single video frame, or several complete audio frames. Ownership of the packet remains with the caller, and the decoder will not write to the packet. The decoder may create a reference to the packet data (or copy it if the packet is not reference-counted). Unlike with older APIs, the packet is always fully consumed, and if it contains multiple frames (e.g. some audio codecs), will require you to call avcodec_receive_frame() multiple times afterwards before you can send a new packet. It can be NULL (or an AVPacket with data set to NULL and size set to 0); in this case, it is considered a flush packet, which signals the end of the stream. Sending the first flush packet will return success. Subsequent ones are unnecessary and will return AVERROR_EOF. If the decoder still has frames buffered, it will return them after sending a flush packet.
Returns
0 on success, otherwise negative error code: AVERROR(EAGAIN): input is not accepted in the current state - user must read output with avcodec_receive_frame() (once all output is read, the packet should be resent, and the call will not fail with EAGAIN). AVERROR_EOF: the decoder has been flushed, and no new packets can be sent to it (also returned if more than 1 flush packet is sent) AVERROR(EINVAL): codec not opened, it is an encoder, or requires flush AVERROR(ENOMEM): failed to add packet to internal queue, or similar other errors: legitimate decoding errors

看一下FFmpeg4.1.3中相关代码

int avcodec_send_packet(AVCodecContext *avctx, const AVPacket *avpkt)
{
AVCodecInternal *avci = avctx->internal;
int ret;

//检查是否打开解码器

if (!avcodec_is_open(avctx) || !av_codec_is_decoder(avctx->codec))
return AVERROR(EINVAL);

//清空解码器

if (avctx->internal->draining)
return AVERROR_EOF;

if (avpkt && !avpkt->size && avpkt->data)
return AVERROR(EINVAL);

//擦除缓冲区数据包==初始化

av_packet_unref(avci->buffer_pkt);
if (avpkt && (avpkt->data || avpkt->side_data_elems)) {

//copy packet
ret = av_packet_ref(avci->buffer_pkt, avpkt);
if (ret < 0)
return ret;
}

//packet去除编码开始部分的冗余信息,并加载到bsfs

ret = av_bsf_send_packet(avci->filter.bsfs[0], avci->buffer_pkt);//Submit a packet for filtering
if (ret < 0) {
av_packet_unref(avci->buffer_pkt);
return ret;
}

if (!avci->buffer_frame->buf[0]) {

//解码核心
ret = decode_receive_frame_internal(avctx, avci->buffer_frame);
if (ret < 0 && ret != AVERROR(EAGAIN) && ret != AVERROR_EOF)
return ret;
}

return 0;
}

具体的原理和解释可参考https://www.cnblogs.com/TaigaCon/p/10041926.html

FFmpeg avcodec_send_packet压缩包函数的更多相关文章

  1. FFmpeg(2)-avformat_open_input()函数详解并示例打开mp4文件

    一. 解封装 pts 是显示的时间 dts是解码的时间, 这个时间是用来做同步. av_register_all(), 注册所有的格式.包括解封装格式和加封装格式. avformat_network_ ...

  2. ffmpeg的API函数用法 :sws_scale函数的用法-具体应用

    移植ffmpeg过程中,遇到swscale的用法问题,所以查到这篇文章.文章虽然已经过去很长时间,但是还有颇多可以借鉴之处.谢谢“咕咕钟. 转自:http://guguclock.blogspot.c ...

  3. FFmpeg 的sws_getContext函数 、sws_scale函数

    FFmpeg里面的sws_scale库可以在一个函数里面同时实现:1.图像色彩空间转换:2.分辨率缩放:3.前后图像滤波处理. 其核心函数主要有三个: // 初始化sws_scalestruct Sw ...

  4. 零基础学习视频解码之FFMpeg中比较重要的函数以及数据结构

    http://www.cnblogs.com/tanlon/p/3879081.html 在正式开始解码练习前先了解下关于FFmpeg中比较重要的函数以及数据结构. 1. 数据结构:  (1) AVF ...

  5. ffmpeg.c函数结构简单分析(画图)

    前一阵子研究转码的时候看了FFmpeg的源代码.由于ffmpeg.c的代码相对比较长,而且其中有相当一部分是AVFilter有关的代码(这一部分一直不太熟),因此之前学习FFmpeg的时候一直也没有好 ...

  6. [原]零基础学习视频解码之FFMpeg中比较重要的函数以及数据结构

    在正式开始解码练习前先了解下关于FFmpeg中比较重要的函数以及数据结构. 1. 数据结构:  (1) AVFormatContext  AVFormatContext是一个贯穿始终的数据结构,很多函 ...

  7. windows环境下搭建ffmpeg开发环境

           ffmpeg是一个开源.跨平台的程序库,能够使用在windows.linux等平台下,本文将简单解说windows环境下ffmpeg开发环境搭建过程,本人使用的操作系统为windows ...

  8. ffmpeg学习笔记-初识ffmpeg

    ffmpeg用来对音视频进行处理,那么在使用ffmpeg前就需要ffmpeg有一个大概的了解,这里使用雷神的ppt素材进行整理,以便于复习 音视频基础知识 视频播放器的原理 播放视频的流程大致如下: ...

  9. FFmpeg开发笔记(五):ffmpeg解码的基本流程详解(ffmpeg3新解码api)

    若该文为原创文章,未经允许不得转载原博主博客地址:https://blog.csdn.net/qq21497936原博主博客导航:https://blog.csdn.net/qq21497936/ar ...

随机推荐

  1. 解决ExpressSpreadSheet 中文乱码问题[备查]

    cxSpreadSheet和F1Book等都提供了类似Excel的操作, 但是相比F1Book, cxSpreadSheet的中文支持还不是很完善.在设置了wordbreak为true的时候,里面的中 ...

  2. python下的线程 进程,以及如何实现并发服务器

    在一个CPU(一核)的电脑上, 程序的运行是并发运行的,调度的算法叫时间片轮转法,也叫轮询法 在多CPU(多核)的电脑上,一个CPU跑一个程序,刚程序运行数量小于核心数时,程序是并行的 并发:看上去一 ...

  3. Spring Cloud-hystrix使用例子(七)

    继承方式 HystrixCommand public class UserSelectAllCommand extends HystrixCommand<List<User>> ...

  4. Efficient ticket lock synchronization implementation using early wakeup in the presence of oversubscription

    A turn-oriented thread and/or process synchronization facility obtains a ticket value from a monoton ...

  5. [bzoj3717][PA2014]Pakowanie_动态规划_状压dp

    Pakowanie bzoj-3717 PA-2014 题目大意:给你n个物品m个包,物品有体积包有容量,问装下这些物品最少用几个包. 注释:$1\le n\le 24$,$1\le m\le 100 ...

  6. tomcat日志采集

    1. 采集tomcat确实比之前的需求复杂很多,我在搭建了一个tomcat的环境,然后产生如下报错先贴出来: Jan 05, 2017 10:53:35 AM org.apache.catalina. ...

  7. Android开发之BUG专讲:入门篇(一)

    前言: 本文作者:周才智 转载须注明作者与出处.违者必究. 原文地址:http://segmentfault.com/a/1190000004380690 话说诸葛亮是一个优秀的程序员,每个锦囊都是应 ...

  8. GNU TeXmacs 1.99.8 发布,所见即所得科学编辑器(看看老实的GUI)

    GNU TeXmacs 1.99.8 已发布,这是一个支持各种数学公式的所见即所得编辑器,可以用来编辑文本.图形.数学.交互内容,它的界面非常友好,并且内置高质量的排版引擎. 更新内容: bug 修复 ...

  9. php模版静态化技术

    PHP页面的静态化很有必要,尤其是在CMS系统中,一些内容一旦生成,基本上不会有变化,这时如果用html将页面静态化,无疑会减少服务其解析PHP页面的负担.以下是看书学来的PHP静态化技术,记录之以备 ...

  10. hihoCoder-1830 2018亚洲区预选赛北京赛站网络赛 C.Cheat 模拟

    题面 题意:4个人围一圈坐着,每个人13张牌,然后从第一个人开始,必须按照A-K的顺序出牌,一个人出牌后,剩下的人依次可以选择是否质疑他,例如,第一个人现在必须出8(因为按照A-K顺序轮到了),可是他 ...