00001 #include "quicktime.h"
00002
00003 int usage(void)
00004 {
00005 printf("usage: yuv4toyuv <input movie> <output.yuv>\n");
00006 printf(" Write a YUV4 encoded movie as a planar YUV 4:2:0 file.\n");
00007 exit(1);
00008 }
00009
00010 int main(int argc, char *argv[])
00011 {
00012 quicktime_t *file;
00013 FILE *output;
00014 int64_t length, width, height, bytes;
00015 char *buffer_in, *y_out, *u_out, *v_out;
00016 char *y_out1, *y_out2, *u_out1, *v_out1;
00017 char *input_row;
00018 int i, j, k, l, m;
00019
00020 if(argc < 3)
00021 {
00022 usage();
00023 }
00024
00025 if(!(file = quicktime_open(argv[1], 1, 0)))
00026 {
00027 printf("Open input failed\n");
00028 exit(1);
00029 }
00030
00031 if(!(output = fopen(argv[2], "wb")))
00032 {
00033 perror("Open output failed");
00034 exit(1);
00035 }
00036
00037 if(!quicktime_video_tracks(file))
00038 {
00039 printf("No video tracks.\n");
00040 exit(1);
00041 }
00042
00043 length = quicktime_video_length(file, 0);
00044 width = quicktime_video_width(file, 0);
00045 height = quicktime_video_height(file, 0);
00046 bytes = width * height + width * height / 2;
00047 buffer_in = calloc(1, bytes);
00048 y_out = calloc(1, width * height);
00049 u_out = calloc(1, width * height / 4);
00050 v_out = calloc(1, width * height / 4);
00051
00052 for(i = 0; i < length; i++)
00053 {
00054 quicktime_set_video_position(file, i, 0);
00055 quicktime_read_data(file, buffer_in, bytes);
00056
00057 u_out1 = u_out;
00058 v_out1 = v_out;
00059 for(j = 0; j < height; j += 2)
00060 {
00061
00062 input_row = &buffer_in[j * width + j * width / 2];
00063 y_out1 = y_out + j * width;
00064 y_out2 = y_out1 + width;
00065
00066 for(k = 0; k < width / 2; k++)
00067 {
00068 *u_out1++ = (int)*input_row++ + 0x80;
00069 *v_out1++ = (int)*input_row++ + 0x80;
00070 *y_out1++ = *input_row++;
00071 *y_out1++ = *input_row++;
00072 *y_out2++ = *input_row++;
00073 *y_out2++ = *input_row++;
00074 }
00075 }
00076
00077 if(!fwrite(y_out, width * height, 1, output))
00078 {
00079 perror("write failed");
00080 fclose(output);
00081 exit(1);
00082 }
00083 if(!fwrite(u_out, width * height / 4, 1, output))
00084 {
00085 perror("write failed");
00086 fclose(output);
00087 exit(1);
00088 }
00089 if(!fwrite(v_out, width * height / 4, 1, output))
00090 {
00091 perror("write failed");
00092 fclose(output);
00093 exit(1);
00094 }
00095 }
00096
00097 quicktime_close(file);
00098 }