initial commit
[goodguy/history.git] / cinelerra-5.0 / quicktime / rechunk.c
1 #include "funcprotos.h"
2 #include "quicktime.h"
3 #include <string.h>
4
5
6 int usage(void)
7 {
8         printf("usage: rechunk [-f framerate] [-w width] [-h height] [-c fourcc] <input frames> <output movie>\n");
9         printf("        Concatenate input frames into a Quicktime movie.\n");
10         exit(1);
11         return 0;
12 }
13
14 int main(int argc, char *argv[])
15 {
16         quicktime_t *file;
17         FILE *input;
18         int result = 0;
19         int i, j;
20         int64_t length;
21         char string[1024], *output = 0;
22         char *data = 0;
23         int bytes = 0, old_bytes = 0;
24         float output_rate = 0;
25         float input_rate;
26         int64_t input_frame;
27         int64_t new_length;
28         int rgb_to_ppm = 0;
29         char **input_frames = 0;
30         int total_input_frames = 0;
31         int width = 720, height = 480;
32         char compressor[5] = "yv12";
33
34         if(argc < 3)
35         {
36                 usage();
37         }
38
39         for(i = 1, j = 0; i < argc; i++)
40         {
41                 if(!strcmp(argv[i], "-f"))
42                 {
43                         if(i + 1 < argc)
44                         {
45                                 output_rate = atof(argv[++i]);
46                         }
47                         else
48                                 usage();
49                 }
50                 else
51                 if(!strcmp(argv[i], "-w"))
52                 {
53                         if(i + 1 < argc)
54                                 width = atol(argv[++i]);
55                         else
56                                 usage();
57                 }
58                 else
59                 if(!strcmp(argv[i], "-h"))
60                 {
61                         if(i + 1 < argc)
62                                 height = atol(argv[++i]);
63                         else
64                                 usage();
65                 }
66                 else
67                 if(!strcmp(argv[i], "-c"))
68                 {
69                         if(i + 1 < argc)
70                         {
71                                 strncpy(compressor, argv[++i], 4);
72                         }
73                         else
74                                 usage();
75                 }
76                 if(i == argc - 1)
77                 {
78                         output = argv[i];
79                 }
80                 else
81                 {
82                         total_input_frames++;
83                         input_frames = realloc(input_frames, sizeof(char*) * total_input_frames);
84                         input_frames[total_input_frames - 1] = argv[i];
85                 }
86         }
87
88         if(!input) usage();
89
90         if(input = fopen(output, "rb"))
91         {
92                 printf("Output file already exists.\n");
93                 exit(1);
94         }
95
96         if(!(file = quicktime_open(output, 0, 1)))
97         {
98                 printf("Open failed\n");
99                 exit(1);
100         }
101         
102         quicktime_set_video(file, 1, width, height, output_rate, compressor);
103         
104         for(i = 0; i < total_input_frames; i++)
105         {
106 /* Get output file */
107                 if(!(input = fopen(input_frames[i], "rb")))
108                 {
109                         perror("Open failed");
110                         continue;
111                 }
112
113 /* Get input frame */
114                 fseek(input, 0, SEEK_END);
115                 bytes = ftell(input);
116                 fseek(input, 0, SEEK_SET);
117                 data = realloc(data, bytes);
118
119                 fread(data, bytes, 1, input);
120                 quicktime_write_frame(file, data, bytes, 0);
121                 fclose(input);
122         }
123
124         quicktime_close(file);
125 }