mpeg2encoptions.cc

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

CC
555
字号
/* mpeg2encoptions.cc - Encoder control parameter class   *//* (C) 2000/2001/2003 Andrew Stevens, Rainer Johanni *//* This software is free software; you can redistribute it *  and/or modify it under the terms of the GNU General Public License *  as published by the Free Software Foundation; either version 2 of *  the License, or (at your option) any later version. * *  This program is distributed in the hope that it will be useful, *  but WITHOUT ANY WARRANTY; without even the implied warranty of *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU *  General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA * 02111-1307, USA. * */#include <config.h>#include "format_codes.h"#include "mpegconsts.h"#include "mpeg2encoder.hh"MPEG2EncOptions::MPEG2EncOptions(){    // Parameters initialised to -1 indicate a format-dependent    // or stream inferred default.    format = MPEG_FORMAT_MPEG1;    bitrate    = 0;    nonvid_bitrate = 0;    quant      = 0;    searchrad  = 16;    mpeg       = 1;    aspect_ratio = 0;    frame_rate  = 0;    fieldenc   = -1; /* 0: progressive, 1 = frame pictures,                        interlace frames with field MC and DCT                        in picture 2 = field pictures                     */    norm       = 0;  /* 'n': NTSC, 'p': PAL, 's': SECAM, else unspecified */    rate_control = 0;    me44_red	= 2;    me22_red	= 3;	    hf_quant = 0;    hf_q_boost = 0.0;    act_boost = 0.0;    boost_var_ceil = 10*10;    video_buffer_size = 0;    seq_length_limit = 0;    min_GOP_size = -1;    max_GOP_size = -1;    closed_GOPs = 0;    preserve_B = 0;    Bgrp_size = 1;/* * Set the default to 0 until this error:     INFO: [mpeg2enc] Signaling last frame = 499     mpeg2enc: seqencoder.cc:433: void SeqEncoder::EncodeStream(): Assertion `pass1coded.size() == 0' failed.     Abort * Is fixed.*/    num_cpus = 0;    vid32_pulldown = 0;    svcd_scan_data = -1;    seq_hdr_every_gop = 0;    seq_end_every_gop = 0;    still_size = 0;    pad_stills_to_vbv_buffer_size = 0;    vbv_buffer_still_size = 0;    force_interlacing = Y4M_UNKNOWN;    input_interlacing = Y4M_UNKNOWN;    mpeg2_dc_prec = 1;    ignore_constraints = 0;    unit_coeff_elim = 0;    force_cbr = 0;    verbose = 1;    hack_svcd_hds_bug = 1;    hack_altscan_bug = 0;    /* dual prime Disabled by default. --dualprime-mpeg2 to enable (set to 1) */    hack_dualprime = 0;    force_cbr = 0;};static int infer_mpeg1_aspect_code( char norm, mpeg_aspect_code_t mpeg2_code ){	switch( mpeg2_code )	{	case 1 :					/* 1:1 */		return 1;	case 2 :					/* 4:3 */		if( norm == 'p' || norm == 's' )			return 8;	    else if( norm == 'n' )			return 12;		else 			return 0;	case 3 :					/* 16:9 */		if( norm == 'p' || norm == 's' )			return 3;	    else if( norm == 'n' )			return 6;		else			return 0;	default :		return 0;				/* Unknown */	}} int MPEG2EncOptions::InferStreamDataParams( const MPEG2EncInVidParams &strm){	int nerr = 0;	/* Infer norm, aspect ratios and frame_rate if not specified */	if( frame_rate == 0 )	{		if(strm.frame_rate_code<1 || strm.frame_rate_code>8)		{			mjpeg_error("Input stream with unknown frame-rate and no frame-rate specified with -a!");			++nerr;		}		else			frame_rate = strm.frame_rate_code;	}	if( norm == 0 && (strm.frame_rate_code==3 || strm.frame_rate_code == 2) )	{		mjpeg_info("Assuming norm PAL");		norm = 'p';	}	if( norm == 0 && (strm.frame_rate_code==4 || strm.frame_rate_code == 1) )	{		mjpeg_info("Assuming norm NTSC");		norm = 'n';	}	if( frame_rate != 0 )	{		if( strm.frame_rate_code != frame_rate &&             mpeg_valid_framerate_code(strm.frame_rate_code) )		{			mjpeg_warn( "Specified display frame-rate %3.2f will over-ride", 						Y4M_RATIO_DBL(mpeg_framerate(frame_rate)));			mjpeg_warn( "(different!) frame-rate %3.2f of the input stream",						Y4M_RATIO_DBL(mpeg_framerate(strm.frame_rate_code)));		}	}	if( aspect_ratio == 0 )	{		aspect_ratio = strm.aspect_ratio_code;	}	if( aspect_ratio == 0 )	{		mjpeg_warn( "No aspect ratio specifed and no guess possible: assuming 4:3 display aspect!");		aspect_ratio = 2;	}	/* Convert to MPEG1 coding if we're generating MPEG1 */	if( mpeg == 1 )	{		aspect_ratio = infer_mpeg1_aspect_code( norm, aspect_ratio );	}    input_interlacing = strm.interlacing_code;    if (input_interlacing == Y4M_UNKNOWN) {        mjpeg_warn("Unknown input interlacing; assuming progressive.");        input_interlacing = Y4M_ILACE_NONE;    }    /* 'fieldenc' is dependent on input stream interlacing:         a) Interlaced streams are subsampled _per_field_;             progressive streams are subsampled over whole frame.         b) 'fieldenc' sets/clears the MPEG2 'progressive-frame' flag,            which tells decoder how subsampling was performed.    */    if (fieldenc == -1) {        /* not set yet... so set fieldenc from input interlacing */        switch (input_interlacing) {        case Y4M_ILACE_TOP_FIRST:        case Y4M_ILACE_BOTTOM_FIRST:            fieldenc = 1; /* interlaced frames */            mjpeg_info("Interlaced input - selecting interlaced encoding.");            break;        case Y4M_ILACE_NONE:            fieldenc = 0; /* progressive frames */            mjpeg_info("Progressive input - selecting progressive encoding.");            break;        default:            mjpeg_warn("Unknown input interlacing; assuming progressive.");            fieldenc = 0;            break;        }    } else {        /* fieldenc has been set already... so double-check for user */        switch (input_interlacing) {        case Y4M_ILACE_TOP_FIRST:        case Y4M_ILACE_BOTTOM_FIRST:            if (fieldenc == 0) {                mjpeg_warn("Progressive encoding selected with interlaced input!");                mjpeg_warn("  (This will damage the chroma channels.)");            }            break;        case Y4M_ILACE_NONE:            if (fieldenc != 0) {                mjpeg_warn("Interlaced encoding selected with progressive input!");                mjpeg_warn("  (This will damage the chroma channels.)");            }            break;        }    }	return nerr;}int MPEG2EncOptions::CheckBasicConstraints(){	int nerr = 0;	if( vid32_pulldown )	{		if( mpeg == 1 )			mjpeg_error_exit1( "MPEG-1 cannot encode 3:2 pulldown (for transcoding to VCD set 24fps)!" );		if( frame_rate != 4 && frame_rate != 5  )		{			if( frame_rate == 1 || frame_rate == 2 )			{				frame_rate += 3;				mjpeg_warn("3:2 movie pulldown with frame rate set to decode rate not display rate");				mjpeg_warn("3:2 Setting frame rate code to display rate = %d (%2.3f fps)", 						   frame_rate,						   Y4M_RATIO_DBL(mpeg_framerate(frame_rate)));			}			else			{				mjpeg_error( "3:2 movie pulldown not sensible for %2.3f fps dispay rate",							Y4M_RATIO_DBL(mpeg_framerate(frame_rate)));				++nerr;			}		}		if( fieldenc == 2 )		{			mjpeg_error( "3:2 pulldown only possible for frame pictures (-I 1 or -I 0)");			++nerr;		}	}	    if ((mpeg == 1) && (fieldenc != 0)) {        mjpeg_error("Interlaced encoding (-I != 0) is not supported by MPEG-1.");        ++nerr;    }	if(  !mpeg_valid_aspect_code(mpeg, aspect_ratio) )	{		mjpeg_error("For MPEG-%d, aspect ratio code  %d is illegal", 					mpeg, aspect_ratio);		++nerr;	}			if( min_GOP_size > max_GOP_size )	{		mjpeg_error( "Min GOP size must be <= Max GOP size" );		++nerr;	}

⌨️ 快捷键说明

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