Gentoo Websites Logo
Go to: Gentoo Home Documentation Forums Lists Bugs Planet Store Wiki Get Gentoo!
View | Details | Raw Unified | Return to bug 100869
Collapse All | Expand All

(-)lavtools.org/lavaddwav.c (-1 / +1 lines)
Lines 155-161 Link Here
155
   }
155
   }
156
156
157
   lav_out = lav_open_output_file(argv[3],
157
   lav_out = lav_open_output_file(argv[3],
158
                                  lav_filetype(lav_fd),
158
                                  lav_fd->format,
159
                                  lav_video_width (lav_fd),
159
                                  lav_video_width (lav_fd),
160
                                  lav_video_height(lav_fd),
160
                                  lav_video_height(lav_fd),
161
                                  lav_video_interlacing(lav_fd),
161
                                  lav_video_interlacing(lav_fd),
(-)lavtools.org/lav_io.c (-110 / +142 lines)
Lines 36-42 Link Here
36
#endif
36
#endif
37
37
38
#ifdef HAVE_LIBQUICKTIME
38
#ifdef HAVE_LIBQUICKTIME
39
#include <quicktime.h>
39
#include <quicktime/quicktime.h>
40
#include <quicktime/lqt.h>
40
#endif
41
#endif
41
42
42
extern int AVI_errno;
43
extern int AVI_errno;
Lines 275-280 Link Here
275
                    int asize, int achans, long arate)
276
                    int asize, int achans, long arate)
