当前位置: 首页 > news >正文

FFmpeg 4.3 音视频-多路H265监控录放C++开发十三:将AVFrame转换成AVPacket。视频编码原理.编码相关api,H264特殊参数说明

前提:

从前面的学习我们知道 AVFrame中是最原始的 视频数据,这一节开始我们需要将这个最原始的视频数据 压缩成 AVPacket数据,

我们前面,将YUV数据或者 RGBA 数据装进入了 AVFrame里面,并且在SDL中显示。

也就是说:对于安防项目来说,我们将原始从摄像头数据(YUV,RGB)转换成 AVFrame后,可以直接显示出来。但是如果我们将要数据存储,则要将 AVFrame转成  AVPacket.

视频编码 以及原理

从摄像头得到原始数据 ---- > 像素格式转换---->编码 ------>封装

编码的原因很好理解,YUV数据太大了,我们要编码成 h264,h265 等较小的格式

背后的原理是这样,一个YUV视频是由一张一张YUV图片组成的。

帧内压缩:

我们将一张YUV图片,假设是 1280x728大小的,我们将其划分成16x16的大小,总有一些像素点是一样的,或者接近的,例如下图:

帧间压缩:

假设上述图片是YUV 的第一张图片,第二帧图片是师爷 在讲话,那么第二帧图片可能只是嘴巴变化了一下,那么我们参考第一张图片,去存储第二张图片,就只用存储第二章图片 和 第一张图片不同的地方就好。。在还原的时候,参考第一张图片和差异,通过算法还原,这就叫做帧间压缩

我们这一节将 AVFrame转成 AVPacket,实际上就是编码的过程,

AVPacket 重要函数以及重要结构体成员

FFmpeg存放压缩后的音视频数据的结构体:AVPacket简介,结构体,函数-CSDN博客

从avframe 变成 avpacket 也就是编码,编码相关API

1.查找编码器

/**
 * Find a registered encoder with a matching codec ID.
 *
 * @param id AVCodecID of the requested encoder
 * @return An encoder if one was found, NULL otherwise.
 */


const AVCodec *avcodec_find_encoder(enum AVCodecID id);

如果参数 是 AVCodecID ,那么对应的值如下,重要的为    

AV_CODEC_ID_H264, 

#define AV_CODEC_ID_H265 AV_CODEC_ID_HEVC

