ffmpeg编码器支持情况

ffmpeg 音视频编码器需要查看支持才能用否则打不开编码器。

下面代码将展示查看ffmpeg中音频支持声道,采样率,样本情况;视频支持输入yuv格式情况,具体看下面代码。

int audio_support(AVCodec * pCodec,int *channel,int * playout,int *samplePerSec,AVSampleFormat_t * sample_fmt)
{
	//支持的声道
	if(NULL != pCodec->channel_layouts)
	{
		uint64_t layout = av_get_default_channel_layout(*channel);
		if(0 == layout)
		{
			return 0;
		}

		int i = 0;	
		int j = 0;
		while(0 != pCodec->channel_layouts[j])
		{
			printf("pCodec->channel_layouts[j] : %d\n",pCodec->channel_layouts[j]);
			++j;
		}
		while(0 != pCodec->channel_layouts[i])
		{
			if(layout == pCodec->channel_layouts[i])
			{
				break;
			}
			++i;
		}
		//未找到
		if(0 == pCodec->channel_layouts[i])
		{
			*playout = pCodec->channel_layouts[i-1];
			*channel = av_get_channel_layout_nb_channels(*playout);
		}
	}

	//支持的采样率
	if(NULL != pCodec->supported_samplerates)
	{
		int i = 0;
		int j = 0;
		while(0 != pCodec->supported_samplerates[j])
		{
			printf("pCodec->supported_samplerates[j] : %d\n",pCodec->supported_samplerates[j]);
			++j;
		}
		while(0 != pCodec->supported_samplerates[i])
		{
			if(*samplePerSec == pCodec->supported_samplerates[i])
			{
				break;
			}
			++i;
		}
		//未找到
		if(0 == pCodec->supported_samplerates[i])
		{
			*samplePerSec = pCodec->supported_samplerates[i-1];
		}
	}

	//支持的样本
	if(NULL != pCodec->sample_fmts)
	{
		int i = 0;
		int j = 0;
		while(-1 != pCodec->sample_fmts[j])
		{
			printf("pCodec->sample_fmts[j] : %d\n",pCodec->sample_fmts[j]);
			++j;
		}
		while(-1 != pCodec->sample_fmts[i])
		{
			if(*sample_fmt == pCodec->sample_fmts[i])
			{
				break;
			}
			++i;
		}
		//未找到
		if(-1 == pCodec->sample_fmts[i])
		{
			*sample_fmt = (AVSampleFormat_t)pCodec->sample_fmts[i-1];
		}
	}

	return 1;
}

int video_support(AVCodec * pCodec,AVPixelFormat * video_pixelfromat)
{
	//支持的yuv格式
	if(NULL != pCodec->pix_fmts)
	{
		int i = 0;
		int j = 0;
		while(0 != pCodec->pix_fmts[j])
		{
			printf("pCodec->pix_fmts[j] : %d\n",pCodec->pix_fmts[j]);
			++j;
		}
		while(0 != pCodec->pix_fmts[i])
		{
			if(*video_pixelfromat == pCodec->pix_fmts[i])
			{
				break;
			}
			++i;
		}
		//未找到
		if(-1 == pCodec->pix_fmts[i])
		{
			*video_pixelfromat = pCodec->pix_fmts[i-1];
		}
	}
	return 1;
}
输入支持情况如图:

ffmpeg编码器支持情况_第1张图片


上面是音频编码器支持的采样率,样本,以及视频支持的输入yuv格式。

交流请加QQ群:62054820
QQ:379969650



你可能感兴趣的:(ffmpeg编码器支持情况)