h264转avi,编译通过源码 下载本文

cfg->psz_fin = NULL; cfg->psz_fout = NULL; cfg->f_fps = 25.0;

memcpy( cfg->fcc, \

/* Parse command line options */ opterr = 0; // no error message for( ;; ) {

int long_options_index;

static struct option long_options[] = {

{ \ no_argument, NULL, 'h' }, { \ required_argument, NULL, 'i' }, { \ { \ required_argument, NULL, 'f' }, { \ required_argument, NULL, 'c' }, {0, 0, 0, 0} };

int c;

c = getopt_long( argc, argv, \

long_options, &long_options_index);

if( c == -1 ) {

break; }

switch( c ) {

case 'h': Help(); return -1;

case 0: break; case 'i':

cfg->psz_fin = strdup( optarg ); break; case 'o':

cfg->psz_fout = strdup( optarg ); break;

case 'f':

cfg->f_fps = atof( optarg ); break; case 'c':

memset( cfg->fcc, ' ', 4 );

memcpy( cfg->fcc, optarg, strlen( optarg ) < 4 ? strlen( optarg ) : 4 ); break;

default:

fprintf( stderr, \ return -1; } }

return 0; }

/***************************************************************************** * h264_parser_*:

*****************************************************************************/ void h264_parser_init( h264_t *h ) {

h->i_width = 0; h->i_height = 0; h->b_key = 0;

h->i_nal_type = -1; h->i_ref_idc = -1; h->i_idr_pic_id = -1; h->i_frame_num = -1;

h->i_log2_max_frame_num = 0; h->i_poc = -1;

h->i_poc_type = -1; }

void h264_parser_parse( h264_t *h, nal_t *nal, int *pb_nal_start ) {

bs_t s;

*pb_nal_start = 0;

if( nal->i_type == NAL_SPS || nal->i_type == NAL_PPS ) *pb_nal_start = 1;

bs_init( &s, nal->p_payload, nal->i_payload ); if( nal->i_type == NAL_SPS )

{

int i_tmp;

i_tmp = bs_read( &s, 8 ); bs_skip( &s, 1+1+1 + 5 + 8 ); /* sps id */

bs_read_ue( &s );

if( i_tmp >= 100 ) {

bs_read_ue( &s ); // chroma_format_idc bs_read_ue( &s ); // bit_depth_luma_minus8 bs_read_ue( &s ); // bit_depth_chroma_minus8

bs_skip( &s, 1 ); // qpprime_y_zero_transform_bypass_flag if( bs_read( &s, 1 ) ) // seq_scaling_matrix_present_flag {

int i, j;

for( i = 0; i < 8; i++ ) {

if( bs_read( &s, 1 ) ) // seq_scaling_list_present_flag[i] {

uint8_t i_tmp = 8;

for( j = 0; j < (i<6?16:64); j++ ) {

i_tmp += bs_read_se( &s ); if( i_tmp == 0 ) break; } } } } }

/* Skip i_log2_max_frame_num */

h->i_log2_max_frame_num = bs_read_ue( &s ) + 4; /* Read poc_type */

h->i_poc_type = bs_read_ue( &s ); if( h->i_poc_type == 0 ) {

h->i_log2_max_poc_lsb = bs_read_ue( &s ) + 4; }

else if( h->i_poc_type == 1 ) {

int i_cycle;

/* skip b_delta_pic_order_always_zero */ bs_skip( &s, 1 );

/* skip i_offset_for_non_ref_pic */ bs_read_se( &s );

/* skip i_offset_for_top_to_bottom_field */ bs_read_se( &s );

/* read i_num_ref_frames_in_poc_cycle */ i_cycle = bs_read_ue( &s ); if( i_cycle > 256 ) i_cycle = 256; while( i_cycle > 0 ) {

/* skip i_offset_for_ref_frame */ bs_read_se(&s ); } }

/* i_num_ref_frames */ bs_read_ue( &s );

/* b_gaps_in_frame_num_value_allowed */ bs_skip( &s, 1 );

/* Read size */

h->i_width = 16 * ( bs_read_ue( &s ) + 1 ); h->i_height = 16 * ( bs_read_ue( &s ) + 1 );

/* b_frame_mbs_only */ i_tmp = bs_read( &s, 1 ); if( i_tmp == 0 ) {

bs_skip( &s, 1 ); }

/* b_direct8x8_inference */ bs_skip( &s, 1 );

/* crop ? */

i_tmp = bs_read( &s, 1 ); if( i_tmp ) {

/* left */

h->i_width -= 2 * bs_read_ue( &s ); /* right */

h->i_width -= 2 * bs_read_ue( &s ); /* top */

h->i_height -= 2 * bs_read_ue( &s ); /* bottom */