home *** CD-ROM | disk | FTP | other *** search
/ Geek 6 / Geek-006.iso / linux / video / xmovie-1.5.3.tar.gz / xmovie-1.5.3.tar / xmovie-1.5.3 / quicktime / yuv4toyuv.c < prev    next >
C/C++ Source or Header  |  2000-11-29  |  2KB  |  99 lines

  1. #include "quicktime.h"
  2.  
  3. int usage(void)
  4. {
  5.     printf("usage: yuv4toyuv <input movie> <output.yuv>\n");
  6.     printf("    Write a YUV4 encoded movie as a planar YUV 4:2:0 file.\n");
  7.     exit(1);
  8. }
  9.  
  10. int main(int argc, char *argv[])
  11. {
  12.     quicktime_t *file;
  13.     FILE *output;
  14.     long length, width, height, bytes;
  15.     char *buffer_in, *y_out, *u_out, *v_out;
  16.     char *y_out1, *y_out2, *u_out1, *v_out1;
  17.     char *input_row;
  18.     int i, j, k, l, m;
  19.  
  20.     if(argc < 3)
  21.     {
  22.         usage();
  23.     }
  24.  
  25.     if(!(file = quicktime_open(argv[1], 1, 0)))
  26.     {
  27.         printf("Open input failed\n");
  28.         exit(1);
  29.     }
  30.  
  31.     if(!(output = fopen(argv[2], "wb")))
  32.     {
  33.         perror("Open output failed");
  34.         exit(1);
  35.     }
  36.  
  37.     if(!quicktime_video_tracks(file))
  38.     {
  39.         printf("No video tracks.\n");
  40.         exit(1);
  41.     }
  42.  
  43.     length = quicktime_video_length(file, 0);
  44.     width = quicktime_video_width(file, 0);
  45.     height = quicktime_video_height(file, 0);
  46.     bytes = width * height + width * height / 2;
  47.     buffer_in = calloc(1, bytes);
  48.     y_out = calloc(1, width * height);
  49.     u_out = calloc(1, width * height / 4);
  50.     v_out = calloc(1, width * height / 4);
  51.  
  52.     for(i = 0; i < length; i++)
  53.     {
  54.         quicktime_set_video_position(file, i, 0);
  55.         quicktime_read_data(file, buffer_in, bytes);
  56.  
  57.         u_out1 = u_out;
  58.         v_out1 = v_out;
  59.         for(j = 0; j < height; j += 2)
  60.         {
  61. // Get 2 rows
  62.             input_row = &buffer_in[j * width  + j * width / 2];
  63.             y_out1 = y_out + j * width;
  64.             y_out2 = y_out1 + width;
  65.  
  66.             for(k = 0; k < width / 2; k++)
  67.             {
  68.                 *u_out1++ = (int)*input_row++ + 0x80;
  69.                 *v_out1++ = (int)*input_row++ + 0x80;
  70.                 *y_out1++ = *input_row++;
  71.                 *y_out1++ = *input_row++;
  72.                 *y_out2++ = *input_row++;
  73.                 *y_out2++ = *input_row++;
  74.             }
  75.         }
  76.  
  77.         if(!fwrite(y_out, width * height, 1, output))
  78.         {
  79.             perror("write failed");
  80.             fclose(output);
  81.             exit(1);
  82.         }
  83.         if(!fwrite(u_out, width * height / 4, 1, output))
  84.         {
  85.             perror("write failed");
  86.             fclose(output);
  87.             exit(1);
  88.         }
  89.         if(!fwrite(v_out, width * height / 4, 1, output))
  90.         {
  91.             perror("write failed");
  92.             fclose(output);
  93.             exit(1);
  94.         }
  95.     }
  96.  
  97.     quicktime_close(file);
  98. }
  99.