mpeg2encoptions.cc

来自「Motion JPEG编解码器源代码」· CC 代码 · 共 555 行 · 第 1/2 页

CC
555
字号
    if( preserve_B && Bgrp_size == 0 )    {		mjpeg_error_exit1("Preserving I/P frame spacing is impossible for still encoding" );    }	if( preserve_B && 		( min_GOP_size % Bgrp_size != 0 ||		  max_GOP_size % Bgrp_size != 0 )		)	{		mjpeg_error("Preserving I/P frame spacing is impossible if min and max GOP sizes are" );		mjpeg_error_exit1("Not both divisible by %d", Bgrp_size );	}	switch( format )	{	case MPEG_FORMAT_SVCD_STILL :	case MPEG_FORMAT_SVCD_NSR :	case MPEG_FORMAT_SVCD : 		if( aspect_ratio != 2 && aspect_ratio != 3 )			mjpeg_error_exit1("SVCD only supports 4:3 and 16:9 aspect ratios");		if( svcd_scan_data )		{			mjpeg_warn( "Generating dummy SVCD scan-data offsets to be filled in by \"vcdimager\"");			mjpeg_warn( "If you're not using vcdimager you may wish to turn this off using -d");		}		break;	}	return nerr;}bool MPEG2EncOptions::SetFormatPresets( const MPEG2EncInVidParams &strm ){    int nerr = 0;    in_img_width = strm.horizontal_size;    in_img_height = strm.vertical_size;	switch( format  )	{	case MPEG_FORMAT_MPEG1 :  /* Generic MPEG1 */		mjpeg_info( "Selecting generic MPEG1 output profile");		if( video_buffer_size == 0 )			video_buffer_size = 46;		if (bitrate == 0)			bitrate = 1151929;		break;	case MPEG_FORMAT_VCD :		mpeg = 1;		bitrate = 1151929;		video_buffer_size = 46;        	preserve_B = true;        	Bgrp_size = 3;        	min_GOP_size = 9;		max_GOP_size = norm == 'n' ? 18 : 15;		mjpeg_info("VCD default options selected");			case MPEG_FORMAT_VCD_NSR : /* VCD format, non-standard rate */		mjpeg_info( "Selecting VCD output profile");		mpeg = 1;		svcd_scan_data = 0;		seq_hdr_every_gop = 1;		if (bitrate == 0)			bitrate = 1151929;		if (video_buffer_size == 0)			video_buffer_size = 46 * bitrate / 1151929;        	if (seq_length_limit == 0 )            		seq_length_limit = 700;        	if (nonvid_bitrate == 0)            		nonvid_bitrate = 230;		break;			case  MPEG_FORMAT_MPEG2 : 		mjpeg_info( "Selecting generic MPEG2 output profile");		mpeg = 2;		if (!force_cbr && quant == 0)			quant = 8;		if (video_buffer_size == 0)			video_buffer_size = 230;		break;	case MPEG_FORMAT_SVCD :		mjpeg_info("SVCD standard settings selected");		if (nonvid_bitrate == 0)		   /* 224 kbps for audio + around 2% of 2788800 bits */		   nonvid_bitrate = 288; 		if (bitrate == 0 || bitrate > 2788800 - nonvid_bitrate * 1000)		   bitrate = 2788800 - nonvid_bitrate * 1000;		max_GOP_size = norm == 'n' ? 18 : 15;		video_buffer_size = 230;	case  MPEG_FORMAT_SVCD_NSR :		/* Non-standard data-rate */		mjpeg_info( "Selecting SVCD output profile");		mpeg = 2;		if (!force_cbr && quant == 0)			quant = 8;		if( svcd_scan_data == -1 )			svcd_scan_data = 1;		if (video_buffer_size == 0)			video_buffer_size = 230;		if( min_GOP_size == -1 )            		min_GOP_size = 9;        	seq_hdr_every_gop = 1;        	if (seq_length_limit == 0)            		seq_length_limit = 700;        	if (nonvid_bitrate == 0)            		nonvid_bitrate = 230;        	break;	case MPEG_FORMAT_VCD_STILL :		mjpeg_info( "Selecting VCD Stills output profile");		mpeg = 1;		quant = 0;	/* We want to try and hit our size target */		/* We choose a generous nominal bit-rate as there's only 		   one frame per sequence ;-).  It *is* too small to fill 		   the frame-buffer in less than one PAL/NTSC frame		   period though...*/		bitrate = 8000000;		/* Now we select normal/hi-resolution based on the input stream		   resolution. 		*/				if( in_img_width == 352 && 			(in_img_height == 240 || in_img_height == 288 ) )		{			/* VCD normal resolution still */			if( still_size == 0 )				still_size = 30*1024;			if( still_size < 20*1024 || still_size > 42*1024 )			{				mjpeg_error_exit1( "VCD normal-resolution stills must be >= 20KB and <= 42KB each");			}			/* VBV delay encoded normally */			vbv_buffer_still_size = 46*1024;			video_buffer_size = 46;			pad_stills_to_vbv_buffer_size = 0;		}		else if( in_img_width == 704 &&				 (in_img_height == 480 || in_img_height == 576) )		{			/* VCD high-resolution stills: only these use vbv_delay			 to encode picture size...			*/			if( still_size == 0 )				still_size = 125*1024;			if( still_size < 46*1024 || still_size > 220*1024 )			{				mjpeg_error_exit1( "VCD normal-resolution stills should be >= 46KB and <= 220KB each");			}			vbv_buffer_still_size = still_size;			video_buffer_size = 224;			pad_stills_to_vbv_buffer_size = 1;					}		else		{			mjpeg_error("VCD normal resolution stills must be 352x288 (PAL) or 352x240 (NTSC)");			mjpeg_error_exit1( "VCD high resolution stills must be 704x576 (PAL) or 704x480 (NTSC)");		}		seq_hdr_every_gop = 1;		seq_end_every_gop = 1;		min_GOP_size = 1;		max_GOP_size = 1;		break;	case MPEG_FORMAT_SVCD_STILL :		mjpeg_info( "Selecting SVCD Stills output profile");		mpeg = 2;		quant = 0;	/* We want to try and hit our size target */		/* We choose a generous nominal bitrate as there's only one 		   frame per sequence ;-). It *is* too small to fill the 		   frame-buffer in less than one PAL/NTSC frame 		   period though...		*/		bitrate = 2500000;		video_buffer_size = 230;		vbv_buffer_still_size = 220*1024;		pad_stills_to_vbv_buffer_size = 0;		/* Now we select normal/hi-resolution based on the input stream		   resolution. 		*/				if( in_img_width == 480 && 			(in_img_height == 480 || in_img_height == 576 ) )		{			mjpeg_info( "SVCD normal-resolution stills selected." );			if( still_size == 0 )				still_size = 90*1024;		}		else if( in_img_width == 704 &&				 (in_img_height == 480 || in_img_height == 576) )		{			mjpeg_info( "SVCD high-resolution stills selected." );			if( still_size == 0 )				still_size = 125*1024;		}		else		{			mjpeg_error("SVCD normal resolution stills must be 480x576 (PAL) or 480x480 (NTSC)");			mjpeg_error_exit1( "SVCD high resolution stills must be 704x576 (PAL) or 704x480 (NTSC)");		}		if( still_size < 30*1024 || still_size > 200*1024 )		{			mjpeg_error_exit1( "SVCD resolution stills must be >= 30KB and <= 200KB each");		}		seq_hdr_every_gop = 1;		seq_end_every_gop = 1;		min_GOP_size = 1;		max_GOP_size = 1;		break;	case MPEG_FORMAT_DVD :	case MPEG_FORMAT_DVD_NAV :		mjpeg_info( "Selecting DVD output profile");		mpeg = 2;		if (bitrate == 0)			bitrate = 7500000;        	if (video_buffer_size == 0)            		video_buffer_size = 230;		if (!force_cbr && quant == 0)			quant = 8;		seq_hdr_every_gop = 1;		break;	}    /*     * At this point the command line arguments have been processed, the format (-f)     * selection has had a chance to set the bitrate.  IF --cbr was used and we     * STILL do not have a bitrate set then declare an error because a Constant     * Bit Rate of 0 makes no sense (most of the time CBR doesn't either ... ;))     */     if (force_cbr && bitrate == 0)        {        nerr++;        mjpeg_error("--cbr used but no bitrate set with -b or -f!");        }    switch( mpeg )    {    case 1 :        if( min_GOP_size == -1 )            min_GOP_size = 12;        if( max_GOP_size == -1 )            max_GOP_size = 12;        break;    case 2:        if( min_GOP_size == -1 )            min_GOP_size = 9;        if( max_GOP_size == -1 )            max_GOP_size = (norm == 'n' ? 18 : 15);        break;    }	if( svcd_scan_data == -1 )		svcd_scan_data = 0;	nerr += InferStreamDataParams(strm);	nerr += CheckBasicConstraints();	return nerr != 0;}/*  * Local variables: *  c-file-style: "stroustrup" *  tab-width: 4 *  indent-tabs-mode: nil * End: */

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?