一个有趣的avs编码器(注意,是avs,而不是avs2噢)

本章附件是一个清华大学写的关于avs编解码器:
https://download.csdn.net/download/weixin_43360707/87793302
该编码器遵循了stuffing bit:
在这里插入图片描述

打开文件夹后,如下:
在这里插入图片描述

可以看出这个是个跨平台的工程,提供了windows vs2015的工程文件sln,以及linux的makefile,因为本次我们考虑的是avs encoder,所以进入到lencod:
在这里插入图片描述
看到里面有个makefile,这个就是我们的makefile文件。
我们执行

make

结果出现下面错误:
在这里插入图片描述
我们进入到文件fast_me.c中,删除PartCalMad前面的inline
在这里插入图片描述
重新编译,通过,在bin目录下看到如下:
在这里插入图片描述
lencod.exe就是我们要的编码器。
打开encoder.cfg文件,修改:

InputFile              = "/workspace/encoder/libx264_640x360_baseline_5_frames-420.yuv" # Input sequence, YUV 4:2:0/4:2:2
SourceWidth            = 640         # Image width  in Pels
SourceHeight           = 360         # Image height in Pels
TraceFile              = "trace_enc.txt"
ReconFile              = "test_rec.yuv"
OutputFile             = "test-cai.avs"

在这里插入图片描述
然后执行:
lencod.exe -f encoder.cfg就可以正常编码了:
蔡振成_Zhencheng > 一个有趣的avs编码器(注意,是avs,而不是avs2噢) > image2023-5-17_16-51-48.png
用mediainfo查看编码后的视频:
蔡振成_Zhencheng > 一个有趣的avs编码器(注意,是avs,而不是avs2噢) > image2023-5-17_16-52-43.png
对于avs 1的尺寸,有下列严格要求:

