音视频开发18 FFmpeg AVCodec 说明,AVCodecContext 说明

FFmpegAVCodec结构体 AVCodecFFmpeg中最重要的结构体之一,它记录了编解码器中的重要信息,其定义位于libavcodec\codec.h中,如下所示 阅读详情

AVCodec 

AVCodec:是音视频编解码器结构体,用于定义特定的编解码器。
它包含了编解码器的类型、名称、支持的音视频格式、编解码函数等。
通过AVCodec结构体,可以查询和获取系统中可用的编解码器,并与AVCodecContext关联以进行音视频编解码操作。

对于音频,一定要知道 采样率,采样格式,声道数   

采样率: Sampling Rate 44100. 每秒中采集多少个音频点。 在ffmpeg 中 对应类型为 AVRational *supported_framerates
采样格式:16 bit, 32 bit, 在ffmpeg 中 对应类型为 AVSampleFormat
声道数: 1为单声道,2 为立体声 在ffmpeg 中 对应类型为 AVChannelLayout


对于视频,一定要知道视频的像素,视频的格式-也就是RGB/yuv, fps

像素,1600*780  暂时没有对应的值
RGB/YUV类型,AVPixelFormat AV_PIX_FMT_YUV420P
fps(每秒播放多少个图片)  AVRational *supported_framerates

const char *name:编解码器的名字,比较短

const char *long_name:编解码器的名字,全称,比较长

enum AVMediaType type:指明了类型,是视频,音频,还是字幕

enum AVCodecID id:ID,不重复

const AVRational *supported_framerates:支持的帧率(仅视频)

const enum AVPixelFormat *pix_fmts:支持的像素格式(仅视频)

const int *supported_samplerates:支持的采样率(仅音频)

const enum AVSampleFormat *sample_fmts:支持的采样格式(仅音频)

const uint64_t *channel_layouts:支持的声道数(仅音频)

int priv_data_size:私有数据的大小
————————————————

                            版权声明:本文为博主原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接和本声明。
                        
原文链接:https://blog.csdn.net/leixiaohua1020/article/details/14215833

typedef struct AVCodec {
    /**
     * Name of the codec implementation.
     * The name is globally unique among encoders and among decoders (but an
     * encoder and a decoder can share the same name).
     * This is the primary way to find a codec from the user perspective.
     *编解码器实现的名称。
		 *该名称在编码器和解码器之间是全局唯一的(但编码器和解码器可以共享相同的名称)。
		 *这是从用户角度找到编解码器的主要方法。
     */
    const char *name;
    
    
    /**
     * Descriptive name for the codec, meant to be more human readable than name.
     * You should use the NULL_IF_CONFIG_SMALL() macro to define it.
     *编解码器的描述性名称,意味着比名称更易于阅读。
		 *您应该使用NULL_IF_CONFIG_SMALL()宏来定义它。
     */
    const char *long_name;
    
    //该编解码器的 类型,enum AVMediaType type; 类似 AVMEDIA_TYPE_VIDEO,AVMEDIA_TYPE_AUDIO
    enum AVMediaType type;
    
    
    //类似 AV_CODEC_ID_AAC,AV_CODEC_ID_H264 , AAC 对应的值是十进制是86018,十六进制是15002
    enum AVCodecID id;
    
    
    /**
     * Codec capabilities.
     * see AV_CODEC_CAP_*
     * int capabilities;
     * AAC 作为 encoder 的值是98,对应的二进制是 0110 0010,对应的如下的三个值 或 起来
     *      #define AV_CODEC_CAP_DR1                 (1 <<  1)
            #define AV_CODEC_CAP_DELAY               (1 <<  5)
            #define AV_CODEC_CAP_SMALL_LAST_FRAME    (1 <<  6)
     */
    int capabilities;
    
    ///< maximum value for lowres supported by the decoder
    /// 视频专用 解码器支持的低分辨率的最大值
    uint8_t max_lowres;                     ///< maximum value for lowres supported by the decoder
    
    // 支持的帧率(仅视频)
    const AVRational *supported_framerates; ///< array of supported framerates, or NULL if any, array is terminated by {0,0}
    
    
    /// 支持的像素格式(仅视频)
    const enum AVPixelFormat *pix_fmts;     ///< array of supported pixel formats, or NULL if unknown, array is terminated by -1
    
    ///支持的采样率(仅音频)
    const int *supported_samplerates;       ///< array of supported audio samplerates, or NULL if unknown, array is terminated by 0
    
    ///支持的采样格式(仅音频)
    const enum AVSampleFormat *sample_fmts; ///< array of supported sample formats, or NULL if unknown, array is terminated by -1





#if FF_API_OLD_CHANNEL_LAYOUT
    /**
     * @deprecated use ch_layouts instead
     */
    attribute_deprecated
    const uint64_t *channel_layouts;         ///< array of support channel layouts, or NULL if unknown. array is terminated by 0
#endif
    const AVClass *priv_class;              ///< AVClass for the private context
    const AVProfile *profiles;              ///< array of recognized profiles, or NULL if unknown, array is terminated by {AV_PROFILE_UNKNOWN}

    /**
     * Group name of the codec implementation.
     * This is a short symbolic name of the wrapper backing this codec. A
     * wrapper uses some kind of external implementation for the codec, such
     * as an external library, or a codec implementation provided by the OS or
     * the hardware.
     * If this field is NULL, this is a builtin, libavcodec native codec.
     * If non-NULL, this will be the suffix in AVCodec.name in most cases
     * (usually AVCodec.name will be of the form "<codec_name>_<wrapper_name>").
     */
    const char *wrapper_name;

    /**
     * Array of supported channel layouts, terminated with a zeroed layout.
     */
    const AVChannelLayout *ch_layouts;
} AVCodec;