276
{
277
{
277
   lav_file_t *lav_fd = (lav_file_t*) malloc(sizeof(lav_file_t));
278
   lav_file_t *lav_fd = (lav_file_t*) malloc(sizeof(lav_file_t));
279
   char *extension, *tempfile;
278
280
279
   if(lav_fd==0) { internal_error=ERROR_MALLOC; return 0; }
281
   if(lav_fd==0) { internal_error=ERROR_MALLOC; return 0; }
280
282
Lines 284-311 Link Here
284
   lav_fd->qt_fd       = 0;
286
   lav_fd->qt_fd       = 0;
285
   lav_fd->format      = format;
287
   lav_fd->format      = format;
286
   /* Sanity check: do not create a quicktime file that is named with .avi */
288
   /* Sanity check: do not create a quicktime file that is named with .avi */
287
   if(rindex(filename, '.') != NULL)
289
   extension = rindex(filename, '.');
290
   if (extension != NULL)
288
   {
291
   {
289
      if((format == 'a' || format == 'A') && strcmp(rindex(filename, '.')+1, "avi")) {
292
      extension++;
290
        internal_error = ERROR_FORMAT;
293
      switch(format)
291
        return 0;
294
        {
292
      }
295
        case 'a':
293
      if(format == 'q' && (strcmp(rindex(filename, '.')+1, "qt") 
296
        case 'A':
294
           && strcmp(rindex(filename, '.')+1, "mov") && strcmp(rindex(filename, '.')+1,"moov"))) {
297
          if (strcmp(extension, "avi") && strcmp(extension, "AVI")) 
295
        internal_error = ERROR_FORMAT;
298
            {
296
        return 0;
299
               internal_error = ERROR_FORMAT;
297
      }
300
               return 0;
298
      if(format == 'j' && strcmp(rindex(filename, '.')+1, "jpg")
301
            }
299
           && strcmp(rindex(filename, '.')+1, "jpeg")) {
302
          break;
300
        internal_error = ERROR_FORMAT;
303
        case 'q':
301
        return 0;
304
          if (strcmp(extension,  "qt") && strcmp(extension,  "QT") &&
302
      }
305
              strcmp(extension, "mov") && strcmp(extension, "MOV") && 
306
              strcmp(extension,"moov") && strcmp(extension,"MOOV")) 
307
            {
308
             internal_error = ERROR_FORMAT;
309
             return 0;
310
            }
311
          break;
312
        case 'j':
313
          if (strcmp(extension, "jpg") && strcmp(extension, "jpg") &&
314
              strcmp(extension,"jpeg") && strcmp(extension,"JPEG"))
315
            {
316
              internal_error = ERROR_FORMAT;
317
              return 0;
318
            }
319
          break;
320
        }
303
   }
321
   }
304
   lav_fd->interlacing = interlaced ? lav_query_polarity(format) :
322
   lav_fd->interlacing = interlaced ? lav_query_polarity(format) :
305
                                      LAV_NOT_INTERLACED;
323
                                      LAV_NOT_INTERLACED;
306
   lav_fd->has_audio   = (asize>0 && achans>0);
324
   lav_fd->has_audio   = (asize>0 && achans>0);
307
   lav_fd->bps         = (asize*achans+7)/8;
325
   lav_fd->bps         = (asize*achans+7)/8;
308
   lav_fd->is_MJPG     = 1;
309
   lav_fd->MJPG_chroma = CHROMAUNKNOWN;
326
   lav_fd->MJPG_chroma = CHROMAUNKNOWN;
310
327
311
   switch(format)
328
   switch(format)
Lines 321-341 Link Here
321
         if (asize) AVI_set_audio(lav_fd->avi_fd, achans, arate, asize, WAVE_FORMAT_PCM);
338
         if (asize) AVI_set_audio(lav_fd->avi_fd, achans, arate, asize, WAVE_FORMAT_PCM);
322
         return lav_fd;
339
         return lav_fd;
323
340
324
      case 'j': {
341
      case 'j':
325
326
        /* Open JPEG output file */
342
        /* Open JPEG output file */
327
        char tempfile[256];
343
	tempfile = (char *)malloc(strlen(filename) + strlen(TMP_EXTENSION) + 1);
328
344
	if (tempfile == NULL)
345
	   {
346
	   internal_error=ERROR_MALLOC;
347
	   return(0);
348
	   }
329
        strcpy(tempfile, filename);
349
        strcpy(tempfile, filename);
330
        strcat(tempfile, TMP_EXTENSION);
350
        strcat(tempfile, TMP_EXTENSION);
331
332
        lav_fd->jpeg_filename = strdup(filename);
351
        lav_fd->jpeg_filename = strdup(filename);
333
        lav_fd->jpeg_fd = open(tempfile, O_CREAT | O_TRUNC | O_WRONLY, 0644);
352
        lav_fd->jpeg_fd = open(tempfile, O_CREAT | O_TRUNC | O_WRONLY, 0644);
334
353
	free(tempfile);
335
        return lav_fd;
354
        return lav_fd;
336
      }
337
      case 'q':
338
355
356
      case 'q':
339
#ifdef HAVE_LIBQUICKTIME
357
#ifdef HAVE_LIBQUICKTIME
340
         /* open quicktime output file */
358
         /* open quicktime output file */
341
359
Lines 364-389 Link Here
364
}
382
}
365
383
366
int lav_close(lav_file_t *lav_file)
384
int lav_close(lav_file_t *lav_file)
367
{
385
   {
368
   int res;
386
   int res;
387
   char *tempfile;
369
388
370
   video_format = lav_file->format; internal_error = 0; /* for error messages */
389
   video_format = lav_file->format; internal_error = 0; /* for error messages */
371
390
372
   switch(lav_file->format)
391
   switch (lav_file->format)
373
   {
392
      {
374
      case 'a':
393
      case 'a':
375
      case 'A':
394
      case 'A':
376
         res = AVI_close( lav_file->avi_fd );
395
         res = AVI_close( lav_file->avi_fd );
377
         break;
396
         break;
378
      case 'j': {
397
      case 'j':
379
         char tempfile[256];
398
	 tempfile = (char *)malloc(strlen(lav_file->jpeg_filename) + 
399
				   strlen(TMP_EXTENSION) + 1);
400
	 if (tempfile == NULL)
401
	    {
402
	    res = -1;
403
	    break;
404
	    }
380
         strcpy(tempfile, lav_file->jpeg_filename);
405
         strcpy(tempfile, lav_file->jpeg_filename);
381
         strcat(tempfile, TMP_EXTENSION);
406
         strcat(tempfile, TMP_EXTENSION);
382
         res = close(lav_file->jpeg_fd);
407
         res = close(lav_file->jpeg_fd);
383
         rename(tempfile, lav_file->jpeg_filename);
408
         rename(tempfile, lav_file->jpeg_filename);
409
	 free(tempfile);
384
         free(lav_file->jpeg_filename);
410
         free(lav_file->jpeg_filename);
385
         break;
411
         break;
386
      }
387
#ifdef HAVE_LIBQUICKTIME
412
#ifdef HAVE_LIBQUICKTIME
388
      case 'q':
413
      case 'q':
389
         res = quicktime_close( lav_file->qt_fd );
414
         res = quicktime_close( lav_file->qt_fd );
Lines 391-402 Link Here
391
#endif
416
#endif
392
      default:
417
      default:
393
         res = -1;
418
         res = -1;
394
   }
419
      }
395
396
   free(lav_file);
420
   free(lav_file);
397
398
   return res;
421
   return res;
399
}
422
   }
