r969: Render format selector: Do not change the path name when the format is changed.
[cinelerra_cv/ct.git] / quicktime / yuv4toyuv.c
blob796d2ba11369381b0d918bb374e71a32677dd6f8
1 #include "quicktime.h"
3 int usage(void)
5 printf("usage: yuv4toyuv <input movie> <output.yuv>\n");
6 printf(" Write a YUV4 encoded movie as a planar YUV 4:2:0 file.\n");
7 exit(1);
10 int main(int argc, char *argv[])
12 quicktime_t *file;
13 FILE *output;
14 int64_t length, width, height, bytes;
15 char *buffer_in, *y_out, *u_out, *v_out;
16 char *y_out1, *y_out2, *u_out1, *v_out1;
17 char *input_row;
18 int i, j, k, l, m;
20 if(argc < 3)
22 usage();
25 if(!(file = quicktime_open(argv[1], 1, 0)))
27 printf("Open input failed\n");
28 exit(1);
31 if(!(output = fopen(argv[2], "wb")))
33 perror("Open output failed");
34 exit(1);
37 if(!quicktime_video_tracks(file))
39 printf("No video tracks.\n");
40 exit(1);
43 length = quicktime_video_length(file, 0);
44 width = quicktime_video_width(file, 0);
45 height = quicktime_video_height(file, 0);
46 bytes = width * height + width * height / 2;
47 buffer_in = calloc(1, bytes);
48 y_out = calloc(1, width * height);
49 u_out = calloc(1, width * height / 4);
50 v_out = calloc(1, width * height / 4);
52 for(i = 0; i < length; i++)
54 quicktime_set_video_position(file, i, 0);
55 quicktime_read_data(file, buffer_in, bytes);
57 u_out1 = u_out;
58 v_out1 = v_out;
59 for(j = 0; j < height; j += 2)
61 // Get 2 rows
62 input_row = &buffer_in[j * width + j * width / 2];
63 y_out1 = y_out + j * width;
64 y_out2 = y_out1 + width;
66 for(k = 0; k < width / 2; k++)
68 *u_out1++ = (int)*input_row++ + 0x80;
69 *v_out1++ = (int)*input_row++ + 0x80;
70 *y_out1++ = *input_row++;
71 *y_out1++ = *input_row++;
72 *y_out2++ = *input_row++;
73 *y_out2++ = *input_row++;
77 if(!fwrite(y_out, width * height, 1, output))
79 perror("write failed");
80 fclose(output);
81 exit(1);
83 if(!fwrite(u_out, width * height / 4, 1, output))
85 perror("write failed");
86 fclose(output);
87 exit(1);
89 if(!fwrite(v_out, width * height / 4, 1, output))
91 perror("write failed");
92 fclose(output);
93 exit(1);
97 quicktime_close(file);