视频和音频对应的参数

音频

对于音频,一定要知道 采样率,采样格式,声道数   

采样率: Sampling Rate 44100. 每秒中采集多少个音频点。 在ffmpeg 中 对应类型为 AVRational *supported_framerates
采样格式:16 bit, 32 bit, 在ffmpeg 中 对应类型为 AVSampleFormat
声道数: 1为单声道,2 为立体声 在ffmpeg 中 对应类型为 AVChannelLayout


    const enum AVSampleFormat *sample_fmts; ///< array of supported sample formats, or NULL if unknown, array is terminated by -1
    音频格式,支持的样本格式的数组,如果未知则为NULL,数组以-1终止   AVSampleFormat  AV_SAMPLE_FMT_S16,音频格式

    const AVChannelLayout *ch_layouts;  //Array of supported channel layouts, terminated with a zeroed layout.
   	音频的声道数
   	
   	const int *supported_samplerates;       ///< array of supported audio samplerates, or NULL if unknown, array is terminated by 0
    支持的音频采样率数组,如果未知则为NULL,数组由0终止    int * 所支持的音频采样率 数组 如果有值,应该是44100,48000等







视频

对于视频,一定要知道视频的像素,视频的格式-也就是RGB/yuv, fps

像素,1600*780  暂时没有对应的值,这也很好理解,AVCodec 是编解码器的参数,编解码厂商支持的视频应该是多大的都应该支持

RGB/YUV类型,AVPixelFormat AV_PIX_FMT_YUV420P  对应 pix_fmts
fps(每秒播放多少个图片)  AVRational *supported_framerates


    // 支持的帧率(仅视频)
    const AVRational *supported_framerates; ///< array of supported framerates, or NULL if any, array is terminated by {0,0}
    
    
    /// 支持的像素格式(仅视频)
    const enum AVPixelFormat *pix_fmts;     ///< array of supported pixel formats, or NULL if unknown, array is terminated by -1
    

详细介绍几个变量:

1.enum AVMediaType type

AVMediaType定义如下

enum AVMediaType {
    AVMEDIA_TYPE_UNKNOWN = -1,  ///< Usually treated as AVMEDIA_TYPE_DATA
    AVMEDIA_TYPE_VIDEO,
    AVMEDIA_TYPE_AUDIO,
    AVMEDIA_TYPE_DATA,          ///< Opaque data information usually continuous
    AVMEDIA_TYPE_SUBTITLE,
    AVMEDIA_TYPE_ATTACHMENT,    ///< Opaque data information usually sparse
    AVMEDIA_TYPE_NB
};

2.enum AVCodecID id

AVCodecID定义如下:

enum AVCodecID {
    AV_CODEC_ID_NONE,
 
