⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 mpeg2enc.cc

📁 Motion JPEG编解码器源代码
💻 CC
📖 第 1 页 / 共 2 页
字号:
"    Force setting of playback field order to bottom or top first\n""--multi-thread|-M num\n""    Activate multi-threading to optimise throughput on a system with num CPU's\n""    [0..32], 0=no multithreading, (default: 0)\n""--correct-svcd-hds|-C\n""    Force SVCD horizontal_display_size to be 480 - standards say 540 or 720\n""    But many DVD/SVCD players screw up with these values.\n""--no-constraints\n""    Deactivate constraints for maximum video resolution and sample rate.\n""    Could expose bugs in the software at very high resolutions!\n""--no-altscan-mpeg2\n""    Deactivate the use of the alternate block pattern for MPEG-2.  This is\n""    A work-around for a Bug in an obscure hardware decoder.\n""--dualprime-mpeg2\n""    Turn ON use of dual-prime motion compensation. Default is OFF unless this option is used\n""--custom-quant-matrices|-K kvcd|tmpgenc|default|hi-res|file=inputfile|help\n""    Request custom or userspecified (from a file) quantization matrices\n""--unit-coeff-elim|-E num\n""    Skip picture blocks which appear to carry little information\n""    because they code to only unit coefficients. The number specifies\n""    how aggresively this should be done. A negative value means DC\n""    coefficients are included.  Reasonable values -40 to 40\n""--b-per-refframe| -R 0|1|2\n""    The number of B frames to generate between each I/P frame\n""--cbr|-u\n""    For MPEG-2 force the use of (suboptimal) ConstantBitRate (CBR) encoding\n""--help|-?\n""    Print this lot out!\n"	);	exit(0);}void MPEG2EncCmdLineOptions::StartupBanner(){	mjpeg_info("Encoding MPEG-%d video to %s",mpeg, outfilename);	mjpeg_info("Horizontal size: %d pel",in_img_width);	mjpeg_info("Vertical size: %d pel",in_img_height);	mjpeg_info("Aspect ratio code: %d = %s",                aspect_ratio,               mpeg_aspect_code_definition(mpeg,aspect_ratio));	mjpeg_info("Frame rate code:   %d = %s",               frame_rate,               mpeg_framerate_code_definition(frame_rate));	if(bitrate) 		mjpeg_info("Bitrate: %d KBit/s",bitrate/1000);	else		mjpeg_info( "Bitrate: VCD");	if(quant) 		mjpeg_info("Quality factor: %d (Quantisation = %.0f) (1=best, 31=worst)",                   quant,                    RateCtl::InvScaleQuant( mpeg == 1 ? 0 : 1, quant)            );	mjpeg_info("Field order for input: %s", 			   mpeg_interlace_code_definition(input_interlacing) );	if( seq_length_limit )	{		mjpeg_info( "New Sequence every %d Mbytes", seq_length_limit );		mjpeg_info( "Assuming non-video stream of %d Kbps", nonvid_bitrate );	}	else		mjpeg_info( "Sequence unlimited length" );	mjpeg_info("Search radius: %d",searchrad);	if (mpeg == 2)           {           mjpeg_info("DualPrime: %s", hack_dualprime == 1 ? "yes" : "no");           }}int MPEG2EncCmdLineOptions::SetFromCmdLine( int argc,	char *argv[] ){    int n;    int nerr = 0;    static const char	short_options[]=        "m:a:f:n:b:z:T:B:q:o:S:I:r:M:4:2:A:Q:X:D:g:G:v:V:F:N:tpdsZHOcCPK:E:R:";#ifdef HAVE_GETOPT_LONG    static struct option long_options[]={        { "verbose",           1, 0, 'v' },        { "format",            1, 0, 'f' },        { "aspect",            1, 0, 'a' },        { "frame-rate",        1, 0, 'F' },        { "video-bitrate",     1, 0, 'b' },        { "nonvideo-bitrate",  1, 0, 'B' },        { "intra_dc_prec",     1, 0, 'D' },        { "quantisation",      1, 0, 'q' },        { "output",            1, 0, 'o' },        { "target-still-size", 1, 0, 'T' },        { "interlace-mode",    1, 0, 'I' },        { "motion-search-radius", 1, 0, 'r'},        { "reduction-4x4",  1, 0, '4'},        { "reduction-2x2",  1, 0, '2'},        { "min-gop-size",      1, 0, 'g'},        { "max-gop-size",      1, 0, 'G'},        { "closed-gop",        0, 0, 'c'},        { "force-b-b-p", 0, &preserve_B, 1},        { "ratecontroller", 1, 0, 'A' },        { "quantisation-reduction", 1, 0, 'Q' },        { "quant-reduction-max-var", 1, 0, 'X' },        { "video-buffer",      1, 0, 'V' },        { "video-norm",        1, 0, 'n' },        { "sequence-length",   1, 0, 'S' },        { "3-2-pulldown",      0, &vid32_pulldown, 'p'},        { "keep-hf",           0, 0, 'H' },        { "reduce-hf",         1, 0, 'N' },        { "sequence-header-every-gop", 0, &seq_hdr_every_gop, 1},        { "no-dummy-svcd-SOF", 0, &svcd_scan_data, 0 },        { "correct-svcd-hds", 0, &hack_svcd_hds_bug, 0},        { "no-constraints", 0, &ignore_constraints, 1},        { "no-altscan-mpeg2", 0, &hack_altscan_bug, 1},        { "dualprime-mpeg2", 0, &hack_dualprime, 1},        { "playback-field-order", 1, 0, 'z'},        { "multi-thread",      1, 0, 'M' },        { "custom-quant-matrices", 1, 0, 'K'},        { "unit-coeff-elim",   1, 0, 'E'},        { "b-per-refframe",    1, 0, 'R' },	    { "cbr",               0, 0, 'u'},        { "help",              0, 0, '?' },        { 0,                   0, 0, 0 }    };    while( (n=getopt_long(argc,argv,short_options,long_options, NULL)) != -1 )#else    while( (n=getopt(argc,argv,short_options)) != -1)#endif	{		switch(n) {        case 0 :                /* Flag setting handled by getopt-long */            break;		case 'b':			bitrate = atoi(optarg)*1000;			break;		case 'T' :			still_size = atoi(optarg)*1024;			if( still_size < 20*1024 || still_size > 500*1024 )			{				mjpeg_error( "-T requires arg 20..500" );				++nerr;			}			break;		case 'B':			nonvid_bitrate = atoi(optarg);			if( nonvid_bitrate < 0 )			{				mjpeg_error("-B requires arg > 0");				++nerr;			}			break;        case 'D':            mpeg2_dc_prec = atoi(optarg)-8;            if( mpeg2_dc_prec < 0 || mpeg2_dc_prec > 3 )            {                mjpeg_error( "-D requires arg [8..11]" );                ++nerr;            }            break;        case 'C':            hack_svcd_hds_bug = 0;            break;		case 'q':			quant = atoi(optarg);			if(quant<1 || quant>32)			{				mjpeg_error("-q option requires arg 1 .. 32");				++nerr;			}			break;        case 'a' :			aspect_ratio = atoi(optarg);            if( aspect_ratio == 0 )				DisplayAspectRatios();			/* Checking has to come later once MPEG 1/2 has been selected...*/			if( aspect_ratio < 0 )			{				mjpeg_error( "-a option must be positive");				++nerr;			}			break;       case 'F' :			frame_rate = atoi(optarg);            if( frame_rate == 0 )				DisplayFrameRates();			if( !mpeg_valid_framerate_code(frame_rate) )			{                mjpeg_error( "illegal -F value (use -F 0 to list options)" );				++nerr;			}			break;		case 'o':			outfilename = optarg;			break;		case 'I':			fieldenc = atoi(optarg);			if( fieldenc < 0 || fieldenc > 2 )			{				mjpeg_error("-I option requires 0,1 or 2");				++nerr;			}			break;		case 'r':			searchrad = atoi(optarg);			if(searchrad<0 || searchrad>32)			{				mjpeg_error("-r option requires arg 0 .. 32");				++nerr;			}			break;		case 'M':			num_cpus = atoi(optarg);			if(num_cpus<0 || num_cpus>32)			{				mjpeg_error("-M option requires arg 0..32");				++nerr;			}			break;		case '4':			me44_red = atoi(optarg);			if(me44_red<0 || me44_red>4)			{				mjpeg_error("-4 option requires arg 0..4");				++nerr;			}			break;					case '2':			me22_red = atoi(optarg);			if(me22_red<0 || me22_red>4)			{				mjpeg_error("-2 option requires arg 0..4");				++nerr;			}			break;		case 'v':			verbose = atoi(optarg);			if( verbose < 0 || verbose > 2 )				++nerr;			break;		case 'V' :			video_buffer_size = atoi(optarg);			if(video_buffer_size<20 || video_buffer_size>4000)			{				mjpeg_error("-v option requires arg 20..4000");				++nerr;			}			break;		case 'S' :			seq_length_limit = atoi(optarg);			if(seq_length_limit<1 )			{				mjpeg_error("-S option requires arg > 1");				++nerr;			}			break;		case 'p' :			vid32_pulldown = 1;			break;		case 'z' :			if( strlen(optarg) != 1 || (optarg[0] != 't' && optarg[0] != 'b' ) )			{				mjpeg_error("-z option requires arg b or t" );				++nerr;			}			else if( optarg[0] == 't' )				force_interlacing = Y4M_ILACE_TOP_FIRST;			else if( optarg[0] == 'b' )				force_interlacing = Y4M_ILACE_BOTTOM_FIRST;			break;		case 'f' :			format = atoi(optarg);			if( format < MPEG_FORMAT_FIRST ||				format > MPEG_FORMAT_LAST )			{				mjpeg_error("-f option requires arg [%d..%d]", 							MPEG_FORMAT_FIRST, MPEG_FORMAT_LAST);				++nerr;			}							break;		case 'n' :			switch( optarg[0] )			{			case 'p' :			case 'n' :			case 's' :				norm = optarg[0];				break;			default :				mjpeg_error("-n option requires arg n or p, or s.");				++nerr;			}			break;		case 'g' :			min_GOP_size = atoi(optarg);			break;		case 'G' :			max_GOP_size = atoi(optarg);			break;        	case 'c' :            		closed_GOPs = true;            		break;		case 'P' :			preserve_B = true;			break;		case 'N':            hf_q_boost = atof(optarg);            if (hf_q_boost <0.0 || hf_q_boost > 2.0)            {                mjpeg_error( "-N option requires arg 0.0 .. 2.0" );                ++nerr;                hf_q_boost = 0.0;            }			if (hf_quant == 0 && hf_q_boost != 0.0)			   hf_quant = 1;			break;		case 'H':			hf_quant = 2;            		break;		case 'K':			ParseCustomOption(optarg);			break;        case 'u':		    force_cbr = 1;    		break;        case 'E':            unit_coeff_elim = atoi(optarg);            if (unit_coeff_elim < -40 || unit_coeff_elim > 40)            {                mjpeg_error( "-E option range arg -40 to 40" );                ++nerr;            }            break;        case 'R' :            Bgrp_size = atoi(optarg)+1;            if( Bgrp_size<1 || Bgrp_size>3)            {                mjpeg_error( "-R option arg 0|1|2" );                ++nerr;            }            break;		case 's' :			seq_hdr_every_gop = 1;			break;		case 'd' :			svcd_scan_data = 0;			break;		case 'A' :			rate_control = atoi(optarg);			if( rate_control < 0 || rate_control > 1 )			{				mjpeg_error( "-A option requires arg [0,1]");				++nerr;			}			break;		case 'Q' :			act_boost = atof(optarg);			if( act_boost < 0.0 || act_boost > 4.0)			{				mjpeg_error( "-Q option requires arg 0.0 .. 4.0");				++nerr;			}			break;		case 'X' :			boost_var_ceil = atof(optarg);			if( boost_var_ceil <0 || boost_var_ceil > 50*50 )			{				mjpeg_error( "-X option requires arg 0 .. 2500" );				++nerr;			}			break;		case ':' :			mjpeg_error( "Missing parameter to option!" );		case '?':		default:			++nerr;		}	}	/* Select input stream */	if(optind!=argc)	{		if( optind == argc-1 )		{			istrm_fd = open( argv[optind], O_RDONLY );			if( istrm_fd < 0 )			{				mjpeg_error( "Unable to open: %s: ",argv[optind] );				perror("");				++nerr;			}		}		else			++nerr;	}	else		istrm_fd = 0; /* stdin */	if(!outfilename)	{		mjpeg_error("Output file name (-o option) is required!");		++nerr;	}/*  * Probably not necessary but err on the safe side.  If someone wants to * waste space by using a Constant Bit Rate stream then disable the '-q' * parameter.  Further checks for CBR are made in mpeg2encoptions.cc */    if (force_cbr != 0)       quant = 0;    return nerr;}class YUV4MPEGEncoder : public MPEG2Encoder{public:    YUV4MPEGEncoder( MPEG2EncCmdLineOptions &options );    void Encode();};YUV4MPEGEncoder::YUV4MPEGEncoder( MPEG2EncCmdLineOptions &cmd_options ) :    MPEG2Encoder( cmd_options ){    reader = new Y4MPipeReader( parms, cmd_options.istrm_fd );    MPEG2EncInVidParams strm;	reader->StreamPictureParams(strm);	cmd_options.SetFormatPresets( strm );    cmd_options.StartupBanner();    writer = new FILE_StrmWriter( parms, cmd_options.outfilename );    quantizer = new Quantizer( parms );        if( cmd_options.rate_control == 0 )    {        mjpeg_info( "Using one-pass rate controller" );        bitrate_controller = new OnTheFlyRateCtl( parms );    }    /* TODONOW    else     {        mjpeg_info( "Using Pass1 rate controller" );        bitrate_controller = new Pass1RateCtl( parms );    }    */    seqencoder = new SeqEncoder( parms, *reader, *quantizer,                                 *writer, *bitrate_controller);    // This order is important! Don't change...    parms.Init( options );    reader->Init();    quantizer->Init();    seqencoder->Init();}void YUV4MPEGEncoder::Encode( ){    bool more;    seqencoder->EncodeStream();    //while( seqencoder->EncodeFrame() );}int main( int argc,	char *argv[] ){	/* Set up error logging.  The initial handling level is LOG_INFO	 */    MPEG2EncCmdLineOptions options;	mjpeg_default_handler_verbosity(options.verbose);    if( options.SetFromCmdLine( argc, argv ) != 0 )		options.Usage();	mjpeg_default_handler_verbosity(options.verbose);    YUV4MPEGEncoder encoder( options );    encoder.Encode();#ifdef OUTPUT_STAT	if( statfile != NULL )		fclose(statfile);#endif#ifdef ALTIVEC_BENCHMARK	print_benchmark_statistics();#endif	return 0;}/*  * Local variables: *  c-file-style: "stroustrup" *  tab-width: 4 *  indent-tabs-mode: nil * End: */

⌨️ 快捷键说明

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