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");
10 int main(int argc
, char *argv
[])
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
;
25 if(!(file
= quicktime_open(argv
[1], 1, 0)))
27 printf("Open input failed\n");
31 if(!(output
= fopen(argv
[2], "wb")))
33 perror("Open output failed");
37 if(!quicktime_video_tracks(file
))
39 printf("No video tracks.\n");
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
);
59 for(j
= 0; j
< height
; j
+= 2)
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");
83 if(!fwrite(u_out
, width
* height
/ 4, 1, output
))
85 perror("write failed");
89 if(!fwrite(v_out
, width
* height
/ 4, 1, output
))
91 perror("write failed");
97 quicktime_close(file
);