400
423
401
int lav_write_frame(lav_file_t *lav_file, uint8_t *buff, long size, long count)
424
int lav_write_frame(lav_file_t *lav_file, uint8_t *buff, long size, long count)
402
{
425
{
Lines 523-532 Link Here
523
546
524
int lav_write_audio(lav_file_t *lav_file, uint8_t *buff, long samps)
547
int lav_write_audio(lav_file_t *lav_file, uint8_t *buff, long samps)
525
{
548
{
526
   int res;
549
   int res = -1;
527
#ifdef	HAVE_LIBQUICKTIME
550
#ifdef HAVE_LIBQUICKTIME
528
   int	n, nb;
551
   int i, j;
529
   uint8_t *hbuff;
552
   int16_t *buff16 = (int16_t *)buff, **qt_audion;
553
   int channels = lav_audio_channels(lav_file);
554
   int bits = lav_audio_bits(lav_file);
530
#endif
555
#endif
531
556
532
   video_format = lav_file->format; internal_error = 0; /* for error messages */
557
   video_format = lav_file->format; internal_error = 0; /* for error messages */
Lines 535-567 Link Here
535
   {
560
   {
536
      case 'a':
561
      case 'a':
537
      case 'A':
562
      case 'A':
538
         res = AVI_write_audio( lav_file->avi_fd, buff, samps*lav_file->bps);
563
         res = AVI_write_audio(lav_file->avi_fd, buff, samps * lav_file->bps);
539
         break;
564
         break;
540
#ifdef HAVE_LIBQUICKTIME
565
#ifdef HAVE_LIBQUICKTIME
541
      case 'q':
566
      case 'q':
542
         if(lav_audio_bits(lav_file)==16)
567
	if (bits != 16 || channels > 1)
543
         {
568
	{
544
            nb = samps*2*lav_audio_channels(lav_file);
569
	   /* Deinterleave the audio into the two channels and/or convert
545
            hbuff = (uint8_t *) malloc(nb);
570
	    * bits per sample to the required format.
546
            if(!hbuff) { internal_error=ERROR_MALLOC; return -1; }
571
	    */
547
            for(n=0;n<nb;n+=2)
572
	   qt_audion = malloc(channels * sizeof(*qt_audion));
548
            { hbuff[n] = buff[n+1]; hbuff[n+1] = buff[n]; }
573
	   for (i = 0; i < channels; i++)
549
            res = quicktime_write_audio( lav_file->qt_fd, (char*)hbuff, samps, 0 );
574
	     qt_audion[i] = malloc(samps * sizeof(**qt_audion));
550
            free(hbuff);
575
551
         }
576
	   if (bits == 16)
552
         else
577
	     for (i = 0; i < samps; i++)
553
            res = quicktime_write_audio( lav_file->qt_fd, (char*)buff, samps, 0 );
578
	       for (j = 0; j < channels; j++)
554
         break;
579
		 qt_audion[j][i] = buff16[channels * i + j];
580
	   else 
581
	     if (bits == 8)
582
	       for (i = 0; i < samps; i++)
583
		 for (j = 0; j < channels; j++)
584
		   qt_audion[j][i] = ((int16_t)(buff[channels * i + j]) << 8) ^ 0x8000;
585
586
	   if (bits == 8 || bits == 16)
587
	     res = lqt_encode_audio_track(lav_file->qt_fd, qt_audion, NULL, samps, 0);
588
589
	   for (i = 0; i < channels; i++)
590
	     free(qt_audion[i]);
591
	   free(qt_audion);
592
	 } else {
593
	   qt_audion = &buff16;
594
	   res = lqt_encode_audio_track(lav_file->qt_fd, qt_audion, NULL, samps, 0);
595
	 }
596
	 break;
555
#endif
597
#endif
556
      default:
598
      default:
557
         res = -1;
599
	 break;
558
   }
600
   }
559
601
560
   return res;
602
   return res;
561
}
603
}
562
604
563
564
565
long lav_video_frames(lav_file_t *lav_file)
605
long lav_video_frames(lav_file_t *lav_file)
566
{
606
{
567
   video_format = lav_file->format; internal_error = 0; /* for error messages */
607
   video_format = lav_file->format; internal_error = 0; /* for error messages */
Lines 638-654 Link Here
638
  return;
678
  return;
639
}
679
}
640
680
641
int lav_video_is_MJPG(lav_file_t *lav_file)
642
{
643
   return lav_file->is_MJPG;
644
}
645
646
int lav_video_MJPG_chroma(lav_file_t *lav_file)
681
int lav_video_MJPG_chroma(lav_file_t *lav_file)
647
{
682
{
648
	return lav_file->MJPG_chroma;
683
	return lav_file->MJPG_chroma;
649
}
684
}
650
685
651
652
const char *lav_video_compressor(lav_file_t *lav_file)
686
const char *lav_video_compressor(lav_file_t *lav_file)
653
{
687
{
654
   video_format = lav_file->format; internal_error = 0; /* for error messages */
688
   video_format = lav_file->format; internal_error = 0; /* for error messages */
Lines 797-803 Link Here
797
   return -1;
831
   return -1;
798
}
832
}
799
833
800
801
int lav_set_audio_position(lav_file_t *lav_file, long sample)
834
int lav_set_audio_position(lav_file_t *lav_file, long sample)
802
{
835
{
803
   if(!lav_file->has_audio) return 0;
836
   if(!lav_file->has_audio) return 0;
Lines 809-815 Link Here
809
         return AVI_set_audio_position(lav_file->avi_fd,sample*lav_file->bps);
842
         return AVI_set_audio_position(lav_file->avi_fd,sample*lav_file->bps);
810
#ifdef HAVE_LIBQUICKTIME
843
#ifdef HAVE_LIBQUICKTIME
811
      case 'q':
844
      case 'q':
812
         return quicktime_set_audio_position(lav_file->qt_fd,sample,0);
845
         quicktime_set_audio_position(lav_file->qt_fd,sample,0);
813
#endif
846
#endif
814
   }
847
   }
815
   return -1;
848
   return -1;
Lines 818-830 Link Here
818
long lav_read_audio(lav_file_t *lav_file, uint8_t *audbuf, long samps)
851
long lav_read_audio(lav_file_t *lav_file, uint8_t *audbuf, long samps)
819
{
852
{
820
#ifdef	HAVE_LIBQUICKTIME
853
#ifdef	HAVE_LIBQUICKTIME
821
   long res, n, t;
854
   int64_t last_pos, start_pos;
855
   int res, i, j;
856
   int16_t *audbuf16 = (int16_t *)audbuf, **qt_audion;
857
   int channels = lav_audio_channels(lav_file);
858
   int bits = lav_audio_bits(lav_file);
822
#endif
859
#endif
823
860
824
   if(!lav_file->has_audio)
861
   if(!lav_file->has_audio)
825
   {
862
   {
826
      internal_error = ERROR_NOAUDIO;
863
      internal_error = ERROR_NOAUDIO;
827
      return -1;
864
      return(-1);
828
   }
865
   }
829
   video_format = lav_file->format; internal_error = 0; /* for error messages */
866
   video_format = lav_file->format; internal_error = 0; /* for error messages */
830
   switch(lav_file->format)
867
   switch(lav_file->format)
Lines 834-861 Link Here
834
         return AVI_read_audio(lav_file->avi_fd,audbuf,samps*lav_file->bps)/lav_file->bps;
871
         return AVI_read_audio(lav_file->avi_fd,audbuf,samps*lav_file->bps)/lav_file->bps;
835
#ifdef HAVE_LIBQUICKTIME
872
#ifdef HAVE_LIBQUICKTIME
836
      case 'q':
873
      case 'q':
837
         res = quicktime_read_audio(lav_file->qt_fd,(char*)audbuf,samps,0)/lav_file->bps;
874
	 if (bits != 16 || channels > 1)
838
         if(res<=0) return res;
875
	 {
839
         if(lav_audio_bits(lav_file)==16)
876
	   qt_audion = malloc(channels * sizeof(*qt_audion));
840
         {
877
	   for (i = 0; i < channels; i++)
841
            for(n=0;n<res*2*lav_audio_channels(lav_file);n+=2)
878
	     qt_audion[i] = malloc(samps * sizeof(**qt_audion));
842
            {
879
	 } else {
843
               t = audbuf[n];
880
	   qt_audion = &audbuf16;
844
               audbuf[n] = audbuf[n+1];
881
	 }
845
               audbuf[n+1] = t;
882
846
            }
883
	 start_pos = quicktime_audio_position(lav_file->qt_fd, 0);
847
         }
884
	 lqt_decode_audio_track(lav_file->qt_fd, qt_audion, NULL, samps, 0);
848
         return res;
885
	 last_pos = lqt_last_audio_position(lav_file->qt_fd, 0);
886
	 res = last_pos - start_pos;
887
888
	 if (res > 0 && (bits != 16 || channels > 1))
889
	 {
890
	   /* Interleave the channels of audio into the one buffer provided
891
	    * and/or convert bits per sample to the required format.
892
	    */
893
	   if (bits == 16)
894
	     for (i = 0; i < res; i++)
895
	       for (j = 0; j < channels; j++)
896
		 audbuf16[channels * i + j] = qt_audion[j][i];
897
	   else
898
	     if (bits == 8)
899
	       for (i = 0; i < res; i++)
900
		 for (j = 0; j < channels; j++)
901
		   audbuf[channels * i + j] = (qt_audion[j][i] >> 8) + 0x80;
902
	 }
903
904
	 if (bits != 16 || channels > 1)
905
	 {
906
	   for (i = 0; i < channels; i++)
907
	     free(qt_audion[i]);
908
	   free(qt_audion);
909
	 }
910
	 return res;
849
#endif
911
#endif
850
   }
912
   }
851
   return -1;
913
   return -1;
852
}
914
}
853
915
854
int lav_filetype(lav_file_t *lav_file)
855
{
856
   return lav_file->format;
857
}
858
859
lav_file_t *lav_open_input_file(char *filename)
916
lav_file_t *lav_open_input_file(char *filename)
860
{
917
{
861
   int n;
918
   int n;
Lines 878-888 Link Here
878
   lav_fd->qt_fd       = 0;
935
   lav_fd->qt_fd       = 0;
879
   lav_fd->format      = 0;
936
   lav_fd->format      = 0;
880
   lav_fd->interlacing = LAV_INTER_UNKNOWN;
937
   lav_fd->interlacing = LAV_INTER_UNKNOWN;
881
   lav_fd->sar_w       = 0; /* (0,0) == unknown */
938
   lav_fd->sar_w       = 1; /* unknown - assume square pixels */
882
   lav_fd->sar_h       = 0; 
939
   lav_fd->sar_h       = 1; 
883
   lav_fd->has_audio   = 0;
940
   lav_fd->has_audio   = 0;
884
   lav_fd->bps         = 0;
941
   lav_fd->bps         = 0;
885
   lav_fd->is_MJPG     = 0;
886
   lav_fd->MJPG_chroma = CHROMAUNKNOWN;
942
   lav_fd->MJPG_chroma = CHROMAUNKNOWN;
887
943
888
   /* open video file, try AVI first */
944
   /* open video file, try AVI first */
Lines 1010-1017 Link Here
1010
      return lav_fd;
1066
      return lav_fd;
1011
   }
1067
   }
