FFMPEG学习----遍历所支持的解码器

下面简单介绍一下遍历ffmpeg中的解码器信息的方法(这些解码器以一个链表的形式存储):

1.注册所有编解码器:av_register_all();

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

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

/**
 * If c is NULL, returns the first registered codec,
 * if c is non-NULL, returns the next registered codec after c,
 * or NULL if c is the last one.
 */

int main(void)
{
	char *info = (char *)malloc(40000);
	memset(info, 0, 40000);

	av_register_all();

	AVCodec *c_temp = av_codec_next(NULL);

	while (c_temp != NULL)
	{
		if (c_temp->decode != NULL)
		{
			strcat(info, "[Decode]");
		}
		else
		{
			strcat(info, "[Encode]");
		}
		switch (c_temp->type)
		{
		case AVMEDIA_TYPE_VIDEO:
			strcat(info, "[Video]");
			break;
		case AVMEDIA_TYPE_AUDIO:
			strcat(info, "[Audeo]");
			break;
		default:
			strcat(info, "[Other]");
			break;
		}
		sprintf(info, "%s %10s
", info, c_temp->name);
		c_temp = c_temp->next;
	}
	puts(info);
	free(info);
	return 0;
}


.....

[Decode][Video]     libvpx
[Encode][Video] libvpx-vp9
[Decode][Video] libvpx-vp9
[Encode][Audeo] libwavpack
[Encode][Video]    libwebp
[Encode][Video]    libx264
[Encode][Video] libx264rgb
[Encode][Video]    libx265
[Encode][Video]    libxavs
[Encode][Video]    libxvid
[Decode][Video]    bintext
[Decode][Video]       xbin
[Decode][Video]        idf
[Encode][Video]   h264_qsv
[Encode][Video]   hevc_qsv
[Encode][Video]  mpeg2_qsv

Keep it simple!
作者:N3verL4nd
知识共享,欢迎转载。
原文地址:https://www.cnblogs.com/lgh1992314/p/5834657.html