Commit | Line | Data |
---|---|---|
85f07f22 FB |
1 | /* |
2 | * FFmpeg main | |
01310af2 | 3 | * Copyright (c) 2000-2003 Fabrice Bellard |
85f07f22 | 4 | * |
bf5af568 FB |
5 | * This library is free software; you can redistribute it and/or |
6 | * modify it under the terms of the GNU Lesser General Public | |
7 | * License as published by the Free Software Foundation; either | |
8 | * version 2 of the License, or (at your option) any later version. | |
85f07f22 | 9 | * |
bf5af568 | 10 | * This library is distributed in the hope that it will be useful, |
85f07f22 | 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
bf5af568 FB |
12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
13 | * Lesser General Public License for more details. | |
85f07f22 | 14 | * |
bf5af568 FB |
15 | * You should have received a copy of the GNU Lesser General Public |
16 | * License along with this library; if not, write to the Free Software | |
17 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA | |
85f07f22 | 18 | */ |
daf8e955 | 19 | #define HAVE_AV_CONFIG_H |
ce2749d2 | 20 | #include "common.h" |
daf8e955 | 21 | #include "avformat.h" |
10d104e4 | 22 | #include "framehook.h" |
d4ad24c1 FR |
23 | /* usleep() */ |
24 | #include "os_support.h" | |
daf8e955 | 25 | |
bdc4796f | 26 | #ifndef CONFIG_WIN32 |
85f07f22 FB |
27 | #include <unistd.h> |
28 | #include <fcntl.h> | |
29 | #include <sys/ioctl.h> | |
85f07f22 | 30 | #include <sys/time.h> |
85f07f22 | 31 | #include <termios.h> |
5727b222 | 32 | #include <sys/resource.h> |
9680a722 | 33 | #include <signal.h> |
bdc4796f | 34 | #endif |
f3ec2d46 SG |
35 | #ifdef CONFIG_OS2 |
36 | #include <sys/types.h> | |
37 | #include <sys/select.h> | |
38 | #include <stdlib.h> | |
39 | #endif | |
bf5af568 FB |
40 | #include <time.h> |
41 | #include <ctype.h> | |
85f07f22 | 42 | |
01310af2 FB |
43 | #include "cmdutils.h" |
44 | ||
8aa1e3da MN |
45 | #if !defined(INFINITY) && defined(HUGE_VAL) |
46 | #define INFINITY HUGE_VAL | |
47 | #endif | |
85f07f22 | 48 | |
85f07f22 FB |
49 | /* select an input stream for an output stream */ |
50 | typedef struct AVStreamMap { | |
51 | int file_index; | |
52 | int stream_index; | |
53 | } AVStreamMap; | |
54 | ||
55 | extern const OptionDef options[]; | |
56 | ||
02d504a7 FB |
57 | static void show_help(void); |
58 | static void show_license(void); | |
85f07f22 FB |
59 | |
60 | #define MAX_FILES 20 | |
61 | ||
62 | static AVFormatContext *input_files[MAX_FILES]; | |
63 | static int nb_input_files = 0; | |
64 | ||
65 | static AVFormatContext *output_files[MAX_FILES]; | |
66 | static int nb_output_files = 0; | |
67 | ||
68 | static AVStreamMap stream_maps[MAX_FILES]; | |
69 | static int nb_stream_maps; | |
70 | ||
79fdaa4c FB |
71 | static AVInputFormat *file_iformat; |
72 | static AVOutputFormat *file_oformat; | |
817b23ff | 73 | static AVImageFormat *image_format; |
85f07f22 FB |
74 | static int frame_width = 160; |
75 | static int frame_height = 128; | |
880e8ba7 | 76 | static float frame_aspect_ratio = 0; |
63167088 | 77 | static enum PixelFormat frame_pix_fmt = PIX_FMT_YUV420P; |
ab6d194a MN |
78 | static int frame_topBand = 0; |
79 | static int frame_bottomBand = 0; | |
80 | static int frame_leftBand = 0; | |
81 | static int frame_rightBand = 0; | |
14bea432 MN |
82 | static int frame_rate = 25; |
83 | static int frame_rate_base = 1; | |
3aa102be MN |
84 | static int video_bit_rate = 200*1000; |
85 | static int video_bit_rate_tolerance = 4000*1000; | |
85f07f22 | 86 | static int video_qscale = 0; |
3aa102be MN |
87 | static int video_qmin = 2; |
88 | static int video_qmax = 31; | |
17a70fde MN |
89 | static int video_mb_qmin = 2; |
90 | static int video_mb_qmax = 31; | |
9cdd6a24 MN |
91 | static int video_qdiff = 3; |
92 | static float video_qblur = 0.5; | |
93 | static float video_qcomp = 0.5; | |
ac2830ec | 94 | #if 0 //experimental, (can be removed) |
3aa102be MN |
95 | static float video_rc_qsquish=1.0; |
96 | static float video_rc_qmod_amp=0; | |
97 | static int video_rc_qmod_freq=0; | |
ac2830ec | 98 | #endif |
3aa102be MN |
99 | static char *video_rc_override_string=NULL; |
100 | static char *video_rc_eq="tex^qComp"; | |
101 | static int video_rc_buffer_size=0; | |
102 | static float video_rc_buffer_aggressivity=1.0; | |
103 | static int video_rc_max_rate=0; | |
104 | static int video_rc_min_rate=0; | |
105 | static float video_rc_initial_cplx=0; | |
106 | static float video_b_qfactor = 1.25; | |
107 | static float video_b_qoffset = 1.25; | |
b3a391e8 | 108 | static float video_i_qfactor = -0.8; |
3aa102be | 109 | static float video_i_qoffset = 0.0; |
3bea5386 | 110 | static int me_method = ME_EPZS; |
85f07f22 FB |
111 | static int video_disable = 0; |
112 | static int video_codec_id = CODEC_ID_NONE; | |
113 | static int same_quality = 0; | |
bc6caae2 | 114 | static int b_frames = 0; |
7d1c3fc1 | 115 | static int mb_decision = FF_MB_DECISION_SIMPLE; |
29da453b | 116 | static int use_4mv = 0; |
21e59552 MN |
117 | static int use_aic = 0; |
118 | static int use_umv = 0; | |
cfcf0ffd | 119 | static int do_deinterlace = 0; |
4d2858de MN |
120 | static int workaround_bugs = FF_BUG_AUTODETECT; |
121 | static int error_resilience = 2; | |
122 | static int error_concealment = 3; | |
463678ac | 123 | static int dct_algo = 0; |
2ad1516a | 124 | static int idct_algo = 0; |
1dbb6d90 MN |
125 | static int use_part = 0; |
126 | static int packet_size = 0; | |
f560dd82 | 127 | static int strict = 0; |
59b571c1 | 128 | static int debug = 0; |
b1b77fe9 | 129 | extern int loop_input; /* currently a hack */ |
85f07f22 FB |
130 | |
131 | static int gop_size = 12; | |
132 | static int intra_only = 0; | |
133 | static int audio_sample_rate = 44100; | |
134 | static int audio_bit_rate = 64000; | |
135 | static int audio_disable = 0; | |
136 | static int audio_channels = 1; | |
137 | static int audio_codec_id = CODEC_ID_NONE; | |
138 | ||
0c1a9eda | 139 | static int64_t recording_time = 0; |
85f07f22 FB |
140 | static int file_overwrite = 0; |
141 | static char *str_title = NULL; | |
142 | static char *str_author = NULL; | |
143 | static char *str_copyright = NULL; | |
144 | static char *str_comment = NULL; | |
5727b222 | 145 | static int do_benchmark = 0; |
a0663ba4 | 146 | static int do_hex_dump = 0; |
43f1708f | 147 | static int do_psnr = 0; |
ce7c56c2 | 148 | static int do_vstats = 0; |
5abdb4b1 | 149 | static int do_pass = 0; |
b0368839 | 150 | static int bitexact = 0; |
5abdb4b1 | 151 | static char *pass_logfilename = NULL; |
1629626f FB |
152 | static int audio_stream_copy = 0; |
153 | static int video_stream_copy = 0; | |
5abdb4b1 | 154 | |
bdfcbbed MK |
155 | static int rate_emu = 0; |
156 | ||
8aa3ee32 | 157 | static char *video_grab_format = "video4linux"; |
79a7c268 | 158 | static char *video_device = NULL; |
a5df11ab | 159 | static int video_channel = 0; |
e3ee3283 | 160 | static char *video_standard = "ntsc"; |
79a7c268 | 161 | |
8aa3ee32 | 162 | static char *audio_grab_format = "audio_device"; |
79a7c268 | 163 | static char *audio_device = NULL; |
8aa3ee32 | 164 | |
d9a916e2 | 165 | static int using_stdin = 0; |
f068206e | 166 | static int verbose = 1; |
d9a916e2 | 167 | |
5abdb4b1 | 168 | #define DEFAULT_PASS_LOGFILENAME "ffmpeg2pass" |
85f07f22 FB |
169 | |
170 | typedef struct AVOutputStream { | |
171 | int file_index; /* file index */ | |
172 | int index; /* stream index in the output file */ | |
173 | int source_index; /* AVInputStream index */ | |
174 | AVStream *st; /* stream in the output file */ | |
ec5517d5 FB |
175 | int encoding_needed; /* true if encoding needed for this stream */ |
176 | int frame_number; | |
177 | /* input pts and corresponding output pts | |
178 | for A/V sync */ | |
179 | double sync_ipts; | |
c11ef252 | 180 | double sync_ipts_offset; |
0c1a9eda | 181 | int64_t sync_opts; |
85f07f22 | 182 | /* video only */ |
34b10a57 D |
183 | int video_resample; /* video_resample and video_crop are mutually exclusive */ |
184 | AVPicture pict_tmp; /* temporary image for resampling */ | |
85f07f22 | 185 | ImgReSampleContext *img_resample_ctx; /* for image resampling */ |
34b10a57 D |
186 | |
187 | int video_crop; /* video_resample and video_crop are mutually exclusive */ | |
188 | int topBand; /* cropping area sizes */ | |
189 | int leftBand; | |
85f07f22 FB |
190 | |
191 | /* audio only */ | |
192 | int audio_resample; | |
193 | ReSampleContext *resample; /* for audio resampling */ | |
194 | FifoBuffer fifo; /* for compression: one audio fifo per codec */ | |
5abdb4b1 | 195 | FILE *logfile; |
85f07f22 FB |
196 | } AVOutputStream; |
197 | ||
198 | typedef struct AVInputStream { | |
199 | int file_index; | |
200 | int index; | |
201 | AVStream *st; | |
202 | int discard; /* true if stream data should be discarded */ | |
203 | int decoding_needed; /* true if the packets must be decoded in 'raw_fifo' */ | |
0c1a9eda | 204 | int64_t sample_index; /* current sample */ |
ec5517d5 | 205 | int frame_decoded; /* true if a video or audio frame has been decoded */ |
bdfcbbed MK |
206 | |
207 | int64_t start; /* time when read started */ | |
208 | unsigned long frame; /* current frame */ | |
e7d0374f RS |
209 | AVFrac next_pts; /* synthetic pts for cases where pkt.pts == 0 */ |
210 | int64_t pts; /* current pts */ | |
85f07f22 FB |
211 | } AVInputStream; |
212 | ||
213 | typedef struct AVInputFile { | |
214 | int eof_reached; /* true if eof reached */ | |
215 | int ist_index; /* index of first stream in ist_table */ | |
216 | int buffer_size; /* current total buffer size */ | |
217 | int buffer_size_max; /* buffer size at which we consider we can stop | |
218 | buffering */ | |
79fdaa4c | 219 | int nb_streams; /* nb streams we are aware of */ |
85f07f22 FB |
220 | } AVInputFile; |
221 | ||
bdc4796f FB |
222 | #ifndef CONFIG_WIN32 |
223 | ||
85f07f22 FB |
224 | /* init terminal so that we can grab keys */ |
225 | static struct termios oldtty; | |
226 | ||
227 | static void term_exit(void) | |
228 | { | |
229 | tcsetattr (0, TCSANOW, &oldtty); | |
230 | } | |
231 | ||
9680a722 RP |
232 | static volatile sig_atomic_t received_sigterm = 0; |
233 | ||
234 | static void | |
235 | sigterm_handler(int sig) | |
236 | { | |
237 | received_sigterm = sig; | |
238 | term_exit(); | |
239 | } | |
240 | ||
85f07f22 FB |
241 | static void term_init(void) |
242 | { | |
243 | struct termios tty; | |
244 | ||
245 | tcgetattr (0, &tty); | |
246 | oldtty = tty; | |
247 | ||
248 | tty.c_iflag &= ~(IGNBRK|BRKINT|PARMRK|ISTRIP | |
249 | |INLCR|IGNCR|ICRNL|IXON); | |
250 | tty.c_oflag |= OPOST; | |
251 | tty.c_lflag &= ~(ECHO|ECHONL|ICANON|IEXTEN); | |
252 | tty.c_cflag &= ~(CSIZE|PARENB); | |
253 | tty.c_cflag |= CS8; | |
254 | tty.c_cc[VMIN] = 1; | |
255 | tty.c_cc[VTIME] = 0; | |
256 | ||
257 | tcsetattr (0, TCSANOW, &tty); | |
258 | ||
9680a722 RP |
259 | signal(SIGINT , sigterm_handler); /* Interrupt (ANSI). */ |
260 | signal(SIGQUIT, sigterm_handler); /* Quit (POSIX). */ | |
261 | signal(SIGTERM, sigterm_handler); /* Termination (ANSI). */ | |
262 | /* | |
263 | register a function to be called at normal program termination | |
264 | */ | |
85f07f22 | 265 | atexit(term_exit); |
9ddd71fc FR |
266 | #ifdef CONFIG_BEOS_NETSERVER |
267 | fcntl(0, F_SETFL, fcntl(0, F_GETFL) | O_NONBLOCK); | |
268 | #endif | |
85f07f22 FB |
269 | } |
270 | ||
271 | /* read a key without blocking */ | |
272 | static int read_key(void) | |
273 | { | |
9ddd71fc | 274 | int n = 1; |
85f07f22 | 275 | unsigned char ch; |
9ddd71fc FR |
276 | #ifndef CONFIG_BEOS_NETSERVER |
277 | struct timeval tv; | |
85f07f22 FB |
278 | fd_set rfds; |
279 | ||
280 | FD_ZERO(&rfds); | |
281 | FD_SET(0, &rfds); | |
282 | tv.tv_sec = 0; | |
283 | tv.tv_usec = 0; | |
284 | n = select(1, &rfds, NULL, NULL, &tv); | |
9ddd71fc | 285 | #endif |
85f07f22 | 286 | if (n > 0) { |
cb09b2ed PG |
287 | n = read(0, &ch, 1); |
288 | if (n == 1) | |
85f07f22 | 289 | return ch; |
cb09b2ed PG |
290 | |
291 | return n; | |
85f07f22 FB |
292 | } |
293 | return -1; | |
294 | } | |
295 | ||
a38469e1 | 296 | #else |
85f07f22 | 297 | |
a38469e1 FB |
298 | /* no interactive support */ |
299 | static void term_exit(void) | |
85f07f22 | 300 | { |
a38469e1 | 301 | } |
85f07f22 | 302 | |
a38469e1 FB |
303 | static void term_init(void) |
304 | { | |
305 | } | |
85f07f22 | 306 | |
a38469e1 FB |
307 | static int read_key(void) |
308 | { | |
cb09b2ed | 309 | return 0; |
85f07f22 FB |
310 | } |
311 | ||
a38469e1 | 312 | #endif |
bdc4796f | 313 | |
b29f97d1 | 314 | static int read_ffserver_streams(AVFormatContext *s, const char *filename) |
85f07f22 | 315 | { |
79fdaa4c | 316 | int i, err; |
85f07f22 FB |
317 | AVFormatContext *ic; |
318 | ||
79fdaa4c FB |
319 | err = av_open_input_file(&ic, filename, NULL, FFM_PACKET_SIZE, NULL); |
320 | if (err < 0) | |
321 | return err; | |
85f07f22 FB |
322 | /* copy stream format */ |
323 | s->nb_streams = ic->nb_streams; | |
324 | for(i=0;i<ic->nb_streams;i++) { | |
325 | AVStream *st; | |
1e491e29 | 326 | |
e1031171 | 327 | st = av_mallocz(sizeof(AVStream)); |
85f07f22 FB |
328 | memcpy(st, ic->streams[i], sizeof(AVStream)); |
329 | s->streams[i] = st; | |
330 | } | |
331 | ||
332 | av_close_input_file(ic); | |
333 | return 0; | |
334 | } | |
335 | ||
817b23ff | 336 | #define MAX_AUDIO_PACKET_SIZE (128 * 1024) |
85f07f22 FB |
337 | |
338 | static void do_audio_out(AVFormatContext *s, | |
339 | AVOutputStream *ost, | |
340 | AVInputStream *ist, | |
341 | unsigned char *buf, int size) | |
342 | { | |
0c1a9eda | 343 | uint8_t *buftmp; |
d66c7abc SC |
344 | static uint8_t *audio_buf = NULL; |
345 | static uint8_t *audio_out = NULL; | |
558eae03 | 346 | const int audio_out_size= 4*MAX_AUDIO_PACKET_SIZE; |
d66c7abc | 347 | |
85f07f22 FB |
348 | int size_out, frame_bytes, ret; |
349 | AVCodecContext *enc; | |
350 | ||
d66c7abc SC |
351 | /* SC: dynamic allocation of buffers */ |
352 | if (!audio_buf) | |
353 | audio_buf = av_malloc(2*MAX_AUDIO_PACKET_SIZE); | |
354 | if (!audio_out) | |
558eae03 | 355 | audio_out = av_malloc(audio_out_size); |
d66c7abc SC |
356 | if (!audio_buf || !audio_out) |
357 | return; /* Should signal an error ! */ | |
358 | ||
359 | ||
85f07f22 FB |
360 | enc = &ost->st->codec; |
361 | ||
362 | if (ost->audio_resample) { | |
363 | buftmp = audio_buf; | |
364 | size_out = audio_resample(ost->resample, | |
365 | (short *)buftmp, (short *)buf, | |
366 | size / (ist->st->codec.channels * 2)); | |
367 | size_out = size_out * enc->channels * 2; | |
368 | } else { | |
369 | buftmp = buf; | |
370 | size_out = size; | |
371 | } | |
372 | ||
373 | /* now encode as many frames as possible */ | |
a0663ba4 | 374 | if (enc->frame_size > 1) { |
85f07f22 FB |
375 | /* output resampled raw samples */ |
376 | fifo_write(&ost->fifo, buftmp, size_out, | |
377 | &ost->fifo.wptr); | |
378 | ||
379 | frame_bytes = enc->frame_size * 2 * enc->channels; | |
380 | ||
381 | while (fifo_read(&ost->fifo, audio_buf, frame_bytes, | |
382 | &ost->fifo.rptr) == 0) { | |
558eae03 | 383 | ret = avcodec_encode_audio(enc, audio_out, audio_out_size, |
a0663ba4 | 384 | (short *)audio_buf); |
ec5517d5 | 385 | av_write_frame(s, ost->index, audio_out, ret); |
85f07f22 FB |
386 | } |
387 | } else { | |
a0663ba4 FB |
388 | /* output a pcm frame */ |
389 | /* XXX: change encoding codec API to avoid this ? */ | |
390 | switch(enc->codec->id) { | |
391 | case CODEC_ID_PCM_S16LE: | |
392 | case CODEC_ID_PCM_S16BE: | |
393 | case CODEC_ID_PCM_U16LE: | |
394 | case CODEC_ID_PCM_U16BE: | |
395 | break; | |
396 | default: | |
397 | size_out = size_out >> 1; | |
398 | break; | |
399 | } | |
400 | ret = avcodec_encode_audio(enc, audio_out, size_out, | |
ff29712a | 401 | (short *)buftmp); |
ec5517d5 | 402 | av_write_frame(s, ost->index, audio_out, ret); |
85f07f22 FB |
403 | } |
404 | } | |
405 | ||
10d104e4 PG |
406 | static void pre_process_video_frame(AVInputStream *ist, AVPicture *picture, void **bufp) |
407 | { | |
408 | AVCodecContext *dec; | |
409 | AVPicture *picture2; | |
410 | AVPicture picture_tmp; | |
0c1a9eda | 411 | uint8_t *buf = 0; |
10d104e4 PG |
412 | |
413 | dec = &ist->st->codec; | |
414 | ||
415 | /* deinterlace : must be done before any resize */ | |
416 | if (do_deinterlace) { | |
417 | int size; | |
418 | ||
419 | /* create temporary picture */ | |
420 | size = avpicture_get_size(dec->pix_fmt, dec->width, dec->height); | |
421 | buf = av_malloc(size); | |
422 | if (!buf) | |
423 | return; | |
424 | ||
425 | picture2 = &picture_tmp; | |
426 | avpicture_fill(picture2, buf, dec->pix_fmt, dec->width, dec->height); | |
427 | ||
428 | if (avpicture_deinterlace(picture2, picture, | |
429 | dec->pix_fmt, dec->width, dec->height) < 0) { | |
430 | /* if error, do not deinterlace */ | |
431 | av_free(buf); | |
432 | buf = NULL; | |
433 | picture2 = picture; | |
434 | } | |
435 | } else { | |
436 | picture2 = picture; | |
437 | } | |
438 | ||
439 | frame_hook_process(picture2, dec->pix_fmt, dec->width, dec->height); | |
440 | ||
441 | if (picture != picture2) | |
442 | *picture = *picture2; | |
443 | *bufp = buf; | |
444 | } | |
445 | ||
ec5517d5 FB |
446 | /* we begin to correct av delay at this threshold */ |
447 | #define AV_DELAY_MAX 0.100 | |
85f07f22 FB |
448 | |
449 | static void do_video_out(AVFormatContext *s, | |
450 | AVOutputStream *ost, | |
451 | AVInputStream *ist, | |
34b10a57 | 452 | AVPicture *in_picture, |
ec5517d5 | 453 | int *frame_size, AVOutputStream *audio_sync) |
85f07f22 | 454 | { |
ec5517d5 | 455 | int nb_frames, i, ret; |
34b10a57 D |
456 | AVPicture *final_picture, *formatted_picture; |
457 | AVPicture picture_format_temp, picture_crop_temp; | |
0c1a9eda ZK |
458 | static uint8_t *video_buffer; |
459 | uint8_t *buf = NULL, *buf1 = NULL; | |
cfcf0ffd | 460 | AVCodecContext *enc, *dec; |
85f07f22 | 461 | |
33a1f1a3 | 462 | #define VIDEO_BUFFER_SIZE (1024*1024) |
33a1f1a3 | 463 | |
85f07f22 | 464 | enc = &ost->st->codec; |
cfcf0ffd | 465 | dec = &ist->st->codec; |
85f07f22 | 466 | |
ec5517d5 FB |
467 | /* by default, we output a single frame */ |
468 | nb_frames = 1; | |
469 | ||
204c0f48 PG |
470 | *frame_size = 0; |
471 | ||
ec5517d5 FB |
472 | /* NOTE: the A/V sync is always done by considering the audio is |
473 | the master clock. It is suffisant for transcoding or playing, | |
474 | but not for the general case */ | |
475 | if (audio_sync) { | |
476 | /* compute the A-V delay and duplicate/remove frames if needed */ | |
e7d0374f RS |
477 | double adelta, vdelta, av_delay; |
478 | ||
479 | adelta = audio_sync->sync_ipts - ((double)audio_sync->sync_opts * | |
480 | s->pts_num / s->pts_den); | |
481 | ||
482 | vdelta = ost->sync_ipts - ((double)ost->sync_opts * | |
483 | s->pts_num / s->pts_den); | |
484 | ||
485 | av_delay = adelta - vdelta; | |
486 | // printf("delay=%f\n", av_delay); | |
487 | if (av_delay < -AV_DELAY_MAX) | |
488 | nb_frames = 2; | |
489 | else if (av_delay > AV_DELAY_MAX) | |
490 | nb_frames = 0; | |
10d104e4 PG |
491 | } else { |
492 | double vdelta; | |
493 | ||
e7d0374f RS |
494 | vdelta = (double)(ost->st->pts.val) * s->pts_num / s->pts_den - (ost->sync_ipts - ost->sync_ipts_offset); |
495 | if (vdelta < 100 && vdelta > -100 && ost->sync_ipts_offset) { | |
496 | if (vdelta < -AV_DELAY_MAX) | |
497 | nb_frames = 2; | |
498 | else if (vdelta > AV_DELAY_MAX) | |
499 | nb_frames = 0; | |
500 | } else { | |
501 | ost->sync_ipts_offset -= vdelta; | |
502 | if (!ost->sync_ipts_offset) | |
503 | ost->sync_ipts_offset = 0.000001; /* one microsecond */ | |
10d104e4 | 504 | } |
ec5517d5 | 505 | } |
445f1b83 RS |
506 | |
507 | #if defined(AVSYNC_DEBUG) | |
508 | static char *action[] = { "drop frame", "copy frame", "dup frame" }; | |
509 | if (audio_sync) | |
510 | fprintf(stderr, "Input APTS %12.6f, output APTS %12.6f, ", | |
511 | (double) audio_sync->sync_ipts, | |
512 | (double) audio_sync->st->pts.val * s->pts_num / s->pts_den); | |
513 | fprintf(stderr, "Input VPTS %12.6f, output VPTS %12.6f: %s\n", | |
514 | (double) ost->sync_ipts, | |
515 | (double) ost->st->pts.val * s->pts_num / s->pts_den, | |
516 | action[nb_frames]); | |
517 | #endif | |
518 | ||
ec5517d5 | 519 | if (nb_frames <= 0) |
85f07f22 | 520 | return; |
ce7c56c2 | 521 | |
cb09b2ed | 522 | if (!video_buffer) |
ec5517d5 FB |
523 | video_buffer = av_malloc(VIDEO_BUFFER_SIZE); |
524 | if (!video_buffer) | |
525 | return; | |
c04643a2 | 526 | |
cfcf0ffd FB |
527 | /* convert pixel format if needed */ |
528 | if (enc->pix_fmt != dec->pix_fmt) { | |
529 | int size; | |
530 | ||
531 | /* create temporary picture */ | |
532 | size = avpicture_get_size(enc->pix_fmt, dec->width, dec->height); | |
0f1578af | 533 | buf = av_malloc(size); |
cfcf0ffd FB |
534 | if (!buf) |
535 | return; | |
34b10a57 D |
536 | formatted_picture = &picture_format_temp; |
537 | avpicture_fill(formatted_picture, buf, enc->pix_fmt, dec->width, dec->height); | |
cfcf0ffd | 538 | |
34b10a57 D |
539 | if (img_convert(formatted_picture, enc->pix_fmt, |
540 | in_picture, dec->pix_fmt, | |
cfcf0ffd FB |
541 | dec->width, dec->height) < 0) { |
542 | fprintf(stderr, "pixel format conversion not handled\n"); | |
543 | goto the_end; | |
544 | } | |
545 | } else { | |
34b10a57 | 546 | formatted_picture = in_picture; |
cfcf0ffd FB |
547 | } |
548 | ||
549 | /* XXX: resampling could be done before raw format convertion in | |
550 | some cases to go faster */ | |
551 | /* XXX: only works for YUV420P */ | |
85f07f22 | 552 | if (ost->video_resample) { |
34b10a57 D |
553 | final_picture = &ost->pict_tmp; |
554 | img_resample(ost->img_resample_ctx, final_picture, formatted_picture); | |
555 | } else if (ost->video_crop) { | |
556 | picture_crop_temp.data[0] = formatted_picture->data[0] + | |
557 | (ost->topBand * formatted_picture->linesize[0]) + ost->leftBand; | |
558 | ||
559 | picture_crop_temp.data[1] = formatted_picture->data[1] + | |
560 | ((ost->topBand >> 1) * formatted_picture->linesize[1]) + | |
561 | (ost->leftBand >> 1); | |
562 | ||
563 | picture_crop_temp.data[2] = formatted_picture->data[2] + | |
564 | ((ost->topBand >> 1) * formatted_picture->linesize[2]) + | |
565 | (ost->leftBand >> 1); | |
566 | ||
567 | picture_crop_temp.linesize[0] = formatted_picture->linesize[0]; | |
568 | picture_crop_temp.linesize[1] = formatted_picture->linesize[1]; | |
569 | picture_crop_temp.linesize[2] = formatted_picture->linesize[2]; | |
570 | final_picture = &picture_crop_temp; | |
85f07f22 | 571 | } else { |
34b10a57 | 572 | final_picture = formatted_picture; |
85f07f22 | 573 | } |
85f07f22 FB |
574 | /* duplicates frame if needed */ |
575 | /* XXX: pb because no interleaving */ | |
ec5517d5 | 576 | for(i=0;i<nb_frames;i++) { |
e8750b00 FR |
577 | if (s->oformat->flags & AVFMT_RAWPICTURE) { |
578 | /* raw pictures are written as AVPicture structure to | |
579 | avoid any copies. We support temorarily the older | |
580 | method. */ | |
581 | av_write_frame(s, ost->index, | |
582 | (uint8_t *)final_picture, sizeof(AVPicture)); | |
583 | } else { | |
492cd3a9 | 584 | AVFrame big_picture; |
1e491e29 | 585 | |
492cd3a9 | 586 | memset(&big_picture, 0, sizeof(AVFrame)); |
34b10a57 | 587 | *(AVPicture*)&big_picture= *final_picture; |
1e491e29 | 588 | |
85f07f22 FB |
589 | /* handles sameq here. This is not correct because it may |
590 | not be a global option */ | |
591 | if (same_quality) { | |
1e491e29 MN |
592 | big_picture.quality = ist->st->quality; |
593 | }else | |
594 | big_picture.quality = ost->st->quality; | |
6dc96cb0 | 595 | |
cfcf0ffd | 596 | ret = avcodec_encode_video(enc, |
33a1f1a3 | 597 | video_buffer, VIDEO_BUFFER_SIZE, |
1e491e29 | 598 | &big_picture); |
44429457 | 599 | //enc->frame_number = enc->real_pict_num; |
ec5517d5 | 600 | av_write_frame(s, ost->index, video_buffer, ret); |
ce7c56c2 | 601 | *frame_size = ret; |
a5dc85ef | 602 | //fprintf(stderr,"\nFrame: %3d %3d size: %5d type: %d", |
44429457 | 603 | // enc->frame_number-1, enc->real_pict_num, ret, |
a5dc85ef | 604 | // enc->pict_type); |
5abdb4b1 FB |
605 | /* if two pass, output log */ |
606 | if (ost->logfile && enc->stats_out) { | |
607 | fprintf(ost->logfile, "%s", enc->stats_out); | |
608 | } | |
85f07f22 | 609 | } |
ec5517d5 | 610 | ost->frame_number++; |
85f07f22 | 611 | } |
ec5517d5 | 612 | the_end: |
0f1578af FB |
613 | av_free(buf); |
614 | av_free(buf1); | |
85f07f22 FB |
615 | } |
616 | ||
140cb663 MN |
617 | static double psnr(double d){ |
618 | if(d==0) return INFINITY; | |
b29f97d1 | 619 | return -10.0*log(d)/log(10.0); |
140cb663 MN |
620 | } |
621 | ||
ec5517d5 FB |
622 | static void do_video_stats(AVFormatContext *os, AVOutputStream *ost, |
623 | int frame_size) | |
ce7c56c2 J |
624 | { |
625 | static FILE *fvstats=NULL; | |
0c1a9eda | 626 | static int64_t total_size = 0; |
ce7c56c2 | 627 | char filename[40]; |
bf5af568 FB |
628 | time_t today2; |
629 | struct tm *today; | |
ce7c56c2 J |
630 | AVCodecContext *enc; |
631 | int frame_number; | |
0c1a9eda | 632 | int64_t ti; |
ce7c56c2 J |
633 | double ti1, bitrate, avg_bitrate; |
634 | ||
635 | if (!fvstats) { | |
636 | today2 = time(NULL); | |
637 | today = localtime(&today2); | |
638 | sprintf(filename, "vstats_%02d%02d%02d.log", today->tm_hour, | |
639 | today->tm_min, | |
640 | today->tm_sec); | |
641 | fvstats = fopen(filename,"w"); | |
642 | if (!fvstats) { | |
643 | perror("fopen"); | |
644 | exit(1); | |
645 | } | |
646 | } | |
647 | ||
648 | ti = MAXINT64; | |
649 | enc = &ost->st->codec; | |
650 | total_size += frame_size; | |
651 | if (enc->codec_type == CODEC_TYPE_VIDEO) { | |
ec5517d5 | 652 | frame_number = ost->frame_number; |
492cd3a9 | 653 | fprintf(fvstats, "frame= %5d q= %2.1f ", frame_number, enc->coded_frame->quality); |
140cb663 | 654 | if (enc->flags&CODEC_FLAG_PSNR) |
492cd3a9 | 655 | fprintf(fvstats, "PSNR= %6.2f ", psnr(enc->coded_frame->error[0]/(enc->width*enc->height*255.0*255.0))); |
ce7c56c2 J |
656 | |
657 | fprintf(fvstats,"f_size= %6d ", frame_size); | |
ec5517d5 FB |
658 | /* compute pts value */ |
659 | ti1 = (double)ost->st->pts.val * os->pts_num / os->pts_den; | |
ce7c56c2 J |
660 | if (ti1 < 0.01) |
661 | ti1 = 0.01; | |
662 | ||
14bea432 | 663 | bitrate = (double)(frame_size * 8) * enc->frame_rate / enc->frame_rate_base / 1000.0; |
ce7c56c2 J |
664 | avg_bitrate = (double)(total_size * 8) / ti1 / 1000.0; |
665 | fprintf(fvstats, "s_size= %8.0fkB time= %0.3f br= %7.1fkbits/s avg_br= %7.1fkbits/s ", | |
666 | (double)total_size / 1024, ti1, bitrate, avg_bitrate); | |
3db320ea | 667 | fprintf(fvstats,"type= %c\n", av_get_pict_type_char(enc->coded_frame->pict_type)); |
ce7c56c2 | 668 | } |
ec5517d5 FB |
669 | } |
670 | ||
b29f97d1 ZK |
671 | static void print_report(AVFormatContext **output_files, |
672 | AVOutputStream **ost_table, int nb_ostreams, | |
673 | int is_last_report) | |
ec5517d5 FB |
674 | { |
675 | char buf[1024]; | |
676 | AVOutputStream *ost; | |
677 | AVFormatContext *oc, *os; | |
0c1a9eda | 678 | int64_t total_size; |
ec5517d5 FB |
679 | AVCodecContext *enc; |
680 | int frame_number, vid, i; | |
681 | double bitrate, ti1, pts; | |
0c1a9eda | 682 | static int64_t last_time = -1; |
ec5517d5 FB |
683 | |
684 | if (!is_last_report) { | |
0c1a9eda | 685 | int64_t cur_time; |
ec5517d5 FB |
686 | /* display the report every 0.5 seconds */ |
687 | cur_time = av_gettime(); | |
688 | if (last_time == -1) { | |
689 | last_time = cur_time; | |
690 | return; | |
691 | } | |
692 | if ((cur_time - last_time) < 500000) | |
693 | return; | |
694 | last_time = cur_time; | |
695 | } | |
696 | ||
ce7c56c2 | 697 | |
ec5517d5 FB |
698 | oc = output_files[0]; |
699 | ||
700 | total_size = url_ftell(&oc->pb); | |
701 | ||
702 | buf[0] = '\0'; | |
703 | ti1 = 1e10; | |
704 | vid = 0; | |
705 | for(i=0;i<nb_ostreams;i++) { | |
706 | ost = ost_table[i]; | |
707 | os = output_files[ost->file_index]; | |
708 | enc = &ost->st->codec; | |
10d104e4 | 709 | if (vid && enc->codec_type == CODEC_TYPE_VIDEO) { |
1e491e29 | 710 | sprintf(buf + strlen(buf), "q=%2.1f ", |
492cd3a9 | 711 | enc->coded_frame->quality); |
10d104e4 | 712 | } |
ec5517d5 FB |
713 | if (!vid && enc->codec_type == CODEC_TYPE_VIDEO) { |
714 | frame_number = ost->frame_number; | |
1e491e29 | 715 | sprintf(buf + strlen(buf), "frame=%5d q=%2.1f ", |
492cd3a9 | 716 | frame_number, enc->coded_frame ? enc->coded_frame->quality : 0); |
140cb663 | 717 | if (enc->flags&CODEC_FLAG_PSNR) |
492cd3a9 | 718 | sprintf(buf + strlen(buf), "PSNR= %6.2f ", psnr(enc->coded_frame->error[0]/(enc->width*enc->height*255.0*255.0))); |
ec5517d5 FB |
719 | vid = 1; |
720 | } | |
721 | /* compute min output value */ | |
722 | pts = (double)ost->st->pts.val * os->pts_num / os->pts_den; | |
5d9827bc | 723 | if ((pts < ti1) && (pts > 0)) |
ec5517d5 FB |
724 | ti1 = pts; |
725 | } | |
726 | if (ti1 < 0.01) | |
727 | ti1 = 0.01; | |
ec5517d5 | 728 | |
f068206e BE |
729 | if (verbose || is_last_report) { |
730 | bitrate = (double)(total_size * 8) / ti1 / 1000.0; | |
731 | ||
732 | sprintf(buf + strlen(buf), | |
ec5517d5 FB |
733 | "size=%8.0fkB time=%0.1f bitrate=%6.1fkbits/s", |
734 | (double)total_size / 1024, ti1, bitrate); | |
f068206e BE |
735 | |
736 | fprintf(stderr, "%s \r", buf); | |
ec5517d5 FB |
737 | fflush(stderr); |
738 | } | |
f068206e BE |
739 | |
740 | if (is_last_report) | |
741 | fprintf(stderr, "\n"); | |
ce7c56c2 J |
742 | } |
743 | ||
85f07f22 FB |
744 | /* |
745 | * The following code is the main loop of the file converter | |
746 | */ | |
747 | static int av_encode(AVFormatContext **output_files, | |
748 | int nb_output_files, | |
749 | AVFormatContext **input_files, | |
750 | int nb_input_files, | |
751 | AVStreamMap *stream_maps, int nb_stream_maps) | |
752 | { | |
445f1b83 | 753 | int ret, i, j, k, n, nb_istreams = 0, nb_ostreams = 0; |
85f07f22 FB |
754 | AVFormatContext *is, *os; |
755 | AVCodecContext *codec, *icodec; | |
756 | AVOutputStream *ost, **ost_table = NULL; | |
757 | AVInputStream *ist, **ist_table = NULL; | |
bdc4796f | 758 | AVInputFile *file_table; |
51bd4565 | 759 | AVFormatContext *stream_no_data; |
cb09b2ed | 760 | int key; |
bdc4796f | 761 | |
51bd4565 | 762 | file_table= (AVInputFile*) av_mallocz(nb_input_files * sizeof(AVInputFile)); |
bdc4796f FB |
763 | if (!file_table) |
764 | goto fail; | |
85f07f22 | 765 | |
85f07f22 FB |
766 | /* input stream init */ |
767 | j = 0; | |
768 | for(i=0;i<nb_input_files;i++) { | |
769 | is = input_files[i]; | |
770 | file_table[i].ist_index = j; | |
79fdaa4c | 771 | file_table[i].nb_streams = is->nb_streams; |
85f07f22 FB |
772 | j += is->nb_streams; |
773 | } | |
774 | nb_istreams = j; | |
775 | ||
776 | ist_table = av_mallocz(nb_istreams * sizeof(AVInputStream *)); | |
777 | if (!ist_table) | |
bdc4796f | 778 | goto fail; |
85f07f22 FB |
779 | |
780 | for(i=0;i<nb_istreams;i++) { | |
781 | ist = av_mallocz(sizeof(AVInputStream)); | |
782 | if (!ist) | |
783 | goto fail; | |
784 | ist_table[i] = ist; | |
785 | } | |
786 | j = 0; | |
787 | for(i=0;i<nb_input_files;i++) { | |
788 | is = input_files[i]; | |
789 | for(k=0;k<is->nb_streams;k++) { | |
790 | ist = ist_table[j++]; | |
791 | ist->st = is->streams[k]; | |
792 | ist->file_index = i; | |
793 | ist->index = k; | |
794 | ist->discard = 1; /* the stream is discarded by default | |
795 | (changed later) */ | |
bdfcbbed MK |
796 | |
797 | if (ist->st->codec.rate_emu) { | |
798 | ist->start = av_gettime(); | |
799 | ist->frame = 0; | |
800 | } | |
85f07f22 FB |
801 | } |
802 | } | |
803 | ||
804 | /* output stream init */ | |
805 | nb_ostreams = 0; | |
806 | for(i=0;i<nb_output_files;i++) { | |
807 | os = output_files[i]; | |
808 | nb_ostreams += os->nb_streams; | |
809 | } | |
810 | if (nb_stream_maps > 0 && nb_stream_maps != nb_ostreams) { | |
811 | fprintf(stderr, "Number of stream maps must match number of output streams\n"); | |
812 | exit(1); | |
813 | } | |
814 | ||
bd073980 BF |
815 | /* Sanity check the mapping args -- do the input files & streams exist? */ |
816 | for(i=0;i<nb_stream_maps;i++) { | |
817 | int fi = stream_maps[i].file_index; | |
818 | int si = stream_maps[i].stream_index; | |
819 | ||
820 | if (fi < 0 || fi > nb_input_files - 1 || | |
821 | si < 0 || si > file_table[fi].nb_streams - 1) { | |
822 | fprintf(stderr,"Could not find input stream #%d.%d\n", fi, si); | |
823 | exit(1); | |
824 | } | |
825 | } | |
826 | ||
85f07f22 FB |
827 | ost_table = av_mallocz(sizeof(AVOutputStream *) * nb_ostreams); |
828 | if (!ost_table) | |
829 | goto fail; | |
830 | for(i=0;i<nb_ostreams;i++) { | |
831 | ost = av_mallocz(sizeof(AVOutputStream)); | |
832 | if (!ost) | |
833 | goto fail; | |
834 | ost_table[i] = ost; | |
835 | } | |
836 | ||
837 | n = 0; | |
838 | for(k=0;k<nb_output_files;k++) { | |
839 | os = output_files[k]; | |
840 | for(i=0;i<os->nb_streams;i++) { | |
841 | int found; | |
842 | ost = ost_table[n++]; | |
843 | ost->file_index = k; | |
844 | ost->index = i; | |
845 | ost->st = os->streams[i]; | |
846 | if (nb_stream_maps > 0) { | |
847 | ost->source_index = file_table[stream_maps[n-1].file_index].ist_index + | |
848 | stream_maps[n-1].stream_index; | |
bd073980 BF |
849 | |
850 | /* Sanity check that the stream types match */ | |
851 | if (ist_table[ost->source_index]->st->codec.codec_type != ost->st->codec.codec_type) { | |
852 | fprintf(stderr, "Codec type mismatch for mapping #%d.%d -> #%d.%d\n", | |
853 | stream_maps[n-1].file_index, stream_maps[n-1].stream_index, | |
854 | ost->file_index, ost->index); | |
855 | exit(1); | |
856 | } | |
857 | ||
85f07f22 FB |
858 | } else { |
859 | /* get corresponding input stream index : we select the first one with the right type */ | |
860 | found = 0; | |
861 | for(j=0;j<nb_istreams;j++) { | |
862 | ist = ist_table[j]; | |
863 | if (ist->discard && | |
864 | ist->st->codec.codec_type == ost->st->codec.codec_type) { | |
865 | ost->source_index = j; | |
866 | found = 1; | |
867 | } | |
868 | } | |
869 | ||
870 | if (!found) { | |
871 | /* try again and reuse existing stream */ | |
872 | for(j=0;j<nb_istreams;j++) { | |
873 | ist = ist_table[j]; | |
874 | if (ist->st->codec.codec_type == ost->st->codec.codec_type) { | |
875 | ost->source_index = j; | |
876 | found = 1; | |
877 | } | |
878 | } | |
879 | if (!found) { | |
880 | fprintf(stderr, "Could not find input stream matching output stream #%d.%d\n", | |
881 | ost->file_index, ost->index); | |
882 | exit(1); | |
883 | } | |
884 | } | |
885 | } | |
886 | ist = ist_table[ost->source_index]; | |
887 | ist->discard = 0; | |
888 | } | |
889 | } | |
890 | ||
85f07f22 FB |
891 | /* for each output stream, we compute the right encoding parameters */ |
892 | for(i=0;i<nb_ostreams;i++) { | |
893 | ost = ost_table[i]; | |
894 | ist = ist_table[ost->source_index]; | |
895 | ||
896 | codec = &ost->st->codec; | |
897 | icodec = &ist->st->codec; | |
898 | ||
1629626f FB |
899 | if (ost->st->stream_copy) { |
900 | /* if stream_copy is selected, no need to decode or encode */ | |
901 | codec->codec_id = icodec->codec_id; | |
902 | codec->codec_type = icodec->codec_type; | |
903 | codec->codec_tag = icodec->codec_tag; | |
904 | codec->bit_rate = icodec->bit_rate; | |
905 | switch(codec->codec_type) { | |
906 | case CODEC_TYPE_AUDIO: | |
907 | codec->sample_rate = icodec->sample_rate; | |
908 | codec->channels = icodec->channels; | |
909 | break; | |
910 | case CODEC_TYPE_VIDEO: | |
911 | codec->frame_rate = icodec->frame_rate; | |
14bea432 | 912 | codec->frame_rate_base = icodec->frame_rate_base; |
1629626f FB |
913 | codec->width = icodec->width; |
914 | codec->height = icodec->height; | |
915 | break; | |
916 | default: | |
917 | av_abort(); | |
918 | } | |
919 | } else { | |
920 | switch(codec->codec_type) { | |
921 | case CODEC_TYPE_AUDIO: | |
85f07f22 FB |
922 | if (fifo_init(&ost->fifo, 2 * MAX_AUDIO_PACKET_SIZE)) |
923 | goto fail; | |
1629626f | 924 | |
85f07f22 FB |
925 | if (codec->channels == icodec->channels && |
926 | codec->sample_rate == icodec->sample_rate) { | |
927 | ost->audio_resample = 0; | |
928 | } else { | |
e0d2714a J |
929 | if (codec->channels != icodec->channels && |
930 | icodec->codec_id == CODEC_ID_AC3) { | |
931 | /* Special case for 5:1 AC3 input */ | |
932 | /* and mono or stereo output */ | |
6dc96cb0 J |
933 | /* Request specific number of channels */ |
934 | icodec->channels = codec->channels; | |
935 | if (codec->sample_rate == icodec->sample_rate) | |
936 | ost->audio_resample = 0; | |
937 | else { | |
938 | ost->audio_resample = 1; | |
939 | ost->resample = audio_resample_init(codec->channels, icodec->channels, | |
940 | codec->sample_rate, | |
941 | icodec->sample_rate); | |
743739d2 MN |
942 | if(!ost->resample) |
943 | { | |
944 | printf("Can't resample. Aborting.\n"); | |
945 | av_abort(); | |
946 | } | |
6dc96cb0 | 947 | } |
e0d2714a J |
948 | /* Request specific number of channels */ |
949 | icodec->channels = codec->channels; | |
950 | } else { | |
951 | ost->audio_resample = 1; | |
952 | ost->resample = audio_resample_init(codec->channels, icodec->channels, | |
85f07f22 FB |
953 | codec->sample_rate, |
954 | icodec->sample_rate); | |
743739d2 MN |
955 | if(!ost->resample) |
956 | { | |
957 | printf("Can't resample. Aborting.\n"); | |
958 | av_abort(); | |
959 | } | |
e0d2714a | 960 | } |
85f07f22 FB |
961 | } |
962 | ist->decoding_needed = 1; | |
963 | ost->encoding_needed = 1; | |
1629626f FB |
964 | break; |
965 | case CODEC_TYPE_VIDEO: | |
85f07f22 | 966 | if (codec->width == icodec->width && |
34b10a57 D |
967 | codec->height == icodec->height && |
968 | frame_topBand == 0 && | |
969 | frame_bottomBand == 0 && | |
970 | frame_leftBand == 0 && | |
971 | frame_rightBand == 0) | |
972 | { | |
973 | ost->video_resample = 0; | |
974 | ost->video_crop = 0; | |
975 | } else if ((codec->width == icodec->width - | |
976 | (frame_leftBand + frame_rightBand)) && | |
977 | (codec->height == icodec->height - | |
978 | (frame_topBand + frame_bottomBand))) | |
979 | { | |
85f07f22 | 980 | ost->video_resample = 0; |
34b10a57 D |
981 | ost->video_crop = 1; |
982 | ost->topBand = frame_topBand; | |
983 | ost->leftBand = frame_leftBand; | |
85f07f22 | 984 | } else { |
0c1a9eda | 985 | uint8_t *buf; |
85f07f22 | 986 | ost->video_resample = 1; |
34b10a57 | 987 | ost->video_crop = 0; // cropping is handled as part of resample |
0f1578af | 988 | buf = av_malloc((codec->width * codec->height * 3) / 2); |
85f07f22 FB |
989 | if (!buf) |
990 | goto fail; | |
991 | ost->pict_tmp.data[0] = buf; | |
992 | ost->pict_tmp.data[1] = ost->pict_tmp.data[0] + (codec->width * codec->height); | |
993 | ost->pict_tmp.data[2] = ost->pict_tmp.data[1] + (codec->width * codec->height) / 4; | |
994 | ost->pict_tmp.linesize[0] = codec->width; | |
995 | ost->pict_tmp.linesize[1] = codec->width / 2; | |
996 | ost->pict_tmp.linesize[2] = codec->width / 2; | |
997 | ||
ab6d194a | 998 | ost->img_resample_ctx = img_resample_full_init( |
85f07f22 | 999 | ost->st->codec.width, ost->st->codec.height, |
ab6d194a MN |
1000 | ist->st->codec.width, ist->st->codec.height, |
1001 | frame_topBand, frame_bottomBand, | |
1002 | frame_leftBand, frame_rightBand); | |
85f07f22 FB |
1003 | } |
1004 | ost->encoding_needed = 1; | |
1005 | ist->decoding_needed = 1; | |
1629626f FB |
1006 | break; |
1007 | default: | |
1008 | av_abort(); | |
85f07f22 | 1009 | } |
1629626f FB |
1010 | /* two pass mode */ |
1011 | if (ost->encoding_needed && | |
1012 | (codec->flags & (CODEC_FLAG_PASS1 | CODEC_FLAG_PASS2))) { | |
1013 | char logfilename[1024]; | |
1014 | FILE *f; | |
1015 | int size; | |
1016 | char *logbuffer; | |
1017 | ||
1018 | snprintf(logfilename, sizeof(logfilename), "%s-%d.log", | |
1019 | pass_logfilename ? | |
1020 | pass_logfilename : DEFAULT_PASS_LOGFILENAME, i); | |
1021 | if (codec->flags & CODEC_FLAG_PASS1) { | |
1022 | f = fopen(logfilename, "w"); | |
1023 | if (!f) { | |
1024 | perror(logfilename); | |
1025 | exit(1); | |
1026 | } | |
1027 | ost->logfile = f; | |
1028 | } else { | |
1029 | /* read the log file */ | |
1030 | f = fopen(logfilename, "r"); | |
1031 | if (!f) { | |
1032 | perror(logfilename); | |
1033 | exit(1); | |
1034 | } | |
1035 | fseek(f, 0, SEEK_END); | |
1036 | size = ftell(f); | |
1037 | fseek(f, 0, SEEK_SET); | |
1038 | logbuffer = av_malloc(size + 1); | |
1039 | if (!logbuffer) { | |
1040 | fprintf(stderr, "Could not allocate log buffer\n"); | |
1041 | exit(1); | |
1042 | } | |
1043 | fread(logbuffer, 1, size, f); | |
1044 | fclose(f); | |
1045 | logbuffer[size] = '\0'; | |
1046 | codec->stats_in = logbuffer; | |
5abdb4b1 | 1047 | } |
5abdb4b1 FB |
1048 | } |
1049 | } | |
85f07f22 FB |
1050 | } |
1051 | ||
1629626f FB |
1052 | /* dump the file output parameters - cannot be done before in case |
1053 | of stream copy */ | |
1054 | for(i=0;i<nb_output_files;i++) { | |
1055 | dump_format(output_files[i], i, output_files[i]->filename, 1); | |
1056 | } | |
1057 | ||
1058 | /* dump the stream mapping */ | |
1059 | fprintf(stderr, "Stream mapping:\n"); | |
1060 | for(i=0;i<nb_ostreams;i++) { | |
1061 | ost = ost_table[i]; | |
1062 | fprintf(stderr, " Stream #%d.%d -> #%d.%d\n", | |
1063 | ist_table[ost->source_index]->file_index, | |
1064 | ist_table[ost->source_index]->index, | |
1065 | ost->file_index, | |
1066 | ost->index); | |
1067 | } | |
1068 | ||
85f07f22 FB |
1069 | /* open each encoder */ |
1070 | for(i=0;i<nb_ostreams;i++) { | |
1071 | ost = ost_table[i]; | |
1072 | if (ost->encoding_needed) { | |
1073 | AVCodec *codec; | |
1074 | codec = avcodec_find_encoder(ost->st->codec.codec_id); | |
1075 | if (!codec) { | |
1076 | fprintf(stderr, "Unsupported codec for output stream #%d.%d\n", | |
1077 | ost->file_index, ost->index); | |
1078 | exit(1); | |
1079 | } | |
1080 | if (avcodec_open(&ost->st->codec, codec) < 0) { | |
1081 | fprintf(stderr, "Error while opening codec for stream #%d.%d - maybe incorrect parameters such as bit_rate, rate, width or height\n", | |
1082 | ost->file_index, ost->index); | |
1083 | exit(1); | |
1084 | } | |
1085 | } | |
1086 | } | |
1087 | ||
1088 | /* open each decoder */ | |
1089 | for(i=0;i<nb_istreams;i++) { | |
1090 | ist = ist_table[i]; | |
1091 | if (ist->decoding_needed) { | |
1092 | AVCodec *codec; | |
1093 | codec = avcodec_find_decoder(ist->st->codec.codec_id); | |
1094 | if (!codec) { | |
10d104e4 PG |
1095 | fprintf(stderr, "Unsupported codec (id=%d) for input stream #%d.%d\n", |
1096 | ist->st->codec.codec_id, ist->file_index, ist->index); | |
85f07f22 FB |
1097 | exit(1); |
1098 | } | |
1099 | if (avcodec_open(&ist->st->codec, codec) < 0) { | |
1100 | fprintf(stderr, "Error while opening codec for input stream #%d.%d\n", | |
1101 | ist->file_index, ist->index); | |
1102 | exit(1); | |
1103 | } | |
6dc96cb0 J |
1104 | //if (ist->st->codec.codec_type == CODEC_TYPE_VIDEO) |
1105 | // ist->st->codec.flags |= CODEC_FLAG_REPEAT_FIELD; | |
ec5517d5 | 1106 | ist->frame_decoded = 1; |
85f07f22 FB |
1107 | } |
1108 | } | |
1109 | ||
1110 | /* init pts */ | |
1111 | for(i=0;i<nb_istreams;i++) { | |
1112 | ist = ist_table[i]; | |
445f1b83 | 1113 | is = input_files[ist->file_index]; |
e7d0374f | 1114 | ist->pts = 0; |
445f1b83 RS |
1115 | switch (ist->st->codec.codec_type) { |
1116 | case CODEC_TYPE_AUDIO: | |
e7d0374f | 1117 | av_frac_init(&ist->next_pts, |
445f1b83 RS |
1118 | 0, 0, is->pts_num * ist->st->codec.sample_rate); |
1119 | break; | |
1120 | case CODEC_TYPE_VIDEO: | |
e7d0374f | 1121 | av_frac_init(&ist->next_pts, |
445f1b83 RS |
1122 | 0, 0, is->pts_num * ist->st->codec.frame_rate); |
1123 | break; | |
1124 | default: | |
1125 | break; | |
1126 | } | |
85f07f22 FB |
1127 | } |
1128 | ||
1129 | /* compute buffer size max (should use a complete heuristic) */ | |
1130 | for(i=0;i<nb_input_files;i++) { | |
1131 | file_table[i].buffer_size_max = 2048; | |
1132 | } | |
1133 | ||
1134 | /* open files and write file headers */ | |
1135 | for(i=0;i<nb_output_files;i++) { | |
1136 | os = output_files[i]; | |
79fdaa4c | 1137 | if (av_write_header(os) < 0) { |
a38469e1 FB |
1138 | fprintf(stderr, "Could not write header for output file #%d (incorrect codec paramters ?)\n", i); |
1139 | ret = -EINVAL; | |
1140 | goto fail; | |
1141 | } | |
85f07f22 FB |
1142 | } |
1143 | ||
a38469e1 | 1144 | #ifndef CONFIG_WIN32 |
d9a916e2 CY |
1145 | if ( !using_stdin ) |
1146 | fprintf(stderr, "Press [q] to stop encoding\n"); | |
a38469e1 FB |
1147 | #endif |
1148 | term_init(); | |
1149 | ||
51bd4565 | 1150 | stream_no_data = 0; |
cb09b2ed | 1151 | key = -1; |
51bd4565 | 1152 | |
3633ada5 | 1153 | #ifndef CONFIG_WIN32 |
d9a916e2 | 1154 | for(; received_sigterm == 0;) { |
3633ada5 BE |
1155 | #else |
1156 | for(;;) { | |
1157 | #endif | |
85f07f22 FB |
1158 | int file_index, ist_index; |
1159 | AVPacket pkt; | |
0c1a9eda | 1160 | uint8_t *ptr; |
85f07f22 | 1161 | int len; |
0c1a9eda | 1162 | uint8_t *data_buf; |
85f07f22 FB |
1163 | int data_size, got_picture; |
1164 | AVPicture picture; | |
1165 | short samples[AVCODEC_MAX_AUDIO_FRAME_SIZE / 2]; | |
10d104e4 | 1166 | void *buffer_to_free; |
ec5517d5 FB |
1167 | double pts_min; |
1168 | ||
85f07f22 | 1169 | redo: |
a38469e1 | 1170 | /* if 'q' pressed, exits */ |
d9a916e2 | 1171 | if (!using_stdin) { |
cb09b2ed PG |
1172 | /* read_key() returns 0 on EOF */ |
1173 | key = read_key(); | |
1174 | if (key == 'q') | |
1175 | break; | |
1176 | } | |
a38469e1 | 1177 | |
ec5517d5 FB |
1178 | /* select the stream that we must read now by looking at the |
1179 | smallest output pts */ | |
85f07f22 | 1180 | file_index = -1; |
ec5517d5 FB |
1181 | pts_min = 1e10; |
1182 | for(i=0;i<nb_ostreams;i++) { | |
1183 | double pts; | |
1184 | ost = ost_table[i]; | |
1185 | os = output_files[ost->file_index]; | |
1186 | ist = ist_table[ost->source_index]; | |
1187 | pts = (double)ost->st->pts.val * os->pts_num / os->pts_den; | |
1188 | if (!file_table[ist->file_index].eof_reached && | |
1189 | pts < pts_min) { | |
1190 | pts_min = pts; | |
85f07f22 FB |
1191 | file_index = ist->file_index; |
1192 | } | |
1193 | } | |
1194 | /* if none, if is finished */ | |
51bd4565 | 1195 | if (file_index < 0) { |
85f07f22 | 1196 | break; |
ec5517d5 FB |
1197 | } |
1198 | ||
85f07f22 | 1199 | /* finish if recording time exhausted */ |
ec5517d5 | 1200 | if (recording_time > 0 && pts_min >= (recording_time / 1000000.0)) |
85f07f22 | 1201 | break; |
ec5517d5 | 1202 | |
85f07f22 | 1203 | /* read a packet from it and output it in the fifo */ |
85f07f22 FB |
1204 | is = input_files[file_index]; |
1205 | if (av_read_packet(is, &pkt) < 0) { | |
1206 | file_table[file_index].eof_reached = 1; | |
1207 | continue; | |
1208 | } | |
51bd4565 PG |
1209 | if (!pkt.size) { |
1210 | stream_no_data = is; | |
1211 | } else { | |
1212 | stream_no_data = 0; | |
1213 | } | |
817b23ff FB |
1214 | if (do_hex_dump) { |
1215 | printf("stream #%d, size=%d:\n", pkt.stream_index, pkt.size); | |
1216 | av_hex_dump(pkt.data, pkt.size); | |
1217 | } | |
79fdaa4c FB |
1218 | /* the following test is needed in case new streams appear |
1219 | dynamically in stream : we ignore them */ | |
1220 | if (pkt.stream_index >= file_table[file_index].nb_streams) | |
bf5af568 | 1221 | goto discard_packet; |
85f07f22 FB |
1222 | ist_index = file_table[file_index].ist_index + pkt.stream_index; |
1223 | ist = ist_table[ist_index]; | |
bf5af568 FB |
1224 | if (ist->discard) |
1225 | goto discard_packet; | |
85f07f22 | 1226 | |
34b10a57 | 1227 | // printf("read #%d.%d size=%d\n", ist->file_index, ist->index, pkt.size); |
85f07f22 FB |
1228 | |
1229 | len = pkt.size; | |
1230 | ptr = pkt.data; | |
1231 | while (len > 0) { | |
85f07f22 FB |
1232 | /* decode the packet if needed */ |
1233 | data_buf = NULL; /* fail safe */ | |
1234 | data_size = 0; | |
1235 | if (ist->decoding_needed) { | |
ec5517d5 FB |
1236 | /* NOTE1: we only take into account the PTS if a new |
1237 | frame has begun (MPEG semantics) */ | |
1238 | /* NOTE2: even if the fraction is not initialized, | |
1239 | av_frac_set can be used to set the integer part */ | |
445f1b83 | 1240 | if (ist->frame_decoded) { |
e7d0374f RS |
1241 | /* If pts is unavailable -- we have to use synthetic one */ |
1242 | if( pkt.pts != AV_NOPTS_VALUE ) | |
1243 | { | |
1244 | ist->pts = ist->next_pts.val = pkt.pts; | |
1245 | } | |
1246 | else | |
1247 | { | |
1248 | ist->pts = ist->next_pts.val; | |
1249 | } | |
ec5517d5 | 1250 | ist->frame_decoded = 0; |
ec5517d5 FB |
1251 | } |
1252 | ||
85f07f22 FB |
1253 | switch(ist->st->codec.codec_type) { |
1254 | case CODEC_TYPE_AUDIO: | |
a0663ba4 FB |
1255 | /* XXX: could avoid copy if PCM 16 bits with same |
1256 | endianness as CPU */ | |
1257 | ret = avcodec_decode_audio(&ist->st->codec, samples, &data_size, | |
1258 | ptr, len); | |
1259 | if (ret < 0) | |
1260 | goto fail_decode; | |
afc80f59 J |
1261 | /* Some bug in mpeg audio decoder gives */ |
1262 | /* data_size < 0, it seems they are overflows */ | |
1263 | if (data_size <= 0) { | |
a0663ba4 FB |
1264 | /* no audio frame */ |
1265 | ptr += ret; | |
1266 | len -= ret; | |
1267 | continue; | |
85f07f22 | 1268 | } |
0c1a9eda | 1269 | data_buf = (uint8_t *)samples; |
e7d0374f | 1270 | av_frac_add(&ist->next_pts, |
445f1b83 | 1271 | is->pts_den * data_size / (2 * ist->st->codec.channels)); |
85f07f22 FB |
1272 | break; |
1273 | case CODEC_TYPE_VIDEO: | |
e8750b00 | 1274 | { |
492cd3a9 | 1275 | AVFrame big_picture; |
1e491e29 | 1276 | |
85f07f22 FB |
1277 | data_size = (ist->st->codec.width * ist->st->codec.height * 3) / 2; |
1278 | ret = avcodec_decode_video(&ist->st->codec, | |
1e491e29 MN |
1279 | &big_picture, &got_picture, ptr, len); |
1280 | picture= *(AVPicture*)&big_picture; | |
1281 | ist->st->quality= big_picture.quality; | |
85f07f22 FB |
1282 | if (ret < 0) { |
1283 | fail_decode: | |
1284 | fprintf(stderr, "Error while decoding stream #%d.%d\n", | |
1285 | ist->file_index, ist->index); | |
1286 | av_free_packet(&pkt); | |
1287 | goto redo; | |
1288 | } | |
1289 | if (!got_picture) { | |
1290 | /* no picture yet */ | |
1291 | ptr += ret; | |
1292 | len -= ret; | |
1293 | continue; | |
1294 | } | |
e7d0374f | 1295 | av_frac_add(&ist->next_pts, |
445f1b83 | 1296 | is->pts_den * ist->st->codec.frame_rate_base); |
85f07f22 FB |
1297 | } |
1298 | break; | |
1299 | default: | |
1300 | goto fail_decode; | |
1301 | } | |
1302 | } else { | |
1303 | data_buf = ptr; | |
1304 | data_size = len; | |
1305 | ret = len; | |
1306 | } | |
85f07f22 FB |
1307 | ptr += ret; |
1308 | len -= ret; | |
1309 | ||
10d104e4 PG |
1310 | buffer_to_free = 0; |
1311 | if (ist->st->codec.codec_type == CODEC_TYPE_VIDEO) { | |
1312 | pre_process_video_frame(ist, &picture, &buffer_to_free); | |
1313 | } | |
1314 | ||
ec5517d5 FB |
1315 | ist->frame_decoded = 1; |
1316 | ||
bdfcbbed MK |
1317 | /* frame rate emulation */ |
1318 | if (ist->st->codec.rate_emu) { | |
14bea432 | 1319 | int64_t pts = av_rescale((int64_t) ist->frame * ist->st->codec.frame_rate_base, 1000000, ist->st->codec.frame_rate); |
bdfcbbed MK |
1320 | int64_t now = av_gettime() - ist->start; |
1321 | if (pts > now) | |
1322 | usleep(pts - now); | |
1323 | ||
1324 | ist->frame++; | |
1325 | } | |
1326 | ||
ec5517d5 FB |
1327 | #if 0 |
1328 | /* mpeg PTS deordering : if it is a P or I frame, the PTS | |
1329 | is the one of the next displayed one */ | |
1330 | /* XXX: add mpeg4 too ? */ | |
1331 | if (ist->st->codec.codec_id == CODEC_ID_MPEG1VIDEO) { | |
1332 | if (ist->st->codec.pict_type != B_TYPE) { | |
0c1a9eda | 1333 | int64_t tmp; |
ec5517d5 FB |
1334 | tmp = ist->last_ip_pts; |
1335 | ist->last_ip_pts = ist->frac_pts.val; | |
1336 | ist->frac_pts.val = tmp; | |
1337 | } | |
1338 | } | |
1339 | #endif | |
85f07f22 | 1340 | /* transcode raw format, encode packets and output them */ |
ec5517d5 | 1341 | |
85f07f22 | 1342 | for(i=0;i<nb_ostreams;i++) { |
ce7c56c2 | 1343 | int frame_size; |
ec5517d5 | 1344 | |
85f07f22 FB |
1345 | ost = ost_table[i]; |
1346 | if (ost->source_index == ist_index) { | |
1347 | os = output_files[ost->file_index]; | |
1348 | ||
ec5517d5 | 1349 | #if 0 |
e7d0374f RS |
1350 | printf("%d: got pts=%f %f\n", i, pkt.pts / 90000.0, |
1351 | (ist->pts - ost->st->pts.val) / 90000.0); | |
ec5517d5 | 1352 | #endif |
e7d0374f RS |
1353 | /* set the input output pts pairs */ |
1354 | ost->sync_ipts = (double)ist->pts * is->pts_num / | |
1355 | is->pts_den; | |
1356 | /* XXX: take into account the various fifos, | |
1357 | in particular for audio */ | |
1358 | ost->sync_opts = ost->st->pts.val; | |
1359 | //printf("ipts=%lld sync_ipts=%f sync_opts=%lld pts.val=%lld pkt.pts=%lld\n", ist->pts, ost->sync_ipts, ost->sync_opts, ost->st->pts.val, pkt.pts); | |
ec5517d5 | 1360 | |
85f07f22 FB |
1361 | if (ost->encoding_needed) { |
1362 | switch(ost->st->codec.codec_type) { | |
1363 | case CODEC_TYPE_AUDIO: | |
1364 | do_audio_out(os, ost, ist, data_buf, data_size); | |
1365 | break; | |
1366 | case CODEC_TYPE_VIDEO: | |
ec5517d5 FB |
1367 | /* find an audio stream for synchro */ |
1368 | { | |
1369 | int i; | |
1370 | AVOutputStream *audio_sync, *ost1; | |
1371 | audio_sync = NULL; | |
1372 | for(i=0;i<nb_ostreams;i++) { | |
1373 | ost1 = ost_table[i]; | |
1374 | if (ost1->file_index == ost->file_index && | |
1375 | ost1->st->codec.codec_type == CODEC_TYPE_AUDIO) { | |
1376 | audio_sync = ost1; | |
1377 | break; | |
1378 | } | |
1379 | } | |
1380 | ||
1381 | do_video_out(os, ost, ist, &picture, &frame_size, audio_sync); | |
204c0f48 | 1382 | if (do_vstats && frame_size) |
ec5517d5 FB |
1383 | do_video_stats(os, ost, frame_size); |
1384 | } | |
85f07f22 | 1385 | break; |
51bd4565 | 1386 | default: |
c04643a2 | 1387 | av_abort(); |
85f07f22 FB |
1388 | } |
1389 | } else { | |
18531e52 MN |
1390 | AVFrame avframe; |
1391 | ||
85f07f22 | 1392 | /* no reencoding needed : output the packet directly */ |
10bb7023 | 1393 | /* force the input stream PTS */ |
18531e52 | 1394 | |
18531e52 MN |
1395 | memset(&avframe, 0, sizeof(AVFrame)); |
1396 | ost->st->codec.coded_frame= &avframe; | |
e738cee9 | 1397 | avframe.key_frame = pkt.flags & PKT_FLAG_KEY; |
18531e52 | 1398 | |
ec5517d5 | 1399 | av_write_frame(os, ost->index, data_buf, data_size); |
b2722d0a | 1400 | ost->st->codec.frame_number++; |
9ce2f2b1 | 1401 | ost->frame_number++; |
85f07f22 FB |
1402 | } |
1403 | } | |
1404 | } | |
10d104e4 | 1405 | av_free(buffer_to_free); |
85f07f22 | 1406 | } |
bf5af568 | 1407 | discard_packet: |
85f07f22 FB |
1408 | av_free_packet(&pkt); |
1409 | ||
ec5517d5 FB |
1410 | /* dump report by using the output first video and audio streams */ |
1411 | print_report(output_files, ost_table, nb_ostreams, 0); | |
85f07f22 | 1412 | } |
a38469e1 | 1413 | term_exit(); |
85f07f22 FB |
1414 | |
1415 | /* dump report by using the first video and audio streams */ | |
ec5517d5 FB |
1416 | print_report(output_files, ost_table, nb_ostreams, 1); |
1417 | ||
85f07f22 FB |
1418 | /* close each encoder */ |
1419 | for(i=0;i<nb_ostreams;i++) { | |
1420 | ost = ost_table[i]; | |
1421 | if (ost->encoding_needed) { | |
5abdb4b1 | 1422 | av_freep(&ost->st->codec.stats_in); |
85f07f22 FB |
1423 | avcodec_close(&ost->st->codec); |
1424 | } | |
1425 | } | |
1426 | ||
1427 | /* close each decoder */ | |
1428 | for(i=0;i<nb_istreams;i++) { | |
1429 | ist = ist_table[i]; | |
1430 | if (ist->decoding_needed) { | |
1431 | avcodec_close(&ist->st->codec); | |
1432 | } | |
1433 | } | |
1434 | ||
1435 | ||
1436 | /* write the trailer if needed and close file */ | |
1437 | for(i=0;i<nb_output_files;i++) { | |
1438 | os = output_files[i]; | |
79fdaa4c | 1439 | av_write_trailer(os); |
85f07f22 FB |
1440 | } |
1441 | /* finished ! */ | |
1442 | ||
1443 | ret = 0; | |
1444 | fail1: | |
0f1578af | 1445 | av_free(file_table); |
bdc4796f | 1446 | |
85f07f22 FB |
1447 | if (ist_table) { |
1448 | for(i=0;i<nb_istreams;i++) { | |
1449 | ist = ist_table[i]; | |
0f1578af | 1450 | av_free(ist); |
85f07f22 | 1451 | } |
0f1578af | 1452 | av_free(ist_table); |
85f07f22 FB |
1453 | } |
1454 | if (ost_table) { | |
1455 | for(i=0;i<nb_ostreams;i++) { | |
1456 | ost = ost_table[i]; | |
1457 | if (ost) { | |
5abdb4b1 FB |
1458 | if (ost->logfile) { |
1459 | fclose(ost->logfile); | |
1460 | ost->logfile = NULL; | |
1461 | } | |
bf5af568 FB |
1462 | fifo_free(&ost->fifo); /* works even if fifo is not |
1463 | initialized but set to zero */ | |
0f1578af | 1464 | av_free(ost->pict_tmp.data[0]); |
85f07f22 FB |
1465 | if (ost->video_resample) |
1466 | img_resample_close(ost->img_resample_ctx); | |
1467 | if (ost->audio_resample) | |
1468 | audio_resample_close(ost->resample); | |
0f1578af | 1469 | av_free(ost); |
85f07f22 FB |
1470 | } |
1471 | } | |
0f1578af | 1472 | av_free(ost_table); |
85f07f22 FB |
1473 | } |
1474 | return ret; | |
1475 | fail: | |
1476 | ret = -ENOMEM; | |
1477 | goto fail1; | |
1478 | } | |
1479 | ||
1480 | #if 0 | |
1481 | int file_read(const char *filename) | |
1482 | { | |
1483 | URLContext *h; | |
1484 | unsigned char buffer[1024]; | |
1485 | int len, i; | |
1486 | ||
1487 | if (url_open(&h, filename, O_RDONLY) < 0) { | |
1488 | printf("could not open '%s'\n", filename); | |
1489 | return -1; | |
1490 | } | |
1491 | for(;;) { | |
1492 | len = url_read(h, buffer, sizeof(buffer)); | |
1493 | if (len <= 0) | |
1494 | break; | |
1495 | for(i=0;i<len;i++) putchar(buffer[i]); | |
1496 | } | |
1497 | url_close(h); | |
1498 | return 0; | |
1499 | } | |
1500 | #endif | |
1501 | ||
b29f97d1 | 1502 | static void opt_image_format(const char *arg) |
817b23ff FB |
1503 | { |
1504 | AVImageFormat *f; | |
1505 | ||
1506 | for(f = first_image_format; f != NULL; f = f->next) { | |
1507 | if (!strcmp(arg, f->name)) | |
1508 | break; | |
1509 | } | |
1510 | if (!f) { | |
1511 | fprintf(stderr, "Unknown image format: '%s'\n", arg); | |
1512 | exit(1); | |
1513 | } | |
1514 | image_format = f; | |
1515 | } | |
1516 | ||
b29f97d1 | 1517 | static void opt_format(const char *arg) |
85f07f22 | 1518 | { |
817b23ff FB |
1519 | /* compatibility stuff for pgmyuv */ |
1520 | if (!strcmp(arg, "pgmyuv")) { | |
1521 | opt_image_format(arg); | |
1522 | arg = "image"; | |
1523 | } | |
1524 | ||
79fdaa4c FB |
1525 | file_iformat = av_find_input_format(arg); |
1526 | file_oformat = guess_format(arg, NULL, NULL); | |
1527 | if (!file_iformat && !file_oformat) { | |
1528 | fprintf(stderr, "Unknown input or output format: %s\n", arg); | |
85f07f22 FB |
1529 | exit(1); |
1530 | } | |
85f07f22 FB |
1531 | } |
1532 | ||
b29f97d1 | 1533 | static void opt_video_bitrate(const char *arg) |
85f07f22 FB |
1534 | { |
1535 | video_bit_rate = atoi(arg) * 1000; | |
1536 | } | |
1537 | ||
b29f97d1 | 1538 | static void opt_video_bitrate_tolerance(const char *arg) |
9cdd6a24 MN |
1539 | { |
1540 | video_bit_rate_tolerance = atoi(arg) * 1000; | |
1541 | } | |
1542 | ||
b29f97d1 | 1543 | static void opt_video_bitrate_max(const char *arg) |
3aa102be MN |
1544 | { |
1545 | video_rc_max_rate = atoi(arg) * 1000; | |
1546 | } | |
1547 | ||
b29f97d1 | 1548 | static void opt_video_bitrate_min(const char *arg) |
3aa102be MN |
1549 | { |
1550 | video_rc_min_rate = atoi(arg) * 1000; | |
1551 | } | |
1552 | ||
b29f97d1 | 1553 | static void opt_video_buffer_size(const char *arg) |
946c8a12 MN |
1554 | { |
1555 | video_rc_buffer_size = atoi(arg) * 1000; | |
1556 | } | |
1557 | ||
b29f97d1 | 1558 | static void opt_video_rc_eq(char *arg) |
3aa102be MN |
1559 | { |
1560 | video_rc_eq = arg; | |
1561 | } | |
1562 | ||
b29f97d1 | 1563 | static void opt_video_rc_override_string(char *arg) |
ac2830ec MN |
1564 | { |
1565 | video_rc_override_string = arg; | |
1566 | } | |
1567 | ||
3aa102be | 1568 | |
b29f97d1 | 1569 | static void opt_workaround_bugs(const char *arg) |
fe670d09 MN |
1570 | { |
1571 | workaround_bugs = atoi(arg); | |
1572 | } | |
1573 | ||
b29f97d1 | 1574 | static void opt_dct_algo(const char *arg) |
463678ac MN |
1575 | { |
1576 | dct_algo = atoi(arg); | |
1577 | } | |
1578 | ||
b29f97d1 | 1579 | static void opt_idct_algo(const char *arg) |
2ad1516a MN |
1580 | { |
1581 | idct_algo = atoi(arg); | |
1582 | } | |
1583 | ||
1584 | ||
b29f97d1 | 1585 | static void opt_error_resilience(const char *arg) |
8409b8fe MN |
1586 | { |
1587 | error_resilience = atoi(arg); | |
1588 | } | |
1589 | ||
b29f97d1 | 1590 | static void opt_error_concealment(const char *arg) |
4d2858de MN |
1591 | { |
1592 | error_concealment = atoi(arg); | |
1593 | } | |
1594 | ||
b29f97d1 | 1595 | static void opt_debug(const char *arg) |
59b571c1 MN |
1596 | { |
1597 | debug = atoi(arg); | |
1598 | } | |
4d2858de | 1599 | |
f068206e BE |
1600 | static void opt_verbose(const char *arg) |
1601 | { | |
1602 | verbose = atoi(arg); | |
1603 | } | |
1604 | ||
b29f97d1 | 1605 | static void opt_frame_rate(const char *arg) |
85f07f22 | 1606 | { |
445f1b83 RS |
1607 | if (parse_frame_rate(&frame_rate, &frame_rate_base, arg) < 0) { |
1608 | fprintf(stderr, "Incorrect frame rate\n"); | |
1609 | exit(1); | |
1610 | } | |
85f07f22 FB |
1611 | } |
1612 | ||
b29f97d1 | 1613 | static void opt_frame_crop_top(const char *arg) |
ab6d194a MN |
1614 | { |
1615 | frame_topBand = atoi(arg); | |
1616 | if (frame_topBand < 0) { | |
1617 | fprintf(stderr, "Incorrect top crop size\n"); | |
1618 | exit(1); | |
1619 | } | |
1620 | if ((frame_topBand % 2) != 0) { | |
1621 | fprintf(stderr, "Top crop size must be a multiple of 2\n"); | |
1622 | exit(1); | |
1623 | } | |
1624 | if ((frame_topBand) >= frame_height){ | |
1625 | fprintf(stderr, "Vertical crop dimensions are outside the range of the original image.\nRemember to crop first and scale second.\n"); | |
1626 | exit(1); | |
1627 | } | |
1628 | frame_height -= frame_topBand; | |
1629 | } | |
1630 | ||
b29f97d1 | 1631 | static void opt_frame_crop_bottom(const char *arg) |
ab6d194a MN |
1632 | { |
1633 | frame_bottomBand = atoi(arg); | |
1634 | if (frame_bottomBand < 0) { | |
1635 | fprintf(stderr, "Incorrect bottom crop size\n"); | |
1636 | exit(1); | |
1637 | } | |
1638 | if ((frame_bottomBand % 2) != 0) { | |
1639 | fprintf(stderr, "Bottom crop size must be a multiple of 2\n"); | |
1640 | exit(1); | |
1641 | } | |
1642 | if ((frame_bottomBand) >= frame_height){ | |
1643 | fprintf(stderr, "Vertical crop dimensions are outside the range of the original image.\nRemember to crop first and scale second.\n"); | |
1644 | exit(1); | |
1645 | } | |
1646 | frame_height -= frame_bottomBand; | |
1647 | } | |
1648 | ||
b29f97d1 | 1649 | static void opt_frame_crop_left(const char *arg) |
ab6d194a MN |
1650 | { |
1651 | frame_leftBand = atoi(arg); | |
1652 | if (frame_leftBand < 0) { | |
1653 | fprintf(stderr, "Incorrect left crop size\n"); | |
1654 | exit(1); | |
1655 | } | |
1656 | if ((frame_leftBand % 2) != 0) { | |
1657 | fprintf(stderr, "Left crop size must be a multiple of 2\n"); | |
1658 | exit(1); | |
1659 | } | |
1660 | if ((frame_leftBand) >= frame_width){ | |
1661 | fprintf(stderr, "Horizontal crop dimensions are outside the range of the original image.\nRemember to crop first and scale second.\n"); | |
1662 | exit(1); | |
1663 | } | |
1664 | frame_width -= frame_leftBand; | |
1665 | } | |
1666 | ||
b29f97d1 | 1667 | static void opt_frame_crop_right(const char *arg) |
ab6d194a MN |
1668 | { |
1669 | frame_rightBand = atoi(arg); | |
1670 | if (frame_rightBand < 0) { | |
1671 | fprintf(stderr, "Incorrect right crop size\n"); | |
1672 | exit(1); | |
1673 | } | |
1674 | if ((frame_rightBand % 2) != 0) { | |
1675 | fprintf(stderr, "Right crop size must be a multiple of 2\n"); | |
1676 | exit(1); | |
1677 | } | |
1678 | if ((frame_rightBand) >= frame_width){ | |
1679 | fprintf(stderr, "Horizontal crop dimensions are outside the range of the original image.\nRemember to crop first and scale second.\n"); | |
1680 | exit(1); | |
1681 | } | |
1682 | frame_width -= frame_rightBand; | |
1683 | } | |
1684 | ||
b29f97d1 | 1685 | static void opt_frame_size(const char *arg) |
85f07f22 | 1686 | { |
445f1b83 | 1687 | if (parse_image_size(&frame_width, &frame_height, arg) < 0) { |
85f07f22 FB |
1688 | fprintf(stderr, "Incorrect frame size\n"); |
1689 | exit(1); | |
1690 | } | |
1691 | if ((frame_width % 2) != 0 || (frame_height % 2) != 0) { | |
1692 | fprintf(stderr, "Frame size must be a multiple of 2\n"); | |
1693 | exit(1); | |
1694 | } | |
1695 | } | |
1696 | ||
63167088 RS |
1697 | static void opt_frame_pix_fmt(const char *arg) |
1698 | { | |
1699 | frame_pix_fmt = avcodec_get_pix_fmt(arg); | |
1700 | } | |
1701 | ||
5fe03e38 RS |
1702 | static void opt_frame_aspect_ratio(const char *arg) |
1703 | { | |
1704 | int x = 0, y = 0; | |
1705 | double ar = 0; | |
1706 | const char *p; | |
1707 | ||
1708 | p = strchr(arg, ':'); | |
1709 | if (p) { | |
1710 | x = strtol(arg, (char **)&arg, 10); | |
1711 | if (arg == p) | |
1712 | y = strtol(arg+1, (char **)&arg, 10); | |
1713 | if (x > 0 && y > 0) | |
1714 | ar = (double)x / (double)y; | |
1715 | } else | |
1716 | ar = strtod(arg, (char **)&arg); | |
1717 | ||
1718 | if (!ar) { | |
1719 | fprintf(stderr, "Incorrect aspect ratio specification.\n"); | |
1720 | exit(1); | |
1721 | } | |
1722 | frame_aspect_ratio = ar; | |
1723 | } | |
1724 | ||
b29f97d1 | 1725 | static void opt_gop_size(const char *arg) |
85f07f22 FB |
1726 | { |
1727 | gop_size = atoi(arg); | |
1728 | } | |
1729 | ||
b29f97d1 | 1730 | static void opt_b_frames(const char *arg) |
bc6caae2 J |
1731 | { |
1732 | b_frames = atoi(arg); | |
1733 | if (b_frames > FF_MAX_B_FRAMES) { | |
1734 | fprintf(stderr, "\nCannot have more than %d B frames, increase FF_MAX_B_FRAMES.\n", FF_MAX_B_FRAMES); | |
1735 | exit(1); | |
1736 | } else if (b_frames < 1) { | |
1737 | fprintf(stderr, "\nNumber of B frames must be higher than 0\n"); | |
1738 | exit(1); | |
1739 | } | |
1740 | } | |
1741 | ||
7d1c3fc1 MN |
1742 | static void opt_mb_decision(const char *arg) |
1743 | { | |
1744 | mb_decision = atoi(arg); | |
1745 | } | |
1746 | ||
b29f97d1 | 1747 | static void opt_qscale(const char *arg) |
85f07f22 FB |
1748 | { |
1749 | video_qscale = atoi(arg); | |
1750 | if (video_qscale < 0 || | |
1751 | video_qscale > 31) { | |
1752 | fprintf(stderr, "qscale must be >= 1 and <= 31\n"); | |
1753 | exit(1); | |
1754 | } | |
1755 | } | |
1756 | ||
b29f97d1 | 1757 | static void opt_qmin(const char *arg) |
9cdd6a24 MN |
1758 | { |
1759 | video_qmin = atoi(arg); | |
1760 | if (video_qmin < 0 || | |
1761 | video_qmin > 31) { | |
1762 | fprintf(stderr, "qmin must be >= 1 and <= 31\n"); | |
1763 | exit(1); | |
1764 | } | |
1765 | } | |
1766 | ||
b29f97d1 | 1767 | static void opt_qmax(const char *arg) |
9cdd6a24 MN |
1768 | { |
1769 | video_qmax = atoi(arg); | |
1770 | if (video_qmax < 0 || | |
1771 | video_qmax > 31) { | |
1772 | fprintf(stderr, "qmax must be >= 1 and <= 31\n"); | |
1773 | exit(1); | |
1774 | } | |
1775 | } | |
1776 | ||
b29f97d1 | 1777 | static void opt_mb_qmin(const char *arg) |
17a70fde MN |
1778 | { |
1779 | video_mb_qmin = atoi(arg); | |
1780 | if (video_mb_qmin < 0 || | |
1781 | video_mb_qmin > 31) { | |
1782 | fprintf(stderr, "qmin must be >= 1 and <= 31\n"); | |
1783 | exit(1); | |
1784 | } | |
1785 | } | |
1786 | ||
b29f97d1 | 1787 | static void opt_mb_qmax(const char *arg) |
17a70fde MN |
1788 | { |
1789 | video_mb_qmax = atoi(arg); | |
1790 | if (video_mb_qmax < 0 || | |
1791 | video_mb_qmax > 31) { | |
1792 | fprintf(stderr, "qmax must be >= 1 and <= 31\n"); | |
1793 | exit(1); | |
1794 | } | |
1795 | } | |
1796 | ||
b29f97d1 | 1797 | static void opt_qdiff(const char *arg) |
9cdd6a24 MN |
1798 | { |
1799 | video_qdiff = atoi(arg); | |
1800 | if (video_qdiff < 0 || | |
1801 | video_qdiff > 31) { | |
1802 | fprintf(stderr, "qdiff must be >= 1 and <= 31\n"); | |
1803 | exit(1); | |
1804 | } | |
1805 | } | |
1806 | ||
b29f97d1 | 1807 | static void opt_qblur(const char *arg) |
9cdd6a24 MN |
1808 | { |
1809 | video_qblur = atof(arg); | |
1810 | } | |
1811 | ||
b29f97d1 | 1812 | static void opt_qcomp(const char *arg) |
9cdd6a24 MN |
1813 | { |
1814 | video_qcomp = atof(arg); | |
1815 | } | |
85f07f22 | 1816 | |
b29f97d1 | 1817 | static void opt_rc_initial_cplx(const char *arg) |
ac2830ec MN |
1818 | { |
1819 | video_rc_initial_cplx = atof(arg); | |
1820 | } | |
b29f97d1 | 1821 | static void opt_b_qfactor(const char *arg) |
29700fa6 MN |
1822 | { |
1823 | video_b_qfactor = atof(arg); | |
1824 | } | |
b29f97d1 | 1825 | static void opt_i_qfactor(const char *arg) |
29700fa6 MN |
1826 | { |
1827 | video_i_qfactor = atof(arg); | |
1828 | } | |
b29f97d1 | 1829 | static void opt_b_qoffset(const char *arg) |
29700fa6 MN |
1830 | { |
1831 | video_b_qoffset = atof(arg); | |
1832 | } | |
b29f97d1 | 1833 | static void opt_i_qoffset(const char *arg) |
29700fa6 MN |
1834 | { |
1835 | video_i_qoffset = atof(arg); | |
1836 | } | |
1837 | ||
b29f97d1 | 1838 | static void opt_packet_size(const char *arg) |
1dbb6d90 MN |
1839 | { |
1840 | packet_size= atoi(arg); | |
1841 | } | |
1842 | ||
b29f97d1 | 1843 | static void opt_strict(const char *arg) |
f560dd82 MN |
1844 | { |
1845 | strict= atoi(arg); | |
1846 | } | |
1847 | ||
b29f97d1 | 1848 | static void opt_audio_bitrate(const char *arg) |
85f07f22 FB |
1849 | { |
1850 | audio_bit_rate = atoi(arg) * 1000; | |
1851 | } | |
1852 | ||
b29f97d1 | 1853 | static void opt_audio_rate(const char *arg) |
85f07f22 FB |
1854 | { |
1855 | audio_sample_rate = atoi(arg); | |
1856 | } | |
1857 | ||
b29f97d1 | 1858 | static void opt_audio_channels(const char *arg) |
85f07f22 FB |
1859 | { |
1860 | audio_channels = atoi(arg); | |
1861 | } | |
1862 | ||
b29f97d1 | 1863 | static void opt_video_device(const char *arg) |
85f07f22 | 1864 | { |
e9a9e0c2 | 1865 | video_device = av_strdup(arg); |
85f07f22 FB |
1866 | } |
1867 | ||
b29f97d1 | 1868 | static void opt_video_channel(const char *arg) |
a5df11ab FB |
1869 | { |
1870 | video_channel = strtol(arg, NULL, 0); | |
1871 | } | |
1872 | ||
e3ee3283 AB |
1873 | static void opt_video_standard(const char *arg) |
1874 | { | |
1875 | video_standard = av_strdup(arg); | |
1876 | } | |
1877 | ||
b29f97d1 | 1878 | static void opt_audio_device(const char *arg) |
85f07f22 | 1879 | { |
e9a9e0c2 | 1880 | audio_device = av_strdup(arg); |
85f07f22 FB |
1881 | } |
1882 | ||
b29f97d1 | 1883 | static void opt_dv1394(const char *arg) |
8aa3ee32 MK |
1884 | { |
1885 | video_grab_format = "dv1394"; | |
1501987b | 1886 | audio_grab_format = NULL; |
8aa3ee32 MK |
1887 | } |
1888 | ||
b29f97d1 | 1889 | static void opt_audio_codec(const char *arg) |
85f07f22 FB |
1890 | { |
1891 | AVCodec *p; | |
1892 | ||
1629626f FB |
1893 | if (!strcmp(arg, "copy")) { |
1894 | audio_stream_copy = 1; | |
85f07f22 | 1895 | } else { |
1629626f FB |
1896 | p = first_avcodec; |
1897 | while (p) { | |
1898 | if (!strcmp(p->name, arg) && p->type == CODEC_TYPE_AUDIO) | |
1899 | break; | |
1900 | p = p->next; | |
1901 | } | |
1902 | if (p == NULL) { | |
1903 | fprintf(stderr, "Unknown audio codec '%s'\n", arg); | |
1904 | exit(1); | |
1905 | } else { | |
1906 | audio_codec_id = p->id; | |
1907 | } | |
85f07f22 FB |
1908 | } |
1909 | } | |
1910 | ||
b29f97d1 | 1911 | static void add_frame_hooker(const char *arg) |
10d104e4 PG |
1912 | { |
1913 | int argc = 0; | |
1914 | char *argv[64]; | |
1915 | int i; | |
e9a9e0c2 | 1916 | char *args = av_strdup(arg); |
10d104e4 PG |
1917 | |
1918 | argv[0] = strtok(args, " "); | |
1919 | while (argc < 62 && (argv[++argc] = strtok(NULL, " "))) { | |
1920 | } | |
1921 | ||
1922 | i = frame_hook_add(argc, argv); | |
1923 | ||
1924 | if (i != 0) { | |
1925 | fprintf(stderr, "Failed to add video hook function: %s\n", arg); | |
1926 | exit(1); | |
1927 | } | |
1928 | } | |
1929 | ||
85f07f22 FB |
1930 | const char *motion_str[] = { |
1931 | "zero", | |
1932 | "full", | |
1933 | "log", | |
1934 | "phods", | |
7084c149 MN |
1935 | "epzs", |
1936 | "x1", | |
85f07f22 FB |
1937 | NULL, |
1938 | }; | |
1939 | ||
b29f97d1 | 1940 | static void opt_motion_estimation(const char *arg) |
85f07f22 FB |
1941 | { |
1942 | const char **p; | |
1943 | p = motion_str; | |
1944 | for(;;) { | |
1945 | if (!*p) { | |
1946 | fprintf(stderr, "Unknown motion estimation method '%s'\n", arg); | |
1947 | exit(1); | |
1948 | } | |
1949 | if (!strcmp(*p, arg)) | |
1950 | break; | |
1951 | p++; | |
1952 | } | |
101bea5f | 1953 | me_method = (p - motion_str) + 1; |
85f07f22 FB |
1954 | } |
1955 | ||
b29f97d1 | 1956 | static void opt_video_codec(const char *arg) |
85f07f22 FB |
1957 | { |
1958 | AVCodec *p; | |
1959 | ||
1629626f FB |
1960 | if (!strcmp(arg, "copy")) { |
1961 | video_stream_copy = 1; | |
85f07f22 | 1962 | } else { |
1629626f FB |
1963 | p = first_avcodec; |
1964 | while (p) { | |
1965 | if (!strcmp(p->name, arg) && p->type == CODEC_TYPE_VIDEO) | |
1966 | break; | |
1967 | p = p->next; | |
1968 | } | |
1969 | if (p == NULL) { | |
1970 | fprintf(stderr, "Unknown video codec '%s'\n", arg); | |
1971 | exit(1); | |
1972 | } else { | |
1973 | video_codec_id = p->id; | |
1974 | } | |
85f07f22 FB |
1975 | } |
1976 | } | |
1977 | ||
b29f97d1 | 1978 | static void opt_map(const char *arg) |
85f07f22 FB |
1979 | { |
1980 | AVStreamMap *m; | |
1981 | const char *p; | |
1982 | ||
1983 | p = arg; | |
1984 | m = &stream_maps[nb_stream_maps++]; | |
1985 | ||
1986 | m->file_index = strtol(arg, (char **)&p, 0); | |
1987 | if (*p) | |
1988 | p++; | |
a5dc85ef J |
1989 | |
1990 | m->stream_index = strtol(p, (char **)&p, 0); | |
85f07f22 FB |
1991 | } |
1992 | ||
b29f97d1 | 1993 | static void opt_recording_time(const char *arg) |
85f07f22 FB |
1994 | { |
1995 | recording_time = parse_date(arg, 1); | |
1996 | } | |
1997 | ||
b29f97d1 | 1998 | static void opt_input_file(const char *filename) |
85f07f22 FB |
1999 | { |
2000 | AVFormatContext *ic; | |
2001 | AVFormatParameters params, *ap = ¶ms; | |
14bea432 | 2002 | int err, i, ret, rfps, rfps_base; |
85f07f22 | 2003 | |
b242baa4 FB |
2004 | if (!strcmp(filename, "-")) |
2005 | filename = "pipe:"; | |
2006 | ||
d9a916e2 CY |
2007 | using_stdin |= !strcmp(filename, "pipe:" ) || |
2008 | !strcmp( filename, "/dev/stdin" ); | |
2009 | ||
85f07f22 | 2010 | /* get default parameters from command line */ |
79fdaa4c FB |
2011 | memset(ap, 0, sizeof(*ap)); |
2012 | ap->sample_rate = audio_sample_rate; | |
2013 | ap->channels = audio_channels; | |
2014 | ap->frame_rate = frame_rate; | |
14bea432 | 2015 | ap->frame_rate_base = frame_rate_base; |
79fdaa4c FB |
2016 | ap->width = frame_width; |
2017 | ap->height = frame_height; | |
817b23ff | 2018 | ap->image_format = image_format; |
63167088 | 2019 | ap->pix_fmt = frame_pix_fmt; |
79fdaa4c FB |
2020 | |
2021 | /* open the input file with generic libav function */ | |
2022 | err = av_open_input_file(&ic, filename, file_iformat, 0, ap); | |
85f07f22 | 2023 | if (err < 0) { |
79fdaa4c | 2024 | print_error(filename, err); |
85f07f22 FB |
2025 | exit(1); |
2026 | } | |
2027 | ||
79fdaa4c FB |
2028 | /* If not enough info to get the stream parameters, we decode the |
2029 | first frames to get it. (used in mpeg case for example) */ | |
2030 | ret = av_find_stream_info(ic); | |
85f07f22 FB |
2031 | if (ret < 0) { |
2032 | fprintf(stderr, "%s: could not find codec parameters\n", filename); | |
2033 | exit(1); | |
2034 | } | |
2035 | ||
2036 | /* update the current parameters so that they match the one of the input stream */ | |
2037 | for(i=0;i<ic->nb_streams;i++) { | |
2038 | AVCodecContext *enc = &ic->streams[i]->codec; | |
2039 | switch(enc->codec_type) { | |
2040 | case CODEC_TYPE_AUDIO: | |
e0d2714a | 2041 | //fprintf(stderr, "\nInput Audio channels: %d", enc->channels); |
85f07f22 FB |
2042 | audio_channels = enc->channels; |
2043 | audio_sample_rate = enc->sample_rate; | |
2044 | break; | |
2045 | case CODEC_TYPE_VIDEO: | |
2046 | frame_height = enc->height; | |
2047 | frame_width = enc->width; | |
880e8ba7 | 2048 | frame_aspect_ratio = enc->aspect_ratio; |
63167088 | 2049 | frame_pix_fmt = enc->pix_fmt; |
14bea432 MN |
2050 | rfps = ic->streams[i]->r_frame_rate; |
2051 | rfps_base = ic->streams[i]->r_frame_rate_base; | |
fe670d09 | 2052 | enc->workaround_bugs = workaround_bugs; |
8409b8fe | 2053 | enc->error_resilience = error_resilience; |
4d2858de | 2054 | enc->error_concealment = error_concealment; |
2ad1516a | 2055 | enc->idct_algo= idct_algo; |
59b571c1 | 2056 | enc->debug= debug; |
d7425f59 MN |
2057 | /* if(enc->codec->capabilities & CODEC_CAP_TRUNCATED) |
2058 | enc->flags|= CODEC_FLAG_TRUNCATED; */ | |
0da71265 | 2059 | if(/*enc->codec_id==CODEC_ID_MPEG4 || */enc->codec_id==CODEC_ID_MPEG1VIDEO || enc->codec_id==CODEC_ID_H264) |
d7425f59 | 2060 | enc->flags|= CODEC_FLAG_TRUNCATED; |
b0368839 MN |
2061 | |
2062 | if(bitexact) | |
2063 | enc->flags|= CODEC_FLAG_BITEXACT; | |
d7425f59 | 2064 | |
14bea432 MN |
2065 | assert(enc->frame_rate_base == rfps_base); // should be true for now |
2066 | if (enc->frame_rate != rfps) { | |
6dc96cb0 | 2067 | fprintf(stderr,"\nSeems that stream %d comes from film source: %2.2f->%2.2f\n", |
14bea432 MN |
2068 | i, (float)enc->frame_rate / enc->frame_rate_base, |
2069 | (float)rfps / rfps_base); | |
79fdaa4c | 2070 | } |
bf5af568 | 2071 | /* update the current frame rate to match the stream frame rate */ |
14bea432 MN |
2072 | frame_rate = rfps; |
2073 | frame_rate_base = rfps_base; | |
bdfcbbed MK |
2074 | |
2075 | enc->rate_emu = rate_emu; | |
85f07f22 | 2076 | break; |
51bd4565 | 2077 | default: |
c04643a2 | 2078 | av_abort(); |
85f07f22 FB |
2079 | } |
2080 | } | |
2081 | ||
2082 | input_files[nb_input_files] = ic; | |
2083 | /* dump the file content */ | |
2084 | dump_format(ic, nb_input_files, filename, 0); | |
2085 | nb_input_files++; | |
79fdaa4c FB |
2086 | file_iformat = NULL; |
2087 | file_oformat = NULL; | |
817b23ff | 2088 | image_format = NULL; |
bdfcbbed MK |
2089 | |
2090 | rate_emu = 0; | |
85f07f22 FB |
2091 | } |
2092 | ||
b29f97d1 | 2093 | static void check_audio_video_inputs(int *has_video_ptr, int *has_audio_ptr) |
919f448d FB |
2094 | { |
2095 | int has_video, has_audio, i, j; | |
2096 | AVFormatContext *ic; | |
2097 | ||
2098 | has_video = 0; | |
2099 | has_audio = 0; | |
2100 | for(j=0;j<nb_input_files;j++) { | |
2101 | ic = input_files[j]; | |
2102 | for(i=0;i<ic->nb_streams;i++) { | |
2103 | AVCodecContext *enc = &ic->streams[i]->codec; | |
2104 | switch(enc->codec_type) { | |
2105 | case CODEC_TYPE_AUDIO: | |
2106 | has_audio = 1; | |
2107 | break; | |
2108 | case CODEC_TYPE_VIDEO: | |
2109 | has_video = 1; | |
2110 | break; | |
51bd4565 | 2111 | default: |
c04643a2 | 2112 | av_abort(); |
919f448d FB |
2113 | } |
2114 | } | |
2115 | } | |
2116 | *has_video_ptr = has_video; | |
2117 | *has_audio_ptr = has_audio; | |
2118 | } | |
2119 | ||
b29f97d1 | 2120 | static void opt_output_file(const char *filename) |
85f07f22 FB |
2121 | { |
2122 | AVStream *st; | |
2123 | AVFormatContext *oc; | |
919f448d | 2124 | int use_video, use_audio, nb_streams, input_has_video, input_has_audio; |
85f07f22 | 2125 | int codec_id; |
817b23ff | 2126 | AVFormatParameters params, *ap = ¶ms; |
85f07f22 FB |
2127 | |
2128 | if (!strcmp(filename, "-")) | |
2129 | filename = "pipe:"; | |
2130 | ||
2131 | oc = av_mallocz(sizeof(AVFormatContext)); | |
2132 | ||
79fdaa4c FB |
2133 | if (!file_oformat) { |
2134 | file_oformat = guess_format(NULL, filename, NULL); | |
2135 | if (!file_oformat) { | |
2136 | fprintf(stderr, "Unable for find a suitable output format for '%s'\n", | |
2137 | filename); | |
2138 | exit(1); | |
2139 | } | |
85f07f22 FB |
2140 | } |
2141 | ||
79fdaa4c | 2142 | oc->oformat = file_oformat; |
85f07f22 | 2143 | |
79fdaa4c | 2144 | if (!strcmp(file_oformat->name, "ffm") && |
85f07f22 FB |
2145 | strstart(filename, "http:", NULL)) { |
2146 | /* special case for files sent to ffserver: we get the stream | |
2147 | parameters from ffserver */ | |
2148 | if (read_ffserver_streams(oc, filename) < 0) { | |
2149 | fprintf(stderr, "Could not read stream parameters from '%s'\n", filename); | |
2150 | exit(1); | |
2151 | } | |
2152 | } else { | |
79fdaa4c FB |
2153 | use_video = file_oformat->video_codec != CODEC_ID_NONE; |
2154 | use_audio = file_oformat->audio_codec != CODEC_ID_NONE; | |
919f448d | 2155 | |
e30a2846 FB |
2156 | /* disable if no corresponding type found and at least one |
2157 | input file */ | |
2158 | if (nb_input_files > 0) { | |
2159 | check_audio_video_inputs(&input_has_video, &input_has_audio); | |
2160 | if (!input_has_video) | |
2161 | use_video = 0; | |
2162 | if (!input_has_audio) | |
2163 | use_audio = 0; | |
2164 | } | |
919f448d FB |
2165 | |
2166 | /* manual disable */ | |
85f07f22 FB |
2167 | if (audio_disable) { |
2168 | use_audio = 0; | |
2169 | } | |
2170 | if (video_disable) { | |
2171 | use_video = 0; | |
2172 | } | |
2173 | ||
2174 | nb_streams = 0; | |
2175 | if (use_video) { | |
2176 | AVCodecContext *video_enc; | |
2177 | ||
2178 | st = av_mallocz(sizeof(AVStream)); | |
2179 | if (!st) { | |
2180 | fprintf(stderr, "Could not alloc stream\n"); | |
2181 | exit(1); | |
2182 | } | |
1e491e29 | 2183 | avcodec_get_context_defaults(&st->codec); |
85f07f22 | 2184 | |
1629626f FB |
2185 | video_enc = &st->codec; |
2186 | if (video_stream_copy) { | |
2187 | st->stream_copy = 1; | |
2188 | video_enc->codec_type = CODEC_TYPE_VIDEO; | |
2189 | } else { | |
ac2830ec MN |
2190 | char *p; |
2191 | int i; | |
2192 | ||
1629626f FB |
2193 | codec_id = file_oformat->video_codec; |
2194 | if (video_codec_id != CODEC_ID_NONE) | |
2195 | codec_id = video_codec_id; | |
2196 | ||
2197 | video_enc->codec_id = codec_id; | |
2198 | ||
2199 | video_enc->bit_rate = video_bit_rate; | |
2200 | video_enc->bit_rate_tolerance = video_bit_rate_tolerance; | |
2201 | video_enc->frame_rate = frame_rate; | |
14bea432 | 2202 | video_enc->frame_rate_base = frame_rate_base; |
1629626f FB |
2203 | |
2204 | video_enc->width = frame_width; | |
2205 | video_enc->height = frame_height; | |
880e8ba7 | 2206 | video_enc->aspect_ratio = frame_aspect_ratio; |
63167088 | 2207 | video_enc->pix_fmt = frame_pix_fmt; |
1629626f FB |
2208 | |
2209 | if (!intra_only) | |
2210 | video_enc->gop_size = gop_size; | |
2211 | else | |
2212 | video_enc->gop_size = 0; | |
2213 | if (video_qscale || same_quality) { | |
2214 | video_enc->flags |= CODEC_FLAG_QSCALE; | |
1e491e29 | 2215 | st->quality = video_qscale; |
1629626f | 2216 | } |
b0368839 MN |
2217 | |
2218 | if(bitexact) | |
2219 | video_enc->flags |= CODEC_FLAG_BITEXACT; | |
2220 | ||
7d1c3fc1 MN |
2221 | video_enc->mb_decision = mb_decision; |
2222 | ||
21e59552 MN |
2223 | if (use_umv) { |
2224 | video_enc->flags |= CODEC_FLAG_H263P_UMV; | |
2225 | } | |
2226 | if (use_aic) { | |
2227 | video_enc->flags |= CODEC_FLAG_H263P_AIC; | |
2228 | } | |
1629626f | 2229 | if (use_4mv) { |
7d1c3fc1 | 2230 | video_enc->mb_decision = FF_MB_DECISION_BITS; //FIXME remove |
1629626f FB |
2231 | video_enc->flags |= CODEC_FLAG_4MV; |
2232 | } | |
bc6caae2 | 2233 | |
1629626f FB |
2234 | if(use_part) |
2235 | video_enc->flags |= CODEC_FLAG_PART; | |
1dbb6d90 MN |
2236 | |
2237 | ||
1629626f | 2238 | if (b_frames) { |
1629626f FB |
2239 | video_enc->max_b_frames = b_frames; |
2240 | video_enc->b_frame_strategy = 0; | |
2241 | video_enc->b_quant_factor = 2.0; | |
bc6caae2 | 2242 | } |
bc6caae2 | 2243 | |
1629626f FB |
2244 | video_enc->qmin = video_qmin; |
2245 | video_enc->qmax = video_qmax; | |
17a70fde MN |
2246 | video_enc->mb_qmin = video_mb_qmin; |
2247 | video_enc->mb_qmax = video_mb_qmax; | |
1629626f FB |
2248 | video_enc->max_qdiff = video_qdiff; |
2249 | video_enc->qblur = video_qblur; | |
2250 | video_enc->qcompress = video_qcomp; | |
2251 | video_enc->rc_eq = video_rc_eq; | |
59b571c1 | 2252 | video_enc->debug= debug; |
ac2830ec MN |
2253 | |
2254 | p= video_rc_override_string; | |
2255 | for(i=0; p; i++){ | |
2256 | int start, end, q; | |
2257 | int e=sscanf(p, "%d,%d,%d", &start, &end, &q); | |
2258 | if(e!=3){ | |
2259 | fprintf(stderr, "error parsing rc_override\n"); | |
2260 | exit(1); | |
2261 | } | |
2262 | video_enc->rc_override= | |
47e2a6e6 FB |
2263 | av_realloc(video_enc->rc_override, |
2264 | sizeof(RcOverride)*(i+1)); | |
ac2830ec MN |
2265 | video_enc->rc_override[i].start_frame= start; |
2266 | video_enc->rc_override[i].end_frame = end; | |
2267 | if(q>0){ | |
2268 | video_enc->rc_override[i].qscale= q; | |
2269 | video_enc->rc_override[i].quality_factor= 1.0; | |
2270 | } | |
2271 | else{ | |
2272 | video_enc->rc_override[i].qscale= 0; | |
2273 | video_enc->rc_override[i].quality_factor= -q/100.0; | |
2274 | } | |
2275 | p= strchr(p, '/'); | |
2276 | if(p) p++; | |
2277 | } | |
2278 | video_enc->rc_override_count=i; | |
2279 | ||
1629626f FB |
2280 | video_enc->rc_max_rate = video_rc_max_rate; |
2281 | video_enc->rc_min_rate = video_rc_min_rate; | |
2282 | video_enc->rc_buffer_size = video_rc_buffer_size; | |
2283 | video_enc->rc_buffer_aggressivity= video_rc_buffer_aggressivity; | |
ac2830ec | 2284 | video_enc->rc_initial_cplx= video_rc_initial_cplx; |
1629626f FB |
2285 | video_enc->i_quant_factor = video_i_qfactor; |
2286 | video_enc->b_quant_factor = video_b_qfactor; | |
2287 | video_enc->i_quant_offset = video_i_qoffset; | |
2288 | video_enc->b_quant_offset = video_b_qoffset; | |
2289 | video_enc->dct_algo = dct_algo; | |
2290 | video_enc->idct_algo = idct_algo; | |
f560dd82 | 2291 | video_enc->strict_std_compliance = strict; |
1629626f FB |
2292 | if(packet_size){ |
2293 | video_enc->rtp_mode= 1; | |
2294 | video_enc->rtp_payload_size= packet_size; | |
2295 | } | |
9cdd6a24 | 2296 | |
1629626f | 2297 | if (do_psnr) |
140cb663 | 2298 | video_enc->flags|= CODEC_FLAG_PSNR; |
e4986da9 | 2299 | |
1629626f | 2300 | video_enc->me_method = me_method; |
5abdb4b1 | 2301 | |
1629626f FB |
2302 | /* two pass mode */ |
2303 | if (do_pass) { | |
2304 | if (do_pass == 1) { | |
2305 | video_enc->flags |= CODEC_FLAG_PASS1; | |
2306 | } else { | |
2307 | video_enc->flags |= CODEC_FLAG_PASS2; | |
2308 | } | |
5abdb4b1 | 2309 | } |
cfcf0ffd | 2310 | } |
85f07f22 FB |
2311 | oc->streams[nb_streams] = st; |
2312 | nb_streams++; | |
2313 | } | |
2314 | ||
2315 | if (use_audio) { | |
2316 | AVCodecContext *audio_enc; | |
2317 | ||
2318 | st = av_mallocz(sizeof(AVStream)); | |
2319 | if (!st) { | |
2320 | fprintf(stderr, "Could not alloc stream\n"); | |
2321 | exit(1); | |
2322 | } | |
1e491e29 | 2323 | avcodec_get_context_defaults(&st->codec); |
1629626f | 2324 | |
85f07f22 | 2325 | audio_enc = &st->codec; |
85f07f22 | 2326 | audio_enc->codec_type = CODEC_TYPE_AUDIO; |
1629626f FB |
2327 | if (audio_stream_copy) { |
2328 | st->stream_copy = 1; | |
2329 | } else { | |
2330 | codec_id = file_oformat->audio_codec; | |
2331 | if (audio_codec_id != CODEC_ID_NONE) | |
2332 | codec_id = audio_codec_id; | |
2333 | audio_enc->codec_id = codec_id; | |
2334 | ||
2335 | audio_enc->bit_rate = audio_bit_rate; | |
2336 | audio_enc->sample_rate = audio_sample_rate; | |
2337 | /* For audio codecs other than AC3 we limit */ | |
2338 | /* the number of coded channels to stereo */ | |
2339 | if (audio_channels > 2 && codec_id != CODEC_ID_AC3) { | |
2340 | audio_enc->channels = 2; | |
2341 | } else | |
2342 | audio_enc->channels = audio_channels; | |
2343 | } | |
85f07f22 FB |
2344 | oc->streams[nb_streams] = st; |
2345 | nb_streams++; | |
2346 | } | |
2347 | ||
2348 | oc->nb_streams = nb_streams; | |
2349 | ||
2350 | if (!nb_streams) { | |
919f448d | 2351 | fprintf(stderr, "No audio or video streams available\n"); |
85f07f22 FB |
2352 | exit(1); |
2353 | } | |
2354 | ||
2355 | if (str_title) | |
79fdaa4c | 2356 | pstrcpy(oc->title, sizeof(oc->title), str_title); |
85f07f22 | 2357 | if (str_author) |
79fdaa4c | 2358 | pstrcpy(oc->author, sizeof(oc->author), str_author); |
85f07f22 | 2359 | if (str_copyright) |
79fdaa4c | 2360 | pstrcpy(oc->copyright, sizeof(oc->copyright), str_copyright); |
85f07f22 | 2361 | if (str_comment) |
79fdaa4c | 2362 | pstrcpy(oc->comment, sizeof(oc->comment), str_comment); |
85f07f22 FB |
2363 | } |
2364 | ||
1629626f | 2365 | output_files[nb_output_files++] = oc; |
85f07f22 FB |
2366 | |
2367 | strcpy(oc->filename, filename); | |
919f448d FB |
2368 | |
2369 | /* check filename in case of an image number is expected */ | |
79fdaa4c FB |
2370 | if (oc->oformat->flags & AVFMT_NEEDNUMBER) { |
2371 | if (filename_number_test(oc->filename) < 0) { | |
2372 | print_error(oc->filename, AVERROR_NUMEXPECTED); | |
919f448d | 2373 | exit(1); |
79fdaa4c | 2374 | } |
919f448d FB |
2375 | } |
2376 | ||
79fdaa4c | 2377 | if (!(oc->oformat->flags & AVFMT_NOFILE)) { |
85f07f22 FB |
2378 | /* test if it already exists to avoid loosing precious files */ |
2379 | if (!file_overwrite && | |
2380 | (strchr(filename, ':') == NULL || | |
2381 | strstart(filename, "file:", NULL))) { | |
2382 | if (url_exist(filename)) { | |
2383 | int c; | |
2384 | ||
d9a916e2 CY |
2385 | if ( !using_stdin ) { |
2386 | fprintf(stderr,"File '%s' already exists. Overwrite ? [y/N] ", filename); | |
2387 | fflush(stderr); | |
2388 | c = getchar(); | |
2389 | if (toupper(c) != 'Y') { | |
2390 | fprintf(stderr, "Not overwriting - exiting\n"); | |
2391 | exit(1); | |
2392 | } | |
2393 | } | |
2394 | else { | |
2395 | fprintf(stderr,"File '%s' already exists. Exiting.\n", filename); | |
85f07f22 | 2396 | exit(1); |
d9a916e2 | 2397 | } |
85f07f22 FB |
2398 | } |
2399 | } | |
2400 | ||
2401 | /* open the file */ | |
2402 | if (url_fopen(&oc->pb, filename, URL_WRONLY) < 0) { | |
2403 | fprintf(stderr, "Could not open '%s'\n", filename); | |
2404 | exit(1); | |
2405 | } | |
2406 | } | |
2407 | ||
817b23ff FB |
2408 | memset(ap, 0, sizeof(*ap)); |
2409 | ap->image_format = image_format; | |
2410 | if (av_set_parameters(oc, ap) < 0) { | |
2411 | fprintf(stderr, "%s: Invalid encoding parameters\n", | |
2412 | oc->filename); | |
2413 | exit(1); | |
2414 | } | |
2415 | ||
85f07f22 | 2416 | /* reset some options */ |
79fdaa4c FB |
2417 | file_oformat = NULL; |
2418 | file_iformat = NULL; | |
817b23ff | 2419 | image_format = NULL; |
85f07f22 FB |
2420 | audio_disable = 0; |
2421 | video_disable = 0; | |
2422 | audio_codec_id = CODEC_ID_NONE; | |
2423 | video_codec_id = CODEC_ID_NONE; | |
1629626f FB |
2424 | audio_stream_copy = 0; |
2425 | video_stream_copy = 0; | |
85f07f22 FB |
2426 | } |
2427 | ||
a38469e1 | 2428 | /* prepare dummy protocols for grab */ |
b29f97d1 | 2429 | static void prepare_grab(void) |
a38469e1 FB |
2430 | { |
2431 | int has_video, has_audio, i, j; | |
2432 | AVFormatContext *oc; | |
2433 | AVFormatContext *ic; | |
79a7c268 | 2434 | AVFormatParameters vp1, *vp = &vp1; |
a38469e1 | 2435 | AVFormatParameters ap1, *ap = &ap1; |
79a7c268 | 2436 | |
a38469e1 FB |
2437 | /* see if audio/video inputs are needed */ |
2438 | has_video = 0; | |
2439 | has_audio = 0; | |
2440 | memset(ap, 0, sizeof(*ap)); | |
79a7c268 | 2441 | memset(vp, 0, sizeof(*vp)); |
a38469e1 FB |
2442 | for(j=0;j<nb_output_files;j++) { |
2443 | oc = output_files[j]; | |
2444 | for(i=0;i<oc->nb_streams;i++) { | |
2445 | AVCodecContext *enc = &oc->streams[i]->codec; | |
2446 | switch(enc->codec_type) { | |
2447 | case CODEC_TYPE_AUDIO: | |
2448 | if (enc->sample_rate > ap->sample_rate) | |
2449 | ap->sample_rate = enc->sample_rate; | |
2450 | if (enc->channels > ap->channels) | |
2451 | ap->channels = enc->channels; | |
2452 | has_audio = 1; | |
2453 | break; | |
2454 | case CODEC_TYPE_VIDEO: | |
79a7c268 FB |
2455 | if (enc->width > vp->width) |
2456 | vp->width = enc->width; | |
2457 | if (enc->height > vp->height) | |
2458 | vp->height = enc->height; | |
14bea432 MN |
2459 | |
2460 | assert(enc->frame_rate_base == DEFAULT_FRAME_RATE_BASE); | |
2461 | if (enc->frame_rate > vp->frame_rate){ | |
2462 | vp->frame_rate = enc->frame_rate; | |
2463 | vp->frame_rate_base = enc->frame_rate_base; | |
2464 | } | |
a38469e1 FB |
2465 | has_video = 1; |
2466 | break; | |
51bd4565 | 2467 | default: |
c04643a2 | 2468 | av_abort(); |
a38469e1 FB |
2469 | } |
2470 | } | |
2471 | } | |
2472 | ||
2473 | if (has_video == 0 && has_audio == 0) { | |
2474 | fprintf(stderr, "Output file must have at least one audio or video stream\n"); | |
2475 | exit(1); | |
2476 | } | |
2477 | ||
2478 | if (has_video) { | |
79fdaa4c | 2479 | AVInputFormat *fmt1; |
8aa3ee32 | 2480 | fmt1 = av_find_input_format(video_grab_format); |
a5df11ab FB |
2481 | vp->device = video_device; |
2482 | vp->channel = video_channel; | |
e3ee3283 | 2483 | vp->standard = video_standard; |
79a7c268 | 2484 | if (av_open_input_file(&ic, "", fmt1, 0, vp) < 0) { |
bf5af568 | 2485 | fprintf(stderr, "Could not find video grab device\n"); |
a38469e1 FB |
2486 | exit(1); |
2487 | } | |
79fdaa4c | 2488 | /* by now video grab has one stream */ |
14bea432 MN |
2489 | ic->streams[0]->r_frame_rate = vp->frame_rate; |
2490 | ic->streams[0]->r_frame_rate_base = vp->frame_rate_base; | |
a38469e1 | 2491 | input_files[nb_input_files] = ic; |
79a7c268 | 2492 | dump_format(ic, nb_input_files, "", 0); |
a38469e1 FB |
2493 | nb_input_files++; |
2494 | } | |
1501987b | 2495 | if (has_audio && audio_grab_format) { |
79fdaa4c | 2496 | AVInputFormat *fmt1; |
8aa3ee32 | 2497 | fmt1 = av_find_input_format(audio_grab_format); |
79a7c268 | 2498 | ap->device = audio_device; |
79fdaa4c | 2499 | if (av_open_input_file(&ic, "", fmt1, 0, ap) < 0) { |
bf5af568 | 2500 | fprintf(stderr, "Could not find audio grab device\n"); |
a38469e1 FB |
2501 | exit(1); |
2502 | } | |
2503 | input_files[nb_input_files] = ic; | |
79a7c268 | 2504 | dump_format(ic, nb_input_files, "", 0); |
a38469e1 FB |
2505 | nb_input_files++; |
2506 | } | |
2507 | } | |
2508 | ||
5abdb4b1 | 2509 | /* same option as mencoder */ |
b29f97d1 | 2510 | static void opt_pass(const char *pass_str) |
5abdb4b1 FB |
2511 | { |
2512 | int pass; | |
2513 | pass = atoi(pass_str); | |
2514 | if (pass != 1 && pass != 2) { | |
2515 | fprintf(stderr, "pass number can be only 1 or 2\n"); | |
2516 | exit(1); | |
2517 | } | |
2518 | do_pass = pass; | |
2519 | } | |
a38469e1 | 2520 | |
f3ec2d46 | 2521 | #if defined(CONFIG_WIN32) || defined(CONFIG_OS2) |
0c1a9eda | 2522 | static int64_t getutime(void) |
5727b222 | 2523 | { |
f3ec2d46 | 2524 | return av_gettime(); |
5727b222 | 2525 | } |
bdc4796f | 2526 | #else |
0c1a9eda | 2527 | static int64_t getutime(void) |
bdc4796f | 2528 | { |
f3ec2d46 SG |
2529 | struct rusage rusage; |
2530 | ||
2531 | getrusage(RUSAGE_SELF, &rusage); | |
2532 | return (rusage.ru_utime.tv_sec * 1000000LL) + rusage.ru_utime.tv_usec; | |
bdc4796f FB |
2533 | } |
2534 | #endif | |
5727b222 | 2535 | |
79fdaa4c FB |
2536 | extern int ffm_nopts; |
2537 | ||
b29f97d1 | 2538 | static void opt_bitexact(void) |
79fdaa4c | 2539 | { |
b0368839 | 2540 | bitexact=1; |
79fdaa4c FB |
2541 | /* disable generate of real time pts in ffm (need to be supressed anyway) */ |
2542 | ffm_nopts = 1; | |
2543 | } | |
2544 | ||
b29f97d1 | 2545 | static void show_formats(void) |
85f07f22 | 2546 | { |
79fdaa4c FB |
2547 | AVInputFormat *ifmt; |
2548 | AVOutputFormat *ofmt; | |
817b23ff | 2549 | AVImageFormat *image_fmt; |
85f07f22 FB |
2550 | URLProtocol *up; |
2551 | AVCodec *p; | |
2552 | const char **pp; | |
2553 | ||
817b23ff | 2554 | printf("Output audio/video file formats:"); |
79fdaa4c FB |
2555 | for(ofmt = first_oformat; ofmt != NULL; ofmt = ofmt->next) { |
2556 | printf(" %s", ofmt->name); | |
85f07f22 FB |
2557 | } |
2558 | printf("\n"); | |
817b23ff FB |
2559 | |
2560 | printf("Input audio/video file formats:"); | |
79fdaa4c FB |
2561 | for(ifmt = first_iformat; ifmt != NULL; ifmt = ifmt->next) { |
2562 | printf(" %s", ifmt->name); | |
85f07f22 FB |
2563 | } |
2564 | printf("\n"); | |
2565 | ||
817b23ff FB |
2566 | printf("Output image formats:"); |
2567 | for(image_fmt = first_image_format; image_fmt != NULL; | |
2568 | image_fmt = image_fmt->next) { | |
2569 | if (image_fmt->img_write) | |
2570 | printf(" %s", image_fmt->name); | |
2571 | } | |
2572 | printf("\n"); | |
2573 | ||
2574 | printf("Input image formats:"); | |
2575 | for(image_fmt = first_image_format; image_fmt != NULL; | |
2576 | image_fmt = image_fmt->next) { | |
2577 | if (image_fmt->img_read) | |
2578 | printf(" %s", image_fmt->name); | |
2579 | } | |
2580 | printf("\n"); | |
2581 | ||
85f07f22 FB |
2582 | printf("Codecs:\n"); |
2583 | printf(" Encoders:"); | |
2584 | for(p = first_avcodec; p != NULL; p = p->next) { | |
2585 | if (p->encode) | |
2586 | printf(" %s", p->name); | |
2587 | } | |
2588 | printf("\n"); | |
2589 | ||
2590 | printf(" Decoders:"); | |
2591 | for(p = first_avcodec; p != NULL; p = p->next) { | |
2592 | if (p->decode) | |
2593 | printf(" %s", p->name); | |
2594 | } | |
2595 | printf("\n"); | |
2596 | ||
2597 | printf("Supported file protocols:"); | |
2598 | for(up = first_protocol; up != NULL; up = up->next) | |
2599 | printf(" %s:", up->name); | |
2600 | printf("\n"); | |
2601 | ||
ba2a8cb4 | 2602 | printf("Frame size, frame rate abbreviations: ntsc pal qntsc qpal sntsc spal film ntsc-film sqcif qcif cif 4cif\n"); |
85f07f22 FB |
2603 | printf("Motion estimation methods:"); |
2604 | pp = motion_str; | |
2605 | while (*pp) { | |
2606 | printf(" %s", *pp); | |
101bea5f | 2607 | if ((pp - motion_str + 1) == ME_ZERO) |
85f07f22 | 2608 | printf("(fastest)"); |
101bea5f | 2609 | else if ((pp - motion_str + 1) == ME_FULL) |
85f07f22 | 2610 | printf("(slowest)"); |
101bea5f | 2611 | else if ((pp - motion_str + 1) == ME_EPZS) |
85f07f22 FB |
2612 | printf("(default)"); |
2613 | pp++; | |
2614 | } | |
2615 | printf("\n"); | |
2616 | exit(1); | |
2617 | } | |
2618 | ||
85f07f22 | 2619 | const OptionDef options[] = { |
02d504a7 FB |
2620 | /* main options */ |
2621 | { "L", 0, {(void*)show_license}, "show license" }, | |
bdc4796f FB |
2622 | { "h", 0, {(void*)show_help}, "show help" }, |
2623 | { "formats", 0, {(void*)show_formats}, "show available formats, codecs, protocols, ..." }, | |
2624 | { "f", HAS_ARG, {(void*)opt_format}, "force format", "fmt" }, | |
817b23ff | 2625 | { "img", HAS_ARG, {(void*)opt_image_format}, "force image format", "img_fmt" }, |
bdc4796f FB |
2626 | { "i", HAS_ARG, {(void*)opt_input_file}, "input file name", "filename" }, |
2627 | { "y", OPT_BOOL, {(void*)&file_overwrite}, "overwrite output files" }, | |
2628 | { "map", HAS_ARG | OPT_EXPERT, {(void*)opt_map}, "set input stream mapping", "file:stream" }, | |
2629 | { "t", HAS_ARG, {(void*)opt_recording_time}, "set the recording time", "duration" }, | |
2630 | { "title", HAS_ARG | OPT_STRING, {(void*)&str_title}, "set the title", "string" }, | |
2631 | { "author", HAS_ARG | OPT_STRING, {(void*)&str_author}, "set the author", "string" }, | |
2632 | { "copyright", HAS_ARG | OPT_STRING, {(void*)&str_copyright}, "set the copyright", "string" }, | |
2633 | { "comment", HAS_ARG | OPT_STRING, {(void*)&str_comment}, "set the comment", "string" }, | |
1d366fce | 2634 | { "debug", HAS_ARG | OPT_EXPERT, {(void*)opt_debug}, "print specific debug info", "" }, |
bdc4796f | 2635 | { "benchmark", OPT_BOOL | OPT_EXPERT, {(void*)&do_benchmark}, |
5727b222 | 2636 | "add timings for benchmarking" }, |
a0663ba4 FB |
2637 | { "hex", OPT_BOOL | OPT_EXPERT, {(void*)&do_hex_dump}, |
2638 | "dump each input packet" }, | |
79fdaa4c | 2639 | { "bitexact", OPT_EXPERT, {(void*)opt_bitexact}, "only use bit exact algorithms (for codec testing)" }, |
b1b77fe9 FB |
2640 | { "re", OPT_BOOL | OPT_EXPERT, {(void*)&rate_emu}, "read input at native frame rate", "" }, |
2641 | { "loop", OPT_BOOL | OPT_EXPERT, {(void*)&loop_input}, "loop (current only works with images)" }, | |
f068206e | 2642 | { "v", HAS_ARG, {(void*)opt_verbose}, "control amount of logging", "verbose" }, |
02d504a7 FB |
2643 | |
2644 | /* video options */ | |
2645 | { "b", HAS_ARG | OPT_VIDEO, {(void*)opt_video_bitrate}, "set video bitrate (in kbit/s)", "bitrate" }, | |
2646 | { "r", HAS_ARG | OPT_VIDEO, {(void*)opt_frame_rate}, "set frame rate (Hz value, fraction or abbreviation)", "rate" }, | |
02d504a7 FB |
2647 | { "s", HAS_ARG | OPT_VIDEO, {(void*)opt_frame_size}, "set frame size (WxH or abbreviation)", "size" }, |
2648 | { "aspect", HAS_ARG | OPT_VIDEO, {(void*)opt_frame_aspect_ratio}, "set aspect ratio (4:3, 16:9 or 1.3333, 1.7777)", "aspect" }, | |
2649 | { "pix_fmt", HAS_ARG | OPT_EXPERT | OPT_VIDEO, {(void*)opt_frame_pix_fmt}, "set pixel format", "format" }, | |
2650 | { "croptop", HAS_ARG | OPT_VIDEO, {(void*)opt_frame_crop_top}, "set top crop band size (in pixels)", "size" }, | |
2651 | { "cropbottom", HAS_ARG | OPT_VIDEO, {(void*)opt_frame_crop_bottom}, "set bottom crop band size (in pixels)", "size" }, | |
2652 | { "cropleft", HAS_ARG | OPT_VIDEO, {(void*)opt_frame_crop_left}, "set left crop band size (in pixels)", "size" }, | |
2653 | { "cropright", HAS_ARG | OPT_VIDEO, {(void*)opt_frame_crop_right}, "set right crop band size (in pixels)", "size" }, | |
2654 | { "g", HAS_ARG | OPT_EXPERT | OPT_VIDEO, {(void*)opt_gop_size}, "set the group of picture size", "gop_size" }, | |
2655 | { "intra", OPT_BOOL | OPT_EXPERT | OPT_VIDEO, {(void*)&intra_only}, "use only intra frames"}, | |
2656 | { "vn", OPT_BOOL | OPT_VIDEO, {(void*)&video_disable}, "disable video" }, | |
2657 | { "qscale", HAS_ARG | OPT_EXPERT | OPT_VIDEO, {(void*)opt_qscale}, "use fixed video quantiser scale (VBR)", "q" }, | |
2658 | { "qmin", HAS_ARG | OPT_EXPERT | OPT_VIDEO, {(void*)opt_qmin}, "min video quantiser scale (VBR)", "q" }, | |
2659 | { "qmax", HAS_ARG | OPT_EXPERT | OPT_VIDEO, {(void*)opt_qmax}, "max video quantiser scale (VBR)", "q" }, | |
2660 | { "mbqmin", HAS_ARG | OPT_EXPERT | OPT_VIDEO, {(void*)opt_mb_qmin}, "min macroblock quantiser scale (VBR)", "q" }, | |
2661 | { "mbqmax", HAS_ARG | OPT_EXPERT | OPT_VIDEO, {(void*)opt_mb_qmax}, "max macroblock quantiser scale (VBR)", "q" }, | |
2662 | { "qdiff", HAS_ARG | OPT_EXPERT | OPT_VIDEO, {(void*)opt_qdiff}, "max difference between the quantiser scale (VBR)", "q" }, | |
2663 | { "qblur", HAS_ARG | OPT_EXPERT | OPT_VIDEO, {(void*)opt_qblur}, "video quantiser scale blur (VBR)", "blur" }, | |
2664 | { "qcomp", HAS_ARG | OPT_EXPERT | OPT_VIDEO, {(void*)opt_qcomp}, "video quantiser scale compression (VBR)", "compression" }, | |
2665 | { "rc_init_cplx", HAS_ARG | OPT_EXPERT | OPT_VIDEO, {(void*)opt_rc_initial_cplx}, "initial complexity for 1-pass encoding", "complexity" }, | |
2666 | { "b_qfactor", HAS_ARG | OPT_EXPERT | OPT_VIDEO, {(void*)opt_b_qfactor}, "qp factor between p and b frames", "factor" }, | |
2667 | { "i_qfactor", HAS_ARG | OPT_EXPERT | OPT_VIDEO, {(void*)opt_i_qfactor}, "qp factor between p and i frames", "factor" }, | |
2668 | { "b_qoffset", HAS_ARG | OPT_EXPERT | OPT_VIDEO, {(void*)opt_b_qoffset}, "qp offset between p and b frames", "offset" }, | |
2669 | { "i_qoffset", HAS_ARG | OPT_EXPERT | OPT_VIDEO, {(void*)opt_i_qoffset}, "qp offset between p and i frames", "offset" }, | |
2670 | // { "b_strategy", HAS_ARG | OPT_EXPERT, {(void*)opt_b_strategy}, "dynamic b frame selection strategy", "strategy" }, | |
2671 | { "rc_eq", HAS_ARG | OPT_EXPERT | OPT_VIDEO, {(void*)opt_video_rc_eq}, "set rate control equation", "equation" }, | |
d95ac2c5 | 2672 | { "rc_override", HAS_ARG | OPT_EXPERT | OPT_VIDEO, {(void*)opt_video_rc_override_string}, "rate control override for specific intervals", "override" }, |
02d504a7 FB |
2673 | { "bt", HAS_ARG | OPT_VIDEO, {(void*)opt_video_bitrate_tolerance}, "set video bitrate tolerance (in kbit/s)", "tolerance" }, |
2674 | { "maxrate", HAS_ARG | OPT_VIDEO, {(void*)opt_video_bitrate_max}, "set max video bitrate tolerance (in kbit/s)", "bitrate" }, | |
2675 | { "minrate", HAS_ARG | OPT_VIDEO, {(void*)opt_video_bitrate_min}, "set min video bitrate tolerance (in kbit/s)", "bitrate" }, | |
2676 | { "bufsize", HAS_ARG | OPT_VIDEO, {(void*)opt_video_buffer_size}, "set ratecontrol buffere size (in kbit)", "size" }, | |
2677 | { "vcodec", HAS_ARG | OPT_VIDEO, {(void*)opt_video_codec}, "force video codec ('copy' to copy stream)", "codec" }, | |
2678 | { "me", HAS_ARG | OPT_EXPERT | OPT_VIDEO, {(void*)opt_motion_estimation}, "set motion estimation method", | |
2679 | "method" }, | |
2680 | { "dct_algo", HAS_ARG | OPT_EXPERT | OPT_VIDEO, {(void*)opt_dct_algo}, "set dct algo", "algo" }, | |
2681 | { "idct_algo", HAS_ARG | OPT_EXPERT | OPT_VIDEO, {(void*)opt_idct_algo}, "set idct algo", "algo" }, | |
2682 | { "er", HAS_ARG | OPT_EXPERT | OPT_VIDEO, {(void*)opt_error_resilience}, "set error resilience", "n" }, | |
d95ac2c5 | 2683 | { "ec", HAS_ARG | OPT_EXPERT | OPT_VIDEO, {(void*)opt_error_concealment}, "set error concealment", "bit_mask" }, |
02d504a7 FB |
2684 | { "bf", HAS_ARG | OPT_EXPERT | OPT_VIDEO, {(void*)opt_b_frames}, "use 'frames' B frames (only MPEG-4)", "frames" }, |
2685 | { "hq", OPT_BOOL, {(void*)&mb_decision}, "activate high quality settings" }, | |
2686 | { "mbd", HAS_ARG | OPT_EXPERT | OPT_VIDEO, {(void*)opt_mb_decision}, "macroblock decision", "mode" }, | |
2687 | { "4mv", OPT_BOOL | OPT_EXPERT | OPT_VIDEO, {(void*)&use_4mv}, "use four motion vector by macroblock (only MPEG-4)" }, | |
2688 | { "part", OPT_BOOL | OPT_EXPERT | OPT_VIDEO, {(void*)&use_part}, "use data partitioning (only MPEG-4)" }, | |
2689 | { "bug", HAS_ARG | OPT_EXPERT | OPT_VIDEO, {(void*)opt_workaround_bugs}, "workaround not auto detected encoder bugs", "param" }, | |
2690 | { "ps", HAS_ARG | OPT_EXPERT, {(void*)opt_packet_size}, "set packet size in bits", "size" }, | |
2691 | { "strict", HAS_ARG | OPT_EXPERT | OPT_VIDEO, {(void*)opt_strict}, "how strictly to follow the standarts", "strictness" }, | |
2692 | { "sameq", OPT_BOOL | OPT_VIDEO, {(void*)&same_quality}, | |
2693 | "use same video quality as source (implies VBR)" }, | |
2694 | { "pass", HAS_ARG | OPT_VIDEO, {(void*)&opt_pass}, "select the pass number (1 or 2)", "n" }, | |
2695 | { "passlogfile", HAS_ARG | OPT_STRING | OPT_VIDEO, {(void*)&pass_logfilename}, "select two pass log file name", "file" }, | |
2696 | { "deinterlace", OPT_BOOL | OPT_EXPERT | OPT_VIDEO, {(void*)&do_deinterlace}, | |
2697 | "deinterlace pictures" }, | |
2698 | { "psnr", OPT_BOOL | OPT_EXPERT | OPT_VIDEO, {(void*)&do_psnr}, "calculate PSNR of compressed frames" }, | |
2699 | { "vstats", OPT_BOOL | OPT_EXPERT | OPT_VIDEO, {(void*)&do_vstats}, "dump video coding statistics to file" }, | |
2700 | { "vhook", HAS_ARG | OPT_EXPERT | OPT_VIDEO, {(void*)add_frame_hooker}, "insert video processing module", "module" }, | |
02d504a7 FB |
2701 | { "aic", OPT_BOOL | OPT_EXPERT | OPT_VIDEO, {(void*)&use_aic}, "enable Advanced intra coding (h263+)" }, |
2702 | { "umv", OPT_BOOL | OPT_EXPERT | OPT_VIDEO, {(void*)&use_umv}, "enable Unlimited Motion Vector (h263+)" }, | |
02d504a7 FB |
2703 | |
2704 | /* audio options */ | |
2705 | { "ab", HAS_ARG | OPT_AUDIO, {(void*)opt_audio_bitrate}, "set audio bitrate (in kbit/s)", "bitrate", }, | |
2706 | { "ar", HAS_ARG | OPT_AUDIO, {(void*)opt_audio_rate}, "set audio sampling rate (in Hz)", "rate" }, | |
2707 | { "ac", HAS_ARG | OPT_AUDIO, {(void*)opt_audio_channels}, "set number of audio channels", "channels" }, | |
2708 | { "an", OPT_BOOL | OPT_AUDIO, {(void*)&audio_disable}, "disable audio" }, | |
2709 | { "acodec", HAS_ARG | OPT_AUDIO, {(void*)opt_audio_codec}, "force audio codec ('copy' to copy stream)", "codec" }, | |
2710 | ||
2711 | /* grab options */ | |
2712 | { "vd", HAS_ARG | OPT_EXPERT | OPT_VIDEO | OPT_GRAB, {(void*)opt_video_device}, "set video grab device", "device" }, | |
2713 | { "vc", HAS_ARG | OPT_EXPERT | OPT_VIDEO | OPT_GRAB, {(void*)opt_video_channel}, "set video grab channel (DV1394 only)", "channel" }, | |
2714 | { "tvstd", HAS_ARG | OPT_EXPERT | OPT_VIDEO | OPT_GRAB, {(void*)opt_video_standard}, "set television standard (NTSC, PAL (SECAM))", "standard" }, | |
2715 | { "dv1394", OPT_EXPERT | OPT_GRAB, {(void*)opt_dv1394}, "set DV1394 grab", "" }, | |
2716 | { "ad", HAS_ARG | OPT_EXPERT | OPT_AUDIO | OPT_GRAB, {(void*)opt_audio_device}, "set audio device", "device" }, | |
85f07f22 FB |
2717 | { NULL, }, |
2718 | }; | |
2719 | ||
02d504a7 FB |
2720 | static void show_banner(void) |
2721 | { | |
2722 | printf("ffmpeg version " FFMPEG_VERSION ", Copyright (c) 2000-2003 Fabrice Bellard\n"); | |
2723 | } | |
2724 | ||
2725 | static void show_license(void) | |
2726 | { | |
2727 | show_banner(); | |
2728 | printf( | |
2729 | "This library is free software; you can redistribute it and/or\n" | |
2730 | "modify it under the terms of the GNU Lesser General Public\n" | |
2731 | "License as published by the Free Software Foundation; either\n" | |
2732 | "version 2 of the License, or (at your option) any later version.\n" | |
2733 | "\n" | |
2734 | "This library is distributed in the hope that it will be useful,\n" | |
2735 | "but WITHOUT ANY WARRANTY; without even the implied warranty of\n" | |
2736 | "MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU\n" | |
2737 | "Lesser General Public License for more details.\n" | |
2738 | "\n" | |
2739 | "You should have received a copy of the GNU Lesser General Public\n" | |
2740 | "License along with this library; if not, write to the Free Software\n" | |
2741 | "Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA\n" | |
2742 | ); | |
2743 | exit(1); | |
2744 | } | |
2745 | ||
2746 | static void show_help(void) | |
01310af2 | 2747 | { |
02d504a7 | 2748 | show_banner(); |
01310af2 FB |
2749 | printf("usage: ffmpeg [[options] -i input_file]... {[options] outfile}...\n" |
2750 | "Hyper fast Audio and Video encoder\n"); | |
2751 | printf("\n"); | |
02d504a7 FB |
2752 | show_help_options(options, "Main options:\n", |
2753 | OPT_EXPERT | OPT_AUDIO | OPT_VIDEO, 0); | |
2754 | show_help_options(options, "\nVideo options:\n", | |
2755 | OPT_EXPERT | OPT_AUDIO | OPT_VIDEO | OPT_GRAB, | |
2756 | OPT_VIDEO); | |
2757 | show_help_options(options, "\nAdvanced Video options:\n", | |
2758 | OPT_EXPERT | OPT_AUDIO | OPT_VIDEO | OPT_GRAB, | |
2759 | OPT_VIDEO | OPT_EXPERT); | |
2760 | show_help_options(options, "\nAudio options:\n", | |
2761 | OPT_EXPERT | OPT_AUDIO | OPT_VIDEO | OPT_GRAB, | |
2762 | OPT_AUDIO); | |
2763 | show_help_options(options, "\nAdvanced Audio options:\n", | |
2764 | OPT_EXPERT | OPT_AUDIO | OPT_VIDEO | OPT_GRAB, | |
2765 | OPT_AUDIO | OPT_EXPERT); | |
2766 | show_help_options(options, "\nAudio/Video grab options:\n", | |
2767 | OPT_GRAB, | |
2768 | OPT_GRAB); | |
2769 | show_help_options(options, "\nAdvanced options:\n", | |
2770 | OPT_EXPERT | OPT_AUDIO | OPT_VIDEO | OPT_GRAB, | |
2771 | OPT_EXPERT); | |
01310af2 FB |
2772 | exit(1); |
2773 | } | |
2774 | ||
2775 | void parse_arg_file(const char *filename) | |
2776 | { | |
2777 | opt_output_file(filename); | |
2778 | } | |
2779 | ||
85f07f22 FB |
2780 | int main(int argc, char **argv) |
2781 | { | |
01310af2 | 2782 | int i; |
0c1a9eda | 2783 | int64_t ti; |
63b15e55 | 2784 | |
2c4ae653 | 2785 | av_register_all(); |
85f07f22 FB |
2786 | |
2787 | if (argc <= 1) | |
2788 | show_help(); | |
a38469e1 FB |
2789 | |
2790 | /* parse options */ | |
01310af2 | 2791 | parse_options(argc, argv, options); |
85f07f22 | 2792 | |
01310af2 FB |
2793 | /* file converter / grab */ |
2794 | if (nb_output_files <= 0) { | |
2795 | fprintf(stderr, "Must supply at least one output file\n"); | |
2796 | exit(1); | |
2797 | } | |
2798 | ||
2799 | if (nb_input_files == 0) { | |
2800 | prepare_grab(); | |
a38469e1 FB |
2801 | } |
2802 | ||
2803 | ti = getutime(); | |
2804 | av_encode(output_files, nb_output_files, input_files, nb_input_files, | |
2805 | stream_maps, nb_stream_maps); | |
2806 | ti = getutime() - ti; | |
2807 | if (do_benchmark) { | |
2808 | printf("bench: utime=%0.3fs\n", ti / 1000000.0); | |
85f07f22 FB |
2809 | } |
2810 | ||
2811 | /* close files */ | |
2812 | for(i=0;i<nb_output_files;i++) { | |
4fca59f2 ZK |
2813 | /* maybe av_close_output_file ??? */ |
2814 | AVFormatContext *s = output_files[i]; | |
2815 | int j; | |
2816 | if (!(s->oformat->flags & AVFMT_NOFILE)) | |
2817 | url_fclose(&s->pb); | |
2818 | for(j=0;j<s->nb_streams;j++) | |
2819 | av_free(s->streams[j]); | |
2820 | av_free(s); | |
85f07f22 | 2821 | } |
79fdaa4c FB |
2822 | for(i=0;i<nb_input_files;i++) |
2823 | av_close_input_file(input_files[i]); | |
85f07f22 | 2824 | |
855ea723 | 2825 | av_free_static(); |
db40a39a MN |
2826 | |
2827 | ||
e45a2872 | 2828 | #ifdef POWERPC_PERFORMANCE_REPORT |
35e5fb06 RD |
2829 | extern void powerpc_display_perf_report(void); |
2830 | powerpc_display_perf_report(); | |
e45a2872 | 2831 | #endif /* POWERPC_PERFORMANCE_REPORT */ |
db40a39a | 2832 | |
9680a722 RP |
2833 | #ifndef CONFIG_WIN32 |
2834 | if (received_sigterm) { | |
2835 | fprintf(stderr, | |
2836 | "Received signal %d: terminating.\n", | |
2837 | (int) received_sigterm); | |
2838 | exit (255); | |
2839 | } | |
2840 | #endif | |
2841 | exit(0); /* not all OS-es handle main() return value */ | |
85f07f22 FB |
2842 | return 0; |
2843 | } |