"Fossies" - the Fresh Open Source Software Archive

Member "quicktime4linux-2.3/dechunk.c" (9 Jan 2007, 2248 Bytes) of package /linux/privat/old/quicktime4linux-2.3-src.tar.gz:


As a special service "Fossies" has tried to format the requested source page into HTML format using (guessed) C and C++ source code syntax highlighting (style: standard) with prefixed line numbers and code folding option. Alternatively you can here view or download the uninterpreted source code file.

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