applied AkhIL's cinelerra-cv surround patch
[cinelerra_cv/ct.git] / quicktime / rechunk.c
blob02fcdda41d7cd9bd18894190e18d72b24fb6a741
1 #include "funcprotos.h"
2 #include "quicktime.h"
4 int usage(void)
6 printf("usage: rechunk [-f framerate] [-w width] [-h height] [-c fourcc] <input frames> <output movie>\n");
7 printf(" Concatenate input frames into a Quicktime movie.\n");
8 exit(1);
9 return 0;
12 int main(int argc, char *argv[])
14 quicktime_t *file;
15 FILE *input;
16 int result = 0;
17 int i, j;
18 int64_t length;
19 char string[1024], *output = 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 rgb_to_ppm = 0;
27 char **input_frames = 0;
28 int total_input_frames = 0;
29 int width = 720, height = 480;
30 char compressor[5] = "yv12";
32 if(argc < 3)
34 usage();
37 for(i = 1, j = 0; i < argc; i++)
39 if(!strcmp(argv[i], "-f"))
41 if(i + 1 < argc)
43 output_rate = atof(argv[++i]);
45 else
46 usage();
48 else
49 if(!strcmp(argv[i], "-w"))
51 if(i + 1 < argc)
52 width = atol(argv[++i]);
53 else
54 usage();
56 else
57 if(!strcmp(argv[i], "-h"))
59 if(i + 1 < argc)
60 height = atol(argv[++i]);
61 else
62 usage();
64 else
65 if(!strcmp(argv[i], "-c"))
67 if(i + 1 < argc)
69 strncpy(compressor, argv[++i], 4);
71 else
72 usage();
74 if(i == argc - 1)
76 output = argv[i];
78 else
80 total_input_frames++;
81 input_frames = realloc(input_frames, sizeof(char*) * total_input_frames);
82 input_frames[total_input_frames - 1] = argv[i];
86 if(!input) usage();
88 if(input = fopen(output, "rb"))
90 printf("Output file already exists.\n");
91 exit(1);
94 if(!(file = quicktime_open(output, 0, 1)))
96 printf("Open failed\n");
97 exit(1);
100 quicktime_set_video(file, 1, width, height, output_rate, compressor);
102 for(i = 0; i < total_input_frames; i++)
104 /* Get output file */
105 if(!(input = fopen(input_frames[i], "rb")))
107 perror("Open failed");
108 continue;
111 /* Get input frame */
112 fseek(input, 0, SEEK_END);
113 bytes = ftell(input);
114 fseek(input, 0, SEEK_SET);
115 data = realloc(data, bytes);
117 fread(data, bytes, 1, input);
118 quicktime_write_frame(file, data, bytes, 0);
119 fclose(input);
122 quicktime_close(file);