/*
*************************************************************************
* Function:Checks the validity of input parameters in the specified level
* Input:
* Output:
* Return: 
* Attention:
* Author:  LiShao, Tsinghua, 20070327
*************************************************************************
*/
static void LevelCheck()
{
	float framerate[8]={24000/1001,24,25,30000/1001,30,50,60000/1001,60};
	if(input->frame_rate_code<1||input->frame_rate_code>8)
		{
			printf("\n Undefined frame_rate in all levels. \n");
			exit(0);
		}
	switch (input->level_id)
	{
	case 0x10:
	case 0x11: //rm52k
		{
			if(input->img_width>352)
			{
				printf("\n Image Width exceeds level 2.0 restriction.\n");
				exit(-1);
			}
			else 
				if(input->img_height>288)
					{
						printf("\n Image height exceeds level 2.0 restriction.\n");
						exit(-1);
					}
				else
					{
						if(input->frame_rate_code>5)
						{
							printf("\n Current frame_rate is not support in Level_2.0 .\n");
							exit(-1);
						}
						else 
						{
							if((long)(input->img_width)*(long)(input->img_height)*(framerate[input->frame_rate_code-1])>2534400)
							{
								printf("\n Luma Sampling Rate invalid for level 2.0.\n");
								exit(-1);
							}
						}
					}
						
			if((long)(input->img_width)*(long)(input->img_height)/256>396)
			{
				printf("\n The number of macroblock per frame exceeds 396 in level 2.0.\n");
				exit(-1);
			}
			
			if((long)(input->img_width)*(long)(input->img_height)*framerate[input->frame_rate_code-1]/256>11880)
			{
				printf(" \n The number of macroblock per second exceeds 11880 in level 2.0.\n");
				exit(-1);
			}
			
			if(input->chroma_format!=1)
			{
				printf("\n In level 2.0 only format 4:2:0 is supported.\n");
				exit(-1);
			}

			//rm52k
			if(input->level_id==0x10 && input->bbv_buffer_size>122880)
			{
				printf("\n Invalid Bbv_Buffer_Size input.\n");
				exit(-1);
			}

			if(input->level_id==0x11 && input->bbv_buffer_size>311296)
			{
				printf("\n Invalid Bbv_Buffer_Size input.\n");
				exit(-1);
			}
			//rm52k

			break;  
		}

	case 0x20:
		{
			if(input->img_width>720)
			{
				printf("\n Image Width exceeds level 4.0's restriction.\n");
				exit(-1);
			}
			else 
				if(input->img_height>576)
					{
						printf("\n Imgage Height exceeds level 4.0's restriction.\n");
						exit(-1);
					}
				else
					{
						if(input->frame_rate_code>5)
						{
							printf("\n Current frame_rate is not support in Level_4.0 .\n");
							exit(-1);
						}
						else
						{
							if((long)(input->img_width)*(long)(input->img_height)*(long)(framerate[input->frame_rate_code-1])>10368000)
							{
								printf("\n Luma Sampling Rate invalid for level 4.0.\n");
								exit(-1);
							}		
						}
					}
		
			if((long)(input->img_width)*(long)(input->img_height)/256>4050)
			{
				printf(" \n The number of macroblock per frame exceeds 1,620 for Level_4.0.\n");
				exit(-1);
			}
			
			if((long)(input->img_width)*(long)(input->img_height)*framerate[input->frame_rate_code-1]/256>40500)
			{
				printf(" \n The number of macroblock per second exceeds 40500 in Level_4.0.\n");
				exit(-1);
			}
			
			if(input->chroma_format!=1)
			{
				printf("\n In level 4.0 only format 4:2:0 is supported.\n");
				exit(-1);
			}

			if(input->bbv_buffer_size>1228800)  //rm52k
			{
				printf("\n Invalid Bbv_Buffer_Size input.\n");
				exit(-1);
			}

			break;
		}

		case 0x22:
		{
			if(input->img_width>720)
			{
				printf("\n Imgage Width exceeds level 4.2's restriction.\n");
				exit(-1);
			}
			else 
				if(input->img_height>576)
					{
						printf("\n Image Height exceeds level 4.2's restriction.\n");
						exit(-1);
					}
				else
					{
						if(input->frame_rate_code>5)
						{
							printf("\n Current frame_rate is not support in Level_4.2 .\n");
							exit(-1);
						}
						else
						{
							if((long)(input->img_width)*(long)(input->img_height)*(long)(framerate[input->frame_rate_code-1])>10368000)
							{
								printf("\n Luma Sampling Rate invalid for level 4.2.\n");
								exit(-1);
							}
						}
					}
			if((long)(input->img_width)*(long)(input->img_height)/256>1620)
			{
				printf(" \n The number of macroblock per frame exceeds 1,620 for Level_4.2.\n");
				exit(-1);
			}
			
			if((long)(input->img_width)*(long)(input->img_height)*framerate[input->frame_rate_code-1]/256>40500)
			{
				printf(" \n The number of macroblock per second exceeds 40500 in Level_4.2.\n");
				exit(-1);
			}
			
			if(input->chroma_format!=1&&input->chroma_format!=2)
			{
				printf("\n In level 4.2 only format 4:2:0 and 4:2:2 are supported.\n");
				exit(-1);
			}

			if(input->bbv_buffer_size>1851392)  //rm52k
			{
				printf("\n Invalid Bbv_Buffer_Size input.\n");
				exit(-1);
			}

			break;
		}

	case 0x40:
	case 0x41:  //rm52k
		{
			if(input->img_width>1920)
			{
				printf("\n Imgage Width exceeds level 6.0's restriction.\n");
				exit(-1);
			}
			else 
				if(input->img_height>1152)
					{
						printf("\n Image Height exceeds level 6.0's restriction.\n");
						exit(-1);
					}
				else
					{
						if((long)(input->img_width)*(long)(input->img_height)*(long)(framerate[input->frame_rate_code-1])>62668800)
							{
								printf("\n Luma Sampling Rate invalid for level 6.0.\n");
								exit(-1);
							}
					}	
			
			if((long)(input->img_width)*(long)(input->img_height)/256>8160)
			{
				printf(" \n The number of macroblock per frame exceeds 8160 for Level_6.0.\n");
				exit(-1);
			}
			
			if((long)(input->img_width)*(long)(input->img_height)*framerate[input->frame_rate_code-1]/256>244800)
			{
				printf(" \n The number of macroblock per second exceeds 244800 in Level_6.0.\n");
				exit(-1);
			}
			
			if(input->chroma_format!=1)
			{
				printf("\n In level 6.0 only format 4:2:0 is supported.\n");
				exit(-1);
			}

			//rm52k
			if(input->level_id==0x40 && input->bbv_buffer_size>2457600) 
			{
				printf("\n Invalid Bbv_Buffer_Size input.\n");
				exit(-1);
			}

			if(input->level_id==0x41 && input->bbv_buffer_size>6144000) 
			{
				printf("\n Invalid Bbv_Buffer_Size input.\n");
				exit(-1);
			}
			//rm52k

			break; 
		}		
	
	case 0x42:
		{
			if(input->img_width>1920)
			{
				printf("\n Imgage Width exceeds level 6.2's restriction.\n");
				exit(-1);
			}
			else 
				if(input->img_height>1152)
					{
						printf("\n Imgage Height exceeds level 6.2's restriction.\n");
						exit(-1);
					}
				else
					{
						if((long)(input->img_width)*(long)(input->img_height)*(long)(framerate[input->frame_rate_code-1])>62668800)
							{
								printf("\n Luma Sampling Rate invalid for level 6.2.\n");
								exit(-1);
							}
					}
			
			if((long)(input->img_width)*(long)(input->img_height)/256>8160)
			{
				printf(" \n The number of macroblock per frame exceeds 8160 for Level_6.2.\n");
				exit(-1);
			}
			
			if((long)(input->img_width)*(long)(input->img_height)*framerate[input->frame_rate_code-1]/256>244800)
			{
				printf(" \n The number of macroblock per second exceeds 244800 in Level_6.2.\n");
				exit(-1);
			}
			
			if(input->chroma_format!=1&&input->chroma_format!=2)
			{
				printf("\n In level 6.2 only format 4:2:0 and 4:2:2 are supported.\n");
				exit(-1);
			}

			if(input->bbv_buffer_size>3686400)  //rm52k
			{
				printf("\n Invalid Bbv_Buffer_Size input.\n");
				exit(-1);
			}

			break;
		}

	default: 
		{
		printf("\n No such level_ID. \n");
		exit(-1);
		}
	}
	
}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值