首页
学习
活动
专区
圈层
工具
发布
    • 综合排序
    • 最热优先
    • 最新优先
    时间不限
  • 来自专栏Linux驱动

    6.AVCodecContext和AVCodec

    和 extradata_size 两个成员表述了相应 Codec 使用的私有数据; codec成员关联相应的编解码器; priv_data 成员关联各个具体编解码器独有的属性 context,与 AVCodec 编码:由libavcodec在avcodec_open2()中设置。 解码:可以由一些解码器设置以指示恒定的帧大小. int frame_number; //帧计数器,由libavcodec设置。 AVCodec AVCodec 是类似 COM 接口的数据结构,表示音视频编解码器,着重于功能函数. next 成员用于把所有支持的编解码器连接成链表,便于遍历查找; id 确定唯 一编 解 码器 ; *vc = avcodec_alloc_context3(vcodec); //构造AVCodecContext ,并将vcodec填入AVCodecContext中 avcodec_parameters_to_context ; //打开解码器,由于之前调用avcodec_alloc_context3(vcodec)初始化了vc,那么codec(第2个参数)可以填NULL

    1.5K10发布于 2020-09-10
  • 来自专栏猿计划

    ffmpeg中AVCodec是否需要手动销毁?

    在开发到退出一个视频播放功能时,看到对AVCodec*这个指针做了初始化,但是突然有一个好奇的疑问,这个AVCodec到底是否需要人工手动销毁? (v_codec); 可以看到在av_find_best_stream内部针对const AVCodec *指针做了初始化,然后把初始化后的AVCodec传递给了avcodec_alloc_context3 #avcodec_alloc_context3: AVCodecContext *avcodec_alloc_context3(const AVCodec *codec); AVCodecContext 我们再追一下销毁AVCodecContext的函数avcodec_free_context: libavcodec/options.c #avcodec_free_context: 再看avcodec_close AVCodec的close函数; (2)在avcodec_close函数中close后赋值为了NULL;

    64200编辑于 2024-05-24
  • 来自专栏软件研发

    解决方案:avcodec_receive_packet AVERROR(EAGAIN)

    解决方案:avcodec_receive_packet AVERROR(EAGAIN)在使用FFmpeg进行音视频编解码时,我们经常会遇到各种错误和异常情况。 其中,一个常见的错误是avcodec_receive_packet返回AVERROR(EAGAIN)。本篇博客将围绕这个错误展开讨论,并提供解决方案。 解决方案要解决avcodec_receive_packet返回AVERROR(EAGAIN)错误,我们可以采取以下策略:在收到AVERROR(EAGAIN)错误后,继续调用avcodec_receive_packet 总结: avcodec_receive_packet返回AVERROR(EAGAIN)可能是因为解码器内部缓冲区没有可用的数据包。 通过适当地处理该错误,如继续调用avcodec_receive_packet函数,或确保输入数据源连续提供数据,我们可以有效地解决这个问题。

    1.4K10编辑于 2023-12-13
  • 来自专栏全栈程序员必看

    ffmpeg h264解码器提取

    使用ffmpeg解码可以参考ffmpeg源码下的doc/examples/decoding_encoding.c 1.首先设置解码器参数( avcodec_find_decoder(CODEC_ID_H264 ) 将decode函数指针为 h264_decoder, 即 AVCodec ff_h264_decoder = { .name = “h264”, () 函数进行解码 avcodec_decode_video通过调avctx->codec->decode函数来完成具体解码器的调用 其中 avctx为 AVCodecContext类型, AVCodec ff_h264_decoder;//在h264.c中定义 AVCodec *codec = &ff_h264_decoder;// AVCodecContext * ); avctx= avcodec_alloc_context(); picture= avcodec_alloc_frame(); if(codec->capabilities

    1.3K10编辑于 2022-07-04
  • 来自专栏韩曙亮的移动开发专栏

    【Android FFMPEG 开发】FFMPEG 获取编解码器 ( 获取编解码参数 | 查找编解码器 | 获取编解码器上下文 | 设置上下文参数 | 打开编解码器 )

    ( ) 获取当前音视频流使用的编解码器 ; //① 查找 当前流 使用的编码方式 , 进而查找编解码器 ( 可能失败 , 不支持的解码方式 ) AVCodec *avCodec = avcodec_find_decoder AVCodecContext *avCodecContext = avcodec_alloc_context3(avCodec); ④ 设置编解码器上下文参数 : 调用 avcodec_parameters_to_context = avcodec_open2(avCodecContext, avCodec, 0); I . ; ① enum AVCodecID id 参数 : 代表了一个编码数据的特定类型 ; ( 详情查看 I . 3 . ① 小节内容 ) ② AVCodec *avCodec 返回值 : 返回值是 AVCodec *avCodec = avcodec_find_decoder(codecParameters->codec_id); //查找失败处理 if(avCodec ==

    1.3K20编辑于 2023-03-27
  • 来自专栏曾大稳的博客

    ffmpeg 视频解码h264和yuv

    () //将AVCodecParameters转换为AVCodecContext avcodec_parameters_to_context() //获取解码器 avcodec_find_decoder () //解码数据源 ,和avcodec_send_packet配合使用 avcodec_receive_frame() //图像转换 sws_scale() //写入文件 fwrite() 回收 获取解码器并打开 pCodecCtx = avcodec_alloc_context3(NULL); if (avcodec_parameters_to_context(pCodecCtx, pFmtCtx “flush_decoder”功能简而言之即直接调用avcodec_decode_video2()获得AVFrame,而不再向解码器传递AVPacket。 = NULL) { avcodec_close(pCodecCtx); } if (pFmtCtx !

    4.5K20发布于 2018-09-11
  • 来自专栏音视频开发之旅

    音视频开发之旅(34) - 基于FFmpeg实现简单的视频解码器

    根据视频流信息的codec_id找到对应的解码器_ avcodec_open2 使用给定的AVCodec初始化AVCodecContext_ 初始化输出文件、解码AVPacket和AVFrame结构体 av_read_frame 开始一帧一帧读取 avcodec_send_packet avcodec_receive_frame 格式转换 、分别写入YUV文件 Opengl渲染(本篇不涉及,放到后面单独篇学习实践 Find a registered decoder with a matching codec ID AVCodec *avcodec_find_decoder(enum AVCodecID id) ; 根据codecID找到一个注册过的解码器 5. avcodec_open2 Initialize the AVCodecContext to use the given AVCodec int avcodec_open2 (AVCodecContext *avctx, const AVCodec *codec, AVDictionary **options); 使用给定的AVCodec初始化AVCodecContext_

    1.7K00发布于 2021-02-28
  • 来自专栏全栈程序员必看

    C++ ffmpeg+dxva2实现硬解码「建议收藏」

    (const AVCodec *codec); 申请AVCodecContext空间。 codec:输入的AVCodec。 options:一些选项。例如使用libx264编码的时候,“preset”,“tune”等都可以通过该参数设置。 avcodec_close(AVCodecContext *avctx); 参考讲解:关闭编码器 avcodec_free_context(AVCodecContext **avctx); 释放解码器上下文 avcodec_flush_buffers(pCodecCtx); // 清空内部缓存的帧数据 continue; } while (ret >= 0) { ret = avcodec_receive_frame (pCodecCtx); avcodec_close(pCodecCtx); //close,如果为rk3399的硬件编解码,则需要等待MPP_Buff释放完成后再关闭?

    3K10编辑于 2022-11-16
  • 来自专栏进击的多媒体开发

    FFmpeg 实现视频 封装 与 解封装

    avcodec_find_decoder函数定义如下: AVCodec *avcodec_find_decoder(enum AVCodecID id); 该函数参数为AVCodecID指定了请求的解码器 avcodec_open2函数定义如下: int avcodec_open2(AVCodecContext *avctx, const AVCodec *codec, AVDictionary **options 该函数的主要作用是根据给定的AVCodec初始化AVCodecContext,在使用该函数之前,待初始化的AVCodecContext结构需要先使用avcodec_alloc_context3分配好。 其中的参数 AVCodec可以通过avcodec_find_decoder_by_nameavcodec_find_encoder_by_nameavcodec_find_decoder或avcodec_find_endcoder codec) exit(1); context = avcodec_alloc_context3(codec); if(avcodec_open2(context, codec, opts)

    3K30发布于 2020-07-24
  • 来自专栏进击的多媒体开发

    刨根问底 | FFmpeg 解码 API 以及在解码过程中存在的丢帧问题

    背景 在优化视频客观全参考算法(主要是PSNR, SSIM, MS-SSIM)时,我们首先利用FFmpeg提供的API(avcodec_send_packet(),avcodec_receive_frame () 编码API avcodec_send_frame() avcodec_receive_packet() /** * @ingroup libavc * @defgroup lavc_encdec (): 编码API avcodec_encode_video2() avcodec_encode_audio2() attribute_deprecated int avcodec_decode_audio4 解码 API 状态机 avcodec_send_packet()和avcodec_receive_frame()不同的返回值代表了解码器的不同的状态。 根据avcodec_send_packet返回值和avcodec_receive_frame返回值中的介绍,可以得到正常情况下,解码过程的状态机,如下图所示。

    3.6K20发布于 2021-11-25
  • 来自专栏方亮

    ffmpeg api的应用——提取视频图片

    ; } AVCodec *avcodec = avcodec_find_decoder(avcodec_ctx->codec_id); if (avcodec_open2(avcodec_ctx.get(), avcodec, NULL) < 0) { std::cerr << "Failed to open 和之前的Context使用套路一致: 使用avcodec_alloc_context3申请空间; 使用avcodec_free_context释放空间; 通过avcodec_parameters_to_context 这次我们要使用avcodec_find_encoder去寻找编码器 void traverse_frame(AVFrame* avframe) { AVCodec *avcodec = avcodec_find_encoder ; avcodec_ctx_output->pix_fmt = AV_PIX_FMT_YUVJ420P; avcodec_ctx_output->codec_id = avcodec->

    1.9K10发布于 2019-01-16
  • 来自专栏呱牛笔记

    AAC的音频编码和解码实现

    extern "C" { #endif #include "libavutil/time.h" #include "libavformat/avformat.h" #include "libavcodec/avcodec.h :64000 */ int init_aac_codec(uint8_t encode_flag, int sample_rate, int channels, int bitrate){     AVCodec ("libfdk_aac");        //input_codec = avcodec_find_encoder(codec_id);         if (! ("libfdk_aac");         //input_codec = avcodec_find_decoder(codec_id);         if (! = NULL){         avcodec_free_context(&input_codec_context);     }     return 0; }

    1.2K20编辑于 2023-05-02
  • 来自专栏音视频开发技术

    FFmpeg编解码处理2-编解码API详解

    编解码API详解 解码使用avcodec_send_packet()和avcodec_receive_frame()两个函数。 编码使用avcodec_send_frame()和avcodec_receive_packet()两个函数。 avcodec_send_packet()多次发送NULL并不会导致解码器中缓存的帧丢失,使用avcodec_flush_buffers()可以立即丢掉解码器中缓存帧。 因此播放完毕时应avcodec_send_packet(NULL)来取完缓存的帧,而SEEK操作或切换流时应调用avcodec_flush_buffers()来直接丢弃缓存帧。 因此编码完毕时应使用avcodec_send_frame(NULL)来取完缓存的帧,而SEEK操作或切换流时应调用avcodec_flush_buffers()来直接丢弃缓存帧。

    3.1K20发布于 2019-03-28
  • 来自专栏Linux驱动

    7.SwrContext音频重采样使用

    *acodecCtx = avcodec_alloc_context3(acodec); //构造AVCodecContext ,并将vcodec填入AVCodecContext中 avcodec_parameters_to_context , NULL,NULL); //打开解码器,由于之前调用avcodec_alloc_context3(acodec)初始化了解码器,那么codec(第2个参数)可以填NULL if ( = 0) { debugErr("avcodec_open2",ret); return ; } SwrContext *swrctx = 0) { debugErr("avcodec_send_packet",ret); continue ; } if(packet->stream_index==audioindex) //判断是音频流 { while( avcodec_receive_frame(acodecCtx

    1.1K30发布于 2020-09-14
  • 来自专栏写代码的海盗

    新手学习FFmpeg - 调用API完成录屏并进行H.264编码

    针对输入设备也就是下面的顺序: avcodec_find_decoder -> avcodec_alloc_context3 -> avcodec_open2 AVInputFormat会有多个数据流( 视频流/音频流),所以首先找到需要处理的流: codecpar->codec_type == AVMEDIA_TYPE_VIDEO 然后依次调用avcodec_find_decoder,avcodec_alloc_context3 和avcodec_open2来初始化codec。 打开输出设备的方法和打开输入设备方法类似: avcodec_find_encoder -> avcodec_alloc_context3 -> avcodec_open2 -> avformat_write_header 处理流程大致为: while av_read_frame | +---> avcodec_send_packet |

    2.5K30发布于 2019-09-05
  • 来自专栏程序员的园——原创文章

    音视频文件解码

    以下是涉及的主要结构体和函数: 结构体 AVCodec:表示一个具体的解码器或编码器。 通过函数 avcodec_find_decoder 或 avcodec_find_decoder_by_name 获取。该结构体包含解码器的各种属性,如支持的格式、名称等。 使用 avcodec_alloc_context3 创建并初始化,与 AVCodec 配合使用。后续在代码中可以看到数据相关的均是使用的该结构体的对象。 const AVCodec *codec = avcodec_find_decoder(codec_id); //初始化解码器上下文 //param codec: 要使用的解码器,可以是nullptr, int avcodec_open2(AVCodecContext *codec_ctx, const AVCodec *codec, AVDictionary options); //释放解码器上下文

    57910编辑于 2024-11-28
  • 来自专栏全栈程序员必看

    FFmpeg 4.x 从入门到精通(一)—— QT 中如何用 FFmpeg 实现软件解码

    5、avcodec_alloc_context3 创建AVCodecContext并分配空间。 avcodec_parameters_to_context()是新的API,替换了旧版本的avcodec_copy_context()。 7、avcodec_open2 用给定的 AVCodec 去初始化 AVCodecContext。 到这儿,解码器的初始化工作已经完成。下面就可以开始真正的解码操作了。 8、avcodec_send_packet 发送数据到后台解码队列。 此处需要注意的是: 一般而言,一次avcodec_send_packet()对应一次avcodec_receive_frame(),但是也会有一次对应多次的情况。

    1.8K20编辑于 2022-09-13
  • 来自专栏Gnep's_Technology_Blog

    AVFormatContext编解码层:理论与实战

    (); 打开编解码器:avcodec_open(); 为解码帧分配内存:avcodec_alloc_frame(); 不停地从码流中提取出帧数据:av_read_frame(); 判断帧的类型,对于视频帧调用 三、编解码 API 详解 解码使用 avcodec_send_packet() 和 avcodec_receive_frame() 两个函数。 编码使用 avcodec_send_frame() 和 avcodec_receive_packet() 两个函数。 :调用一次 avcodec_send_packet(NULL)(返回成功),然后不停调用 avcodec_receive_frame() 直到其返回 AVERROR_EOF,取出所有缓存帧,avcodec_receive_frame :调用一次 avcodec_send_frame(NULL)(返回成功),然后不停调用avcodec_receive_packet() 直到其返回 AVERROR_EOF,取出所有缓存帧,avcodec_receive_packet

    72710编辑于 2023-12-10
  • 来自专栏福大大架构师每日一题

    音视频八股文(6)-- ffmpeg大体介绍和内存模型

    (): 分配解码器上下文• avcodec_find_decoder():根据ID查找解码器• avcodec_find_decoder_by_name():根据解码器名字• avcodec_open2 (): 打开编解码器• avcodec_decode_video2():解码一帧视频数据• avcodec_decode_audio4():解码一帧音频数据• avcodec_send_packet() : 发送编码数据包• avcodec_receive_frame(): 接收解码后数据• avcodec_free_context():释放解码器上下文,包含了avcodec_close()• avcodec_close 之间的关系AVCodecContext 编码器上下文结构体struct AVCodec *codec; AVCodec 每种视频(音频)编解码器int (decode)(AVCodecContext , • type:编解码器类型• id:编解码器ID• 一些编解码的接口函数,比如int (*decode)()◼ AVCodecContext• codec:编解码器的AVCodec,比如指向AVCodec

    85800编辑于 2023-04-26
  • 来自专栏C++

    FFmpeg4.0笔记:封装ffmpeg的解码功能类CDecode

    (&codectx1);\ avcodec_free_context(&codectx2);\ err = av_err2str(ret);\ return false;\ } "; return false; } if (vindex_ >= 0) { vcodectx_ = avcodec_alloc_context3 "; return false; } ret = avcodec_parameters_to_context(vcodectx_, fmtctx_ ->streams[vindex_]->codecpar); CHECKFFRETANDCTX(ret, vcodectx_); ret = avcodec_open2( = nullptr) { avcodec_free_context(&vcodectx_); } if (acodectx_ !

    1.3K30发布于 2019-06-15
领券