r1007: Make configure detect and work on amd64.
[cinelerra_cv/mob.git] / quicktime / dechunk.c
blob963ef36d0a1092b4f532eeb69194f52919ddb611
1 #include "funcprotos.h"
2 #include "quicktime.h"
4 int usage(void)
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;
12 int main(int argc, char *argv[])
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;
29 if(argc < 3)
31 usage();
34 for(i = 1, j = 0; i < argc; i++)
36 if(!strcmp(argv[i], "-f"))
38 if(i + 1 < argc)
40 output_rate = atof(argv[++i]);
42 else
43 usage();
45 else
46 if(j == 0)
48 input = argv[i];
49 j++;
51 else
52 if(j == 1)
54 prefix = argv[i];
55 j++;
59 if(!prefix || !input) usage();
61 if(!(file = quicktime_open(input, 1, 0)))
63 printf("Open failed\n");
64 exit(1);
67 if(!quicktime_video_tracks(file))
69 printf("No video tracks.\n");
70 exit(1);
73 if(quicktime_match_32(quicktime_video_compressor(file, 0), QUICKTIME_RAW))
75 printf("Converting to ppm.\n");
76 rgb_to_ppm = 1;
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);
86 for(i = 0; i < new_length; i++)
88 /* Get output file */
89 sprintf(string, "%s%06d", prefix, i);
90 if(!(output = fopen(string, "wb")))
92 perror("Open failed");
93 exit(1);
96 /* Get input frame */
97 input_frame = (int64_t)(input_rate / output_rate * i);
98 bytes = quicktime_frame_size(file, input_frame, 0);
100 if(data)
102 if(bytes > old_bytes) { free(data); data = 0; }
105 if(!data)
107 old_bytes = bytes;
108 data = malloc(bytes);
111 quicktime_set_video_position(file, input_frame, 0);
112 quicktime_read_data(file, data, bytes);
113 if(rgb_to_ppm)
115 fprintf(output, "P6\n%d %d\n%d\n", width, height, 0xff);
118 if(!fwrite(data, bytes, 1, output))
120 perror("write failed");
122 fclose(output);
125 quicktime_close(file);