1012
1068
1013
   lav_fd->is_MJPG = 1;
1014
1015
   /* Make some checks on the video source, we read the first frame for that */
1069
   /* Make some checks on the video source, we read the first frame for that */
1016
1070
1017
   ierr  = 0;
1071
   ierr  = 0;
Lines 1200-1207 Link Here
1200
   }
1254
   }
1201
}
1255
}
1202
1256
1203
1204
1205
#ifdef HAVE_LIBDV
1257
#ifdef HAVE_LIBDV
1206
static int check_DV2_input(lav_file_t *lav_fd)
1258
static int check_DV2_input(lav_file_t *lav_fd)
1207
{
1259
{
Lines 1209-1216 Link Here
1209
   double len = 0;
1261
   double len = 0;
1210
   unsigned char *frame = NULL;
1262
   unsigned char *frame = NULL;
1211
1263
1212
   lav_fd->is_MJPG = 0;
1213
1214
   /* Make some checks on the video source, we read the first frame for that */
1264
   /* Make some checks on the video source, we read the first frame for that */
1215
1265
1216
   if ( lav_set_video_position(lav_fd,0) ) goto ERREXIT;
1266
   if ( lav_set_video_position(lav_fd,0) ) goto ERREXIT;
Lines 1261-1276 Link Here
1261
}
1311
}
1262
#endif
1312
#endif
1263
1313
1264
1265
1266
static int check_YUV420_input(lav_file_t *lav_fd)
1314
static int check_YUV420_input(lav_file_t *lav_fd)
1267
{
1315
{
1268
   int ierr = 0;
1316
   int ierr = 0;
1269
   double len = 0;
1317
   double len = 0;
1270
   unsigned char *frame = NULL;
1318
   unsigned char *frame = NULL;
1271
1319
1272
   lav_fd->is_MJPG = 0;
1273
1274
   /* Make some checks on the video source, we read the first frame for that */
1320
   /* Make some checks on the video source, we read the first frame for that */
1275
1321
1276
   if ( lav_set_video_position(lav_fd,0) ) goto ERREXIT;
1322
   if ( lav_set_video_position(lav_fd,0) ) goto ERREXIT;
Lines 1312-1328 Link Here
1312
1358
1313
   return res;
1359
   return res;
1314
}
1360
}
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
(-)lavtools.org/lav_io.h (-2 / +1 lines)
Lines 24-30 Link Here
24
typedef void avi_t;
24
typedef void avi_t;
25
#endif
25
#endif
26
26
27
#include "yuv4mpeg.h"
27
#include <yuv4mpeg.h>
28
28
29
#define LAV_INTER_UNKNOWN       Y4M_UNKNOWN
29
#define LAV_INTER_UNKNOWN       Y4M_UNKNOWN
30
#define LAV_NOT_INTERLACED      Y4M_ILACE_NONE
30
#define LAV_NOT_INTERLACED      Y4M_ILACE_NONE
Lines 88-94 Link Here
88
int  lav_read_frame(lav_file_t *lav_file, uint8_t *vidbuf);
88
int  lav_read_frame(lav_file_t *lav_file, uint8_t *vidbuf);
89
int  lav_set_audio_position(lav_file_t *lav_file, long sample);
89
int  lav_set_audio_position(lav_file_t *lav_file, long sample);
90
long lav_read_audio(lav_file_t *lav_file, uint8_t *audbuf, long samps);
90
long lav_read_audio(lav_file_t *lav_file, uint8_t *audbuf, long samps);
91
int  lav_filetype(lav_file_t *lav_file);
92
lav_file_t *lav_open_input_file(char *filename);
91
lav_file_t *lav_open_input_file(char *filename);
93
int  lav_get_field_size(uint8_t * jpegdata, long jpeglen);
92
int  lav_get_field_size(uint8_t * jpegdata, long jpeglen);
94
const char *lav_strerror(void);
93
const char *lav_strerror(void);

Return to bug 100869