main.cpp

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

CPP
623
字号
			break;		case 'V' :			VBR = true;			break;	  		case 'h' :			always_system_headers = true;			break;		case 'b' :            if( ! ParseVideoOpt( optarg ) )            {                mjpeg_error( "Illegal video decoder buffer size(s): %s",                              optarg );                Usage(argv[0]);            }            break;        case 'L':            if( ! ParseLpcmOpt( optarg ) )            {                mjpeg_error( "Illegal LPCM option(s): %s", optarg );                Usage(argv[0]);            }            break;		case 'r':			data_rate = atoi(optarg);			if( data_rate < 0 )				Usage(argv[0]);			/* Convert from kbit/sec (user spec) to 50B/sec units... */			data_rate = (( data_rate * 1000 / 8 + 49) / 50 ) * 50;			break;		case 'O':			if( ! ParseTimeOffset(optarg) )			{				mjpeg_error( "Time offset units if specified must: ms|s|mpt" );				Usage(argv[0]);			}			break;          		case 'l' :  			max_PTS = atoi(optarg);			if( max_PTS < 1  )				Usage(argv[0]);			break;				case 'p' : 			packets_per_pack = atoi(optarg);			if( packets_per_pack < 1 || packets_per_pack > 100  )				Usage(argv[0]);			break;			  		case 'f' :			mux_format = atoi(optarg);			if( mux_format < MPEG_FORMAT_MPEG1 || mux_format > MPEG_FORMAT_LAST                )				Usage(argv[0]);			break;		case 's' :			sector_size = atoi(optarg);			if( sector_size < 256 || sector_size > 16384 )				Usage(argv[0]);			break;		case 'S' :			max_segment_size = atoi(optarg);			if( max_segment_size < 0  )				Usage(argv[0]);			break;		case 'M' :			multifile_segment = true;			break;        case 'W' :            if( ! ParseWorkaroundOpt( optarg ) )            {                Usage(argv[0]);            }            break;		case '?' :		default :			Usage(argv[0]);			break;		}	}	if (argc - optind < 1 || outfile_pattern == NULL)    {			Usage(argv[0]);    }	(void)mjpeg_default_handler_verbosity(verbose);	mjpeg_info( "mplex version %s (%s %s)",VERSION,MPLEX_VER,MPLEX_DATE );    InputStreamsFromCmdLine( argc-(optind-1), argv+optind-1);}/************************************************************************* Usage banner for the command line wrapper.*************************************************************************/    void CmdLineMultiplexJob::Usage(char *str){    fprintf( stderr,	"mjpegtools mplex-2 version " VERSION " (" MPLEX_VER ")\n"	"Usage: %s [params] -o <output filename pattern> <input file>... \n"	"         %%d in the output file name is by segment count\n"	"  where possible params are:\n"	"--verbose|-v num\n"    "  Level of verbosity. 0 = quiet, 1 = normal 2 = verbose/debug\n"	"--format|-f fmt\n"    "  Set defaults for particular MPEG profiles\n"	"  [0 = Generic MPEG1, 1 = VCD, 2 = user-rate VCD, 3 = Generic MPEG2,\n"    "   4 = SVCD, 5 = user-rate SVCD\n"	"   6 = VCD Stills, 7 = SVCD Stills, 8 = DVD with NAV sectors, 9 = DVD]\n"    "--mux-bitrate|-r num\n"    "  Specify data rate of output stream in kbit/sec\n"	"    (default 0=Compute from source streams)\n"	"--video-buffer|-b num [, num...] \n"    "  Specifies decoder buffers size in kB.  [ 20...2000]\n"    "--lpcm-params | -L samppersec:chan:bits [, samppersec:chan:bits]\n"	"--mux-limit|-l num\n"    "  Multiplex only num seconds of material (default 0=multiplex all)\n"	"--sync-offset|-O num ms|s|mpt\n"    "  Specify offset of timestamps (video-audio) in mSec\n"	"--sector-size|-s num\n"    "  Specify sector size in bytes for generic formats [256..16384]\n"    "--vbr|-V\n"    "  Multiplex variable bit-rate video\n"	"--packets-per-pack|-p num\n"    "  Number of packets per pack generic formats [1..100]\n"	"--system-headers|-h\n"    "  Create System header in every pack in generic formats\n"	"--max-segment-size|-S size\n"    "  Maximum size of output file(s) in Mbyte (default: 0) (no limit)\n"	"--ignore-seqend-markers|-M\n"    "  Don't switch to a new output file if a  sequence end marker\n"	"  is encountered ithe input video.\n"    "--workaround|-W workaround [, workaround ]\n"	"--help|-?\n"    "  Print this lot out!\n", str);	exit (1);}bool CmdLineMultiplexJob::ParseLpcmOpt( const char *optarg ){    char *endptr, *startptr;    unsigned int samples_sec;    unsigned int channels;    unsigned int bits_sample;    endptr = const_cast<char *>(optarg);    do     {        startptr = endptr;        samples_sec = static_cast<unsigned int>(strtol(startptr, &endptr, 10));        if( startptr == endptr || *endptr != ':' )            return false;        startptr = endptr+1;        channels = static_cast<unsigned int>(strtol(startptr, &endptr, 10));        if(startptr == endptr || *endptr != ':' )            return false;        startptr = endptr+1;        bits_sample = static_cast<unsigned int>(strtol(startptr, &endptr, 10));        if( startptr == endptr )            return false;        LpcmParams *params = LpcmParams::Checked( samples_sec,                                                  channels,                                                  bits_sample );        if( params == 0 )            return false;        lpcm_param.push_back(params);        if( *endptr == ',' )            ++endptr;    } while( *endptr != '\0' );    return true;}bool CmdLineMultiplexJob::ParseWorkaroundOpt( const char *optarg ){    char *endptr, *startptr;    endptr = const_cast<char *>(optarg);    struct { const char *longname; char shortname; bool *flag; } flag_table[] =        {            { 0, '\0', 0 }        };    for(;;)    {        // Find start of next flag...        while( isspace(*endptr) || *endptr == ',' )            ++endptr;        if( *endptr == '\0' )            break;        startptr = endptr;        // Find end of current flag...        while( *endptr != ' ' && *endptr != ',' && *endptr != '\0' )            ++endptr;                    size_t len = endptr - startptr;        int flag = 0;        while( flag_table[flag].longname != 0 )        {            if( (len == 1 && *startptr == flag_table[flag].shortname ) ||                strncmp( startptr, flag_table[flag].longname, len ) == 0 )            {                *flag_table[flag].flag = true;                break;            }            ++flag;        }        if( flag_table[flag].longname == 0 )        {            std::string message( "Illegal work-around option: not one of " );            flag = 0;            char sep[] = ",";            do            {                message += flag_table[flag].longname;                message += sep;                message += flag_table[flag].shortname;                ++flag;                if( flag_table[flag].longname != 0 )                    message += sep;            }            while( flag_table[flag].longname != 0 );            mjpeg_error( message.c_str() );            return false;        }    }     return true;}bool CmdLineMultiplexJob::ParseVideoOpt( const char *optarg ){    char *endptr, *startptr;    unsigned int buffer_size;    endptr = const_cast<char *>(optarg);    do     {        startptr = endptr;        buffer_size = static_cast<unsigned int>(strtol(startptr, &endptr, 10));        if( startptr == endptr )            return false;        VideoParams *params = VideoParams::Checked( buffer_size );        if( params == 0 )            return false;        video_param.push_back(params);        if( *endptr == ',' )            ++endptr;    }     while( *endptr != '\0' );    return true;}bool CmdLineMultiplexJob::ParseTimeOffset(const char *optarg){    double f;    double persecond=1000.0;    char *e;    f=strtod(optarg,&e);    if( *e ) {        while(isspace(*e)) e++;        if(!strcmp(e,"ms")) persecond=1000.0;        else if(!strcmp(e,"s")) persecond=1.0;        else if(!strcmp(e,"mpt")) persecond=90000.0;		else			return false;    }    video_offset = static_cast<int>(f*CLOCKS/(persecond));	if( video_offset < 0 )	{		audio_offset = - video_offset;		video_offset = 0;	}	return true;}void CmdLineMultiplexJob::InputStreamsFromCmdLine(unsigned int argc, char* argv[] ){	vector<IBitStream *> inputs;    unsigned int i;	for( i = 1; i < argc; ++i )    {		inputs.push_back( new IFileBitStream( argv[i] ) );	}	SetupInputStreams( inputs );}int main (int argc, char* argv[]){	CmdLineMultiplexJob job(argc,argv);	FileOutputStream output( job.outfile_pattern );	Multiplexor mux(job, output);	mux.Multiplex();    return (0);	}			

⌨️ 快捷键说明

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