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

本章附件是一个清华大学写的关于avs编解码器:
https://download.csdn.net/download/weixin_43360707/87793302
该编码器遵循了stuffing bit:
一个有趣的avs编码器(注意,是avs,而不是avs2噢)_第1张图片

打开文件夹后,如下:
一个有趣的avs编码器(注意,是avs,而不是avs2噢)_第2张图片

可以看出这个是个跨平台的工程,提供了windows vs2015的工程文件sln,以及linux的makefile,因为本次我们考虑的是avs encoder,所以进入到lencod:
一个有趣的avs编码器(注意,是avs,而不是avs2噢)_第3张图片
看到里面有个makefile,这个就是我们的makefile文件。
我们执行

make

结果出现下面错误:
一个有趣的avs编码器(注意,是avs,而不是avs2噢)_第4张图片
我们进入到文件fast_me.c中,删除PartCalMad前面的inline
一个有趣的avs编码器(注意,是avs,而不是avs2噢)_第5张图片
重新编译,通过,在bin目录下看到如下:
一个有趣的avs编码器(注意,是avs,而不是avs2噢)_第6张图片
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"

一个有趣的avs编码器(注意,是avs,而不是avs2噢)_第7张图片
然后执行:
lencod.exe -f encoder.cfg就可以正常编码了:
一个有趣的avs编码器(注意,是avs,而不是avs2噢)_第8张图片
用mediainfo查看编码后的视频:
一个有趣的avs编码器(注意,是avs,而不是avs2噢)_第9张图片
对于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);
		}
	}
	
}

你可能感兴趣的:(音视频资料,windows)