enum AVCodecID {AV_CODEC_ID_NONE,/* video codecs */AV_CODEC_ID_MPEG1VIDEO,AV_CODEC_ID_MPEG2VIDEO, ///< preferred ID for MPEG-1/2 video decodingAV_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,AV_CODEC_ID_INDEO3,AV_CODEC_ID_VP3,AV_CODEC_ID_THEORA,AV_CODEC_ID_ASV1,AV_CODEC_ID_ASV2,AV_CODEC_ID_FFV1,AV_CODEC_ID_4XM,AV_CODEC_ID_VCR1,AV_CODEC_ID_CLJR,AV_CODEC_ID_MDEC,AV_CODEC_ID_ROQ,AV_CODEC_ID_INTERPLAY_VIDEO,AV_CODEC_ID_XAN_WC3,AV_CODEC_ID_XAN_WC4,AV_CODEC_ID_RPZA,AV_CODEC_ID_CINEPAK,AV_CODEC_ID_WS_VQA,AV_CODEC_ID_MSRLE,AV_CODEC_ID_MSVIDEO1,AV_CODEC_ID_IDCIN,AV_CODEC_ID_8BPS,AV_CODEC_ID_SMC,AV_CODEC_ID_FLIC,AV_CODEC_ID_TRUEMOTION1,AV_CODEC_ID_VMDVIDEO,AV_CODEC_ID_MSZH,AV_CODEC_ID_ZLIB,AV_CODEC_ID_QTRLE,AV_CODEC_ID_TSCC,AV_CODEC_ID_ULTI,AV_CODEC_ID_QDRAW,AV_CODEC_ID_VIXL,AV_CODEC_ID_QPEG,AV_CODEC_ID_PNG,AV_CODEC_ID_PPM,AV_CODEC_ID_PBM,AV_CODEC_ID_PGM,AV_CODEC_ID_PGMYUV,AV_CODEC_ID_PAM,AV_CODEC_ID_FFVHUFF,AV_CODEC_ID_RV30,AV_CODEC_ID_RV40,AV_CODEC_ID_VC1,AV_CODEC_ID_WMV3,AV_CODEC_ID_LOCO,AV_CODEC_ID_WNV1,AV_CODEC_ID_AASC,AV_CODEC_ID_INDEO2,AV_CODEC_ID_FRAPS,AV_CODEC_ID_TRUEMOTION2,AV_CODEC_ID_BMP,AV_CODEC_ID_CSCD,AV_CODEC_ID_MMVIDEO,AV_CODEC_ID_ZMBV,AV_CODEC_ID_AVS,AV_CODEC_ID_SMACKVIDEO,AV_CODEC_ID_NUV,AV_CODEC_ID_KMVC,AV_CODEC_ID_FLASHSV,AV_CODEC_ID_CAVS,AV_CODEC_ID_JPEG2000,AV_CODEC_ID_VMNC,AV_CODEC_ID_VP5,AV_CODEC_ID_VP6,AV_CODEC_ID_VP6F,AV_CODEC_ID_TARGA,AV_CODEC_ID_DSICINVIDEO,AV_CODEC_ID_TIERTEXSEQVIDEO,AV_CODEC_ID_TIFF,AV_CODEC_ID_GIF,AV_CODEC_ID_DXA,AV_CODEC_ID_DNXHD,AV_CODEC_ID_THP,AV_CODEC_ID_SGI,AV_CODEC_ID_C93,AV_CODEC_ID_BETHSOFTVID,AV_CODEC_ID_PTX,AV_CODEC_ID_TXD,AV_CODEC_ID_VP6A,AV_CODEC_ID_AMV,AV_CODEC_ID_VB,AV_CODEC_ID_PCX,AV_CODEC_ID_SUNRAST,AV_CODEC_ID_INDEO4,AV_CODEC_ID_INDEO5,AV_CODEC_ID_MIMIC,AV_CODEC_ID_RL2,AV_CODEC_ID_ESCAPE124,AV_CODEC_ID_DIRAC,AV_CODEC_ID_BFI,AV_CODEC_ID_CMV,AV_CODEC_ID_MOTIONPIXELS,AV_CODEC_ID_TGV,AV_CODEC_ID_TGQ,AV_CODEC_ID_TQI,AV_CODEC_ID_AURA,AV_CODEC_ID_AURA2,AV_CODEC_ID_V210X,AV_CODEC_ID_TMV,AV_CODEC_ID_V210,AV_CODEC_ID_DPX,AV_CODEC_ID_MAD,AV_CODEC_ID_FRWU,AV_CODEC_ID_FLASHSV2,AV_CODEC_ID_CDGRAPHICS,AV_CODEC_ID_R210,AV_CODEC_ID_ANM,AV_CODEC_ID_BINKVIDEO,AV_CODEC_ID_IFF_ILBM,
#define AV_CODEC_ID_IFF_BYTERUN1 AV_CODEC_ID_IFF_ILBMAV_CODEC_ID_KGV1,AV_CODEC_ID_YOP,AV_CODEC_ID_VP8,AV_CODEC_ID_PICTOR,AV_CODEC_ID_ANSI,AV_CODEC_ID_A64_MULTI,AV_CODEC_ID_A64_MULTI5,AV_CODEC_ID_R10K,AV_CODEC_ID_MXPEG,AV_CODEC_ID_LAGARITH,AV_CODEC_ID_PRORES,AV_CODEC_ID_JV,AV_CODEC_ID_DFA,AV_CODEC_ID_WMV3IMAGE,AV_CODEC_ID_VC1IMAGE,AV_CODEC_ID_UTVIDEO,AV_CODEC_ID_BMV_VIDEO,AV_CODEC_ID_VBLE,AV_CODEC_ID_DXTORY,AV_CODEC_ID_V410,AV_CODEC_ID_XWD,AV_CODEC_ID_CDXL,AV_CODEC_ID_XBM,AV_CODEC_ID_ZEROCODEC,AV_CODEC_ID_MSS1,AV_CODEC_ID_MSA1,AV_CODEC_ID_TSCC2,AV_CODEC_ID_MTS2,AV_CODEC_ID_CLLC,AV_CODEC_ID_MSS2,AV_CODEC_ID_VP9,AV_CODEC_ID_AIC,AV_CODEC_ID_ESCAPE130,AV_CODEC_ID_G2M,AV_CODEC_ID_WEBP,AV_CODEC_ID_HNM4_VIDEO,AV_CODEC_ID_HEVC,
#define AV_CODEC_ID_H265 AV_CODEC_ID_HEVCAV_CODEC_ID_FIC,AV_CODEC_ID_ALIAS_PIX,AV_CODEC_ID_BRENDER_PIX,AV_CODEC_ID_PAF_VIDEO,AV_CODEC_ID_EXR,AV_CODEC_ID_VP7,AV_CODEC_ID_SANM,AV_CODEC_ID_SGIRLE,AV_CODEC_ID_MVC1,AV_CODEC_ID_MVC2,AV_CODEC_ID_HQX,AV_CODEC_ID_TDSC,AV_CODEC_ID_HQ_HQA,AV_CODEC_ID_HAP,AV_CODEC_ID_DDS,AV_CODEC_ID_DXV,AV_CODEC_ID_SCREENPRESSO,AV_CODEC_ID_RSCC,AV_CODEC_ID_AVS2,AV_CODEC_ID_Y41P = 0x8000,AV_CODEC_ID_AVRP,AV_CODEC_ID_012V,AV_CODEC_ID_AVUI,AV_CODEC_ID_AYUV,AV_CODEC_ID_TARGA_Y216,AV_CODEC_ID_V308,AV_CODEC_ID_V408,AV_CODEC_ID_YUV4,AV_CODEC_ID_AVRN,AV_CODEC_ID_CPIA,AV_CODEC_ID_XFACE,AV_CODEC_ID_SNOW,AV_CODEC_ID_SMVJPEG,AV_CODEC_ID_APNG,AV_CODEC_ID_DAALA,AV_CODEC_ID_CFHD,AV_CODEC_ID_TRUEMOTION2RT,AV_CODEC_ID_M101,AV_CODEC_ID_MAGICYUV,AV_CODEC_ID_SHEERVIDEO,AV_CODEC_ID_YLC,AV_CODEC_ID_PSD,AV_CODEC_ID_PIXLET,AV_CODEC_ID_SPEEDHQ,AV_CODEC_ID_FMVC,AV_CODEC_ID_SCPR,AV_CODEC_ID_CLEARVIDEO,AV_CODEC_ID_XPM,AV_CODEC_ID_AV1,AV_CODEC_ID_BITPACKED,AV_CODEC_ID_MSCC,AV_CODEC_ID_SRGC,AV_CODEC_ID_SVG,AV_CODEC_ID_GDV,AV_CODEC_ID_FITS,AV_CODEC_ID_IMM4,AV_CODEC_ID_PROSUMER,AV_CODEC_ID_MWSC,AV_CODEC_ID_WCMV,AV_CODEC_ID_RASC,AV_CODEC_ID_HYMT,AV_CODEC_ID_ARBC,AV_CODEC_ID_AGM,AV_CODEC_ID_LSCR,AV_CODEC_ID_VP4,AV_CODEC_ID_IMM5,AV_CODEC_ID_MVDV,AV_CODEC_ID_MVHA,AV_CODEC_ID_CDTOONS,AV_CODEC_ID_MV30,AV_CODEC_ID_NOTCHLC,AV_CODEC_ID_PFM,/* various PCM "codecs" */AV_CODEC_ID_FIRST_AUDIO = 0x10000,     ///< A dummy id pointing at the start of audio codecsAV_CODEC_ID_PCM_S16LE = 0x10000,AV_CODEC_ID_PCM_S16BE,AV_CODEC_ID_PCM_U16LE,AV_CODEC_ID_PCM_U16BE,AV_CODEC_ID_PCM_S8,AV_CODEC_ID_PCM_U8,AV_CODEC_ID_PCM_MULAW,AV_CODEC_ID_PCM_ALAW,AV_CODEC_ID_PCM_S32LE,AV_CODEC_ID_PCM_S32BE,AV_CODEC_ID_PCM_U32LE,AV_CODEC_ID_PCM_U32BE,AV_CODEC_ID_PCM_S24LE,AV_CODEC_ID_PCM_S24BE,AV_CODEC_ID_PCM_U24LE,AV_CODEC_ID_PCM_U24BE,AV_CODEC_ID_PCM_S24DAUD,AV_CODEC_ID_PCM_ZORK,AV_CODEC_ID_PCM_S16LE_PLANAR,AV_CODEC_ID_PCM_DVD,AV_CODEC_ID_PCM_F32BE,AV_CODEC_ID_PCM_F32LE,AV_CODEC_ID_PCM_F64BE,AV_CODEC_ID_PCM_F64LE,AV_CODEC_ID_PCM_BLURAY,AV_CODEC_ID_PCM_LXF,AV_CODEC_ID_S302M,AV_CODEC_ID_PCM_S8_PLANAR,AV_CODEC_ID_PCM_S24LE_PLANAR,AV_CODEC_ID_PCM_S32LE_PLANAR,AV_CODEC_ID_PCM_S16BE_PLANAR,AV_CODEC_ID_PCM_S64LE = 0x10800,AV_CODEC_ID_PCM_S64BE,AV_CODEC_ID_PCM_F16LE,AV_CODEC_ID_PCM_F24LE,AV_CODEC_ID_PCM_VIDC,/* various ADPCM codecs */AV_CODEC_ID_ADPCM_IMA_QT = 0x11000,AV_CODEC_ID_ADPCM_IMA_WAV,AV_CODEC_ID_ADPCM_IMA_DK3,AV_CODEC_ID_ADPCM_IMA_DK4,AV_CODEC_ID_ADPCM_IMA_WS,AV_CODEC_ID_ADPCM_IMA_SMJPEG,AV_CODEC_ID_ADPCM_MS,AV_CODEC_ID_ADPCM_4XM,AV_CODEC_ID_ADPCM_XA,AV_CODEC_ID_ADPCM_ADX,AV_CODEC_ID_ADPCM_EA,AV_CODEC_ID_ADPCM_G726,AV_CODEC_ID_ADPCM_CT,AV_CODEC_ID_ADPCM_SWF,AV_CODEC_ID_ADPCM_YAMAHA,AV_CODEC_ID_ADPCM_SBPRO_4,AV_CODEC_ID_ADPCM_SBPRO_3,AV_CODEC_ID_ADPCM_SBPRO_2,AV_CODEC_ID_ADPCM_THP,AV_CODEC_ID_ADPCM_IMA_AMV,AV_CODEC_ID_ADPCM_EA_R1,AV_CODEC_ID_ADPCM_EA_R3,AV_CODEC_ID_ADPCM_EA_R2,AV_CODEC_ID_ADPCM_IMA_EA_SEAD,AV_CODEC_ID_ADPCM_IMA_EA_EACS,AV_CODEC_ID_ADPCM_EA_XAS,AV_CODEC_ID_ADPCM_EA_MAXIS_XA,AV_CODEC_ID_ADPCM_IMA_ISS,AV_CODEC_ID_ADPCM_G722,AV_CODEC_ID_ADPCM_IMA_APC,AV_CODEC_ID_ADPCM_VIMA,AV_CODEC_ID_ADPCM_AFC = 0x11800,AV_CODEC_ID_ADPCM_IMA_OKI,AV_CODEC_ID_ADPCM_DTK,AV_CODEC_ID_ADPCM_IMA_RAD,AV_CODEC_ID_ADPCM_G726LE,AV_CODEC_ID_ADPCM_THP_LE,AV_CODEC_ID_ADPCM_PSX,AV_CODEC_ID_ADPCM_AICA,AV_CODEC_ID_ADPCM_IMA_DAT4,AV_CODEC_ID_ADPCM_MTAF,AV_CODEC_ID_ADPCM_AGM,AV_CODEC_ID_ADPCM_ARGO,AV_CODEC_ID_ADPCM_IMA_SSI,AV_CODEC_ID_ADPCM_ZORK,AV_CODEC_ID_ADPCM_IMA_APM,AV_CODEC_ID_ADPCM_IMA_ALP,AV_CODEC_ID_ADPCM_IMA_MTF,AV_CODEC_ID_ADPCM_IMA_CUNNING,/* AMR */AV_CODEC_ID_AMR_NB = 0x12000,AV_CODEC_ID_AMR_WB,/* RealAudio codecs*/AV_CODEC_ID_RA_144 = 0x13000,AV_CODEC_ID_RA_288,/* various DPCM codecs */AV_CODEC_ID_ROQ_DPCM = 0x14000,AV_CODEC_ID_INTERPLAY_DPCM,AV_CODEC_ID_XAN_DPCM,AV_CODEC_ID_SOL_DPCM,AV_CODEC_ID_SDX2_DPCM = 0x14800,AV_CODEC_ID_GREMLIN_DPCM,AV_CODEC_ID_DERF_DPCM,/* audio codecs */AV_CODEC_ID_MP2 = 0x15000,AV_CODEC_ID_MP3, ///< preferred ID for decoding MPEG audio layer 1, 2 or 3AV_CODEC_ID_AAC,AV_CODEC_ID_AC3,AV_CODEC_ID_DTS,AV_CODEC_ID_VORBIS,AV_CODEC_ID_DVAUDIO,AV_CODEC_ID_WMAV1,AV_CODEC_ID_WMAV2,AV_CODEC_ID_MACE3,AV_CODEC_ID_MACE6,AV_CODEC_ID_VMDAUDIO,AV_CODEC_ID_FLAC,AV_CODEC_ID_MP3ADU,AV_CODEC_ID_MP3ON4,AV_CODEC_ID_SHORTEN,AV_CODEC_ID_ALAC,AV_CODEC_ID_WESTWOOD_SND1,AV_CODEC_ID_GSM, ///< as in Berlin toast formatAV_CODEC_ID_QDM2,AV_CODEC_ID_COOK,AV_CODEC_ID_TRUESPEECH,AV_CODEC_ID_TTA,AV_CODEC_ID_SMACKAUDIO,AV_CODEC_ID_QCELP,AV_CODEC_ID_WAVPACK,AV_CODEC_ID_DSICINAUDIO,AV_CODEC_ID_IMC,AV_CODEC_ID_MUSEPACK7,AV_CODEC_ID_MLP,AV_CODEC_ID_GSM_MS, /* as found in WAV */AV_CODEC_ID_ATRAC3,AV_CODEC_ID_APE,AV_CODEC_ID_NELLYMOSER,AV_CODEC_ID_MUSEPACK8,AV_CODEC_ID_SPEEX,AV_CODEC_ID_WMAVOICE,AV_CODEC_ID_WMAPRO,AV_CODEC_ID_WMALOSSLESS,AV_CODEC_ID_ATRAC3P,AV_CODEC_ID_EAC3,AV_CODEC_ID_SIPR,AV_CODEC_ID_MP1,AV_CODEC_ID_TWINVQ,AV_CODEC_ID_TRUEHD,AV_CODEC_ID_MP4ALS,AV_CODEC_ID_ATRAC1,AV_CODEC_ID_BINKAUDIO_RDFT,AV_CODEC_ID_BINKAUDIO_DCT,AV_CODEC_ID_AAC_LATM,AV_CODEC_ID_QDMC,AV_CODEC_ID_CELT,AV_CODEC_ID_G723_1,AV_CODEC_ID_G729,AV_CODEC_ID_8SVX_EXP,AV_CODEC_ID_8SVX_FIB,AV_CODEC_ID_BMV_AUDIO,AV_CODEC_ID_RALF,AV_CODEC_ID_IAC,AV_CODEC_ID_ILBC,AV_CODEC_ID_OPUS,AV_CODEC_ID_COMFORT_NOISE,AV_CODEC_ID_TAK,AV_CODEC_ID_METASOUND,AV_CODEC_ID_PAF_AUDIO,AV_CODEC_ID_ON2AVC,AV_CODEC_ID_DSS_SP,AV_CODEC_ID_CODEC2,AV_CODEC_ID_FFWAVESYNTH = 0x15800,AV_CODEC_ID_SONIC,AV_CODEC_ID_SONIC_LS,AV_CODEC_ID_EVRC,AV_CODEC_ID_SMV,AV_CODEC_ID_DSD_LSBF,AV_CODEC_ID_DSD_MSBF,AV_CODEC_ID_DSD_LSBF_PLANAR,AV_CODEC_ID_DSD_MSBF_PLANAR,AV_CODEC_ID_4GV,AV_CODEC_ID_INTERPLAY_ACM,AV_CODEC_ID_XMA1,AV_CODEC_ID_XMA2,AV_CODEC_ID_DST,AV_CODEC_ID_ATRAC3AL,AV_CODEC_ID_ATRAC3PAL,AV_CODEC_ID_DOLBY_E,AV_CODEC_ID_APTX,AV_CODEC_ID_APTX_HD,AV_CODEC_ID_SBC,AV_CODEC_ID_ATRAC9,AV_CODEC_ID_HCOM,AV_CODEC_ID_ACELP_KELVIN,AV_CODEC_ID_MPEGH_3D_AUDIO,AV_CODEC_ID_SIREN,AV_CODEC_ID_HCA,/* subtitle codecs */AV_CODEC_ID_FIRST_SUBTITLE = 0x17000,          ///< A dummy ID pointing at the start of subtitle codecs.AV_CODEC_ID_DVD_SUBTITLE = 0x17000,AV_CODEC_ID_DVB_SUBTITLE,AV_CODEC_ID_TEXT,  ///< raw UTF-8 textAV_CODEC_ID_XSUB,AV_CODEC_ID_SSA,AV_CODEC_ID_MOV_TEXT,AV_CODEC_ID_HDMV_PGS_SUBTITLE,AV_CODEC_ID_DVB_TELETEXT,AV_CODEC_ID_SRT,AV_CODEC_ID_MICRODVD   = 0x17800,AV_CODEC_ID_EIA_608,AV_CODEC_ID_JACOSUB,AV_CODEC_ID_SAMI,AV_CODEC_ID_REALTEXT,AV_CODEC_ID_STL,AV_CODEC_ID_SUBVIEWER1,AV_CODEC_ID_SUBVIEWER,AV_CODEC_ID_SUBRIP,AV_CODEC_ID_WEBVTT,AV_CODEC_ID_MPL2,AV_CODEC_ID_VPLAYER,AV_CODEC_ID_PJS,AV_CODEC_ID_ASS,AV_CODEC_ID_HDMV_TEXT_SUBTITLE,AV_CODEC_ID_TTML,AV_CODEC_ID_ARIB_CAPTION,/* other specific kind of codecs (generally used for attachments) */AV_CODEC_ID_FIRST_UNKNOWN = 0x18000,           ///< A dummy ID pointing at the start of various fake codecs.AV_CODEC_ID_TTF = 0x18000,AV_CODEC_ID_SCTE_35, ///< Contain timestamp estimated through PCR of program stream.AV_CODEC_ID_EPG,AV_CODEC_ID_BINTEXT    = 0x18800,AV_CODEC_ID_XBIN,AV_CODEC_ID_IDF,AV_CODEC_ID_OTF,AV_CODEC_ID_SMPTE_KLV,AV_CODEC_ID_DVD_NAV,AV_CODEC_ID_TIMED_ID3,AV_CODEC_ID_BIN_DATA,AV_CODEC_ID_PROBE = 0x19000, ///< codec_id is not known (like AV_CODEC_ID_NONE) but lavf should attempt to identify itAV_CODEC_ID_MPEG2TS = 0x20000, /**< _FAKE_ codec to indicate a raw MPEG-2 TS* stream (only used by libavformat) */AV_CODEC_ID_MPEG4SYSTEMS = 0x20001, /**< _FAKE_ codec to indicate a MPEG-4 Systems* stream (only used by libavformat) */AV_CODEC_ID_FFMETADATA = 0x21000,   ///< Dummy codec for streams containing only metadata information.AV_CODEC_ID_WRAPPED_AVFRAME = 0x21001, ///< Passthrough codec, AVFrames wrapped in AVPacket
};

/**
 * Find a registered encoder with the specified name.
 *
 * @param name name of the requested encoder
 * @return An encoder if one was found, NULL otherwise.
 */
 


const AVCodec *avcodec_find_encoder_by_name(const char *name);


 

如果是通过字符查找对应的编码器/解码器,我们怎么知道这个字符是啥编码器呢?

libavcodec/allcodecs.c中开头定义了很多支编解码结构体;如:

可以查看具体的某一个,当然有些只是定义,ffmpeg并没有实现,如果要实现需要