    /* video codecs */
    AV_CODEC_ID_MPEG1VIDEO,
    AV_CODEC_ID_MPEG2VIDEO, ///< preferred ID for MPEG-1/2 video decoding
    AV_CODEC_ID_MPEG2VIDEO_XVMC,
    AV_CODEC_ID_H261,
    AV_CODEC_ID_H263,
    AV_CODEC_ID_RV10,
    AV_CODEC_ID_RV20,
    AV_CODEC_ID_MJPEG,
    AV_CODEC_ID_MJPEGB,
    AV_CODEC_ID_LJPEG,
    AV_CODEC_ID_SP5X,
    AV_CODEC_ID_JPEGLS,
    AV_CODEC_ID_MPEG4,
    AV_CODEC_ID_RAWVIDEO,
    AV_CODEC_ID_MSMPEG4V1,
    AV_CODEC_ID_MSMPEG4V2,
    AV_CODEC_ID_MSMPEG4V3,
    AV_CODEC_ID_WMV1,
    AV_CODEC_ID_WMV2,
    AV_CODEC_ID_H263P,
    AV_CODEC_ID_H263I,
    AV_CODEC_ID_FLV1,
    AV_CODEC_ID_SVQ1,
    AV_CODEC_ID_SVQ3,
    AV_CODEC_ID_DVVIDEO,
    AV_CODEC_ID_HUFFYUV,
    AV_CODEC_ID_CYUV,
    AV_CODEC_ID_H264,
    ...(代码太长,略)
}

3.const enum AVPixelFormat *pix_fmts

AVPixelFormat定义如下:

enum AVPixelFormat {
    AV_PIX_FMT_NONE = -1,
    AV_PIX_FMT_YUV420P,   ///< planar YUV 4:2:0, 12bpp, (1 Cr & Cb sample per 2x2 Y samples)
    AV_PIX_FMT_YUYV422,   ///< packed YUV 4:2:2, 16bpp, Y0 Cb Y1 Cr
    AV_PIX_FMT_RGB24,     ///< packed RGB 8:8:8, 24bpp, RGBRGB...
    AV_PIX_FMT_BGR24,     ///< packed RGB 8:8:8, 24bpp, BGRBGR...
    AV_PIX_FMT_YUV422P,   ///< planar YUV 4:2:2, 16bpp, (1 Cr & Cb sample per 2x1 Y samples)
    AV_PIX_FMT_YUV444P,   ///< planar YUV 4:4:4, 24bpp, (1 Cr & Cb sample per 1x1 Y samples)
    AV_PIX_FMT_YUV410P,   ///< planar YUV 4:1:0,  9bpp, (1 Cr & Cb sample per 4x4 Y samples)
    AV_PIX_FMT_YUV411P,   ///< planar YUV 4:1:1, 12bpp, (1 Cr & Cb sample per 4x1 Y samples)
    AV_PIX_FMT_GRAY8,     ///<        Y        ,  8bpp
    AV_PIX_FMT_MONOWHITE, ///<        Y        ,  1bpp, 0 is white, 1 is black, in each byte pixels are ordered from the msb to the lsb
    AV_PIX_FMT_MONOBLACK, ///<        Y        ,  1bpp, 0 is black, 1 is white, in each byte pixels are ordered from the msb to the lsb
    AV_PIX_FMT_PAL8,      ///< 8 bit with PIX_FMT_RGB32 palette
    AV_PIX_FMT_YUVJ420P,  ///< planar YUV 4:2:0, 12bpp, full scale (JPEG), deprecated in favor of PIX_FMT_YUV420P and setting color_range
    AV_PIX_FMT_YUVJ422P,  ///< planar YUV 4:2:2, 16bpp, full scale (JPEG), deprecated in favor of PIX_FMT_YUV422P and setting color_range
    AV_PIX_FMT_YUVJ444P,  ///< planar YUV 4:4:4, 24bpp, full scale (JPEG), deprecated in favor of PIX_FMT_YUV444P and setting color_range
    AV_PIX_FMT_XVMC_MPEG2_MC,///< XVideo Motion Acceleration via common packet passing
    AV_PIX_FMT_XVMC_MPEG2_IDCT,
    ...(代码太长,略)
}

4.const enum AVSampleFormat *sample_fmts

enum AVSampleFormat {
    AV_SAMPLE_FMT_NONE = -1,
    AV_SAMPLE_FMT_U8,          ///< unsigned 8 bits
    AV_SAMPLE_FMT_S16,         ///< signed 16 bits
    AV_SAMPLE_FMT_S32,         ///< signed 32 bits
    AV_SAMPLE_FMT_FLT,         ///< float
    AV_SAMPLE_FMT_DBL,         ///< double
 
