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 / dechunk.c < prev    next >
C/C++ Source or Header  |  2000-11-29  |  2KB  |  125 lines

  1. #include "quicktime.h"
  2.  
  3. int usage(void)
  4. {
  5.     printf("usage: dechunk [-f framerate] <input movie> <output prefix>\n");
  6.     printf("    Movies containing rgb frames are written as ppm images.\n");
  7.     exit(1);
  8. }
  9.  
  10. int main(int argc, char *argv[])
  11. {
  12.     quicktime_t *file;
  13.     FILE *output;
  14.     int result = 0;
  15.     int i, j;
  16.     long length;
  17.     char string[1024], *prefix = 0, *input = 0;
  18.     char *data = 0;
  19.     int bytes = 0, old_bytes = 0;
  20.     float output_rate = 0;
  21.     float input_rate;
  22.     long input_frame;
  23.     long new_length;
  24.     int width, height;
  25.     int rgb_to_ppm = 0;
  26.  
  27.     if(argc < 3)
  28.     {
  29.         usage();
  30.     }
  31.  
  32.     for(i = 1, j = 0; i < argc; i++)
  33.     {
  34.         if(!strcmp(argv[i], "-f"))
  35.         {
  36.             if(i + 1 < argc)
  37.             {
  38.                 output_rate = atof(argv[++i]);
  39.             }
  40.             else
  41.                 usage();
  42.         }
  43.         else
  44.         if(j == 0)
  45.         {
  46.             input = argv[i];
  47.             j++;
  48.         }
  49.         else
  50.         if(j == 1)
  51.         {
  52.             prefix = argv[i];
  53.             j++;
  54.         }
  55.     }
  56.  
  57.     if(!prefix || !input) usage();
  58.  
  59.     if(!(file = quicktime_open(input, 1, 0)))
  60.     {
  61.         printf("Open failed\n");
  62.         exit(1);
  63.     }
  64.     
  65.     if(!quicktime_video_tracks(file))
  66.     {
  67.         printf("No video tracks.\n");
  68.         exit(1);
  69.     }
  70.     
  71.     if(quicktime_match_32(quicktime_video_compressor(file, 0), QUICKTIME_RAW))
  72.     {
  73.         printf("Converting to ppm.\n");
  74.         rgb_to_ppm = 1;
  75.     }
  76.  
  77.     length = quicktime_video_length(file, 0);
  78.     input_rate = quicktime_frame_rate(file, 0);
  79.     if(!output_rate) output_rate = input_rate;
  80.     new_length = output_rate / input_rate * length;
  81.     width = quicktime_video_width(file, 0);
  82.     height = quicktime_video_height(file, 0);
  83.  
  84.     for(i = 0; i < new_length; i++)
  85.     {
  86. /* Get output file */
  87.         sprintf(string, "%s%06d", prefix, i);
  88.         if(!(output = fopen(string, "wb")))
  89.         {
  90.             perror("Open failed");
  91.             exit(1);
  92.         }
  93.  
  94. /* Get input frame */
  95.         input_frame = (long)(input_rate / output_rate * i);
  96.         bytes = quicktime_frame_size(file, input_frame, 0);
  97.  
  98.         if(data)
  99.         {
  100.             if(bytes > old_bytes) { free(data); data = 0; }
  101.         }
  102.  
  103.         if(!data)
  104.         {
  105.             old_bytes = bytes;
  106.             data = malloc(bytes);
  107.         }
  108.  
  109.         quicktime_set_video_position(file, input_frame, 0);
  110.         quicktime_read_data(file, data, bytes);
  111.         if(rgb_to_ppm)
  112.         {
  113.             fprintf(output, "P6\n%d %d\n%d\n", width, height, 0xff);
  114.         }
  115.  
  116.         if(!fwrite(data, bytes, 1, output))
  117.         {
  118.             perror("write failed");
  119.         }
  120.         fclose(output);
  121.     }
  122.  
  123.     quicktime_close(file);
  124. }
  125.