/** Provide registration of all codecs, parsers and bitstream filters for libavcodec.* Copyright (c) 2002 Fabrice Bellard** This file is part of FFmpeg.** FFmpeg is free software; you can redistribute it and/or* modify it under the terms of the GNU Lesser General Public* License as published by the Free Software Foundation; either* version 2.1 of the License, or (at your option) any later version.** FFmpeg is distributed in the hope that it will be useful,* but WITHOUT ANY WARRANTY; without even the implied warranty of* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU* Lesser General Public License for more details.** You should have received a copy of the GNU Lesser General Public* License along with FFmpeg; if not, write to the Free Software* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA*//*** @file* Provide registration of all codecs, parsers and bitstream filters for libavcodec.*/#include <stdint.h>
#include <string.h>#include "config.h"
#include "config_components.h"
#include "libavutil/thread.h"
#include "codec.h"
#include "codec_id.h"
#include "codec_internal.h"extern const FFCodec ff_a64multi_encoder;
extern const FFCodec ff_a64multi5_encoder;
extern const FFCodec ff_aasc_decoder;
extern const FFCodec ff_aic_decoder;
extern const FFCodec ff_alias_pix_encoder;
extern const FFCodec ff_alias_pix_decoder;
extern const FFCodec ff_agm_decoder;
extern const FFCodec ff_amv_encoder;
extern const FFCodec ff_amv_decoder;
extern const FFCodec ff_anm_decoder;
extern const FFCodec ff_ansi_decoder;
extern const FFCodec ff_apng_encoder;
extern const FFCodec ff_apng_decoder;
extern const FFCodec ff_arbc_decoder;
extern const FFCodec ff_argo_decoder;
extern const FFCodec ff_asv1_encoder;
extern const FFCodec ff_asv1_decoder;
extern const FFCodec ff_asv2_encoder;
extern const FFCodec ff_asv2_decoder;
extern const FFCodec ff_aura_decoder;
extern const FFCodec ff_aura2_decoder;
extern const FFCodec ff_avrp_encoder;
extern const FFCodec ff_avrp_decoder;
extern const FFCodec ff_avrn_decoder;
extern const FFCodec ff_avs_decoder;
extern const FFCodec ff_avui_encoder;
extern const FFCodec ff_avui_decoder;
#if FF_API_AYUV_CODECID
extern const FFCodec ff_ayuv_encoder;
extern const FFCodec ff_ayuv_decoder;
#endif
extern const FFCodec ff_bethsoftvid_decoder;
extern const FFCodec ff_bfi_decoder;
extern const FFCodec ff_bink_decoder;
extern const FFCodec ff_bitpacked_decoder;
extern const FFCodec ff_bitpacked_encoder;
extern const FFCodec ff_bmp_encoder;
extern const FFCodec ff_bmp_decoder;
extern const FFCodec ff_bmv_video_decoder;
extern const FFCodec ff_brender_pix_decoder;
extern const FFCodec ff_c93_decoder;
extern const FFCodec ff_cavs_decoder;
extern const FFCodec ff_cdgraphics_decoder;
extern const FFCodec ff_cdtoons_decoder;
extern const FFCodec ff_cdxl_decoder;
extern const FFCodec ff_cfhd_encoder;
extern const FFCodec ff_cfhd_decoder;
extern const FFCodec ff_cinepak_encoder;
extern const FFCodec ff_cinepak_decoder;
extern const FFCodec ff_clearvideo_decoder;
extern const FFCodec ff_cljr_encoder;
extern const FFCodec ff_cljr_decoder;
extern const FFCodec ff_cllc_decoder;
extern const FFCodec ff_comfortnoise_encoder;
extern const FFCodec ff_comfortnoise_decoder;
extern const FFCodec ff_cpia_decoder;
extern const FFCodec ff_cri_decoder;
extern const FFCodec ff_cscd_decoder;
extern const FFCodec ff_cyuv_decoder;
extern const FFCodec ff_dds_decoder;
extern const FFCodec ff_dfa_decoder;
extern const FFCodec ff_dirac_decoder;
extern const FFCodec ff_dnxhd_encoder;
extern const FFCodec ff_dnxhd_decoder;
extern const FFCodec ff_dpx_encoder;
extern const FFCodec ff_dpx_decoder;
extern const FFCodec ff_dsicinvideo_decoder;
extern const FFCodec ff_dvaudio_decoder;
extern const FFCodec ff_dvvideo_encoder;
extern const FFCodec ff_dvvideo_decoder;
extern const FFCodec ff_dxa_decoder;
extern const FFCodec ff_dxtory_decoder;
extern const FFCodec ff_dxv_decoder;
extern const FFCodec ff_eacmv_decoder;
extern const FFCodec ff_eamad_decoder;
extern const FFCodec ff_eatgq_decoder;
extern const FFCodec ff_eatgv_decoder;
extern const FFCodec ff_eatqi_decoder;
extern const FFCodec ff_eightbps_decoder;
extern const FFCodec ff_eightsvx_exp_decoder;
extern const FFCodec ff_eightsvx_fib_decoder;
extern const FFCodec ff_escape124_decoder;
extern const FFCodec ff_escape130_decoder;
extern const FFCodec ff_exr_encoder;
extern const FFCodec ff_exr_decoder;
extern const FFCodec ff_ffv1_encoder;
extern const FFCodec ff_ffv1_decoder;
extern const FFCodec ff_ffvhuff_encoder;
extern const FFCodec ff_ffvhuff_decoder;
extern const FFCodec ff_fic_decoder;
extern const FFCodec ff_fits_encoder;
extern const FFCodec ff_fits_decoder;
extern const FFCodec ff_flashsv_encoder;
extern const FFCodec ff_flashsv_decoder;
extern const FFCodec ff_flashsv2_encoder;
extern const FFCodec ff_flashsv2_decoder;
extern const FFCodec ff_flic_decoder;
extern const FFCodec ff_flv_encoder;
extern const FFCodec ff_flv_decoder;
extern const FFCodec ff_fmvc_decoder;
extern const FFCodec ff_fourxm_decoder;
extern const FFCodec ff_fraps_decoder;
extern const FFCodec ff_frwu_decoder;
extern const FFCodec ff_g2m_decoder;
extern const FFCodec ff_gdv_decoder;
extern const FFCodec ff_gem_decoder;
extern const FFCodec ff_gif_encoder;
extern const FFCodec ff_gif_decoder;
extern const FFCodec ff_h261_encoder;
extern const FFCodec ff_h261_decoder;
extern const FFCodec ff_h263_encoder;
extern const FFCodec ff_h263_decoder;
extern const FFCodec ff_h263i_decoder;
extern const FFCodec ff_h263p_encoder;
extern const FFCodec ff_h263p_decoder;
extern const FFCodec ff_h263_v4l2m2m_decoder;
extern const FFCodec ff_h264_decoder;
extern const FFCodec ff_h264_crystalhd_decoder;
extern const FFCodec ff_h264_v4l2m2m_decoder;
extern const FFCodec ff_h264_mediacodec_decoder;
extern const FFCodec ff_h264_mediacodec_encoder;
extern const FFCodec ff_h264_mmal_decoder;
extern const FFCodec ff_h264_qsv_decoder;
extern const FFCodec ff_h264_rkmpp_decoder;
extern const FFCodec ff_hap_encoder;
extern const FFCodec ff_hap_decoder;
extern const FFCodec ff_hevc_decoder;
extern const FFCodec ff_hevc_qsv_decoder;
extern const FFCodec ff_hevc_rkmpp_decoder;
extern const FFCodec ff_hevc_v4l2m2m_decoder;
extern const FFCodec ff_hnm4_video_decoder;
extern const FFCodec ff_hq_hqa_decoder;
extern const FFCodec ff_hqx_decoder;
extern const FFCodec ff_huffyuv_encoder;
extern const FFCodec ff_huffyuv_decoder;
extern const FFCodec ff_hymt_decoder;
extern const FFCodec ff_idcin_decoder;
extern const FFCodec ff_iff_ilbm_decoder;
extern const FFCodec ff_imm4_decoder;
extern const FFCodec ff_imm5_decoder;
extern const FFCodec ff_indeo2_decoder;
extern const FFCodec ff_indeo3_decoder;
extern const FFCodec ff_indeo4_decoder;
extern const FFCodec ff_indeo5_decoder;
extern const FFCodec ff_interplay_video_decoder;
extern const FFCodec ff_ipu_decoder;
extern const FFCodec ff_jpeg2000_encoder;
extern const FFCodec ff_jpeg2000_decoder;
extern const FFCodec ff_jpegls_encoder;
extern const FFCodec ff_jpegls_decoder;
extern const FFCodec ff_jv_decoder;
extern const FFCodec ff_kgv1_decoder;
extern const FFCodec ff_kmvc_decoder;
extern const FFCodec ff_lagarith_decoder;
extern const FFCodec ff_ljpeg_encoder;
extern const FFCodec ff_loco_decoder;
extern const FFCodec ff_lscr_decoder;
extern const FFCodec ff_m101_decoder;
extern const FFCodec ff_magicyuv_encoder;
extern const FFCodec ff_magicyuv_decoder;
extern const FFCodec ff_mdec_decoder;
extern const FFCodec ff_media100_decoder;
extern const FFCodec ff_mimic_decoder;
extern const FFCodec ff_mjpeg_encoder;
extern const FFCodec ff_mjpeg_decoder;
extern const FFCodec ff_mjpegb_decoder;
extern const FFCodec ff_mmvideo_decoder;
extern const FFCodec ff_mobiclip_decoder;
extern const FFCodec ff_motionpixels_decoder;
extern const FFCodec ff_mpeg1video_encoder;
extern const FFCodec ff_mpeg1video_decoder;
extern const FFCodec ff_mpeg2video_encoder;
extern const FFCodec ff_mpeg2video_decoder;
extern const FFCodec ff_mpeg4_encoder;
extern const FFCodec ff_mpeg4_decoder;
extern const FFCodec ff_mpeg4_crystalhd_decoder;
extern const FFCodec ff_mpeg4_v4l2m2m_decoder;
extern const FFCodec ff_mpeg4_mmal_decoder;
extern const FFCodec ff_mpegvideo_decoder;
extern const FFCodec ff_mpeg1_v4l2m2m_decoder;
extern const FFCodec ff_mpeg2_mmal_decoder;
extern const FFCodec ff_mpeg2_crystalhd_decoder;
extern const FFCodec ff_mpeg2_v4l2m2m_decoder;
extern const FFCodec ff_mpeg2_qsv_decoder;
extern const FFCodec ff_mpeg2_mediacodec_decoder;
extern const FFCodec ff_msa1_decoder;
extern const FFCodec ff_mscc_decoder;
extern const FFCodec ff_msmpeg4v1_decoder;
extern const FFCodec ff_msmpeg4v2_encoder;
extern const FFCodec ff_msmpeg4v2_decoder;
extern const FFCodec ff_msmpeg4v3_encoder;
extern const FFCodec ff_msmpeg4v3_decoder;
extern const FFCodec ff_msmpeg4_crystalhd_decoder;
extern const FFCodec ff_msp2_decoder;
extern const FFCodec ff_msrle_decoder;
extern const FFCodec ff_mss1_decoder;
extern const FFCodec ff_mss2_decoder;
extern const FFCodec ff_msvideo1_encoder;
extern const FFCodec ff_msvideo1_decoder;
extern const FFCodec ff_mszh_decoder;
extern const FFCodec ff_mts2_decoder;
extern const FFCodec ff_mv30_decoder;
extern const FFCodec ff_mvc1_decoder;
extern const FFCodec ff_mvc2_decoder;
extern const FFCodec ff_mvdv_decoder;
extern const FFCodec ff_mvha_decoder;
extern const FFCodec ff_mwsc_decoder;
extern const FFCodec ff_mxpeg_decoder;
extern const FFCodec ff_notchlc_decoder;
extern const FFCodec ff_nuv_decoder;
extern const FFCodec ff_paf_video_decoder;
extern const FFCodec ff_pam_encoder;
extern const FFCodec ff_pam_decoder;
extern const FFCodec ff_pbm_encoder;
extern const FFCodec ff_pbm_decoder;
extern const FFCodec ff_pcx_encoder;
extern const FFCodec ff_pcx_decoder;
extern const FFCodec ff_pfm_encoder;
extern const FFCodec ff_pfm_decoder;
extern const FFCodec ff_pgm_encoder;
extern const FFCodec ff_pgm_decoder;
extern const FFCodec ff_pgmyuv_encoder;
extern const FFCodec ff_pgmyuv_decoder;
extern const FFCodec ff_pgx_decoder;
extern const FFCodec ff_phm_encoder;
extern const FFCodec ff_phm_decoder;
extern const FFCodec ff_photocd_decoder;
extern const FFCodec ff_pictor_decoder;
extern const FFCodec ff_pixlet_decoder;
extern const FFCodec ff_png_encoder;
extern const FFCodec ff_png_decoder;
extern const FFCodec ff_ppm_encoder;
extern const FFCodec ff_ppm_decoder;
extern const FFCodec ff_prores_encoder;
extern const FFCodec ff_prores_decoder;
extern const FFCodec ff_prores_aw_encoder;
extern const FFCodec ff_prores_ks_encoder;
extern const FFCodec ff_prosumer_decoder;
extern const FFCodec ff_psd_decoder;
extern const FFCodec ff_ptx_decoder;
extern const FFCodec ff_qdraw_decoder;
extern const FFCodec ff_qoi_encoder;
extern const FFCodec ff_qoi_decoder;
extern const FFCodec ff_qpeg_decoder;
extern const FFCodec ff_qtrle_encoder;
extern const FFCodec ff_qtrle_decoder;
extern const FFCodec ff_r10k_encoder;
extern const FFCodec ff_r10k_decoder;
extern const FFCodec ff_r210_encoder;
extern const FFCodec ff_r210_decoder;
extern const FFCodec ff_rasc_decoder;
extern const FFCodec ff_rawvideo_encoder;
extern const FFCodec ff_rawvideo_decoder;
extern const FFCodec ff_rka_decoder;
extern const FFCodec ff_rl2_decoder;
extern const FFCodec ff_roq_encoder;
extern const FFCodec ff_roq_decoder;
extern const FFCodec ff_rpza_encoder;
extern const FFCodec ff_rpza_decoder;
extern const FFCodec ff_rscc_decoder;
extern const FFCodec ff_rv10_encoder;
extern const FFCodec ff_rv10_decoder;
extern const FFCodec ff_rv20_encoder;
extern const FFCodec ff_rv20_decoder;
extern const FFCodec ff_rv30_decoder;
extern const FFCodec ff_rv40_decoder;
extern const FFCodec ff_s302m_encoder;
extern const FFCodec ff_s302m_decoder;
extern const FFCodec ff_sanm_decoder;
extern const FFCodec ff_scpr_decoder;
extern const FFCodec ff_screenpresso_decoder;
extern const FFCodec ff_sga_decoder;
extern const FFCodec ff_sgi_encoder;
extern const FFCodec ff_sgi_decoder;
extern const FFCodec ff_sgirle_decoder;
extern const FFCodec ff_sheervideo_decoder;
extern const FFCodec ff_simbiosis_imx_decoder;
extern const FFCodec ff_smacker_decoder;
extern const FFCodec ff_smc_encoder;
extern const FFCodec ff_smc_decoder;
extern const FFCodec ff_smvjpeg_decoder;
extern const FFCodec ff_snow_encoder;
extern const FFCodec ff_snow_decoder;
extern const FFCodec ff_sp5x_decoder;
extern const FFCodec ff_speedhq_decoder;
extern const FFCodec ff_speedhq_encoder;
extern const FFCodec ff_speex_decoder;
extern const FFCodec ff_srgc_decoder;
extern const FFCodec ff_sunrast_encoder;
extern const FFCodec ff_sunrast_decoder;
extern const FFCodec ff_svq1_encoder;
extern const FFCodec ff_svq1_decoder;
extern const FFCodec ff_svq3_decoder;
extern const FFCodec ff_targa_encoder;
extern const FFCodec ff_targa_decoder;
extern const FFCodec ff_targa_y216_decoder;
extern const FFCodec ff_tdsc_decoder;
extern const FFCodec ff_theora_decoder;
extern const FFCodec ff_thp_decoder;
extern const FFCodec ff_tiertexseqvideo_decoder;
extern const FFCodec ff_tiff_encoder;
extern const FFCodec ff_tiff_decoder;
extern const FFCodec ff_tmv_decoder;
extern const FFCodec ff_truemotion1_decoder;
extern const FFCodec ff_truemotion2_decoder;
extern const FFCodec ff_truemotion2rt_decoder;
extern const FFCodec ff_tscc_decoder;
extern const FFCodec ff_tscc2_decoder;
extern const FFCodec ff_txd_decoder;
extern const FFCodec ff_ulti_decoder;
extern const FFCodec ff_utvideo_encoder;
extern const FFCodec ff_utvideo_decoder;
extern const FFCodec ff_v210_encoder;
extern const FFCodec ff_v210_decoder;
extern const FFCodec ff_v210x_decoder;
extern const FFCodec ff_v308_encoder;
extern const FFCodec ff_v308_decoder;
extern const FFCodec ff_v408_encoder;
extern const FFCodec ff_v408_decoder;
extern const FFCodec ff_v410_encoder;
extern const FFCodec ff_v410_decoder;
extern const FFCodec ff_vb_decoder;
extern const FFCodec ff_vbn_encoder;
extern const FFCodec ff_vbn_decoder;
extern const FFCodec ff_vble_decoder;
extern const FFCodec ff_vc1_decoder;
extern const FFCodec ff_vc1_crystalhd_decoder;
extern const FFCodec ff_vc1image_decoder;
extern const FFCodec ff_vc1_mmal_decoder;
extern const FFCodec ff_vc1_qsv_decoder;
extern const FFCodec ff_vc1_v4l2m2m_decoder;
extern const FFCodec ff_vc2_encoder;
extern const FFCodec ff_vcr1_decoder;
extern const FFCodec ff_vmdvideo_decoder;
extern const FFCodec ff_vmnc_decoder;
extern const FFCodec ff_vp3_decoder;
extern const FFCodec ff_vp4_decoder;
extern const FFCodec ff_vp5_decoder;
extern const FFCodec ff_vp6_decoder;
extern const FFCodec ff_vp6a_decoder;
extern const FFCodec ff_vp6f_decoder;
extern const FFCodec ff_vp7_decoder;
extern const FFCodec ff_vp8_decoder;
extern const FFCodec ff_vp8_rkmpp_decoder;
extern const FFCodec ff_vp8_v4l2m2m_decoder;
extern const FFCodec ff_vp9_decoder;
extern const FFCodec ff_vp9_rkmpp_decoder;
extern const FFCodec ff_vp9_v4l2m2m_decoder;
extern const FFCodec ff_vqa_decoder;
extern const FFCodec ff_vqc_decoder;
extern const FFCodec ff_wbmp_decoder;
extern const FFCodec ff_wbmp_encoder;
extern const FFCodec ff_webp_decoder;
extern const FFCodec ff_wcmv_decoder;
extern const FFCodec ff_wrapped_avframe_encoder;
extern const FFCodec ff_wrapped_avframe_decoder;
extern const FFCodec ff_wmv1_encoder;
extern const FFCodec ff_wmv1_decoder;
extern const FFCodec ff_wmv2_encoder;
extern const FFCodec ff_wmv2_decoder;
extern const FFCodec ff_wmv3_decoder;
extern const FFCodec ff_wmv3_crystalhd_decoder;
extern const FFCodec ff_wmv3image_decoder;
extern const FFCodec ff_wnv1_decoder;
extern const FFCodec ff_xan_wc3_decoder;
extern const FFCodec ff_xan_wc4_decoder;
extern const FFCodec ff_xbm_encoder;
extern const FFCodec ff_xbm_decoder;
extern const FFCodec ff_xface_encoder;
extern const FFCodec ff_xface_decoder;
extern const FFCodec ff_xl_decoder;
extern const FFCodec ff_xpm_decoder;
extern const FFCodec ff_xwd_encoder;
extern const FFCodec ff_xwd_decoder;
extern const FFCodec ff_y41p_encoder;
extern const FFCodec ff_y41p_decoder;
extern const FFCodec ff_ylc_decoder;
extern const FFCodec ff_yop_decoder;
extern const FFCodec ff_yuv4_encoder;
extern const FFCodec ff_yuv4_decoder;
extern const FFCodec ff_zero12v_decoder;
extern const FFCodec ff_zerocodec_decoder;
extern const FFCodec ff_zlib_encoder;
extern const FFCodec ff_zlib_decoder;
extern const FFCodec ff_zmbv_encoder;
extern const FFCodec ff_zmbv_decoder;/* audio codecs */
extern const FFCodec ff_aac_encoder;
extern const FFCodec ff_aac_decoder;
extern const FFCodec ff_aac_fixed_decoder;
extern const FFCodec ff_aac_latm_decoder;
extern const FFCodec ff_ac3_encoder;
extern const FFCodec ff_ac3_decoder;
extern const FFCodec ff_ac3_fixed_encoder;
extern const FFCodec ff_ac3_fixed_decoder;
extern const FFCodec ff_acelp_kelvin_decoder;
extern const FFCodec ff_alac_encoder;
extern const FFCodec ff_alac_decoder;
extern const FFCodec ff_als_decoder;
extern const FFCodec ff_amrnb_decoder;
extern const FFCodec ff_amrwb_decoder;
extern const FFCodec ff_apac_decoder;
extern const FFCodec ff_ape_decoder;
extern const FFCodec ff_aptx_encoder;
extern const FFCodec ff_aptx_decoder;
extern const FFCodec ff_aptx_hd_encoder;
extern const FFCodec ff_aptx_hd_decoder;
extern const FFCodec ff_atrac1_decoder;
extern const FFCodec ff_atrac3_decoder;
extern const FFCodec ff_atrac3al_decoder;
extern const FFCodec ff_atrac3p_decoder;
extern const FFCodec ff_atrac3pal_decoder;
extern const FFCodec ff_atrac9_decoder;
extern const FFCodec ff_binkaudio_dct_decoder;
extern const FFCodec ff_binkaudio_rdft_decoder;
extern const FFCodec ff_bmv_audio_decoder;
extern const FFCodec ff_bonk_decoder;
extern const FFCodec ff_cook_decoder;
extern const FFCodec ff_dca_encoder;
extern const FFCodec ff_dca_decoder;
extern const FFCodec ff_dfpwm_encoder;
extern const FFCodec ff_dfpwm_decoder;
extern const FFCodec ff_dolby_e_decoder;
extern const FFCodec ff_dsd_lsbf_decoder;
extern const FFCodec ff_dsd_msbf_decoder;
extern const FFCodec ff_dsd_lsbf_planar_decoder;
extern const FFCodec ff_dsd_msbf_planar_decoder;
extern const FFCodec ff_dsicinaudio_decoder;
extern const FFCodec ff_dss_sp_decoder;
extern const FFCodec ff_dst_decoder;
extern const FFCodec ff_eac3_encoder;
extern const FFCodec ff_eac3_decoder;
extern const FFCodec ff_evrc_decoder;
extern const FFCodec ff_fastaudio_decoder;
extern const FFCodec ff_ffwavesynth_decoder;
extern const FFCodec ff_flac_encoder;
extern const FFCodec ff_flac_decoder;
extern const FFCodec ff_ftr_decoder;
extern const FFCodec ff_g723_1_encoder;
extern const FFCodec ff_g723_1_decoder;
extern const FFCodec ff_g729_decoder;
extern const FFCodec ff_gsm_decoder;
extern const FFCodec ff_gsm_ms_decoder;
extern const FFCodec ff_hca_decoder;
extern const FFCodec ff_hcom_decoder;
extern const FFCodec ff_hdr_encoder;
extern const FFCodec ff_hdr_decoder;
extern const FFCodec ff_iac_decoder;
extern const FFCodec ff_ilbc_decoder;
extern const FFCodec ff_imc_decoder;
extern const FFCodec ff_interplay_acm_decoder;
extern const FFCodec ff_mace3_decoder;
extern const FFCodec ff_mace6_decoder;
extern const FFCodec ff_metasound_decoder;
extern const FFCodec ff_misc4_decoder;
extern const FFCodec ff_mlp_encoder;
extern const FFCodec ff_mlp_decoder;
extern const FFCodec ff_mp1_decoder;
extern const FFCodec ff_mp1float_decoder;
extern const FFCodec ff_mp2_encoder;
extern const FFCodec ff_mp2_decoder;
extern const FFCodec ff_mp2float_decoder;
extern const FFCodec ff_mp2fixed_encoder;
extern const FFCodec ff_mp3float_decoder;
extern const FFCodec ff_mp3_decoder;
extern const FFCodec ff_mp3adufloat_decoder;
extern const FFCodec ff_mp3adu_decoder;
extern const FFCodec ff_mp3on4float_decoder;
extern const FFCodec ff_mp3on4_decoder;
extern const FFCodec ff_mpc7_decoder;
extern const FFCodec ff_mpc8_decoder;
extern const FFCodec ff_msnsiren_decoder;
extern const FFCodec ff_nellymoser_encoder;
extern const FFCodec ff_nellymoser_decoder;
extern const FFCodec ff_on2avc_decoder;
extern const FFCodec ff_opus_encoder;
extern const FFCodec ff_opus_decoder;
extern const FFCodec ff_paf_audio_decoder;
extern const FFCodec ff_qcelp_decoder;
extern const FFCodec ff_qdm2_decoder;
extern const FFCodec ff_qdmc_decoder;
extern const FFCodec ff_ra_144_encoder;
extern const FFCodec ff_ra_144_decoder;
extern const FFCodec ff_ra_288_decoder;
extern const FFCodec ff_ralf_decoder;
extern const FFCodec ff_sbc_encoder;
extern const FFCodec ff_sbc_decoder;
extern const FFCodec ff_shorten_decoder;
extern const FFCodec ff_sipr_decoder;
extern const FFCodec ff_siren_decoder;
extern const FFCodec ff_smackaud_decoder;
extern const FFCodec ff_sonic_encoder;
extern const FFCodec ff_sonic_decoder;
extern const FFCodec ff_sonic_ls_encoder;
extern const FFCodec ff_tak_decoder;
extern const FFCodec ff_truehd_encoder;
extern const FFCodec ff_truehd_decoder;
extern const FFCodec ff_truespeech_decoder;
extern const FFCodec ff_tta_encoder;
extern const FFCodec ff_tta_decoder;
extern const FFCodec ff_twinvq_decoder;
extern const FFCodec ff_vmdaudio_decoder;
extern const FFCodec ff_vorbis_encoder;
extern const FFCodec ff_vorbis_decoder;
extern const FFCodec ff_wavarc_decoder;
extern const FFCodec ff_wavpack_encoder;
extern const FFCodec ff_wavpack_decoder;
extern const FFCodec ff_wmalossless_decoder;
extern const FFCodec ff_wmapro_decoder;
extern const FFCodec ff_wmav1_encoder;
extern const FFCodec ff_wmav1_decoder;
extern const FFCodec ff_wmav2_encoder;
extern const FFCodec ff_wmav2_decoder;
extern const FFCodec ff_wmavoice_decoder;
extern const FFCodec ff_ws_snd1_decoder;
extern const FFCodec ff_xma1_decoder;
extern const FFCodec ff_xma2_decoder;/* PCM codecs */
extern const FFCodec ff_pcm_alaw_encoder;
extern const FFCodec ff_pcm_alaw_decoder;
extern const FFCodec ff_pcm_bluray_encoder;
extern const FFCodec ff_pcm_bluray_decoder;
extern const FFCodec ff_pcm_dvd_encoder;
extern const FFCodec ff_pcm_dvd_decoder;
extern const FFCodec ff_pcm_f16le_decoder;
extern const FFCodec ff_pcm_f24le_decoder;
extern const FFCodec ff_pcm_f32be_encoder;
extern const FFCodec ff_pcm_f32be_decoder;
extern const FFCodec ff_pcm_f32le_encoder;
extern const FFCodec ff_pcm_f32le_decoder;
extern const FFCodec ff_pcm_f64be_encoder;
extern const FFCodec ff_pcm_f64be_decoder;
extern const FFCodec ff_pcm_f64le_encoder;
extern const FFCodec ff_pcm_f64le_decoder;
extern const FFCodec ff_pcm_lxf_decoder;
extern const FFCodec ff_pcm_mulaw_encoder;
extern const FFCodec ff_pcm_mulaw_decoder;
extern const FFCodec ff_pcm_s8_encoder;
extern const FFCodec ff_pcm_s8_decoder;
extern const FFCodec ff_pcm_s8_planar_encoder;
extern const FFCodec ff_pcm_s8_planar_decoder;
extern const FFCodec ff_pcm_s16be_encoder;
extern const FFCodec ff_pcm_s16be_decoder;
extern const FFCodec ff_pcm_s16be_planar_encoder;
extern const FFCodec ff_pcm_s16be_planar_decoder;
extern const FFCodec ff_pcm_s16le_encoder;
extern const FFCodec ff_pcm_s16le_decoder;
extern const FFCodec ff_pcm_s16le_planar_encoder;
extern const FFCodec ff_pcm_s16le_planar_decoder;
extern const FFCodec ff_pcm_s24be_encoder;
extern const FFCodec ff_pcm_s24be_decoder;
extern const FFCodec ff_pcm_s24daud_encoder;
extern const FFCodec ff_pcm_s24daud_decoder;
extern const FFCodec ff_pcm_s24le_encoder;
extern const FFCodec ff_pcm_s24le_decoder;
extern const FFCodec ff_pcm_s24le_planar_encoder;
extern const FFCodec ff_pcm_s24le_planar_decoder;
extern const FFCodec ff_pcm_s32be_encoder;
extern const FFCodec ff_pcm_s32be_decoder;
extern const FFCodec ff_pcm_s32le_encoder;
extern const FFCodec ff_pcm_s32le_decoder;
extern const FFCodec ff_pcm_s32le_planar_encoder;
extern const FFCodec ff_pcm_s32le_planar_decoder;
extern const FFCodec ff_pcm_s64be_encoder;
extern const FFCodec ff_pcm_s64be_decoder;
extern const FFCodec ff_pcm_s64le_encoder;
extern const FFCodec ff_pcm_s64le_decoder;
extern const FFCodec ff_pcm_sga_decoder;
extern const FFCodec ff_pcm_u8_encoder;
extern const FFCodec ff_pcm_u8_decoder;
extern const FFCodec ff_pcm_u16be_encoder;
extern const FFCodec ff_pcm_u16be_decoder;
extern const FFCodec ff_pcm_u16le_encoder;
extern const FFCodec ff_pcm_u16le_decoder;
extern const FFCodec ff_pcm_u24be_encoder;
extern const FFCodec ff_pcm_u24be_decoder;
extern const FFCodec ff_pcm_u24le_encoder;
extern const FFCodec ff_pcm_u24le_decoder;
extern const FFCodec ff_pcm_u32be_encoder;
extern const FFCodec ff_pcm_u32be_decoder;
extern const FFCodec ff_pcm_u32le_encoder;
extern const FFCodec ff_pcm_u32le_decoder;
extern const FFCodec ff_pcm_vidc_encoder;
extern const FFCodec ff_pcm_vidc_decoder;/* DPCM codecs */
extern const FFCodec ff_cbd2_dpcm_decoder;
extern const FFCodec ff_derf_dpcm_decoder;
extern const FFCodec ff_gremlin_dpcm_decoder;
extern const FFCodec ff_interplay_dpcm_decoder;
extern const FFCodec ff_roq_dpcm_encoder;
extern const FFCodec ff_roq_dpcm_decoder;
extern const FFCodec ff_sdx2_dpcm_decoder;
extern const FFCodec ff_sol_dpcm_decoder;
extern const FFCodec ff_xan_dpcm_decoder;
extern const FFCodec ff_wady_dpcm_decoder;/* ADPCM codecs */
extern const FFCodec ff_adpcm_4xm_decoder;
extern const FFCodec ff_adpcm_adx_encoder;
extern const FFCodec ff_adpcm_adx_decoder;
extern const FFCodec ff_adpcm_afc_decoder;
extern const FFCodec ff_adpcm_agm_decoder;
extern const FFCodec ff_adpcm_aica_decoder;
extern const FFCodec ff_adpcm_argo_decoder;
extern const FFCodec ff_adpcm_argo_encoder;
extern const FFCodec ff_adpcm_ct_decoder;
extern const FFCodec ff_adpcm_dtk_decoder;
extern const FFCodec ff_adpcm_ea_decoder;
extern const FFCodec ff_adpcm_ea_maxis_xa_decoder;
extern const FFCodec ff_adpcm_ea_r1_decoder;
extern const FFCodec ff_adpcm_ea_r2_decoder;
extern const FFCodec ff_adpcm_ea_r3_decoder;
extern const FFCodec ff_adpcm_ea_xas_decoder;
extern const FFCodec ff_adpcm_g722_encoder;
extern const FFCodec ff_adpcm_g722_decoder;
extern const FFCodec ff_adpcm_g726_encoder;
extern const FFCodec ff_adpcm_g726_decoder;
extern const FFCodec ff_adpcm_g726le_encoder;
extern const FFCodec ff_adpcm_g726le_decoder;
extern const FFCodec ff_adpcm_ima_acorn_decoder;
extern const FFCodec ff_adpcm_ima_amv_decoder;
extern const FFCodec ff_adpcm_ima_amv_encoder;
extern const FFCodec ff_adpcm_ima_alp_decoder;
extern const FFCodec ff_adpcm_ima_alp_encoder;
extern const FFCodec ff_adpcm_ima_apc_decoder;
extern const FFCodec ff_adpcm_ima_apm_decoder;
extern const FFCodec ff_adpcm_ima_apm_encoder;
extern const FFCodec ff_adpcm_ima_cunning_decoder;
extern const FFCodec ff_adpcm_ima_dat4_decoder;
extern const FFCodec ff_adpcm_ima_dk3_decoder;
extern const FFCodec ff_adpcm_ima_dk4_decoder;
extern const FFCodec ff_adpcm_ima_ea_eacs_decoder;
extern const FFCodec ff_adpcm_ima_ea_sead_decoder;
extern const FFCodec ff_adpcm_ima_iss_decoder;
extern const FFCodec ff_adpcm_ima_moflex_decoder;
extern const FFCodec ff_adpcm_ima_mtf_decoder;
extern const FFCodec ff_adpcm_ima_oki_decoder;
extern const FFCodec ff_adpcm_ima_qt_encoder;
extern const FFCodec ff_adpcm_ima_qt_decoder;
extern const FFCodec ff_adpcm_ima_rad_decoder;
extern const FFCodec ff_adpcm_ima_ssi_decoder;
extern const FFCodec ff_adpcm_ima_ssi_encoder;
extern const FFCodec ff_adpcm_ima_smjpeg_decoder;
extern const FFCodec ff_adpcm_ima_wav_encoder;
extern const FFCodec ff_adpcm_ima_wav_decoder;
extern const FFCodec ff_adpcm_ima_ws_encoder;
extern const FFCodec ff_adpcm_ima_ws_decoder;
extern const FFCodec ff_adpcm_ms_encoder;
extern const FFCodec ff_adpcm_ms_decoder;
extern const FFCodec ff_adpcm_mtaf_decoder;
extern const FFCodec ff_adpcm_psx_decoder;
extern const FFCodec ff_adpcm_sbpro_2_decoder;
extern const FFCodec ff_adpcm_sbpro_3_decoder;
extern const FFCodec ff_adpcm_sbpro_4_decoder;
extern const FFCodec ff_adpcm_swf_encoder;
extern const FFCodec ff_adpcm_swf_decoder;
extern const FFCodec ff_adpcm_thp_decoder;
extern const FFCodec ff_adpcm_thp_le_decoder;
extern const FFCodec ff_adpcm_vima_decoder;
extern const FFCodec ff_adpcm_xa_decoder;
extern const FFCodec ff_adpcm_xmd_decoder;
extern const FFCodec ff_adpcm_yamaha_encoder;
extern const FFCodec ff_adpcm_yamaha_decoder;
extern const FFCodec ff_adpcm_zork_decoder;/* subtitles */
extern const FFCodec ff_ssa_encoder;
extern const FFCodec ff_ssa_decoder;
extern const FFCodec ff_ass_encoder;
extern const FFCodec ff_ass_decoder;
extern const FFCodec ff_ccaption_decoder;
extern const FFCodec ff_dvbsub_encoder;
extern const FFCodec ff_dvbsub_decoder;
extern const FFCodec ff_dvdsub_encoder;
extern const FFCodec ff_dvdsub_decoder;
extern const FFCodec ff_jacosub_decoder;
extern const FFCodec ff_microdvd_decoder;
extern const FFCodec ff_movtext_encoder;
extern const FFCodec ff_movtext_decoder;
extern const FFCodec ff_mpl2_decoder;
extern const FFCodec ff_pgssub_decoder;
extern const FFCodec ff_pjs_decoder;
extern const FFCodec ff_realtext_decoder;
extern const FFCodec ff_sami_decoder;
extern const FFCodec ff_srt_encoder;
extern const FFCodec ff_srt_decoder;
extern const FFCodec ff_stl_decoder;
extern const FFCodec ff_subrip_encoder;
extern const FFCodec ff_subrip_decoder;
extern const FFCodec ff_subviewer_decoder;
extern const FFCodec ff_subviewer1_decoder;
extern const FFCodec ff_text_encoder;
extern const FFCodec ff_text_decoder;
extern const FFCodec ff_ttml_encoder;
extern const FFCodec ff_vplayer_decoder;
extern const FFCodec ff_webvtt_encoder;
extern const FFCodec ff_webvtt_decoder;
extern const FFCodec ff_xsub_encoder;
extern const FFCodec ff_xsub_decoder;/* external libraries */
extern const FFCodec ff_aac_at_encoder;
extern const FFCodec ff_aac_at_decoder;
extern const FFCodec ff_ac3_at_decoder;
extern const FFCodec ff_adpcm_ima_qt_at_decoder;
extern const FFCodec ff_alac_at_encoder;
extern const FFCodec ff_alac_at_decoder;
extern const FFCodec ff_amr_nb_at_decoder;
extern const FFCodec ff_eac3_at_decoder;
extern const FFCodec ff_gsm_ms_at_decoder;
extern const FFCodec ff_ilbc_at_encoder;
extern const FFCodec ff_ilbc_at_decoder;
extern const FFCodec ff_mp1_at_decoder;
extern const FFCodec ff_mp2_at_decoder;
extern const FFCodec ff_mp3_at_decoder;
extern const FFCodec ff_pcm_alaw_at_encoder;
extern const FFCodec ff_pcm_alaw_at_decoder;
extern const FFCodec ff_pcm_mulaw_at_encoder;
extern const FFCodec ff_pcm_mulaw_at_decoder;
extern const FFCodec ff_qdmc_at_decoder;
extern const FFCodec ff_qdm2_at_decoder;
extern FFCodec ff_libaom_av1_encoder;
extern const FFCodec ff_libaribb24_decoder;
extern const FFCodec ff_libcelt_decoder;
extern const FFCodec ff_libcodec2_encoder;
extern const FFCodec ff_libcodec2_decoder;
extern const FFCodec ff_libdav1d_decoder;
extern const FFCodec ff_libdavs2_decoder;
extern const FFCodec ff_libfdk_aac_encoder;
extern const FFCodec ff_libfdk_aac_decoder;
extern const FFCodec ff_libgsm_encoder;
extern const FFCodec ff_libgsm_decoder;
extern const FFCodec ff_libgsm_ms_encoder;
extern const FFCodec ff_libgsm_ms_decoder;
extern const FFCodec ff_libilbc_encoder;
extern const FFCodec ff_libilbc_decoder;
extern const FFCodec ff_libjxl_decoder;
extern const FFCodec ff_libjxl_encoder;
extern const FFCodec ff_libmp3lame_encoder;
extern const FFCodec ff_libopencore_amrnb_encoder;
extern const FFCodec ff_libopencore_amrnb_decoder;
extern const FFCodec ff_libopencore_amrwb_decoder;
extern const FFCodec ff_libopenjpeg_encoder;
extern const FFCodec ff_libopenjpeg_decoder;
extern const FFCodec ff_libopus_encoder;
extern const FFCodec ff_libopus_decoder;
extern const FFCodec ff_librav1e_encoder;
extern const FFCodec ff_librsvg_decoder;
extern const FFCodec ff_libshine_encoder;
extern const FFCodec ff_libspeex_encoder;
extern const FFCodec ff_libspeex_decoder;
extern const FFCodec ff_libsvtav1_encoder;
extern const FFCodec ff_libtheora_encoder;
extern const FFCodec ff_libtwolame_encoder;
extern const FFCodec ff_libuavs3d_decoder;
extern const FFCodec ff_libvo_amrwbenc_encoder;
extern const FFCodec ff_libvorbis_encoder;
extern const FFCodec ff_libvorbis_decoder;
extern const FFCodec ff_libvpx_vp8_encoder;
extern const FFCodec ff_libvpx_vp8_decoder;
extern FFCodec ff_libvpx_vp9_encoder;
extern FFCodec ff_libvpx_vp9_decoder;
/* preferred over libwebp */
extern const FFCodec ff_libwebp_anim_encoder;
extern const FFCodec ff_libwebp_encoder;
extern const FFCodec ff_libx262_encoder;
#if CONFIG_LIBX264_ENCODER
#include <x264.h>
#if X264_BUILD < 153
#define LIBX264_CONST
#else
#define LIBX264_CONST const
#endif
extern LIBX264_CONST FFCodec ff_libx264_encoder;
#endif
extern const FFCodec ff_libx264rgb_encoder;
extern FFCodec ff_libx265_encoder;
extern const FFCodec ff_libxavs_encoder;
extern const FFCodec ff_libxavs2_encoder;
extern const FFCodec ff_libxvid_encoder;
extern const FFCodec ff_libzvbi_teletext_decoder;/* text */
extern const FFCodec ff_bintext_decoder;
extern const FFCodec ff_xbin_decoder;
extern const FFCodec ff_idf_decoder;/* external libraries, that shouldn't be used by default if one of the* above is available */
extern const FFCodec ff_aac_mf_encoder;
extern const FFCodec ff_ac3_mf_encoder;
extern const FFCodec ff_h263_v4l2m2m_encoder;
extern const FFCodec ff_libaom_av1_decoder;
/* hwaccel hooks only, so prefer external decoders */
extern const FFCodec ff_av1_decoder;
extern const FFCodec ff_av1_cuvid_decoder;
extern const FFCodec ff_av1_mediacodec_decoder;
extern const FFCodec ff_av1_nvenc_encoder;
extern const FFCodec ff_av1_qsv_decoder;
extern const FFCodec ff_av1_qsv_encoder;
extern const FFCodec ff_av1_amf_encoder;
extern const FFCodec ff_libopenh264_encoder;
extern const FFCodec ff_libopenh264_decoder;
extern const FFCodec ff_h264_amf_encoder;
extern const FFCodec ff_h264_cuvid_decoder;
extern const FFCodec ff_h264_mf_encoder;
extern const FFCodec ff_h264_nvenc_encoder;
extern const FFCodec ff_h264_omx_encoder;
extern const FFCodec ff_h264_qsv_encoder;
extern const FFCodec ff_h264_v4l2m2m_encoder;
extern const FFCodec ff_h264_vaapi_encoder;
extern const FFCodec ff_h264_videotoolbox_encoder;
extern const FFCodec ff_hevc_amf_encoder;
extern const FFCodec ff_hevc_cuvid_decoder;
extern const FFCodec ff_hevc_mediacodec_decoder;
extern const FFCodec ff_hevc_mediacodec_encoder;
extern const FFCodec ff_hevc_mf_encoder;
extern const FFCodec ff_hevc_nvenc_encoder;
extern const FFCodec ff_hevc_qsv_encoder;
extern const FFCodec ff_hevc_v4l2m2m_encoder;
extern const FFCodec ff_hevc_vaapi_encoder;
extern const FFCodec ff_hevc_videotoolbox_encoder;
extern const FFCodec ff_libkvazaar_encoder;
extern const FFCodec ff_mjpeg_cuvid_decoder;
extern const FFCodec ff_mjpeg_qsv_encoder;
extern const FFCodec ff_mjpeg_qsv_decoder;
extern const FFCodec ff_mjpeg_vaapi_encoder;
extern const FFCodec ff_mp3_mf_encoder;
extern const FFCodec ff_mpeg1_cuvid_decoder;
extern const FFCodec ff_mpeg2_cuvid_decoder;
extern const FFCodec ff_mpeg2_qsv_encoder;
extern const FFCodec ff_mpeg2_vaapi_encoder;
extern const FFCodec ff_mpeg4_cuvid_decoder;
extern const FFCodec ff_mpeg4_mediacodec_decoder;
extern const FFCodec ff_mpeg4_omx_encoder;
extern const FFCodec ff_mpeg4_v4l2m2m_encoder;
extern const FFCodec ff_prores_videotoolbox_encoder;
extern const FFCodec ff_vc1_cuvid_decoder;
extern const FFCodec ff_vp8_cuvid_decoder;
extern const FFCodec ff_vp8_mediacodec_decoder;
extern const FFCodec ff_vp8_qsv_decoder;
extern const FFCodec ff_vp8_v4l2m2m_encoder;
extern const FFCodec ff_vp8_vaapi_encoder;
extern const FFCodec ff_vp9_cuvid_decoder;
extern const FFCodec ff_vp9_mediacodec_decoder;
extern const FFCodec ff_vp9_qsv_decoder;
extern const FFCodec ff_vp9_vaapi_encoder;
extern const FFCodec ff_vp9_qsv_encoder;// null codecs
extern const FFCodec ff_vnull_decoder;
extern const FFCodec ff_vnull_encoder;
extern const FFCodec ff_anull_decoder;
extern const FFCodec ff_anull_encoder;// The iterate API is not usable with ossfuzz due to the excessive size of binaries created
#if CONFIG_OSSFUZZ
const FFCodec * codec_list[] = {NULL,NULL,NULL
};
#else
#include "libavcodec/codec_list.c"
#endifstatic AVOnce av_codec_static_init = AV_ONCE_INIT;
static void av_codec_init_static(void)
{for (int i = 0; codec_list[i]; i++) {if (codec_list[i]->init_static_data)codec_list[i]->init_static_data((FFCodec*)codec_list[i]);}
}const AVCodec *av_codec_iterate(void **opaque)
{uintptr_t i = (uintptr_t)*opaque;const FFCodec *c = codec_list[i];ff_thread_once(&av_codec_static_init, av_codec_init_static);if (c) {*opaque = (void*)(i + 1);return &c->p;}return NULL;
}static enum AVCodecID remap_deprecated_codec_id(enum AVCodecID id)
{switch(id){//This is for future deprecatec codec ids, its empty since//last major bump but will fill up again over time, please don't remove itdefault                                         : return id;}
}static const AVCodec *find_codec(enum AVCodecID id, int (*x)(const AVCodec *))
{const AVCodec *p, *experimental = NULL;void *i = 0;id = remap_deprecated_codec_id(id);while ((p = av_codec_iterate(&i))) {if (!x(p))continue;if (p->id == id) {if (p->capabilities & AV_CODEC_CAP_EXPERIMENTAL && !experimental) {experimental = p;} elsereturn p;}}return experimental;
}const AVCodec *avcodec_find_encoder(enum AVCodecID id)
{return find_codec(id, av_codec_is_encoder);
}const AVCodec *avcodec_find_decoder(enum AVCodecID id)
{return find_codec(id, av_codec_is_decoder);
}static const AVCodec *find_codec_by_name(const char *name, int (*x)(const AVCodec *))
{void *i = 0;const AVCodec *p;if (!name)return NULL;while ((p = av_codec_iterate(&i))) {if (!x(p))continue;if (strcmp(name, p->name) == 0)return p;}return NULL;
}const AVCodec *avcodec_find_encoder_by_name(const char *name)
{return find_codec_by_name(name, av_codec_is_encoder);
}const AVCodec *avcodec_find_decoder_by_name(const char *name)
{return find_codec_by_name(name, av_codec_is_decoder);
}

2.通过编码器得到编码器上下文

 AVCodecContext *avcodec_alloc_context3(const AVCodec *codec);

/*** Allocate an AVCodecContext and set its fields to default values. The* resulting struct should be freed with avcodec_free_context().** @param codec if non-NULL, allocate private data and initialize defaults*              for the given codec. It is illegal to then call avcodec_open2()*              with a different codec.*              If NULL, then the codec-specific defaults won't be initialized,*              which may result in suboptimal default settings (this is*              important mainly for encoders, e.g. libx264).** @return An AVCodecContext filled with default values or NULL on failure.*/
AVCodecContext *avcodec_alloc_context3(const AVCodec *codec);

3.通过编码器上下文 打开编码器

int avcodec_open2(AVCodecContext *avctx, const AVCodec *codec, AVDictionary **options);

参数:

AVCodecContext *avctx:传递的编码器上下文

const AVCodec *codec:如果我们在 创建编码器的时候,传递的是nullptr,那么这时候就要传递具体的codec

AVDictionary **options:一个包含AVCodecContext和编解码器私有选项的字典。返回时,此对象将填充未找到的选项。(这个红色部分的翻译很二,完全看不懂啥意思,),

重新翻译:(可选)一个包含编解码器特定选项的字符串。 这是一个以key=value形式的选项列表,用,分隔。如果不需要额外的选项,可以直接传递NULL。关于 AVDictionary,很显然,这个AVDictionary是为了AVCodecContext 用的,也就是我们指定的编码器(例如h264)有一些参数需要设置,可以通过AVDictionary设置。

我们有两个疑问在这里:

注意的是通过AVDictionary设置的是 特定编码器特定的参数,如果是通用的参数,avcodec中是有key的,通过avcodec设置就好。

1.怎么知道特定的编码器有哪些参数要设置(例如h264编码器有哪些特殊的参数)

        从这里看出,如果要设置这些参数,首先要明白h264的原理,文件结构,因此这里也很有必要学习x264。 另外这里可以参考如何知道x264的参数,了解x265的参数。

2.如何使用 AVDictionary 设定这些特定的参数

核心就是 使用 av_dict_set 一系列方法。        

这里注意的是:如果有特定的参数,设定到AVDictionary后,才能使用 open。

3.还有一种方法是通过 av_opt_set 设定这些特殊的参数

核心是使用 av_opt_set 一系列方法。

例如 

    /// 恒定速率因子(CRF)av_opt_set_int(c->priv_data, "crf", 23, 0);

/*** Initialize the AVCodecContext to use the given AVCodec. Prior to using this* function the context has to be allocated with avcodec_alloc_context3().** The functions avcodec_find_decoder_by_name(), avcodec_find_encoder_by_name(),* avcodec_find_decoder() and avcodec_find_encoder() provide an easy way for* retrieving a codec.** @note Always call this function before using decoding routines (such as* @ref avcodec_receive_frame()).** @code* av_dict_set(&opts, "b", "2.5M", 0);* codec = avcodec_find_decoder(AV_CODEC_ID_H264);* if (!codec)*     exit(1);** context = avcodec_alloc_context3(codec);** if (avcodec_open2(context, codec, opts) < 0)*     exit(1);* @endcode** @param avctx The context to initialize.* @param codec The codec to open this context for. If a non-NULL codec has been*              previously passed to avcodec_alloc_context3() or*              for this context, then this parameter MUST be either NULL or*              equal to the previously passed codec.* @param options A dictionary filled with AVCodecContext and codec-private options.*                On return this object will be filled with options that were not found.** @return zero on success, a negative value on error* @see avcodec_alloc_context3(), avcodec_find_decoder(), avcodec_find_encoder(),*      av_dict_set(), av_opt_find().*/
int avcodec_open2(AVCodecContext *avctx, const AVCodec *codec, AVDictionary **options);

4. 将avframe数据发送给 编码器上下文

int avcodec_send_frame(AVCodecContext *avctx, const AVFrame *frame);

当然发送前,avframe里面是要有数据的。

/*** Supply a raw video or audio frame to the encoder. Use avcodec_receive_packet()* to retrieve buffered output packets.** @param avctx     codec context* @param[in] frame AVFrame containing the raw audio or video frame to be encoded.*                  Ownership of the frame remains with the caller, and the*                  encoder will not write to the frame. The encoder may create*                  a reference to the frame data (or copy it if the frame is*                  not reference-counted).*                  It can be NULL, in which case it is considered a flush*                  packet.  This signals the end of the stream. If the encoder*                  still has packets buffered, it will return them after this*                  call. Once flushing mode has been entered, additional flush*                  packets are ignored, and sending frames will return*                  AVERROR_EOF.**                  For audio:*                  If AV_CODEC_CAP_VARIABLE_FRAME_SIZE is set, then each frame*                  can have any number of samples.*                  If it is not set, frame->nb_samples must be equal to*                  avctx->frame_size for all frames except the last.*                  The final frame may be smaller than avctx->frame_size.* @retval 0                 success* @retval AVERROR(EAGAIN)   input is not accepted in the current state - user must*                           read output with avcodec_receive_packet() (once all*                           output is read, the packet should be resent, and the*                           call will not fail with EAGAIN).* @retval AVERROR_EOF       the encoder has been flushed, and no new frames can*                           be sent to it* @retval AVERROR(EINVAL)   codec not opened, it is a decoder, or requires flush* @retval AVERROR(ENOMEM)   failed to add packet to internal queue, or similar* @retval "another negative error code" legitimate encoding errors*/
int avcodec_send_frame(AVCodecContext *avctx, const AVFrame *frame);

5.从编码器上下文获得 avpacket

int avcodec_receive_packet(AVCodecContext *avctx, AVPacket *avpkt);

当然在avpacket 的时候,avpacket的空间是需要分配好的。

注意的是1:一帧avframe发送到 解码器上下文,有可能有好几帧avpacket 被解码器上下文 发送出来。

因此在 avcodec_send_frame 调用后,avcodec_receive_packet需要在一个循环中接受 解码器上下文发送出来的 avpacket。循环结束的条件是:avcodec_receive_packet的返回值,注意的是,这个返回值有好几种情况,要分开处理。

注意的是2:另外,循环结束后,还需要通过 avcodec_send_frame 的第二个参数为null,再刷新一下 编码器上下文的缓存。

注意的是3:在循环中,每次通过 avcodec_receive_packet 获得avpacket之后,还应该将avpacket通过 av_packet_unref 将avpacket的引用计数-1,防止内存泄漏。

/*** Read encoded data from the encoder.** @param avctx codec context* @param avpkt This will be set to a reference-counted packet allocated by the*              encoder. Note that the function will always call*              av_packet_unref(avpkt) before doing anything else.* @retval 0               success* @retval AVERROR(EAGAIN) output is not available in the current state - user must*                         try to send input* @retval AVERROR_EOF     the encoder has been fully flushed, and there will be no*                         more output packets* @retval AVERROR(EINVAL) codec not opened, or it is a decoder* @retval "another negative error code" legitimate encoding errors*/
int avcodec_receive_packet(AVCodecContext *avctx, AVPacket *avpkt);

6 代码

#include <iostream>
#include <fstream>
extern "C" {#include "libavcodec/avcodec.h"#include "libavcodec/codec.h"
}
using namespace std;char* yuvfilename = (char *)"400_300_25.yuv";
char* h264filename = (char*)"400_300_25.h264";
ifstream fin;
ofstream fout;AVCodecID codec_id_h264 = AV_CODEC_ID_H264;
AVCodecID codec_id_h265 = AV_CODEC_ID_H265;
AVCodecID codec_id_h265_1 = AV_CODEC_ID_HEVC;
AVCodec* avcodec = nullptr;
AVCodecContext* avcodecContext = nullptr;AVFrame* avframe = nullptr;
AVPacket* avpacket = nullptr;
void freeAndClose();
/***
*
* 目的是从一个YUV文件中,读取YUV数据到AVFrame
* 然后通过 H264编码器将AVFrame 转换成AVPacket
* 将每一帧的AVPacket 直接写入 xxx.h264文件,编码后的数据有带startcode
* h264文件可以通过 VLC 播放器播放,
***/
int main1(int argc, char * argv[]) {cout << "014ChangeAVFrameToAVPakcet start" << endl;int ret = 0;//打开要读取的YUV 文件fin.open(yuvfilename, ios_base::binary);if (!fin) {ret = -1;cout << "open yuv file error yuvfilename = " << yuvfilename << endl;freeAndClose();return ret;}//打开要写入的h264文件fout.open(h264filename, ios_base::binary);if (!fout) {ret = -2;cout << "open h264 file error h264filename = " << h264filename << endl;freeAndClose();return ret;}//1.找到编码器avcodec = avcodec_find_encoder(codec_id_h264);if (avcodec == nullptr) {ret = -3;cout << "avcodec_find_encoder error codec_id_h264 = " << codec_id_h264 << endl;freeAndClose();return ret;}///2. 编码器上下文avcodecContext = avcodec_alloc_context3(avcodec);if (avcodecContext == nullptr) {ret = -3;cout << "avcodec_alloc_context3 error avcodec = " << avcodec->name << endl;freeAndClose();return ret;}///3. 设定编码器上下文的参数,例如视频的宽高,那么这个参数应该是我们要处理的视频的宽高//我们要处理的视频是 400_300_25.yuv///编码的时候,原始的视频是从 摄像头来的,那么也就是说,宽和高我们应该能知道avcodecContext->width = 400;avcodecContext->height = 300;avcodecContext->pix_fmt = AVPixelFormat::AV_PIX_FMT_YUV420P;avcodecContext->time_base = {1,25};avcodecContext->thread_count = 16; //4.打开编码器上下文ret = avcodec_open2(avcodecContext, nullptr, nullptr);if (ret !=0 ) {ret = -4;cout << "avcodec_open2 error  avcodecContext= " << avcodecContext->codec->name << endl;freeAndClose();return ret;}//5.从 YUV 中读取数据到 AVFrame,那么首先要构建AVFrame,让YUV数据有地方放置avframe = av_frame_alloc();if (avframe == nullptr) {ret = -5;cout << "av_frame_alloc error  "  << endl;freeAndClose();return ret;}//5.1 构造 avframe的参数avframe->width = avcodecContext->width;avframe->height = avcodecContext->height;avframe->format = avcodecContext->pix_fmt;//手动的分配 avframe的linesize 和 data的空间大小 start//设置每一行 avframe的大小,还记得YUV420P,每一行的大小是多少吗//avframe->linesize[0] = { avcodecContext->width};//avframe->linesize[1] = { avcodecContext->width /2 };//avframe->linesize[2] = { avcodecContext->width /2 };//创造YUV存放数据的空间,一个avframe放置的就是一张图片的大小,YUV420P的存储是 Y存储在data[0]中,U存储在data[1]中,V存储在data[2]中// YUV420p的大小为 RGB888的一半,Y占1,U占1/4 ,V占1/4.avframe->data[3] = { 0 };avframe->data[0] = new unsigned char[avcodecContext->width * avcodecContext->height];avframe->data[1] = new unsigned char[avcodecContext->width * avcodecContext->height/4];avframe->data[2] = new unsigned char[avcodecContext->width * avcodecContext->height/4];//手动的分配 avframe的linesize 和 data的空间大小 end//获取avframe的空间ret= av_frame_get_buffer(avframe, 0);if (ret <0) {char errbuf[1024] = { 0 };av_strerror(ret, errbuf, sizeof(errbuf) - 1);freeAndClose();return ret;}//手动的分配 AVPacketavpacket = av_packet_alloc();if (avpacket == nullptr) {ret = -6;cout << "av_packet_alloc error  " << endl;freeAndClose();return ret;}//while (!fin.eof()) {if (!av_frame_is_writable(avframe)) {av_frame_make_writable(avframe);}fin.read((char*)avframe->data[0], avcodecContext->width * avcodecContext->height);fin.read((char*)avframe->data[1], avcodecContext->width * avcodecContext->height / 4);fin.read((char*)avframe->data[2], avcodecContext->width * avcodecContext->height / 4);//每次循环时候,理论上 avframe里面已经有了 一张图片的大小,那么下来就需要将这张图片发送给 avcodecContext//注意的是:发送一次avframe,可能收到多次的avpacketret = avcodec_send_frame(avcodecContext, avframe);if (ret != 0) {//说明发送到 编码器的时候就有问题.那么就让继续读取下一帧,也可以直接退出。continue;}if (ret ==0) {//这说明 发送到编码器成功了,那么就要进入一个循环 中获取 avpacketwhile (true) {ret = avcodec_receive_packet(avcodecContext, avpacket);if (ret == AVERROR(EAGAIN) || ret == AVERROR_EOF) {break;}if (ret < 0) {char buf[1024] = { 0 };av_strerror(ret, buf, sizeof(buf) - 1);cerr << "avcodec_receive_packet failed!" << buf << endl;break;}if (ret == 0) {//这时候 说明 编码器中的 avpacket是真的有数据的fout.write((char*)avpacket->data, avpacket->size);av_packet_unref(avpacket);}}}}//刷新ret = avcodec_send_frame(avcodecContext, nullptr);if (ret != 0) {//说明发送到 编码器的时候就有问题.说明没有啥能刷新的cout << "aaa" << endl;}int count = 0;while (ret == 0) {while (true) {ret = avcodec_receive_packet(avcodecContext, avpacket);if (ret == AVERROR(EAGAIN) || ret == AVERROR_EOF) {break;}if (ret < 0) {char buf[1024] = { 0 };av_strerror(ret, buf, sizeof(buf) - 1);cerr << "avcodec_receive_packet failed!" << buf << endl;break;}if (ret == 0) {//这时候 说明 编码器中的 avpacket是真的有数据的count++;fout.write((char*)avpacket->data, avpacket->size);av_packet_unref(avpacket);}}}cout << "count = " << count << endl;freeAndClose();return ret;
}void freeAndClose() {if (!avpacket) {av_packet_free(&avpacket);}if (avframe != nullptr) {int i = 0;while (!avframe->data[i]) {delete avframe->data[i];++i;}}if (avframe != nullptr) {av_frame_free(&avframe);}if (avcodecContext != nullptr) {avcodec_free_context(&avcodecContext);}if (!fout) {fout.close();}if (!fin) {fin.close();}}

7.代码改动,int av_image_get_buffer_size(enum AVPixelFormat pix_fmt, int width, int height, int align); 根据ffmpeg的方法计算一张图片的大小。

前面的代码示例中,我们通过自己分配 avframe->data的空间大小做的,这样是OK的,但是有两个不优秀的地方,

第一是  我们分配的avframe的linesize大小,也是根据不同的 pixfmt要改动。YUV420分配的是:

    avframe->linesize[0] = { avcodecContext->width};
    avframe->linesize[1] = { avcodecContext->width /2 };
    avframe->linesize[2] = { avcodecContext->width /2 };

但是对于其他格式的原始数据,计算方式要改动,因此通用性不强。

第二是代码的通用性不好,YUV420P的图片的大小是    这么计算的

    avframe->data[3] = { 0 };
    avframe->data[0] = new unsigned char[avcodecContext->width * avcodecContext->height];
    avframe->data[1] = new unsigned char[avcodecContext->width * avcodecContext->height/4];
    avframe->data[2] = new unsigned char[avcodecContext->width * avcodecContext->height/4];

但是对于其他格式的原始数据,计算方式要改动,因此通用性不强。

像这样常用的填充 avframe的数据,ffmpeg 已经替我们提供了合适的方法。

根据传递的参数,得到一张图片的大小

 * @param pix_fmt  the pixel format of the image  图片的格式 AVPixelFormat
 * @param width    the width of the image in pixels   图片的宽度
 * @param height   the height of the image in pixels  图片的高度
 * @param align    the assumed linesize alignment   假定的linesize的对齐值: 如果传1,假设这张图片的格式是RGB888(一个像素的大小为 24位,也就是3个字节),则这张图片的大小为  (宽 * 高 * 一个像素的大小)。如果是YUV420P,则是 宽 * 高 * 一个像素的大小(1.5个字节)。
 * @return the buffer size in bytes, a negative error code in case of failure

返回值为 根据 参数 计算出来的这张图片的大小。

/*** Return the size in bytes of the amount of data required to store an* image with the given parameters.** @param pix_fmt  the pixel format of the image* @param width    the width of the image in pixels* @param height   the height of the image in pixels* @param align    the assumed linesize alignment* @return the buffer size in bytes, a negative error code in case of failure*/
int av_image_get_buffer_size(enum AVPixelFormat pix_fmt, int width, int height, int align);

使用 

//先计算出一张图片的大小
int frame_bytes_bufsize = av_image_get_buffer_size((enum AVPixelFormat)frame->format, frame->width,frame->height, 1);//我们在分配对应大小的空间
uint8_t* frame_bytes_buf = (uint8_t*)malloc(frame_bytes_bufsize);//读取YUV文件/或者RGB 文件for (;;) {memset(frame_bytes_buf, 0, frame_bytes_bufsize);size_t read_bytes = fread(frame_bytes_buf, 1, frame_bytes_bufsize, infile);int need_size = av_image_fill_arrays(frame->data, frame->linesize, frame_bytes_buf,(enum AVPixelFormat)frame->format,frame->width, frame->height, 1);///这时候数据已经在 avframe中了///下来处理 avframe 数据
}

