allow ffmpeg video to resample curr_pos, add bluray format
[goodguy/history.git] / cinelerra-5.0 / quicktime / yuv2mov.c
1 #include "colormodels.h"
2 #include "quicktime.h"
3 #include <signal.h>
4 #include <string.h>
5
6
7 quicktime_t *file = 0;
8 //#define COMPRESSOR QUICKTIME_JPEG
9 #define COMPRESSOR QUICKTIME_MP4V
10 #define CROP_Y1 142
11 #define CROP_Y2 942
12 #define INWIDTH 1920
13 #define INHEIGHT 1080
14 #define FRAMERATE (24000.0 / 1001.0)
15 #define QUANTIZATION 5
16
17 void signal_handler(int signum)
18 {
19         printf("Got signal %d\n", signum);
20         if(file)
21         {
22                 quicktime_close(file);
23         }
24         abort();
25 }
26
27
28 int main(int argc, char *argv[])
29 {
30         if(argc < 2)
31         {
32                 printf("Usage: cat yuvstream | yuv2mov movie.mov\n"
33                         "       Create a movie from a yuv 4:2:0 planar stream.\n");
34                 exit(1);
35         }
36
37         signal(SIGINT, signal_handler);
38
39         int i;
40         char filename[1024];
41         filename[0] = 0;
42         for(i = 1; i < argc; i++)
43         {
44                 if(!filename[0])
45                 {
46                         strcpy(filename, argv[i]);
47                 }
48                 else
49                 {
50                         printf("Unknown option %s\n", argv[i]);
51                         exit(1);
52                 }
53         }
54         
55         if(!filename[0])
56         {
57                 printf("No output filename provided.\n");
58                 exit(1);
59         }
60         
61         if(!(file = quicktime_open(filename, 0, 1)))
62         {
63                 printf("Open '%s' failed\n", filename);
64                 exit(1);
65         }
66
67         quicktime_set_video(file, 
68                 1, 
69                 INWIDTH, 
70                 CROP_Y2 - CROP_Y1, 
71                 FRAMERATE, 
72                 COMPRESSOR);
73
74         int value = 0;
75         value = 20000000;
76         quicktime_set_parameter(file, "ffmpeg_bitrate", &value);
77         value = 5000000;
78         quicktime_set_parameter(file, "ffmpeg_bitrate_tolerance", &value);
79         value = 0;
80         quicktime_set_parameter(file, "ffmpeg_interlaced", &value);
81         value = QUANTIZATION;
82         quicktime_set_parameter(file, "ffmpeg_quantizer", &value);
83         value = 45;
84         quicktime_set_parameter(file, "ffmpeg_gop_size", &value);
85         value = 0;
86         quicktime_set_parameter(file, "ffmpeg_fix_bitrate", &value);
87
88         value = 85;
89         quicktime_set_parameter(file, "jpeg_quality", &value);
90
91         int ysize = INWIDTH * INHEIGHT;
92         int csize = INWIDTH * INHEIGHT / 4;
93         unsigned char *buffer = malloc(INWIDTH * INHEIGHT * 3 / 2);
94         unsigned char *outrows[3];
95         int frame = 0;
96         outrows[0] = buffer + CROP_Y1 * INWIDTH;
97         outrows[1] = buffer + ysize + CROP_Y1 / 2 * INWIDTH / 2;
98         outrows[2] = buffer + ysize + csize + CROP_Y1 / 2 * INWIDTH / 2;
99
100         while(!feof(stdin))
101         {
102                 fread(buffer, INWIDTH * INHEIGHT * 3 / 2, 1, stdin);
103                 quicktime_set_cmodel(file, BC_YUV420P);
104                 quicktime_encode_video(file, 
105                         outrows, 
106                         0);
107                 printf("Wrote frame %d\r", frame++);
108                 fflush(stdout);
109         }
110         quicktime_close(file);
111 }
112