4 #include "colormodels.h"
8 #define OUTPUT_PATH "movie.mov"
9 //#define VIDEO_CODEC QUICKTIME_DIVX
10 #define VIDEO_CODEC QUICKTIME_JPEG
11 //#define VIDEO_CODEC QUICKTIME_YUV420
12 #define AUDIO_CODEC QUICKTIME_TWOS
13 //#define AUDIO_CODEC QUICKTIME_VORBIS
16 // Hack for libdv to remove glib dependancy
19 g_log (const char *log_domain,
27 g_logv (const char *log_domain,
36 // Hack for XFree86 4.1.0
38 int atexit(void (*function)(void))
44 // Dump mpeg video to a quicktime movie
48 pthread_mutex_t mutex;
51 void* trap_interrupt()
53 pthread_mutex_lock(&mutex);
58 printf("interrupt trapped 1\n");
59 quicktime_close(output);
60 printf("interrupt trapped 2\n");
62 // Can't join any threads in the mpeg library which may have been interrupted
64 // mpeg3_close(input);
72 int main(int argc, char *argv[])
75 char *row_pointers[3];
79 long afragment = 65536;
83 char input_path[1024];
84 char output_path[1024];
86 long current_frame = 0;
87 long current_sample = 0;
89 pthread_mutex_init(&mutex, NULL);
90 signal(SIGINT, trap_interrupt);
97 printf("Usage: %s [-a] [-v] <mpeg file> <output movie> [frame count]\n", argv[0]);
101 for(i = 1; i < argc; i++)
103 if(!strcmp(argv[i], "-a"))
108 if(!strcmp(argv[i], "-v"))
115 strcpy(input_path, argv[i]);
120 strcpy(output_path, argv[i]);
123 frame_count = atol(argv[i]);
126 //printf("main 1\n");
127 if(!(input = mpeg3_open(input_path)))
131 //printf("main 1\n");
133 if(!(output = quicktime_open(output_path, 0, 1)))
137 //printf("main 1\n");
141 if(!mpeg3_total_vstreams(input))
147 quicktime_set_video(output,
149 mpeg3_video_width(input, layer),
150 mpeg3_video_height(input, layer),
151 mpeg3_frame_rate(input, layer),
153 quicktime_set_jpeg(output, 80, 0);
156 //printf("main 1\n");
160 if(!mpeg3_total_astreams(input))
167 channels = mpeg3_audio_channels(input, astream);
169 quicktime_set_audio(output,
171 mpeg3_sample_rate(input, 0),
175 audio_output = malloc(sizeof(float*) * channels);
176 for(i = 0; i < channels; i++)
177 audio_output[i] = malloc(sizeof(float) * afragment);
180 //printf("main 1\n");
182 // quicktime_set_jpeg(output, 100, 0);
183 mpeg3_set_mmx(input, 0);
185 while((!(do_video && mpeg3_end_of_video(input, layer)) ||
186 !(do_audio && mpeg3_end_of_audio(input, astream))) &&
187 (current_frame < frame_count || frame_count < 0))
189 //printf("%d %d\n", mpeg3_end_of_video(input, layer), mpeg3_end_of_audio(input, astream));
192 if(!mpeg3_end_of_audio(input, astream))
194 int fragment = afragment;
199 for(j = 0; j < mpeg3_audio_channels(input, i); j++, k++)
202 mpeg3_read_audio(input,
203 audio_output[k], /* Pointer to pre-allocated buffer of floats */
204 0, /* Pointer to pre-allocated buffer of int16's */
205 j, /* Channel to decode */
206 fragment, /* Number of samples to decode */
209 mpeg3_reread_audio(input,
210 audio_output[k], /* Pointer to pre-allocated buffer of floats */
211 0, /* Pointer to pre-allocated buffer of int16's */
212 j, /* Channel to decode */
213 fragment, /* Number of samples to decode */
219 quicktime_encode_audio(output,
224 current_sample += fragment;
227 printf(" %d samples written\r", current_sample);
232 current_sample += afragment;
237 if(!mpeg3_end_of_video(input, layer))
241 fragment = (long)((double)current_sample /
242 mpeg3_sample_rate(input, 0) *
243 mpeg3_frame_rate(input, layer) -
248 for(i = 0; i < fragment && !mpeg3_end_of_video(input, layer); i++)
250 mpeg3_read_yuvframe_ptr(input,
256 switch(mpeg3_colormodel(input, layer))
259 quicktime_set_cmodel(output, BC_YUV420P);
262 quicktime_set_cmodel(output, BC_YUV422P);
265 quicktime_encode_video(output,
266 (unsigned char **)row_pointers,
270 printf(" %d frames written\r", current_frame);
279 quicktime_close(output);