8.代码改动 int av_image_fill_arrays(

uint8_t *dst_data[4],

int dst_linesize[4], 

const uint8_t *src,

enum AVPixelFormat pix_fmt,

int width,

int height,

int align);

将第三个参数指针指向的数据,赋值给第一个参数。

那么怎么赋值呢?是根据4,5,6,7参数决定的,因此这里4,5,6,7参数 需要和 av_image_get_buffer_size方法的4个参数一样,不然赋值就有问题了。

这里要注意的是,avframe在这之前的linesize 是按照 通用的方式(一般在32位windows上是按照16位的对齐方式给出的),在这个方法使用后,会根据最后一个参数,重新改动 AVframe的 linesize

/**
 * Setup the data pointers and linesizes based on the specified image
 * parameters and the provided array.
 *
 * The fields of the given image are filled in by using the src
 * address which points to the image data buffer. Depending on the
 * specified pixel format, one or multiple image data pointers and
 * line sizes will be set.  If a planar format is specified, several
 * pointers will be set pointing to the different picture planes and
 * the line sizes of the different planes will be stored in the
 * lines_sizes array. Call with src == NULL to get the required
 * size for the src buffer.
 *
 * To allocate the buffer and fill in the dst_data and dst_linesize in
 * one call, use av_image_alloc().
 *
 * @param dst_data      data pointers to be filled in
 * @param dst_linesize  linesizes for the image in dst_data to be filled in
 * @param src           buffer which will contain or contains the actual image data, can be NULL
 * @param pix_fmt       the pixel format of the image
 * @param width         the width of the image in pixels
 * @param height        the height of the image in pixels
 * @param align         the value used in src for linesize alignment
 * @return the size in bytes required for src, a negative error code
 * in case of failure
 */
