对于不同的编解码器有不同的AV_CODEC_ID_XX的,用avcodec_find_encoder就可以,但是对于一个ID对应多个编解码器的就不行了,
比如aac,faac,fdk_aac,此时需要用avcodec_find_encoder_by_name查找对应的编解码器。当然,可以只编译一个aac,那么默认的就是你编译的那个
/**
* 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.
*/
AVCodec *avcodec_find_encoder(enum AVCodecID id);
/**
* Find a registered encoder with the specified name.
*
* @param name name of the requested encoder
* @return An encoder if one was found, NULL otherwise.
*/
AVCodec *avcodec_find_encoder_by_name(const char *name);
附上源码:
AVCodec *avcodec_find_encoder(enum AVCodecID id)
{
return find_encdec(id, 1);
}
AVCodec *avcodec_find_encoder_bAVCodec *avcodec_find_encoder_by_name(const char *name)
{
AVCodec *p;
if (!name)
return NULL;
p = first_avcodec;
while (p) {
if (av_codec_is_encoder(p) && strcmp(name, p->name) == 0)
return p;
p = p->next;
}
return NULL;
}