00001 #include "funcprotos.h"
00002 #include "quicktime.h"
00003
00004 int usage(void)
00005 {
00006 printf("usage: rechunk [-f framerate] [-w width] [-h height] [-c fourcc] <input frames> <output movie>\n");
00007 printf(" Concatenate input frames into a Quicktime movie.\n");
00008 exit(1);
00009 return 0;
00010 }
00011
00012 int main(int argc, char *argv[])
00013 {
00014 quicktime_t *file;
00015 FILE *input;
00016 int result = 0;
00017 int i, j;
00018 int64_t length;
00019 char string[1024], *output = 0;
00020 char *data = 0;
00021 int bytes = 0, old_bytes = 0;
00022 float output_rate = 0;
00023 float input_rate;
00024 int64_t input_frame;
00025 int64_t new_length;
00026 int rgb_to_ppm = 0;
00027 char **input_frames = 0;
00028 int total_input_frames = 0;
00029 int width = 720, height = 480;
00030 char compressor[5] = "yv12";
00031
00032 if(argc < 3)
00033 {
00034 usage();
00035 }
00036
00037 for(i = 1, j = 0; i < argc; i++)
00038 {
00039 if(!strcmp(argv[i], "-f"))
00040 {
00041 if(i + 1 < argc)
00042 {
00043 output_rate = atof(argv[++i]);
00044 }
00045 else
00046 usage();
00047 }
00048 else
00049 if(!strcmp(argv[i], "-w"))
00050 {
00051 if(i + 1 < argc)
00052 width = atol(argv[++i]);
00053 else
00054 usage();
00055 }
00056 else
00057 if(!strcmp(argv[i], "-h"))
00058 {
00059 if(i + 1 < argc)
00060 height = atol(argv[++i]);
00061 else
00062 usage();
00063 }
00064 else
00065 if(!strcmp(argv[i], "-c"))
00066 {
00067 if(i + 1 < argc)
00068 {
00069 strncpy(compressor, argv[++i], 4);
00070 }
00071 else
00072 usage();
00073 }
00074 if(i == argc - 1)
00075 {
00076 output = argv[i];
00077 }
00078 else
00079 {
00080 total_input_frames++;
00081 input_frames = realloc(input_frames, sizeof(char*) * total_input_frames);
00082 input_frames[total_input_frames - 1] = argv[i];
00083 }
00084 }
00085
00086 if(!input) usage();
00087
00088 if(input = fopen(output, "rb"))
00089 {
00090 printf("Output file already exists.\n");
00091 exit(1);
00092 }
00093
00094 if(!(file = quicktime_open(output, 0, 1)))
00095 {
00096 printf("Open failed\n");
00097 exit(1);
00098 }
00099
00100 quicktime_set_video(file, 1, width, height, output_rate, compressor);
00101
00102 for(i = 0; i < total_input_frames; i++)
00103 {
00104
00105 if(!(input = fopen(input_frames[i], "rb")))
00106 {
00107 perror("Open failed");
00108 continue;
00109 }
00110
00111
00112 fseek(input, 0, SEEK_END);
00113 bytes = ftell(input);
00114 fseek(input, 0, SEEK_SET);
00115 data = realloc(data, bytes);
00116
00117 fread(data, bytes, 1, input);
00118 quicktime_write_frame(file, data, bytes, 0);
00119 fclose(input);
00120 }
00121
00122 quicktime_close(file);
00123 }