int av_image_fill_arrays(uint8_t *dst_data[4], int dst_linesize[4],
                         const uint8_t *src,
                         enum AVPixelFormat pix_fmt, int width, int height, int align);

9.h264/265特殊参数说明

在实际开发中,我们需要在编码速度、网络带宽,视频质量方面做一个权衡,进而选择更符合场景的码控调整方案。下面就说明几种常用的参数

ABR 平均比特率(Average Bit Rate)

(ffmpeg不建议使用,原因是会快速的生成脏编码),但是实际上用的比较多

使用方法:在avcodec_open之前,通过  avcodecContex设置,由于平均比特率是每个编码器都有的参数,因此可以通过 avcodecContex 设置。 avcodecContext->bit_rate = 400000, 注意单位是比特。因此上述设置的 400000,

(Average Bit Rate)恒定平均目标码率,简单场景分配较低bit,复杂场景分配足够bit,使得有限的bit数能够在不同场景下合理分配,这类似VBR。同时一定时间内,平均码率又接近设置的目标码率,这样可以控制输出文件的大小,这又类似CBR。可以认为是CBR和VBR的折中方案,这是大多人的选择。特别在对质量和视频带宽都有要求的情况下,可以优先选择该模式,一般速度是VBR的两倍到三倍,相同体积的视频文件质量却比CBR好很多。

适用场景:ABR在直播和低延时系统用的比较多,因为只编码了一次,所以速度快,同时兼顾了视频质量和带宽,对于转码速度有要求的情况下也可以选择该模式。B站的大部分视频就选择了该模式。

特点:

·视频质量整体可控,同时兼顾了视频码率和速度,是一个折中方案,实际用的比较多;

·使用过程一般要让调用方设置,最低码率、最高码率和平均码率,这些值要尽可能设置合理点;

CQP恒定质量参数Constant Quantization Parameter (CQP)

恒定质量参数Constant Quantization Parameter (CQP)

使用方法:av_opt_set_int(avcodecContext->priv-data,"qp",10,0);

x264和x265 对应的值在 0--51之间,值越大,效果越差。0表示无损编码

x264默认值是23,实际测试值在18时效果较好

x265默认值是28,实际测试值在25时效果较好

固定QP,最简单的码率控制方式,每帧图像都按照一个特定的QP来编码,每帧编码后的数据量有多大是未知的,既不是码率优先模型也不是质量优先模型,不过是实现最简单的模型;

适用场景:一般不建议使用这种方式,因为这种方式不考虑编码内容的复杂性,用相同的压缩比处理每一帧。出来的视频质量码率都不固定。个人觉得只有那种非常简单的场景,比如静止不变的场景运动量很小的场景可以尝试用,一遇到复杂场景,码率波动就非常大。或者在算法研究或者验证可以使用。