    AV_SAMPLE_FMT_U8P,         ///< unsigned 8 bits, planar
    AV_SAMPLE_FMT_S16P,        ///< signed 16 bits, planar
    AV_SAMPLE_FMT_S32P,        ///< signed 32 bits, planar
    AV_SAMPLE_FMT_FLTP,        ///< float, planar
    AV_SAMPLE_FMT_DBLP,        ///< double, planar
 
    AV_SAMPLE_FMT_NB           ///< Number of sample formats. DO NOT USE if linking dynamically
};

每一个编解码器对应一个该结构体,查看一下ffmpeg的源代码,我们可以看一下H.264解码器的结构体如下所示(h264.c):

AVCodec ff_h264_decoder = {
    .name           = "h264",
    .type           = AVMEDIA_TYPE_VIDEO,
    .id             = CODEC_ID_H264,
    .priv_data_size = sizeof(H264Context),
    .init           = ff_h264_decode_init,
    .close          = ff_h264_decode_end,
    .decode         = decode_frame,
    .capabilities   = /*CODEC_CAP_DRAW_HORIZ_BAND |*/ CODEC_CAP_DR1 | CODEC_CAP_DELAY |
                      CODEC_CAP_SLICE_THREADS | CODEC_CAP_FRAME_THREADS,
    .flush= flush_dpb,
    .long_name = NULL_IF_CONFIG_SMALL("H.264 / AVC / MPEG-4 AVC / MPEG-4 part 10"),
    .init_thread_copy      = ONLY_IF_THREADS_ENABLED(decode_init_thread_copy),
    .update_thread_context = ONLY_IF_THREADS_ENABLED(decode_update_thread_context),
    .profiles = NULL_IF_CONFIG_SMALL(profiles),
    .priv_class     = &h264_class,
};

下面简单介绍一下遍历ffmpeg中的解码器信息的方法(这些解码器以一个链表的形式存储):
1.注册所有编解码器:av_register_all();

2.声明一个AVCodec类型的指针,比如说AVCodec* first_c;

3.调用av_codec_next()函数,即可获得指向链表下一个解码器的指针,循环往复可以获得所有解码器的信息。注意,如果想要获得指向第一个解码器的指针,则需要将该函数的参数设置为NULL。
————————————————

                            版权声明:本文为博主原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接和本声明。
                        
原文链接:https://blog.csdn.net/leixiaohua1020/article/details/14215833

AVCodec 中的 AVClass 中debug 数据:

    const AVClass *priv_class = avcodec->priv_class;

AVClass 中的 AVOption 中的关键数据

下面简单解释一下AVOption的几个成员变量:

name:名称。
help:简短的帮助。
offset:选项相对结构体首部地址的偏移量(这个很重要)。
type:选项的类型。
default_val:选项的默认值。
min:选项的最小值。
max:选项的最大值。
flags:一些标记。
unit:该选项所属的逻辑单元,可以为空。

其中,default_val是一个union类型的变量,可以根据选项数据类型的不同,取int,double,char*,AVRational(表示分数)几种类型。type是一个AVOptionType类型的变量。AVOptionType是一个枚举类型.

  AVClass中存储了AVOption类型的数组option,用于存储选项信息。AVClass有一个特点就是它必须位于其支持的结构体的第一个位置。例如,AVFormatContext和AVCodecContext都支持AVClass,观察它们结构体的定义可以发现他们结构体的第一个变量都是AVClass。截取一小段AVFormatContext的定义的开头部分,如下所示。

参考如下的

FFmpeg源代码简单分析:结构体成员管理系统-AVClass_ffmepg avclass-CSDN博客

自己打印的 AVCodec的各种数据:

void printfAVCodec(const AVCodec *avcodec){
    if(avcodec==nullptr){
        cout<<"printfAVCodec error avcodec==nullptr"<<endl;
        return ;
    }
    cout << "avcodec->name = " << avcodec->name << endl;
    cout << "avcodec->long_name = " << avcodec->long_name << endl;

    //该编解码器的 类型,enum AVMediaType type; 类似 AVMEDIA_TYPE_VIDEO,AVMEDIA_TYPE_AUDIO
    cout << "avcodec->type = " << avcodec->type << endl;

    //enum AVCodecID id; 类似 AV_CODEC_ID_AAC,AV_CODEC_ID_H264 , AAC 对应的值是十进制是86018,十六进制是15002
    cout << "avcodec->id = " << avcodec->id << endl;


    /**
     * Codec capabilities.
     * see AV_CODEC_CAP_*
     * int capabilities;
     * AAC 作为 encoder 的值是98,对应的二进制是 0110 0010,对应的如下的三个值 或 起来
     *      #define AV_CODEC_CAP_DR1                 (1 <<  1)
            #define AV_CODEC_CAP_DELAY               (1 <<  5)
            #define AV_CODEC_CAP_SMALL_LAST_FRAME    (1 <<  6)
     */
    cout << "avcodec->capabilities = " << avcodec->capabilities << endl;

    ///< maximum value for lowres supported by the decoder
    /// 视频专用 解码器支持的低分辨率的最大值
    // uint8_t max_lowres;
    cout << "avcodec->max_lowres = " << avcodec->max_lowres << endl;



    ///< array of supported framerates, or NULL if any, array is terminated by {0,0}
    ///const AVRational *supported_framerates;
    ///支持的帧率(仅视频), 类似 每秒25张图片
    if(avcodec->supported_framerates == nullptr){
        cout<<"avcodec->supported_framerates = nullptr"<<endl;
    } else {
        cout<<"avcodec->supported_framerates != nullptr"<<endl;
        const AVRational * avr = avcodec->supported_framerates;
        int i =0;
        while(1){
            if(avr[i].den ==0 && avr[i].num == 0){
                break;
            }
            cout<<"avr["<<i <<"].den = "<< avr[i].den << " avr[" << i << "].num = " << avr[i].num << endl;
            ++i;
        }
    }


    ///< array of supported pixel formats, or NULL if unknown, array is terminated by -1
    ///const enum AVPixelFormat *pix_fmts;
    /// 支持的像素格式(仅视频),类似 AV_PIX_FMT_YUV420P
    if(avcodec->pix_fmts == nullptr){
        cout<<"avcodec->pix_fmts = nullptr"<<endl;
    }else{
        cout<<"avcodec->pix_fmts != nullptr"<<endl;
        const enum AVPixelFormat * avpixelformat = avcodec->pix_fmts;
        int i =0;
        while(1){
            if(avpixelformat[i] == -1){
                break;
            }else{
                cout<<"avpixelformat["<<i<<"] = avpixelformat[i] " <<endl;
                ++i;
            }
        }
    }



    ///< array of supported audio samplerates, or NULL if unknown, array is terminated by 0
    ///     const int *supported_samplerates;
    /// 支持的采样率(仅音频)41000,48000
    if(avcodec->supported_samplerates == nullptr){
        cout<<"avcodec->supported_samplerates = nullptr"<<endl;
    }else{
        cout<<"avcodec->supported_samplerates != nullptr"<<endl;
        const int  * support_samplerates = avcodec->supported_samplerates;
        int i =0;
        while(1){
            if(support_samplerates[i] == 0){
                break;
            }else{
                cout<<"support_samplerates["<<i<<"] = " << support_samplerates[i]<<endl;
                ++i;
            }
        }
    }


    ///支持的采样格式(仅音频),类似 AV_SAMPLE_FMT_S16,FFMpeg 自带的AAC 只支持  AV_SAMPLE_FMT_FLTP,对应的十进制的值是8
    ///< array of supported sample formats, or NULL if unknown, array is terminated by -1
    ///     const enum AVSampleFormat *sample_fmts;

    if(avcodec->sample_fmts == nullptr){
        cout<<"avcodec->sample_fmts = nullptr"<<endl;
    }else{
        cout<<"avcodec->sample_fmts != nullptr"<<endl;
        const enum AVSampleFormat *sample_fmts = avcodec->sample_fmts;
        int i =0;
        while(1){
            if(sample_fmts[i] == -1){
                break;
            }else{
                cout<<"sample_fmts["<<i<<"] = " << sample_fmts[i]<<endl;
                ++i;
            }
        }
    }



    //#if FF_API_OLD_CHANNEL_LAYOUT
    //    /**
    //     * @deprecated use ch_layouts instead
    //     */
    //    attribute_deprecated
    //    const uint64_t *channel_layouts;         ///< array of support channel layouts, or NULL if unknown. array is terminated by 0
    //#endif

    //该编码器支持的声道数量。已经不再使用。可以使用 const AVChannelLayout *ch_layouts; 替代
    const uint64_t *channel_layouts = avcodec->channel_layouts;

    if(channel_layouts == nullptr){
        cout<<"channel_layouts =  nullptr"<<endl; //在ffmepg 6.0的时候,使用编码器ffmpeg自带的AAC,这块为nullptr。这不合理。这里baidu了一下,发现 如下的说法:    // 不是每个codec都给出支持的channel_layout
    }else{
        cout<<"channel_layouts !=  nullptr"<<endl;
        int i = 0;
        while(1){
            if(channel_layouts[i] == 0){
                break;
            }
            cout<<"channel_layouts[<<" << i << "] = " << channel_layouts[i] << endl;
            ++i;
        }
    }

    ///这里为了方便测试 ,将已经废弃的const uint64_t *channel_layouts; 和 const AVChannelLayout *ch_layouts;对比
    /**
     * Array of supported channel layouts, terminated with a zeroed layout.
     */
    ///const AVChannelLayout *ch_layouts;
    const AVChannelLayout *ch_layouts = avcodec->ch_layouts;
    if(ch_layouts == nullptr){
        cout<<"ch_layouts =  nullptr"<<endl; //在ffmepg 6.0的时候,使用编码器ffmpeg自带的AAC,这块为nullptr。这不合理。  baidu说明如下:  // 不是每个codec都给出支持的channel_layout

    }else{
        cout<<"ch_layouts !=  nullptr"<<endl;
        int i = 0;
        while(1){
            if(ch_layouts[i].nb_channels == 0 ){
                break;
            }
            cout<<"
音视频开发实战路径:Linux内核、C++流水线与FFmpeg源码深度解析 音视频开发本质上是面向实时性、高吞吐与跨平台稳定性的系统工程,其核心不在语法或命令行工具,而在于Linux内核机制(如mmap内存映射、SCHED_FIFO实时调度、sendfile零拷贝)、C++资源生命周期管理(RAII/无锁队列/ABI兼容)与FFmpeg底层原理(Demuxing/NALU解析、推送-拉取编解码模型)的深度融合。掌握这些能力,才能应对教育直播低延迟推流、车载DVR私有协议适配、WebRTC弱网拥塞控制等真实场景。本文聚焦音视频开发者必须直面的Linux系统级细节与C++工程实践,覆盖 阅读详情

相关推荐

FFmpeg C++开发指南:从安装到核心架构与实战转码

音视频处理是现代软件开发中的一项基础且关键的技术,其核心在于对多媒体数据进行高效的编解码、封装与处理。理解音视频编解码原理、掌握容器格式与数据流模型,是构建流媒体应用、视频编辑工具等多媒体系统的技术基石。FFmpeg作为一套功能强大的开源多媒体框架,集成了libavcodec、libavformat等核心库,为开发者提供了从底层编解码到高层滤镜处理的全套解决方案,其价值在于能够统一处理复杂的音视频格式转换与流媒体协议。在C++工程实践中,开发者常面临跨平台编译、内存管理以及性能优化等挑战。本文聚焦于FFmp

weixin_30247781的博客 357

FFmpeg学习 avcodec软解码函数分析

前言 本文分析ffmpeg软解码流程,相关函数如下,以find_stream_info中的try_decode_frame为例; 相关函数都在libavcodec包下。 const AVCodec *codec = find_probe_decoder(s, st, st->codecpar->codec_id); /* * Force thread count to 1 since the H.264 decoder will not extract * SPS and PPS to ex

baiiu 1670

FFmpeg实战:如何用C++将PCM音频高效转码为MP3(附完整代码)

本文详细介绍了如何利用FFmpeg和C++实现PCM音频到MP3的高效转码,包括环境配置、编码原理、核心代码实现及性能优化技巧。通过完整的代码示例和实战指南,帮助开发者快速掌握音视频开发中的关键技术,提升音频处理效率。

weixin_29009669的博客 174

FFmpeg】通过编解码ID(AV_CODEC_ID_*)获取编解码器AVCodec指针的过程分析

一、简述 在使用FFmpeg编程时,通过编解码ID(AV_CODEC_ID_*)即可获取对应编解码器AVCodec指针,例如: AVCodec *codec = avcodec_find_encoder(AV_CODEC_ID_H264); 下面以libx264为例,分析源码,探索编解码器从注册、获取到使用的过程。 二、注册 1、说明 在旧版本中,需要使用 avcodec_register_all 来注册所有编解码器 #if LIBAVCODEC_VERSION_INT < AV_VERSION_I

郭老二 3533

ffmpegAVCodecContextAVCodec的关系分析

AVCodecFFmpeg库中两个相关的结构体,它们在音视频编解码中扮演着不同的角色。:是编解码器上下文结构体,用于存储音视频编解码器的参数和状态信息。它包含了进行音视频编解码所需的,如编码器类型、编码参数、解码参数、输入输出格式等。每个音视频流在编解码过程中都需要一个对应的来。在解码过程中,用于接收解码后的音视频数据。在编码过程中,用于传递待编码的音视频数据。AVCodec:是音视频编解码器结构体,用于定义特定的编解码器。它包含了编解码器的类型、名称、支持的音视频格式、编解码函数等。通过。

天之彼方的博客 1337

FFmpeg结构体分析: AVCodecContext编解码器上下文

AVCodecContextFFmpeg编解码上下文的结构体,而AVCodec是编解码参数的结构体。AVCodecContex内部有包含AVCodecAVCodecInternal、AVRational等结构体,包含AVCodecID、AVMediaType、AVPixelFormat、AVSampleForat等枚举类型,包含视频的width、height、framerate、bitrate等关键参数,包含音频的samplerate、channels等参数。

Lce的专栏 2987

Android音视频开发FFmpeg集成与JNI调用实战指南

音视频编解码是多媒体应用开发的核心技术,它涉及将原始音视频数据转换为特定格式进行存储或传输。其原理基于编码算法对数据进行压缩,解码则进行还原。在移动开发领域,Android系统虽然提供了MediaCodec等硬件加速方案,但在处理非标准格式、复杂滤镜或需要跨平台一致性的场景时,原生API往往能力有限。此时,集成功能强大的开源库成为关键解决方案,能够为应用带来专业级的处理能力和广泛的格式兼容性。FFmpeg作为业界公认的“瑞士军刀”,通过其libavcodec、libavformat等核心库,为开发者提供了从

weixin_34038293的博客 463

音视频开发实战路径:C++/Linux/FFmpeg/WebRTC四阶能力闭环

音视频开发是融合操作系统、网络协议、编解码与实时传输的复合型工程能力。其核心原理在于零拷贝内存管理、内核级IO调度、标准音视频数据结构建模,以及可定制化实时传输协议栈。技术价值体现在低延迟、高并发、硬件协同与跨平台稳定性,广泛应用于直播推流、远程协作、智能终端多媒体处理等场景。本文聚焦真实项目验证的进阶路径,以C++为底层语言基础,Linux为运行环境核心,FFmpeg音视频数据解析与处理标准接口,WebRTC为实时交互协议骨架,构建从裸流解析到端到端文件秒传的完整能力闭环。

weixin_30500473的博客 342

音视频demo

ffmpeg-demo · 核心数据结构:AVPacket 的分配、引用、释放管理。 · 拆包与封装:MP4/FLV 中提取 AAC/H.264,以及反向合成 MP4/FLV。 · 解码:音视频包 → 解码 → 输出 PCM/YUV。 · 编码:原始 PCM/YUV → 重采样/格式转换 → 编码输出 AAC/H.264/H.265。 · 硬件加速:NVENC 编码、DXVA2 解码。 · 高级功能:自定义 IO、音频混音、音视频分离存储。 sdl

mix39的博客 1236

Android音视频开发进阶:FFmpeg集成与实战指南

音视频处理是移动应用开发中的核心技术领域,其核心在于对多媒体数据的编解码、封装与处理。FFmpeg作为业界公认的开源音视频处理框架,提供了跨平台的完整解决方案,能够突破Android原生媒体API在格式支持、处理效率与跨平台兼容性方面的局限。通过集成FFmpeg开发者可以实现专业级的视频编辑、格式转换、流媒体处理等高级功能,为应用带来强大的媒体处理能力。本文聚焦于Android平台,详细解析FFmpeg的交叉编译、NDK配置与JNI调用的完整流程,并通过实战演示如何构建一个视频信息提取的Demo应用,帮助

weixin_30535843的博客 361

ffmpeg 重要数据结构接口及分析

一、重要的数据结构及函数列表 I. 数据结构: (1) AVFormatContext (2) AVOutputFormat (3) AVInputFormat (4) AVCodecContext (5) AVCodec (6) AVFrame (7) AVPacket (8) AVPicture (9) AVStream II. 初始化函数: 1. av_regis

零凌灵的专栏 1340

FFMPEG 编程

1. Log #define _CRT_SECURE_NO_WARNINGS extern "C" { #include <libavformat/avformat.h> } int main() { av_log_set_level(AV_LOG_INFO); av_log(NULL, AV_LOG_PANIC, "1.Hello FFMPEG!\n"); av_log(NULL, AV_LOG_FATAL, "2.Hello FFMPEG!\n"); av_log(NULL,

nuptxiaoli 1876

轻量级音视频引擎uclAV:嵌入式场景下替代FFmpeg的实战解析

在嵌入式开发中,音视频处理常面临内存紧张、CPU算力有限、实时性要求高的挑战。通用工具如FFmpeg功能强大,但庞大的体积和较高的资源占用往往不适合资源受限的边缘设备。本文从音视频处理的基本概念出发,解析如何通过模块化裁剪、零拷贝流水线、帧池复用和精简线程模型,构建一套静态体积小于2MB、常驻内存约40MB、端到端延迟低于30ms的轻量级引擎。方案覆盖解码器选型、容器层精简、内存优化、音视频同步及跳帧策略等工程实践,并给出全志V3s、RK3288、RK3588等平台的实测数据。无论是做边缘计算盒子还是智能巡

weixin_33829657的博客 341

iOS学习----------详解FFMPEG API

转载地址:http://3xin2yi.info/wwwroot/tech/doku.php/tech:multimedia:ffmpeg 认识FFmpeg FFMPEG堪称自由软件中最完备的一套多媒体支持库,它几乎实现了所有当下常见的数据封装格式、多媒体传输协议以及音视频编解码器。因此,对于从事多媒体技术开发的工程师来说,深入研究FFMPEG成为一

yziOS的博客 3538

Linux C/C++进阶:从系统编程到AI与音视频实战

系统编程是高性能软件开发的基石,它涉及进程管理、内存分配和I/O操作等核心概念。其原理在于程序通过系统调用与操作系统内核交互,实现对底层硬件资源的安全高效利用。掌握系统编程的技术价值在于能够构建稳定、高性能的服务,例如支撑高并发的网络服务器或低延迟的实时系统。在AI基础设施和音视频处理等热门应用场景中,这些能力尤为关键。本文聚焦于**Linux系统编程**和**高性能网络编程**,通过解析Unix Domain Socket、epoll I/O多路复用等机制,并结合现代C++网络库与FFmpeg实战,为开发

weixin_34146805的博客 438

ffmpeg 编解码

直接上FFmepg 源码 源码注释已经很清楚了,再次我就不废话了。 /**  * @file  * libavcodec API use example.  *  * Note that libavcodec only handles codecs (mpeg, mpeg4, etc...),  * not file formats (avi, vob, mp4, mov, mkv,

白话技术 1413

详解FFMPEG API

转自:http://3xin2yi.info/wwwroot/tech/doku.php/tech:multimedia:ffmpeg http://www.360doc.com/content/12/0613/13/474846_217882148.shtml 认识FFmpeg FFMPEG堪称自由软件中最完备的一套多媒体支持库,它几乎实现了所有当下常见

mengzhengjie的专栏 1130

FFMPEG录屏软件开发之编码AAC

之前讲到了使用ffmpeg读取麦克风并保存成PCM文件。传送门 获取到了PCM之后,下一步当然是编码生成AAC了。 与之前说过的YUV是视频的原始数据类似,PCM是音频的原始数据,因此它的大小也相对比较大,因此就有必要将PCM数据编码。 同样,音频的编码方式也有很多种,常见如MP3,AAC。我们以后使用比较多的就是AAC,因此本文只讲解将pcm编码成AAC。

有志者事竟成 900
上一篇: 音视频开发17 FFmpeg 音频解码- 将 aac 解码成 pcm
下一篇: 音视频开发19 FFmpeg 视频解码- 将 h264 转化成 yuv
hunandede
博客等级 码龄19年 2450粉丝 403原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值