注意:请先记得make distclean一下
1、只需要在libavcodec目录操作即可,编写编码器源代码
#include "avcodec.h"
typedef struct myself_ctx {
int index;
}myself_ctx;
static const AVClass myself_class = {
.class_name = "myself decoder",
.item_name = av_default_item_name,
.version = LIBAVUTIL_VERSION_INT,
};
static av_cold int myself_decoder_init(AVCodecContext *avctx)
{
return 0;
}
static int myself_decoder_frame(AVCodecContext *avctx,void *data,int *got_frame_ptr,AVPacket *avpkt)
{
return 0;
}
AVCodec ff_myself_decoder = {
.name="myself",
.long_name="myself decoder",
.type=AVMEDIA_TYPE_AUDIO,
.priv_data_size=sizeof(myself_ctx),
.id=AV_CODEC_ID_MYSELF,
.init=myself_decoder_init,
.decode=myself_decoder_frame,
.capabilities=AV_CODEC_CAP_DR1,
.priv_class=&myself_class,
};
2、在code_id.h中的AVCodecID中添加编码器ID,找到相应的音频块(AAC为例)或者视频块(H264为例)
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_MYSELF,
3、在codec_desc.h描述文件中添加描述
{
.id = AV_CODEC_ID_ADPCM_G722,
.type = AVMEDIA_TYPE_AUDIO,
.name = "adpcm_g722",
.long_name = NULL_IF_CONFIG_SMALL("G.722 ADPCM"),
.props = AV_CODEC_PROP_INTRA_ONLY | AV_CODEC_PROP_LOSSY,
},
{
.id = AV_CODEC_ID_MYSELF,
.type = AVMEDIA_TYPE_AUDIO,
.name = "myself",
.long_name = NULL_IF_CONFIG_SMALL("myself decoder"),
.props = AV_CODEC_PROP_INTRA_ONLY | AV_CODEC_PROP_LOSSY,
},
4、在allcodec.c文件中加入ff_myself_decoder的声明
extern AVCodec ff_vp9_vaapi_encoder;
extern AVCodec ff_vp9_qsv_encoder;
extern AVCodec ff_myself_decoder;
5、添加编译文件
OBJS-$(CONFIG_G729_DECODER) += g729dec.o lsp.o celp_math.o celp_filters.o acelp_filters.o acelp_pitch_dela
y.o acelp_vectors.o g729postfilter.o
OBJS-$(CONFIG_MYSELF_DECODER) += myselfdec.o
OBJS-$(CONFIG_GDV_DECODER) += gdv.o
6、通过configure查看编码器是否有myself的编码器
7、make完成后通过ffmpeg -coders查看是否添加成功