特点:

·瞬时码率会随场景复杂度波动;

·编码速度快,调控最简单,每帧的QP值相同;

·x264和x265中支持CQP模式,libvpx不支持;

·H.264中QP范围是[0, 51]。QP值越大表示越大的量化步长,编码视频的质量越低。QP为0表示进行无损编码;

CBR 恒定比特率(Constant Bit Rate)

恒定码率,一定时间范围内比特率基本保持的恒定,属于码率优先模型。不支持mp4,输出文件必须为 MPEG-2TS。

使用方式:

        av_opt_set(avcodecContext->priv-data,"nal-hrd","cbr",0);

        int rate = 600000;

        

适用场景:在有线电视方面用的比较多。一般也不建议使用这种方式,虽然输出的码率总是处于一个稳定值,但是质量不稳定,不能充分有效利用网络带宽,因为这种模型不考虑视频内容的复杂性,把所有视频帧的内容统一对待。但是有些编码软件只支持固定质量或者固定码率方式,有时不得不用。用的时候在允许的带宽范围内尽可能把带宽设置大点,以防止复杂运动场景下视频质量很低,如果设置的不合理,在运动场景下直接就糊的看不成了。

特点:

·码率稳定,但是质量不稳定,带宽有效利用率不高,特别当该值设置不合理,在复杂运动场景下,画面非常模糊,非常影响观看体验;

