diff -uprN lavtools.orig/lavaddwav.c lavtools/lavaddwav.c --- lavtools.orig/lavaddwav.c 2005-04-16 14:36:52.000000000 +0200 +++ lavtools/lavaddwav.c 2005-04-16 14:46:18.000000000 +0200 @@ -155,7 +155,7 @@ int main(int argc, char **argv) } lav_out = lav_open_output_file(argv[3], - lav_filetype(lav_fd), + lav_fd->format, lav_video_width (lav_fd), lav_video_height(lav_fd), lav_video_interlacing(lav_fd), diff -uprN lavtools.orig/lav_io.c lavtools/lav_io.c --- lavtools.orig/lav_io.c 2005-04-16 14:36:52.000000000 +0200 +++ lavtools/lav_io.c 2005-04-16 14:37:48.000000000 +0200 @@ -36,7 +36,8 @@ #endif #ifdef HAVE_LIBQUICKTIME -#include +#include +#include #endif extern int AVI_errno; @@ -275,8 +276,9 @@ lav_file_t *lav_open_output_file(char *f int asize, int achans, long arate) { lav_file_t *lav_fd = (lav_file_t*) malloc(sizeof(lav_file_t)); + char *extension, *tempfile; - if(lav_fd==0) { internal_error=ERROR_MALLOC; return 0; } + if (lav_fd == 0) { internal_error=ERROR_MALLOC; return 0; } /* Set lav_fd */ @@ -284,35 +286,49 @@ lav_file_t *lav_open_output_file(char *f lav_fd->qt_fd = 0; lav_fd->format = format; /* Sanity check: do not create a quicktime file that is named with .avi */ - if(rindex(filename, '.') != NULL) + extension = rindex(filename, '.'); + if (extension != NULL) { - if((format == 'a' || format == 'A') && strcmp(rindex(filename, '.')+1, "avi")) { - internal_error = ERROR_FORMAT; - return 0; - } - if(format == 'q' && (strcmp(rindex(filename, '.')+1, "qt") - && strcmp(rindex(filename, '.')+1, "mov") && strcmp(rindex(filename, '.')+1,"moov"))) { - internal_error = ERROR_FORMAT; - return 0; - } - if(format == 'j' && strcmp(rindex(filename, '.')+1, "jpg") - && strcmp(rindex(filename, '.')+1, "jpeg")) { - internal_error = ERROR_FORMAT; - return 0; - } + extension++; + switch(format) + { + case 'a': + case 'A': + if (strcmp(extension, "avi") && strcmp(extension, "AVI")) + { + internal_error = ERROR_FORMAT; + return 0; + } + break; + case 'q': + if (strcmp(extension, "qt") && strcmp(extension, "QT") && + strcmp(extension, "mov") && strcmp(extension, "MOV") && + strcmp(extension,"moov") && strcmp(extension,"MOOV")) + { + internal_error = ERROR_FORMAT; + return 0; + } + break; + case 'j': + if (strcmp(extension, "jpg") && strcmp(extension, "jpg") && + strcmp(extension,"jpeg") && strcmp(extension,"JPEG")) + { + internal_error = ERROR_FORMAT; + return 0; + } + break; + } } lav_fd->interlacing = interlaced ? lav_query_polarity(format) : LAV_NOT_INTERLACED; lav_fd->has_audio = (asize>0 && achans>0); lav_fd->bps = (asize*achans+7)/8; - lav_fd->is_MJPG = 1; lav_fd->MJPG_chroma = CHROMAUNKNOWN; switch(format) { case 'a': case 'A': - /* Open AVI output file */ lav_fd->avi_fd = AVI_open_output_file(filename); @@ -321,21 +337,22 @@ lav_file_t *lav_open_output_file(char *f if (asize) AVI_set_audio(lav_fd->avi_fd, achans, arate, asize, WAVE_FORMAT_PCM); return lav_fd; - case 'j': { - + case 'j': /* Open JPEG output file */ - char tempfile[256]; - + tempfile = (char *)malloc(strlen(filename) + strlen(TMP_EXTENSION) + 1); + if (tempfile == NULL) + { + internal_error=ERROR_MALLOC; + return(0); + } strcpy(tempfile, filename); strcat(tempfile, TMP_EXTENSION); - lav_fd->jpeg_filename = strdup(filename); lav_fd->jpeg_fd = open(tempfile, O_CREAT | O_TRUNC | O_WRONLY, 0644); - + free(tempfile); return lav_fd; - } - case 'q': + case 'q': #ifdef HAVE_LIBQUICKTIME /* open quicktime output file */ @@ -364,26 +381,33 @@ lav_file_t *lav_open_output_file(char *f } int lav_close(lav_file_t *lav_file) -{ + { int res; + char *tempfile; video_format = lav_file->format; internal_error = 0; /* for error messages */ - switch(lav_file->format) - { + switch (lav_file->format) + { case 'a': case 'A': res = AVI_close( lav_file->avi_fd ); break; - case 'j': { - char tempfile[256]; + case 'j': + tempfile = (char *)malloc(strlen(lav_file->jpeg_filename) + + strlen(TMP_EXTENSION) + 1); + if (tempfile == NULL) + { + res = -1; + break; + } strcpy(tempfile, lav_file->jpeg_filename); strcat(tempfile, TMP_EXTENSION); res = close(lav_file->jpeg_fd); rename(tempfile, lav_file->jpeg_filename); + free(tempfile); free(lav_file->jpeg_filename); break; - } #ifdef HAVE_LIBQUICKTIME case 'q': res = quicktime_close( lav_file->qt_fd ); @@ -391,12 +415,10 @@ int lav_close(lav_file_t *lav_file) #endif default: res = -1; - } - + } free(lav_file); - return res; -} + } int lav_write_frame(lav_file_t *lav_file, uint8_t *buff, long size, long count) { @@ -524,9 +546,14 @@ int lav_write_frame(lav_file_t *lav_file int lav_write_audio(lav_file_t *lav_file, uint8_t *buff, long samps) { int res; -#ifdef HAVE_LIBQUICKTIME - int n, nb; - uint8_t *hbuff; +#ifdef HAVE_LIBQUICKTIME + int i, j; + int16_t *qt_audio = (int16_t *)buff, **qt_audion; + int channels = lav_audio_channels(lav_file); + + qt_audion = malloc(channels * sizeof (int16_t **)); + for (i = 0; i < channels; i++) + qt_audion[i] = (int16_t *)malloc(samps * lav_file->bps); #endif video_format = lav_file->format; internal_error = 0; /* for error messages */ @@ -539,19 +566,17 @@ int lav_write_audio(lav_file_t *lav_file break; #ifdef HAVE_LIBQUICKTIME case 'q': - if(lav_audio_bits(lav_file)==16) - { - nb = samps*2*lav_audio_channels(lav_file); - hbuff = (uint8_t *) malloc(nb); - if(!hbuff) { internal_error=ERROR_MALLOC; return -1; } - for(n=0;nqt_fd, (char*)hbuff, samps, 0 ); - free(hbuff); - } - else - res = quicktime_write_audio( lav_file->qt_fd, (char*)buff, samps, 0 ); - break; + /* Deinterleave the audio into the two channels. */ + for (i = 0; i < samps; i++) + { + for (j = 0; j < channels; j++) + qt_audion[j][i] = qt_audio[(2*i) + j]; + } + res = lqt_encode_audio_track(lav_file->qt_fd, qt_audion, NULL,samps,0); + free(qt_audion[0]); + free(qt_audion[1]); + free(qt_audion); + break; #endif default: res = -1; @@ -560,8 +585,6 @@ int lav_write_audio(lav_file_t *lav_file return res; } - - long lav_video_frames(lav_file_t *lav_file) { video_format = lav_file->format; internal_error = 0; /* for error messages */ @@ -638,17 +661,11 @@ void lav_video_sampleaspect(lav_file_t * return; } -int lav_video_is_MJPG(lav_file_t *lav_file) -{ - return lav_file->is_MJPG; -} - int lav_video_MJPG_chroma(lav_file_t *lav_file) { return lav_file->MJPG_chroma; } - const char *lav_video_compressor(lav_file_t *lav_file) { video_format = lav_file->format; internal_error = 0; /* for error messages */ @@ -797,7 +814,6 @@ int lav_read_frame(lav_file_t *lav_file, return -1; } - int lav_set_audio_position(lav_file_t *lav_file, long sample) { if(!lav_file->has_audio) return 0; @@ -809,7 +825,7 @@ int lav_set_audio_position(lav_file_t *l return AVI_set_audio_position(lav_file->avi_fd,sample*lav_file->bps); #ifdef HAVE_LIBQUICKTIME case 'q': - return quicktime_set_audio_position(lav_file->qt_fd,sample,0); + quicktime_set_audio_position(lav_file->qt_fd,sample,0); #endif } return -1; @@ -818,13 +834,20 @@ int lav_set_audio_position(lav_file_t *l long lav_read_audio(lav_file_t *lav_file, uint8_t *audbuf, long samps) { #ifdef HAVE_LIBQUICKTIME - long res, n, t; + int64_t last_pos, start_pos; + int res, i, j; + int16_t *qt_audio = (int16_t *)audbuf, **qt_audion; + int channels = lav_audio_channels(lav_file); + + qt_audion = malloc(channels * sizeof (int16_t **)); + for (i = 0; i < channels; i++) + qt_audion[i] = (int16_t *)malloc(samps * lav_file->bps); #endif if(!lav_file->has_audio) { internal_error = ERROR_NOAUDIO; - return -1; + return(-1); } video_format = lav_file->format; internal_error = 0; /* for error messages */ switch(lav_file->format) @@ -834,28 +857,28 @@ long lav_read_audio(lav_file_t *lav_file return AVI_read_audio(lav_file->avi_fd,audbuf,samps*lav_file->bps)/lav_file->bps; #ifdef HAVE_LIBQUICKTIME case 'q': - res = quicktime_read_audio(lav_file->qt_fd,(char*)audbuf,samps,0)/lav_file->bps; - if(res<=0) return res; - if(lav_audio_bits(lav_file)==16) - { - for(n=0;nqt_fd, 0); + lqt_decode_audio_track(lav_file->qt_fd, qt_audion, NULL, samps, 0); + last_pos = lqt_last_audio_position(lav_file->qt_fd, 0); + res = last_pos - start_pos; + if (res <= 0) + goto out; + /* Interleave the channels of audio into the one buffer provided */ + for (i =0; i < res; i++) + { + for (j = 0; j < channels; j++) + qt_audio[(2*i) + j] = qt_audion[j][i]; + } +out: + free(qt_audion[0]); + free(qt_audion[1]); + free(qt_audion); + return(res); #endif } return -1; } -int lav_filetype(lav_file_t *lav_file) -{ - return lav_file->format; -} - lav_file_t *lav_open_input_file(char *filename) { int n; @@ -878,11 +901,10 @@ lav_file_t *lav_open_input_file(char *fi lav_fd->qt_fd = 0; lav_fd->format = 0; lav_fd->interlacing = LAV_INTER_UNKNOWN; - lav_fd->sar_w = 0; /* (0,0) == unknown */ - lav_fd->sar_h = 0; + lav_fd->sar_w = 1; /* unknown - assume square pixels */ + lav_fd->sar_h = 1; lav_fd->has_audio = 0; lav_fd->bps = 0; - lav_fd->is_MJPG = 0; lav_fd->MJPG_chroma = CHROMAUNKNOWN; /* open video file, try AVI first */ @@ -1010,8 +1032,6 @@ lav_file_t *lav_open_input_file(char *fi return lav_fd; } - lav_fd->is_MJPG = 1; - /* Make some checks on the video source, we read the first frame for that */ ierr = 0; @@ -1200,8 +1220,6 @@ const char *lav_strerror(void) } } - - #ifdef HAVE_LIBDV static int check_DV2_input(lav_file_t *lav_fd) { @@ -1209,8 +1227,6 @@ static int check_DV2_input(lav_file_t *l double len = 0; unsigned char *frame = NULL; - lav_fd->is_MJPG = 0; - /* Make some checks on the video source, we read the first frame for that */ if ( lav_set_video_position(lav_fd,0) ) goto ERREXIT; @@ -1261,16 +1277,12 @@ ERREXIT: } #endif - - static int check_YUV420_input(lav_file_t *lav_fd) { int ierr = 0; double len = 0; unsigned char *frame = NULL; - lav_fd->is_MJPG = 0; - /* Make some checks on the video source, we read the first frame for that */ if ( lav_set_video_position(lav_fd,0) ) goto ERREXIT; @@ -1312,17 +1324,3 @@ int lav_fileno(lav_file_t *lav_file) return res; } - - - - - - - - - - - - - - diff -uprN lavtools.orig/lav_io.h lavtools/lav_io.h --- lavtools.orig/lav_io.h 2005-04-16 14:36:52.000000000 +0200 +++ lavtools/lav_io.h 2005-04-16 14:44:58.000000000 +0200 @@ -24,7 +24,7 @@ typedef void avi_t; #endif -#include "yuv4mpeg.h" +#include #define LAV_INTER_UNKNOWN Y4M_UNKNOWN #define LAV_NOT_INTERLACED Y4M_ILACE_NONE @@ -88,7 +88,6 @@ int lav_set_video_position(lav_file_t * int lav_read_frame(lav_file_t *lav_file, uint8_t *vidbuf); int lav_set_audio_position(lav_file_t *lav_file, long sample); long lav_read_audio(lav_file_t *lav_file, uint8_t *audbuf, long samps); -int lav_filetype(lav_file_t *lav_file); lav_file_t *lav_open_input_file(char *filename); int lav_get_field_size(uint8_t * jpegdata, long jpeglen); const char *lav_strerror(void);