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

avi_write_uint32( a, -1 );

avi_write_uint32( a, a->i_width * a->i_height ); avi_write_uint32( a, 0 );

avi_write_uint16( a, a->i_width ); avi_write_uint16( a, a->i_height );

avi_write_fourcc( a, \ avi_write_uint32( a, 4*12 - 8 ); avi_write_uint32( a, 4*12 - 8 ); avi_write_uint32( a, a->i_width ); avi_write_uint32( a, a->i_height ); avi_write_uint16( a, 1 ); avi_write_uint16( a, 24 ); avi_write_fourcc( a, a->fcc );

avi_write_uint32( a, a->i_width * a->i_height ); avi_write_uint32( a, 0 ); avi_write_uint32( a, 0 ); avi_write_uint32( a, 0 ); avi_write_uint32( a, 0 );

avi_write_fourcc( a, \

avi_write_uint32( a, a->i_movi_end > 0 ? a->i_movi_end - a->i_movi + 4: 0xFFFFFFFF ); avi_write_fourcc( a, \}

void avi_write_idx( avi_t *a ) {

avi_write_fourcc( a, \

avi_write_uint32( a, a->i_frame * 16 ); fwrite( a->idx, a->i_frame * 16, 1, a->f ); }

void avi_init( avi_t *a, FILE *f, float f_fps, char fcc[4] ) {

a->f = f;

a->f_fps = f_fps;

memcpy( a->fcc, fcc, 4 ); a->i_width = 0; a->i_height = 0; a->i_frame = 0; a->i_movi = 0; a->i_riff = 0;

a->i_movi_end = 0; a->i_idx_max = 0;

a->idx = NULL;

avi_write_header( a );

a->i_movi = ftell( a->f ); }

static void avi_set_dw( void *_p, uint32_t dw ) {

uint8_t *p = _p;

p[0] = ( dw )&0xff; p[1] = ( dw >> 8 )&0xff; p[2] = ( dw >> 16)&0xff; p[3] = ( dw >> 24)&0xff; }

void avi_write( avi_t *a, vbuf_t *v, int b_key ) {

int64_t i_pos = ftell( a->f );

/* chunk header */

avi_write_fourcc( a, \ avi_write_uint32( a, v->i_data );

fwrite( v->p_data, v->i_data, 1, a->f );

if( v->i_data&0x01 ) {

/* pad */

fputc( 0, a->f ); }

/* Append idx chunk */

if( a->i_idx_max <= a->i_frame ) {

a->i_idx_max += 1000;

a->idx = realloc( a->idx, a->i_idx_max * 16 ); }

memcpy( &a->idx[4*a->i_frame+0], \

avi_set_dw( &a->idx[4*a->i_frame+1], b_key ? AVIIF_KEYFRAME : 0 ); avi_set_dw( &a->idx[4*a->i_frame+2], i_pos ); avi_set_dw( &a->idx[4*a->i_frame+3], v->i_data );

a->i_frame++; }

void avi_end( avi_t *a ) {

a->i_movi_end = ftell( a->f );

/* write index */ avi_write_idx( a );

a->i_riff = ftell( a->f );

/* Fix header */

fseek( a->f, 0, SEEK_SET ); avi_write_header( a );

fprintf( stderr, \

fprintf( stderr, \ - codec: %4.4s\\n\

fprintf( stderr, \ - size: %dx%d\\n\ fprintf( stderr, \ - fps: %.3f\\n\

fprintf( stderr, \ - frames: %d\\n\}

/***************************************************************************** * nal:

*****************************************************************************/ int nal_decode( nal_t *nal, void *p_data, int i_data ) {

uint8_t *src = p_data;

uint8_t *end = &src[i_data]; uint8_t *dst = nal->p_payload;

nal->i_type = src[0]&0x1f; nal->i_ref_idc = (src[0] >> 5)&0x03;

src++;

while( src < end ) {

if( src < end - 3 && src[0] == 0x00 && src[1] == 0x00 && src[2] == 0x03 ) {

*dst++ = 0x00; *dst++ = 0x00;

src += 3; continue; }

*dst++ = *src++; }

//nal->i_payload = dst - (uint8_t*)p_data;//tangxiaojun nal->i_payload = dst - nal->p_payload;//tangxiaojun return 0; }

#include #include #include #include #include #include #include

#define REPLACE_GETOPT

#define _DIAGASSERT(x) do {} while (0)

#ifdef REPLACE_GETOPT #ifdef __weak_alias

__weak_alias(getopt,_getopt) #endif

int opterr = 1; /* if error message should be printed */ int optind = 1; /* index into parent argv vector */ int optopt = '?'; /* character checked for validity */ int optreset; /* reset getopt */

char *optarg; /* argument associated with option */ #endif