📄 lavaddwav.c
字号:
mjpeg_error("Error reading WAV file %s :%s", chWavFile, strerror(errno)); close(*wav_fd); return 0; } /* Make endian safe */ data[0] = reorder_32(data[0], big_endian); data[2] = reorder_32(data[2], big_endian); data[3] = reorder_32(data[3], big_endian); data[4] = reorder_32(data[4], big_endian); if( data[0] != FOURCC_RIFF || data[2] != FOURCC_WAVE || data[3] != FOURCC_FMT || data[4] > sizeof(data) ) { mjpeg_error("Error in WAV header of %s", chWavFile); close(*wav_fd); return 0; } fmtlen = data[4]; n = read(*wav_fd, (char*)data, fmtlen); if( n !=fmtlen ) { perror("open_wav_file"); close(*wav_fd); return 0; } /* Make endian safe */ data[0] = reorder_32(data[0], big_endian); data[1] = reorder_32(data[1], big_endian); data[3] = reorder_32(data[3], big_endian); if( (data[0]&0xffff) != 1 ) { mjpeg_error("WAV file is not in PCM format %s", chWavFile); close(*wav_fd); return 0; } if( iscan ) { strncpy(ap[ientry]->chFileName, chWavFile, MAX_FILE_NAME); ap[ientry]->audio_chans = (data[0]>>16) & 0xffff; ap[ientry]->audio_rate = data[1]; ap[ientry]->audio_bits = (data[3]>>16) & 0xffff; ap[ientry]->audio_bps = (ap[ientry]->audio_chans * ap[ientry]->audio_bits + 7) / 8; if( ap[ientry]->audio_bps == 0 ) { ap[ientry]->audio_bps = 1; } /* safety first */ } n = read(*wav_fd,(char*)data,8); if( n != 8 ) { mjpeg_error("Read WAV header %s :%s", chWavFile, strerror(errno)); close(*wav_fd); return 0; } /* Make endian safe */ data[0] = reorder_32(data[0], big_endian); data[1] = reorder_32(data[1], big_endian); if( data[0] != FOURCC_DATA ) { mjpeg_error("Error in WAV header %s", chWavFile); close(*wav_fd); return 0; } if( iscan ) { /* check length of Wav file - update structure with correct length */ cur_off = lseek(*wav_fd, 0, SEEK_CUR); cur_end = lseek(*wav_fd, 0, SEEK_END); if( (long)(cur_end - cur_off) != data[1] ) { mjpeg_warn("Repairing data length mismatch with WAV header %s", chWavFile); data[1] = (long)(cur_end - cur_off); } cur_off = lseek(*wav_fd, cur_off, SEEK_SET); ap[ientry]->data_length = data[1]; ap[ientry]->audio_samps = data[1] / ap[ientry]->audio_bps; ap[ientry]->time_length = (double)ap[ientry]->audio_samps / (double)ap[ientry]->audio_rate; } /* success */ return 1;}/********************************************************************/int count_list_entries(char *chFile){ FILE *fp; int ientries = 0; char chformat[10]; char chtmp[MAX_FILE_NAME+1] = "\0"; sprintf(chformat, "%%%ds",MAX_FILE_NAME); fp = fopen(chFile, "rt"); if( fp == NULL ) { mjpeg_error("Unable to open file list %s", chFile); return 0; } while( fscanf(fp, chformat, chtmp) == 1) { ientries++; } fclose(fp); /* return the number of entries */ return ientries;}/********************************************************************/int fill_video_list_entries(char *chFile){ FILE *fp; int ientry = 0; char chformat[10]; char chtmp[MAX_FILE_NAME+1] = "\0"; lav_file_t *lav_tmp = NULL; sprintf(chformat, "%%%ds",MAX_FILE_NAME); fp = fopen(chFile, "rt"); if( fp == NULL ) { mjpeg_error("Unable to open video file list %s", chFile); return 0; } while( fscanf(fp, chformat, chtmp) == 1) { if( !open_lav_file(&lav_tmp, chtmp, ientry, 1) ) { fclose(fp); return 0; } display_video_params(ientry); ientry++; lav_close(lav_tmp); } fclose(fp); return 1;}/********************************************************************/int fill_audio_list_entries(char *chFile){ FILE *fp; int ientry = 0; char chformat[10]; char chtmp[MAX_FILE_NAME+1] = "\0"; int wav_tmp; sprintf(chformat, "%%%ds",MAX_FILE_NAME); fp = fopen(chFile, "rt"); if( fp == NULL ) { mjpeg_error("Unable to open audio file list %s", chFile); return 0; } while( fscanf(fp, chformat, chtmp) == 1) { if( !open_wav_file(&wav_tmp, chtmp, ientry, 1) ) { fclose(fp); return 0; } display_audio_params(ientry); ientry++; close(wav_tmp); } fclose(fp); return 1;}/********************************************************************/void display_video_params(int ientry){ mjpeg_debug("File: %s", vp[ientry]->chFileName); mjpeg_debug(" format: %8c", vp[ientry]->format); mjpeg_debug(" frames: %8ld", vp[ientry]->video_frames); mjpeg_debug(" width: %8d", vp[ientry]->width); mjpeg_debug(" height: %8d", vp[ientry]->height); mjpeg_debug(" interlacing: %8d", vp[ientry]->interlacing); mjpeg_debug(" frames/sec: %8.3f", vp[ientry]->fps); mjpeg_debug(" duration: %8.3f sec", vp[ientry]->time_length); mjpeg_debug(" ");}/********************************************************************/void display_audio_params(int ientry){ mjpeg_debug("File: %s", ap[ientry]->chFileName); mjpeg_debug(" audio samps: %8ld", ap[ientry]->audio_samps); mjpeg_debug(" audio chans: %8d", ap[ientry]->audio_chans); mjpeg_debug(" audio bits: %8d", ap[ientry]->audio_bits); mjpeg_debug(" audio rate: %8ld", ap[ientry]->audio_rate); mjpeg_debug(" duration: %8.3f sec",(double)ap[ientry]->audio_samps/(double)ap[ientry]->audio_rate); mjpeg_debug(" ");}/********************************************************************/int allocate_video_memory(int ientries){ int i; /* allocate memory for array of pointers */ vp = malloc(ientries * sizeof(videoparams *)); if( vp == NULL ) { mjpeg_error("Unable to allocate memory for video file list structure array"); return 0; } memset(vp, 0 , ientries * sizeof(videoparams*)); /* allocate memory for each structure */ for(i=0; i<ientries; i++) { vp[i] = malloc(sizeof(videoparams)); if( vp[i] == NULL ) { mjpeg_error("Unable to allocate memory for video file list structures"); return 0; } memset(vp[i], 0 , sizeof(videoparams)); } return 1;}/********************************************************************/int allocate_audio_memory(int ientries){ int i; /* allocate memory for array of pointers */ ap = malloc(ientries * sizeof(audioparams *)); if( ap == NULL ) { mjpeg_error("Unable to allocate memory for audio file list structure array"); return 0; } memset(ap, 0 , ientries * sizeof(audioparams*)); /* allocate memory for each structure */ for(i=0; i<ientries; i++) { ap[i] = malloc(sizeof(audioparams)); if( ap[i] == NULL ) { mjpeg_error("Unable to allocate memory for audio file list structures"); return 0; } memset(ap[i], 0 , sizeof(audioparams)); } return 1;}/********************************************************************/void free_video_memory(int ientries){ int i; if( vp == NULL ) { return; } for(i=0; i<ientries; i++) { if( vp[i] != NULL ) { free(vp[i]); } } free(vp); vp = NULL;}/********************************************************************/void free_audio_memory(int ientries){ int i; if( ap == NULL ) { return; } for(i=0; i<ientries; i++) { if( ap[i] != NULL ) { free(ap[i]); } } free(ap); ap = NULL;}/********************************************************************/int compare_input_files(int iVidEntries, int iAudEntries){ int i; /* compare video files */ for(i=0; i<iVidEntries; i++) { if( (vp[0]->format != vp[i]->format) || (vp[0]->width != vp[i]->width) || (vp[0]->height != vp[i]->height) || (vp[0]->interlacing != vp[i]->interlacing) || (vp[0]->fps != vp[i]->fps) ) { /* mismatch */ return 0; } } /* compare audio files */ for(i=0; i<iAudEntries; i++) { if( (ap[0]->audio_chans != ap[i]->audio_chans) || (ap[0]->audio_bits != ap[i]->audio_bits) || (ap[0]->audio_rate != ap[i]->audio_rate) ) { /* mismatch */ return 0; } } /* file formats match */ return 1;}/********************************************************************/long find_max_frame_size(int ientries){ int i; long max_frame_size = vp[0]->max_frame_size; for(i=0; i<ientries; i++) { if( max_frame_size < vp[i]->max_frame_size ) { max_frame_size = vp[i]->max_frame_size; } } return max_frame_size;}/********************************************************************/int detect_endian (void){ unsigned int fred; char *pfred; /* The endian detection based on that in lavtrans */ fred = 2 | (1 << (sizeof(int)*8-8)); pfred = (char *)&fred; if(*pfred == 1) { mjpeg_info("System is big endian"); return 1; } else if(*pfred == 2) { mjpeg_info("System is little endian"); return 0; } else { mjpeg_error("Cannot determine if system is big or little endian"); return -1; }}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -