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

#include #include #include #include

#include #define _GNU_SOURCE #include

#ifdef _MSC_VER

#include /* _setmode() */ #include /* _O_BINARY */ #endif

#include \

#define DATA_MAX 3000000 uint8_t data[DATA_MAX];

/* Ctrl-C handler */

static int i_ctrl_c = 0;

static void SigIntHandler( int a ) {

i_ctrl_c = 1; }

typedef struct {

char *psz_fin; char *psz_fout;

float f_fps; char fcc[4]; } cfg_t;

typedef struct {

int i_data;

int i_data_max; uint8_t *p_data; } vbuf_t;

void vbuf_init( vbuf_t * );

void vbuf_add( vbuf_t *, int i_data, void *p_data ); void vbuf_reset( vbuf_t * );

typedef struct {

FILE *f;

float f_fps; char fcc[4];

int i_width; int i_height;

int64_t i_movi;

int64_t i_movi_end; int64_t i_riff;

int i_frame; int i_idx_max; uint32_t *idx; } avi_t;

void avi_init( avi_t *, FILE *, float, char fcc[4] ); void avi_write( avi_t *, vbuf_t *, int ); void avi_end( avi_t * );

enum nal_unit_type_e {

NAL_UNKNOWN = 0, NAL_SLICE = 1,

NAL_SLICE_DPA = 2, NAL_SLICE_DPB = 3, NAL_SLICE_DPC = 4,

NAL_SLICE_IDR = 5, /* ref_idc != 0 */ NAL_SEI = 6, /* ref_idc == 0 */ NAL_SPS = 7, NAL_PPS = 8

/* ref_idc == 0 for 6,9,10,11,12 */ };

enum nal_priority_e {

NAL_PRIORITY_DISPOSABLE = 0, NAL_PRIORITY_LOW = 1, NAL_PRIORITY_HIGH = 2,

NAL_PRIORITY_HIGHEST = 3, };

typedef struct {

int i_ref_idc; /* nal_priority_e */ int i_type; /* nal_unit_type_e */

/* This data are raw payload */ int i_payload; uint8_t *p_payload; } nal_t;

typedef struct {

int i_width; int i_height;

int i_nal_type; int i_ref_idc; int i_idr_pic_id; int i_frame_num; int i_poc;

int b_key;

int i_log2_max_frame_num; int i_poc_type;

int i_log2_max_poc_lsb; } h264_t;

void h264_parser_init( h264_t * );

void h264_parser_parse( h264_t *h, nal_t *n, int *pb_nal_start );

static int nal_decode( nal_t *nal, void *p_data, int i_data );

static void Help( void );

static int Parse( int argc, char **argv, cfg_t * );

static int ParseNAL( nal_t *nal, avi_t *a, h264_t *h, int *pb_slice );

/**************************************************************************** * main:

****************************************************************************/ int main( int argc, char **argv )

{

cfg_t cfg;

FILE *fout; FILE *fin;

vbuf_t vb; avi_t avi; h264_t h264;

nal_t nal; int i_frame; int i_data; int b_eof; int b_key; int b_slice; int type;//tangxiaojun int i_data2;//tangxiaojun

#ifdef _MSC_VER

_setmode(_fileno(stdin), _O_BINARY); /* thanks to Marcos Morais */

_setmode(_fileno(stdout), _O_BINARY); #endif

/* Parse command line */

if( Parse( argc, argv, &cfg ) < 0 ) {

return -1; }

/* Open input */

if( cfg.psz_fin == NULL || *cfg.psz_fin == '\\0' || !strcmp( cfg.psz_fin, \ fin = stdin; else

fin = fopen( cfg.psz_fin, \ if( fin == NULL ) {

fprintf( stderr, \ return -1; }

/* Open output */

if( cfg.psz_fout == NULL || *cfg.psz_fout == '\\0' || !strcmp( cfg.psz_fout, \