·但是输出视频码率基本稳定,便于计算视频体积大小;

CRF 恒定速率因子(Constant Rate Factor)

使用方式:

    avcodecContext->rc_max_rate = 800000;
    avcodecContext->rc_buffer_size = 800000 * 2;
    av_opt_set(avcodecContext->priv_data, "crf", "23", 0);

恒定码率系数。把某一个”视觉质量”作为输出目标。通过降低那些耗费码率但是又难以用肉眼察觉的帧(高速运动或者纹理丰富)的质量提升那些静态帧的码率来达到此目的。

特点:帧间QP变化,帧内宏块的QP变化,输出码率未知,各帧输出的视觉质量基本恒定,这种方式相当于固定质量模式+限制码率峰值的方式。

适用场景:适用于对视频质量有一定要求的场合,CRF值可以简单理解为对视频质量期望的一个输出固定值,希望无论是在运动复杂场景下还是在静止简单情况下,都希望有一个稳定的主观视频质量可以选择该模式,该模式是视频质量优先模型。视频质量可以简单理解为视频的清晰度,像素的细腻程度和视频的流畅度。

特点:

·与恒定QP类似,但追求主观感知到的质量恒定,瞬时码率也会随场景复杂度波动,视频帧之间或者内部宏块之间的QP值都不一样;

·对于快速运动或细节丰富的场景会适当增大量化失真(因为人眼不敏感),反之对于静止或平坦区域则减少量化失真;

·CRF是x264和x265的默认码率控制方式,也可用于libvpx;

·CRF值越大视频压缩率越高,但视频质量越低,各codec的CRF取值范围一般[0-51],但是一般默认值x264用23,x265库默认为28;

·如果你不确定要使用什么CRF,从默认值开始,并根据对输出的主观印象进行更改。如果质量没有足够好则较低的CRF。如果文件太大了则选择更高的CRF。更改±6会导致码率大小的一半/两倍左右的变化,±1会导致码率10%左右的变化。

	//在avcodec_open2 函数 open之前设定参数,通过avcodecContext设定的编码器通用的参数avcodecContext->max_b_frames = 0;//设置没有b帧//设定的是h264 特定的参数,则需要通过av_opt_set方法或者 avcodec_open2的第三个参数AVDictionary设定///preset 预设编码器的参数,用于调节编码速度和质量的平衡//preset 的值有 ultrafase,superfast,veryfast,faster,fast,medium,slow,slower,veryslow,placeboav_opt_set(avcodecContext->priv_data, "preset", "ultrafast", 0);if (ret != 0) {///说明 av_opt_set 方法有errorcout << "av_opt_set preset = ultrafast error" << endl;}///tune 参数,表示的是视频的视觉优化,film,animation,grain,stillimage,///https://blog.csdn.net/hunandede/article/details/140054106?sharetype=blogdetail&sharerId=140054106&sharerefer=PC&sharesource=hunandede&spm=1011.2480.3001.8118ret = av_opt_set(avcodecContext->priv_data, "tune", "film", 0);if (ret !=0) {///说明 av_opt_set 方法有errorcout << "av_opt_set tune = film error" << endl;}///设置比特率相关: 比特率 = 视频大小/视频时间///a. ABR 平均比特率,会让整个视频的平均比特率在您设置的范围内。 ffmpeg不建议使用,原因是会快速的生成脏编码。///b. CQP 恒定质量,不确保比特率,只保证稳定质量输出,h264,h265的QP范围从0--51,值越大,效果越差,x264默认值是23,测试设置为18效果好;x265默认值的28,测试这是为25效果好///c. CBR 恒定比特率,这个需求一般在有线电视中应用,由于mp4不支持NAL填充,输出文件必须为mpeg-2ts///d. CRF 恒定速率因子,提供恒定的质量,值也在0-51,CRF和 CQP的区别在于:每一帧会有不同的QP,根据运动情况 降低或者 提高QP/// a. ABR 平均比特率 使用方法, 注意单位是bitavcodecContext->bit_rate = 400000;/// b.CQP 恒定质量,使用方法,h264,h265的QP范围从0--51av_opt_set_int(avcodecContext->priv_data,"qp",10,0);/// c. CBR 恒定比特率 ,使用方法avcodecContext->bit_rate =    600000;avcodecContext->rc_max_rate = 600000;avcodecContext->rc_min_rate = 600000;avcodecContext->rc_buffer_size = 600000 * 2;av_opt_set(avcodecContext->priv_data,"nal_hrd","cbr",0);///d. CRF 恒定速率因子,提供恒定的质量avcodecContext->rc_max_rate = 800000;avcodecContext->rc_buffer_size = 800000 * 2;av_opt_set(avcodecContext->priv_data, "crf", "23", 0);//4.打开编码器上下文ret = avcodec_open2(avcodecContext, nullptr, nullptr);


http://www.mrgr.cn/news/74839.html

相关文章:

  • 2411rust,实现特征
  • RT-DETR融合[TIP2023]DehazeFormer中的SKFusion模块及相关改进思路
  • SHELL作业
  • unity运行状态下移动、旋转、缩放控制模型
  • 【网络云计算】2024第48周-每日【2024/11/20】小测-理论题-计算机网络概述
  • 线性回归 - 最小二乘法
  • 当出现onnx head和转出的tensorrt head output数量不一致时
  • 求职Leetcode题目(16)
  • 如何解决 Android Studio 中三方库依赖无法找到的问题
  • 准确率调整研究中心
  • cpp中vector的push_back和emplace_back精简小结
  • LeetCode【0047】全排列II
  • HarmonyOS基础:选项卡组件(Tabs)
  • PostgreSQL 查看重复索引
  • 第一课-Rust入门
  • 数据结构查找-哈希表(创建+查找+删除)+(C语言代码)
  • Tofu识别跟踪变焦镜头控制接口与协议
  • 云服务器安装mysql8.0(阿里云或者腾讯云都可以)
  • 比高考还严?该地软考报考减少了5420人,工作人员却增加100多人!
  • 如何使用Jupyter
  • 【机器学习chp2】贝叶斯最优分类器、概率密度函数的参数估计、朴素贝叶斯分类器、高斯判别分析。万字超详细分析总结与思考
  • 真的别跟风了!PMP认证原来只对这些人有用...
  • leveldb存储token的简单实现
  • 理解 C++ 中的 `const` 关键字
  • 域名绑定服务器小白教程
  • [刷题]入门1.矩阵转置