FFmpeg coverage


Directory: ../../../ffmpeg/
File: src/fftools/ffmpeg.c
Date: 2026-09-13 04:46:26
Exec Total Coverage
Lines: 348 485 71.8%
Functions: 20 25 80.0%
Branches: 210 324 64.8%

Line Branch Exec Source
1 /*
2 * Copyright (c) 2000-2003 Fabrice Bellard
3 *
4 * This file is part of FFmpeg.
5 *
6 * FFmpeg is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 2.1 of the License, or (at your option) any later version.
10 *
11 * FFmpeg is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
15 *
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with FFmpeg; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
19 */
20
21 /**
22 * @file
23 * multimedia converter based on the FFmpeg libraries
24 */
25
26 #include "config.h"
27
28 #include <errno.h>
29 #include <limits.h>
30 #include <stdatomic.h>
31 #include <stdint.h>
32 #include <stdlib.h>
33 #include <string.h>
34 #include <time.h>
35
36 #if HAVE_IO_H
37 #include <io.h>
38 #endif
39 #if HAVE_UNISTD_H
40 #include <unistd.h>
41 #endif
42
43 #if HAVE_SYS_RESOURCE_H
44 #include <sys/time.h>
45 #include <sys/types.h>
46 #include <sys/resource.h>
47 #elif HAVE_GETPROCESSTIMES
48 #include <windows.h>
49 #endif
50 #if HAVE_GETPROCESSMEMORYINFO
51 #include <windows.h>
52 #include <psapi.h>
53 #endif
54 #if HAVE_SETCONSOLECTRLHANDLER
55 #include <windows.h>
56 #endif
57
58 #if HAVE_SYS_SELECT_H
59 #include <sys/select.h>
60 #endif
61
62 #if HAVE_TERMIOS_H
63 #include <fcntl.h>
64 #include <sys/ioctl.h>
65 #include <sys/time.h>
66 #include <termios.h>
67 #elif HAVE_KBHIT
68 #include <conio.h>
69 #endif
70
71 #include "libavutil/bprint.h"
72 #include "libavutil/dict.h"
73 #include "libavutil/mem.h"
74 #include "libavutil/time.h"
75
76 #include "libavformat/avformat.h"
77
78 #include "libavdevice/avdevice.h"
79
80 #include "cmdutils.h"
81 #if CONFIG_MEDIACODEC
82 #include "compat/android/binder.h"
83 #endif
84 #include "ffmpeg.h"
85 #include "ffmpeg_sched.h"
86 #include "ffmpeg_utils.h"
87 #include "graph/graphprint.h"
88
89 const char program_name[] = "ffmpeg";
90 const int program_birth_year = 2000;
91
92 FILE *vstats_file;
93
94 typedef struct BenchmarkTimeStamps {
95 int64_t real_usec;
96 int64_t user_usec;
97 int64_t sys_usec;
98 } BenchmarkTimeStamps;
99
100 static BenchmarkTimeStamps get_benchmark_time_stamps(void);
101 static int64_t getmaxrss(void);
102
103 atomic_uint nb_output_dumped = 0;
104
105 static BenchmarkTimeStamps current_time;
106 AVIOContext *progress_avio = NULL;
107
108 InputFile **input_files = NULL;
109 int nb_input_files = 0;
110
111 OutputFile **output_files = NULL;
112 int nb_output_files = 0;
113
114 FilterGraph **filtergraphs;
115 int nb_filtergraphs;
116
117 Decoder **decoders;
118 int nb_decoders;
119
120 #if HAVE_TERMIOS_H
121
122 /* init terminal so that we can grab keys */
123 static struct termios oldtty;
124 static int restore_tty;
125 #endif
126
127 17636 static void term_exit_sigsafe(void)
128 {
129 #if HAVE_TERMIOS_H
130
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 17636 times.
17636 if(restore_tty)
131 tcsetattr (0, TCSANOW, &oldtty);
132 #endif
133 17636 }
134
135 17635 void term_exit(void)
136 {
137 17635 av_log(NULL, AV_LOG_QUIET, "%s", "");
138 17635 term_exit_sigsafe();
139 17635 }
140
141 static volatile int received_sigterm = 0;
142 static volatile int received_nb_signals = 0;
143 static atomic_int transcode_init_done = 0;
144 static volatile int ffmpeg_exited = 0;
145 static int64_t copy_ts_first_pts = AV_NOPTS_VALUE;
146
147 static void
148 1 sigterm_handler(int sig)
149 {
150 int ret;
151 1 received_sigterm = sig;
152 1 received_nb_signals++;
153 1 term_exit_sigsafe();
154
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
1 if(received_nb_signals > 3) {
155 ret = write(2/*STDERR_FILENO*/, "Received > 3 system signals, hard exiting\n",
156 strlen("Received > 3 system signals, hard exiting\n"));
157 if (ret < 0) { /* Do nothing */ };
158 exit(123);
159 }
160 1 }
161
162 #if HAVE_SETCONSOLECTRLHANDLER
163 static BOOL WINAPI CtrlHandler(DWORD fdwCtrlType)
164 {
165 av_log(NULL, AV_LOG_DEBUG, "\nReceived windows signal %ld\n", fdwCtrlType);
166
167 switch (fdwCtrlType)
168 {
169 case CTRL_C_EVENT:
170 case CTRL_BREAK_EVENT:
171 sigterm_handler(SIGINT);
172 return TRUE;
173
174 case CTRL_CLOSE_EVENT:
175 case CTRL_LOGOFF_EVENT:
176 case CTRL_SHUTDOWN_EVENT:
177 sigterm_handler(SIGTERM);
178 /* Basically, with these 3 events, when we return from this method the
179 process is hard terminated, so stall as long as we need to
180 to try and let the main thread(s) clean up and gracefully terminate
181 (we have at most 5 seconds, but should be done far before that). */
182 while (!ffmpeg_exited) {
183 Sleep(0);
184 }
185 return TRUE;
186
187 default:
188 av_log(NULL, AV_LOG_ERROR, "Received unknown windows signal %ld\n", fdwCtrlType);
189 return FALSE;
190 }
191 }
192 #endif
193
194 #ifdef __linux__
195 #define SIGNAL(sig, func) \
196 do { \
197 action.sa_handler = func; \
198 sigaction(sig, &action, NULL); \
199 } while (0)
200 #else
201 #define SIGNAL(sig, func) \
202 signal(sig, func)
203 #endif
204
205 8820 void term_init(void)
206 {
207 #if defined __linux__
208 8820 struct sigaction action = {0};
209 8820 action.sa_handler = sigterm_handler;
210
211 /* block other interrupts while processing this one */
212 8820 sigfillset(&action.sa_mask);
213
214 /* restart interruptible functions (i.e. don't fail with EINTR) */
215 8820 action.sa_flags = SA_RESTART;
216 #endif
217
218 #if HAVE_TERMIOS_H
219 /* A closed fd 0 is later reused by the first opened input file. read_key()
220 * would then read from that input instead of the terminal and corrupt the
221 * stream, so disable interaction when fd 0 is not an open descriptor.
222 */
223
1/4
✗ Branch 0 not taken.
✓ Branch 1 taken 8820 times.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
8820 if (stdin_interaction && fcntl(0, F_GETFD) == -1) {
224 av_log(NULL, AV_LOG_WARNING,
225 "fd 0 is not an open file descriptor, stdin interaction disabled\n");
226 stdin_interaction = 0;
227 }
228
229
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 8820 times.
8820 if (stdin_interaction) {
230 struct termios tty;
231 if (tcgetattr (0, &tty) == 0) {
232 oldtty = tty;
233 restore_tty = 1;
234
235 tty.c_iflag &= ~(IGNBRK|BRKINT|PARMRK|ISTRIP
236 |INLCR|IGNCR|ICRNL|IXON);
237 tty.c_oflag |= OPOST;
238 tty.c_lflag &= ~(ECHO|ECHONL|ICANON|IEXTEN);
239 tty.c_cflag &= ~(CSIZE|PARENB);
240 tty.c_cflag |= CS8;
241 tty.c_cc[VMIN] = 1;
242 tty.c_cc[VTIME] = 0;
243
244 tcsetattr (0, TCSANOW, &tty);
245 }
246 SIGNAL(SIGQUIT, sigterm_handler); /* Quit (POSIX). */
247 }
248 #endif
249
250 8820 SIGNAL(SIGINT , sigterm_handler); /* Interrupt (ANSI). */
251 8820 SIGNAL(SIGTERM, sigterm_handler); /* Termination (ANSI). */
252 #ifdef SIGXCPU
253 8820 SIGNAL(SIGXCPU, sigterm_handler);
254 #endif
255 #ifdef SIGPIPE
256 8820 signal(SIGPIPE, SIG_IGN); /* Broken pipe (POSIX). */
257 #endif
258 #if HAVE_SETCONSOLECTRLHANDLER
259 SetConsoleCtrlHandler((PHANDLER_ROUTINE) CtrlHandler, TRUE);
260 #endif
261 8820 }
262
263 /* read a key without blocking */
264 static int read_key(void)
265 {
266 #if HAVE_TERMIOS_H
267 int n = 1;
268 struct timeval tv;
269 fd_set rfds;
270
271 FD_ZERO(&rfds);
272 FD_SET(0, &rfds);
273 tv.tv_sec = 0;
274 tv.tv_usec = 0;
275 n = select(1, &rfds, NULL, NULL, &tv);
276 if (n > 0) {
277 unsigned char ch;
278 n = read(0, &ch, 1);
279 if (n == 1)
280 return ch;
281
282 return n;
283 }
284 #elif HAVE_KBHIT
285 # if HAVE_PEEKNAMEDPIPE && HAVE_GETSTDHANDLE
286 static int is_pipe;
287 static HANDLE input_handle;
288 DWORD dw, nchars;
289 if(!input_handle){
290 input_handle = GetStdHandle(STD_INPUT_HANDLE);
291 is_pipe = !GetConsoleMode(input_handle, &dw);
292 }
293
294 if (is_pipe) {
295 /* When running under a GUI, you will end here. */
296 if (!PeekNamedPipe(input_handle, NULL, 0, NULL, &nchars, NULL)) {
297 // input pipe may have been closed by the program that ran ffmpeg
298 return -1;
299 }
300 //Read it
301 if(nchars != 0) {
302 unsigned char ch;
303 if (read(0, &ch, 1) == 1)
304 return ch;
305 return 0;
306 }else{
307 return -1;
308 }
309 }
310 # endif
311 if(kbhit())
312 return(getch());
313 #endif
314 return -1;
315 }
316
317 816391 static int decode_interrupt_cb(void *ctx)
318 {
319 816391 return received_nb_signals > atomic_load(&transcode_init_done);
320 }
321
322 const AVIOInterruptCB int_cb = { decode_interrupt_cb, NULL };
323
324 8822 static void ffmpeg_cleanup(int ret)
325 {
326
2/6
✓ Branch 0 taken 8822 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 8822 times.
✗ Branch 4 not taken.
✗ Branch 5 not taken.
8822 if ((print_graphs || print_graphs_file) && nb_output_files > 0)
327 print_filtergraphs(filtergraphs, nb_filtergraphs, input_files, nb_input_files, output_files, nb_output_files);
328
329
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 8822 times.
8822 if (do_benchmark) {
330 int64_t maxrss = getmaxrss() / 1024;
331 av_log(NULL, AV_LOG_INFO, "bench: maxrss=%"PRId64"KiB\n", maxrss);
332 }
333
334
2/2
✓ Branch 0 taken 1272 times.
✓ Branch 1 taken 8822 times.
10094 for (int i = 0; i < nb_filtergraphs; i++)
335 1272 fg_free(&filtergraphs[i]);
336 8822 av_freep(&filtergraphs);
337
338
2/2
✓ Branch 0 taken 8822 times.
✓ Branch 1 taken 8822 times.
17644 for (int i = 0; i < nb_output_files; i++)
339 8822 of_free(&output_files[i]);
340
341
2/2
✓ Branch 0 taken 7724 times.
✓ Branch 1 taken 8822 times.
16546 for (int i = 0; i < nb_input_files; i++)
342 7724 ifile_close(&input_files[i]);
343
344
2/2
✓ Branch 0 taken 1 times.
✓ Branch 1 taken 8822 times.
8823 for (int i = 0; i < nb_decoders; i++)
345 1 dec_free(&decoders[i]);
346 8822 av_freep(&decoders);
347
348
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 8822 times.
8822 if (vstats_file) {
349 if (fclose(vstats_file))
350 av_log(NULL, AV_LOG_ERROR,
351 "Error closing vstats file, loss of information possible: %s\n",
352 av_err2str(AVERROR(errno)));
353 }
354 8822 av_freep(&vstats_filename);
355 8822 of_enc_stats_close();
356
357 8822 hw_device_free_all();
358
359 8822 av_freep(&filter_nbthreads);
360
361 8822 av_freep(&print_graphs_file);
362 8822 av_freep(&print_graphs_format);
363
364 8822 av_freep(&input_files);
365 8822 av_freep(&output_files);
366
367 8822 uninit_opts();
368
369 8822 avformat_network_deinit();
370
371
2/2
✓ Branch 0 taken 1 times.
✓ Branch 1 taken 8821 times.
8822 if (received_sigterm) {
372 1 av_log(NULL, AV_LOG_INFO, "Exiting normally, received signal %d.\n",
373 (int) received_sigterm);
374
4/4
✓ Branch 0 taken 9 times.
✓ Branch 1 taken 8812 times.
✓ Branch 2 taken 2 times.
✓ Branch 3 taken 7 times.
8821 } else if (ret && atomic_load(&transcode_init_done)) {
375 2 av_log(NULL, AV_LOG_INFO, "Conversion failed!\n");
376 }
377 8822 term_exit();
378 8822 ffmpeg_exited = 1;
379 8822 }
380
381 36350 OutputStream *ost_iter(OutputStream *prev)
382 {
383
2/2
✓ Branch 0 taken 18692 times.
✓ Branch 1 taken 17658 times.
36350 int of_idx = prev ? prev->file->index : 0;
384
2/2
✓ Branch 0 taken 18692 times.
✓ Branch 1 taken 17658 times.
36350 int ost_idx = prev ? prev->index + 1 : 0;
385
386
2/2
✓ Branch 0 taken 36358 times.
✓ Branch 1 taken 17658 times.
54016 for (; of_idx < nb_output_files; of_idx++) {
387 36358 OutputFile *of = output_files[of_idx];
388
2/2
✓ Branch 0 taken 18692 times.
✓ Branch 1 taken 17666 times.
36358 if (ost_idx < of->nb_streams)
389 18692 return of->streams[ost_idx];
390
391 17666 ost_idx = 0;
392 }
393
394 17658 return NULL;
395 }
396
397 17404 InputStream *ist_iter(InputStream *prev)
398 {
399
2/2
✓ Branch 0 taken 8401 times.
✓ Branch 1 taken 9003 times.
17404 int if_idx = prev ? prev->file->index : 0;
400
2/2
✓ Branch 0 taken 8401 times.
✓ Branch 1 taken 9003 times.
17404 int ist_idx = prev ? prev->index + 1 : 0;
401
402
2/2
✓ Branch 0 taken 16330 times.
✓ Branch 1 taken 8838 times.
25168 for (; if_idx < nb_input_files; if_idx++) {
403 16330 InputFile *f = input_files[if_idx];
404
2/2
✓ Branch 0 taken 8566 times.
✓ Branch 1 taken 7764 times.
16330 if (ist_idx < f->nb_streams)
405 8566 return f->streams[ist_idx];
406
407 7764 ist_idx = 0;
408 }
409
410 8838 return NULL;
411 }
412
413 1671385 static void frame_data_free(void *opaque, uint8_t *data)
414 {
415 1671385 FrameData *fd = (FrameData *)data;
416
417 1671385 av_frame_side_data_free(&fd->side_data, &fd->nb_side_data);
418 1671385 avcodec_parameters_free(&fd->par_enc);
419 1671385 av_dict_free(&fd->reinit_opts);
420
421 1671385 av_free(data);
422 1671385 }
423
424 3852520 static int frame_data_ensure(AVBufferRef **dst, int writable)
425 {
426 3852520 AVBufferRef *src = *dst;
427
428
6/6
✓ Branch 0 taken 3281792 times.
✓ Branch 1 taken 570728 times.
✓ Branch 2 taken 2741135 times.
✓ Branch 3 taken 540657 times.
✓ Branch 5 taken 1100657 times.
✓ Branch 6 taken 1640478 times.
3852520 if (!src || (writable && !av_buffer_is_writable(src))) {
429 FrameData *fd;
430
431 1671385 fd = av_mallocz(sizeof(*fd));
432
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 1671385 times.
1671385 if (!fd)
433 return AVERROR(ENOMEM);
434
435 1671385 *dst = av_buffer_create((uint8_t *)fd, sizeof(*fd),
436 frame_data_free, NULL, 0);
437
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 1671385 times.
1671385 if (!*dst) {
438 av_buffer_unref(&src);
439 av_freep(&fd);
440 return AVERROR(ENOMEM);
441 }
442
443
2/2
✓ Branch 0 taken 1100657 times.
✓ Branch 1 taken 570728 times.
1671385 if (src) {
444 1100657 const FrameData *fd_src = (const FrameData *)src->data;
445
446 1100657 memcpy(fd, fd_src, sizeof(*fd));
447 1100657 fd->par_enc = NULL;
448 1100657 fd->side_data = NULL;
449 1100657 fd->nb_side_data = 0;
450 1100657 fd->reinit_opts = NULL;
451
452
2/2
✓ Branch 0 taken 1 times.
✓ Branch 1 taken 1100656 times.
1100657 if (fd_src->par_enc) {
453 1 int ret = 0;
454
455 1 fd->par_enc = avcodec_parameters_alloc();
456 2 ret = fd->par_enc ?
457
1/2
✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
1 avcodec_parameters_copy(fd->par_enc, fd_src->par_enc) :
458 AVERROR(ENOMEM);
459
2/4
✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 1 times.
1 if (!ret && fd_src->reinit_opts)
460 ret = av_dict_copy(&fd->reinit_opts, fd_src->reinit_opts, 0);
461
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
1 if (ret < 0) {
462 av_buffer_unref(dst);
463 av_buffer_unref(&src);
464 return ret;
465 }
466 }
467
468
2/2
✓ Branch 0 taken 217 times.
✓ Branch 1 taken 1100440 times.
1100657 if (fd_src->nb_side_data) {
469 217 int ret = clone_side_data(&fd->side_data, &fd->nb_side_data,
470 217 fd_src->side_data, fd_src->nb_side_data, 0);
471
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 217 times.
217 if (ret < 0) {
472 av_buffer_unref(dst);
473 av_buffer_unref(&src);
474 return ret;
475 }
476 }
477
478 1100657 av_buffer_unref(&src);
479 } else {
480 570728 fd->dec.frame_num = UINT64_MAX;
481 570728 fd->dec.pts = AV_NOPTS_VALUE;
482
483
2/2
✓ Branch 0 taken 3995096 times.
✓ Branch 1 taken 570728 times.
4565824 for (unsigned i = 0; i < FF_ARRAY_ELEMS(fd->wallclock); i++)
484 3995096 fd->wallclock[i] = INT64_MIN;
485 }
486 }
487
488 3852520 return 0;
489 }
490
491 1841107 FrameData *frame_data(AVFrame *frame)
492 {
493 1841107 int ret = frame_data_ensure(&frame->opaque_ref, 1);
494
1/2
✓ Branch 0 taken 1841107 times.
✗ Branch 1 not taken.
1841107 return ret < 0 ? NULL : (FrameData*)frame->opaque_ref->data;
495 }
496
497 542995 const FrameData *frame_data_c(AVFrame *frame)
498 {
499 542995 int ret = frame_data_ensure(&frame->opaque_ref, 0);
500
1/2
✓ Branch 0 taken 542995 times.
✗ Branch 1 not taken.
542995 return ret < 0 ? NULL : (const FrameData*)frame->opaque_ref->data;
501 }
502
503 1468418 FrameData *packet_data(AVPacket *pkt)
504 {
505 1468418 int ret = frame_data_ensure(&pkt->opaque_ref, 1);
506
1/2
✓ Branch 0 taken 1468418 times.
✗ Branch 1 not taken.
1468418 return ret < 0 ? NULL : (FrameData*)pkt->opaque_ref->data;
507 }
508
509 const FrameData *packet_data_c(AVPacket *pkt)
510 {
511 int ret = frame_data_ensure(&pkt->opaque_ref, 0);
512 return ret < 0 ? NULL : (const FrameData*)pkt->opaque_ref->data;
513 }
514
515 16542 int check_avoptions_used(const AVDictionary *opts, const AVDictionary *opts_used,
516 void *logctx, int decode)
517 {
518 16542 const AVClass *class = avcodec_get_class();
519 16542 const AVClass *fclass = avformat_get_class();
520
521
2/2
✓ Branch 0 taken 7722 times.
✓ Branch 1 taken 8820 times.
16542 const int flag = decode ? AV_OPT_FLAG_DECODING_PARAM :
522 AV_OPT_FLAG_ENCODING_PARAM;
523 16542 const AVDictionaryEntry *e = NULL;
524
525
2/2
✓ Branch 1 taken 50614 times.
✓ Branch 2 taken 16542 times.
67156 while ((e = av_dict_iterate(opts, e))) {
526 const AVOption *option, *foption;
527 char *optname, *p;
528
529
2/2
✓ Branch 1 taken 49593 times.
✓ Branch 2 taken 1021 times.
50614 if (av_dict_get(opts_used, e->key, NULL, 0))
530 49595 continue;
531
532 1021 optname = av_strdup(e->key);
533
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 1021 times.
1021 if (!optname)
534 return AVERROR(ENOMEM);
535
536 1021 p = strchr(optname, ':');
537
2/2
✓ Branch 0 taken 12 times.
✓ Branch 1 taken 1009 times.
1021 if (p)
538 12 *p = 0;
539
540 1021 option = av_opt_find(&class, optname, NULL, 0,
541 AV_OPT_SEARCH_CHILDREN | AV_OPT_SEARCH_FAKE_OBJ);
542 1021 foption = av_opt_find(&fclass, optname, NULL, 0,
543 AV_OPT_SEARCH_CHILDREN | AV_OPT_SEARCH_FAKE_OBJ);
544 1021 av_freep(&optname);
545
3/4
✓ Branch 0 taken 1021 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 2 times.
✓ Branch 3 taken 1019 times.
1021 if (!option || foption)
546 2 continue;
547
548
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 1019 times.
1019 if (!(option->flags & flag)) {
549 av_log(logctx, AV_LOG_ERROR, "Codec AVOption %s (%s) is not a %s "
550 "option.\n", e->key, option->help ? option->help : "",
551 decode ? "decoding" : "encoding");
552 return AVERROR(EINVAL);
553 }
554
555 1019 av_log(logctx, AV_LOG_WARNING, "Codec AVOption %s (%s) has not been used "
556 "for any stream. The most likely reason is either wrong type "
557 "(e.g. a video option with no video streams) or that it is a "
558 "private option of some decoder which was not actually used "
559
2/2
✓ Branch 0 taken 1014 times.
✓ Branch 1 taken 5 times.
2038 "for any stream.\n", e->key, option->help ? option->help : "");
560 }
561
562 16542 return 0;
563 }
564
565 3297445 void update_benchmark(const char *fmt, ...)
566 {
567
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 3297445 times.
3297445 if (do_benchmark_all) {
568 BenchmarkTimeStamps t = get_benchmark_time_stamps();
569 va_list va;
570 char buf[1024];
571
572 if (fmt) {
573 va_start(va, fmt);
574 vsnprintf(buf, sizeof(buf), fmt, va);
575 va_end(va);
576 av_log(NULL, AV_LOG_INFO,
577 "bench: %8" PRIu64 " user %8" PRIu64 " sys %8" PRIu64 " real %s \n",
578 t.user_usec - current_time.user_usec,
579 t.sys_usec - current_time.sys_usec,
580 t.real_usec - current_time.real_usec, buf);
581 }
582 current_time = t;
583 }
584 3297445 }
585
586 27782 static void print_report(int is_last_report, int64_t timer_start, int64_t cur_time, int64_t pts)
587 {
588 AVBPrint buf, buf_script;
589 27782 int64_t total_size = of_filesize(output_files[0]);
590 int vid;
591 double bitrate;
592 double speed;
593 static int64_t last_time = -1;
594 static int first_report = 1;
595 27782 uint64_t nb_frames_dup = 0, nb_frames_drop = 0;
596 int mins, secs, ms, us;
597 int64_t hours;
598 const char *hours_sign;
599 int ret;
600 float t;
601
602
5/6
✓ Branch 0 taken 27657 times.
✓ Branch 1 taken 125 times.
✓ Branch 2 taken 18937 times.
✓ Branch 3 taken 8720 times.
✓ Branch 4 taken 18937 times.
✗ Branch 5 not taken.
27782 if (!print_stats && !is_last_report && !progress_avio)
603 18937 return;
604
605
2/2
✓ Branch 0 taken 32 times.
✓ Branch 1 taken 8813 times.
8845 if (!is_last_report) {
606
2/2
✓ Branch 0 taken 19 times.
✓ Branch 1 taken 13 times.
32 if (last_time == -1) {
607 19 last_time = cur_time;
608 }
609
3/4
✓ Branch 0 taken 19 times.
✓ Branch 1 taken 13 times.
✓ Branch 2 taken 19 times.
✗ Branch 3 not taken.
32 if (((cur_time - last_time) < stats_period && !first_report) ||
610
3/4
✓ Branch 0 taken 19 times.
✓ Branch 1 taken 13 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 19 times.
32 (first_report && atomic_load(&nb_output_dumped) < nb_output_files))
611 return;
612 32 last_time = cur_time;
613 }
614
615 8845 t = (cur_time-timer_start) / 1000000.0;
616
617 8845 vid = 0;
618 8845 av_bprint_init(&buf, 0, AV_BPRINT_SIZE_AUTOMATIC);
619 8845 av_bprint_init(&buf_script, 0, AV_BPRINT_SIZE_AUTOMATIC);
620
621
2/2
✓ Branch 2 taken 9366 times.
✓ Branch 3 taken 8845 times.
18211 for (OutputStream *ost = ost_iter(NULL); ost; ost = ost_iter(ost)) {
622
2/2
✓ Branch 0 taken 8460 times.
✓ Branch 1 taken 906 times.
9366 const float q = ost->enc ? atomic_load(&ost->quality) / (float) FF_QP2LAMBDA : -1;
623
624
4/4
✓ Branch 0 taken 290 times.
✓ Branch 1 taken 9076 times.
✓ Branch 2 taken 82 times.
✓ Branch 3 taken 208 times.
9366 if (vid && ost->type == AVMEDIA_TYPE_VIDEO) {
625 82 av_bprintf(&buf, "q=%2.1f ", q);
626 82 av_bprintf(&buf_script, "stream_%d_%d_q=%.1f\n",
627 82 ost->file->index, ost->index, q);
628 }
629
4/4
✓ Branch 0 taken 9076 times.
✓ Branch 1 taken 290 times.
✓ Branch 2 taken 7304 times.
✓ Branch 3 taken 1772 times.
9366 if (!vid && ost->type == AVMEDIA_TYPE_VIDEO) {
630 float fps;
631 7304 uint64_t frame_number = atomic_load(&ost->packets_written);
632
633
2/2
✓ Branch 0 taken 1995 times.
✓ Branch 1 taken 5309 times.
7304 fps = t > 1 ? frame_number / t : 0;
634 7304 av_bprintf(&buf, "frame=%5"PRId64" fps=%3.*f q=%3.1f ",
635 frame_number, fps < 9.95, fps, q);
636 7304 av_bprintf(&buf_script, "frame=%"PRId64"\n", frame_number);
637 7304 av_bprintf(&buf_script, "fps=%.2f\n", fps);
638 7304 av_bprintf(&buf_script, "stream_%d_%d_q=%.1f\n",
639 7304 ost->file->index, ost->index, q);
640
2/2
✓ Branch 0 taken 7302 times.
✓ Branch 1 taken 2 times.
7304 if (is_last_report)
641 7302 av_bprintf(&buf, "L");
642
643
2/2
✓ Branch 0 taken 6908 times.
✓ Branch 1 taken 396 times.
7304 if (ost->filter) {
644 6908 nb_frames_dup = atomic_load(&ost->filter->nb_frames_dup);
645 6908 nb_frames_drop = atomic_load(&ost->filter->nb_frames_drop);
646 }
647
648 7304 vid = 1;
649 }
650 }
651
652
2/2
✓ Branch 0 taken 22 times.
✓ Branch 1 taken 8823 times.
8845 if (copy_ts) {
653
2/4
✓ Branch 0 taken 22 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 22 times.
✗ Branch 3 not taken.
22 if (copy_ts_first_pts == AV_NOPTS_VALUE && pts > 1)
654 22 copy_ts_first_pts = pts;
655
1/2
✓ Branch 0 taken 22 times.
✗ Branch 1 not taken.
22 if (copy_ts_first_pts != AV_NOPTS_VALUE)
656 22 pts -= copy_ts_first_pts;
657 }
658
659
2/2
✓ Branch 0 taken 152 times.
✓ Branch 1 taken 8693 times.
8845 us = FFABS64U(pts) % AV_TIME_BASE;
660
2/2
✓ Branch 0 taken 152 times.
✓ Branch 1 taken 8693 times.
8845 secs = FFABS64U(pts) / AV_TIME_BASE % 60;
661
2/2
✓ Branch 0 taken 152 times.
✓ Branch 1 taken 8693 times.
8845 mins = FFABS64U(pts) / AV_TIME_BASE / 60 % 60;
662
2/2
✓ Branch 0 taken 152 times.
✓ Branch 1 taken 8693 times.
8845 hours = FFABS64U(pts) / AV_TIME_BASE / 3600;
663
2/2
✓ Branch 0 taken 126 times.
✓ Branch 1 taken 8719 times.
8845 hours_sign = (pts < 0) ? "-" : "";
664
665
6/6
✓ Branch 0 taken 8723 times.
✓ Branch 1 taken 122 times.
✓ Branch 2 taken 8697 times.
✓ Branch 3 taken 26 times.
✓ Branch 4 taken 8538 times.
✓ Branch 5 taken 159 times.
8845 bitrate = pts != AV_NOPTS_VALUE && pts && total_size >= 0 ? total_size * 8 / (pts / 1000.0) : -1;
666
3/4
✓ Branch 0 taken 8723 times.
✓ Branch 1 taken 122 times.
✓ Branch 2 taken 8723 times.
✗ Branch 3 not taken.
8845 speed = pts != AV_NOPTS_VALUE && t != 0.0 ? (double)pts / AV_TIME_BASE / t : -1;
667
668
2/2
✓ Branch 0 taken 160 times.
✓ Branch 1 taken 8685 times.
8845 if (total_size < 0) av_bprintf(&buf, "size=N/A time=");
669 8685 else av_bprintf(&buf, "size=%8.0fKiB time=", total_size / 1024.0);
670
2/2
✓ Branch 0 taken 122 times.
✓ Branch 1 taken 8723 times.
8845 if (pts == AV_NOPTS_VALUE) {
671 122 av_bprintf(&buf, "N/A ");
672 } else {
673 8723 av_bprintf(&buf, "%s%02"PRId64":%02d:%02d.%02d ",
674 hours_sign, hours, mins, secs, (100 * us) / AV_TIME_BASE);
675 }
676
677
2/2
✓ Branch 0 taken 311 times.
✓ Branch 1 taken 8534 times.
8845 if (bitrate < 0) {
678 311 av_bprintf(&buf, "bitrate=N/A");
679 311 av_bprintf(&buf_script, "bitrate=N/A\n");
680 }else{
681 8534 av_bprintf(&buf, "bitrate=%6.1fkbits/s", bitrate);
682 8534 av_bprintf(&buf_script, "bitrate=%6.1fkbits/s\n", bitrate);
683 }
684
685
2/2
✓ Branch 0 taken 160 times.
✓ Branch 1 taken 8685 times.
8845 if (total_size < 0) av_bprintf(&buf_script, "total_size=N/A\n");
686 8685 else av_bprintf(&buf_script, "total_size=%"PRId64"\n", total_size);
687
2/2
✓ Branch 0 taken 122 times.
✓ Branch 1 taken 8723 times.
8845 if (pts == AV_NOPTS_VALUE) {
688 122 av_bprintf(&buf_script, "out_time_us=N/A\n");
689 122 av_bprintf(&buf_script, "out_time_ms=N/A\n");
690 122 av_bprintf(&buf_script, "out_time=N/A\n");
691 } else {
692 8723 av_bprintf(&buf_script, "out_time_us=%"PRId64"\n", pts);
693 8723 av_bprintf(&buf_script, "out_time_ms=%"PRId64"\n", pts);
694 8723 av_bprintf(&buf_script, "out_time=%s%02"PRId64":%02d:%02d.%06d\n",
695 hours_sign, hours, mins, secs, us);
696 }
697
698
4/4
✓ Branch 0 taken 8829 times.
✓ Branch 1 taken 16 times.
✓ Branch 2 taken 6 times.
✓ Branch 3 taken 8823 times.
8845 if (nb_frames_dup || nb_frames_drop)
699 22 av_bprintf(&buf, " dup=%"PRId64" drop=%"PRId64, nb_frames_dup, nb_frames_drop);
700 8845 av_bprintf(&buf_script, "dup_frames=%"PRId64"\n", nb_frames_dup);
701 8845 av_bprintf(&buf_script, "drop_frames=%"PRId64"\n", nb_frames_drop);
702
703
2/2
✓ Branch 0 taken 126 times.
✓ Branch 1 taken 8719 times.
8845 if (speed < 0) {
704 126 av_bprintf(&buf, " speed=N/A");
705 126 av_bprintf(&buf_script, "speed=N/A\n");
706 } else {
707 8719 av_bprintf(&buf, " speed=%4.3gx", speed);
708 8719 av_bprintf(&buf_script, "speed=%4.3gx\n", speed);
709 }
710
711 8845 secs = (int)t;
712 8845 ms = (int)((t - secs) * 1000);
713 8845 mins = secs / 60;
714 8845 secs %= 60;
715 8845 hours = mins / 60;
716 8845 mins %= 60;
717
718 8845 av_bprintf(&buf, " elapsed=%"PRId64":%02d:%02d.%02d", hours, mins, secs, ms / 10);
719
720
3/4
✓ Branch 0 taken 8720 times.
✓ Branch 1 taken 125 times.
✓ Branch 2 taken 8720 times.
✗ Branch 3 not taken.
8845 if (print_stats || is_last_report) {
721
2/2
✓ Branch 0 taken 8813 times.
✓ Branch 1 taken 32 times.
8845 const char end = is_last_report ? '\n' : '\r';
722
1/4
✗ Branch 0 not taken.
✓ Branch 1 taken 8845 times.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
8845 if (print_stats==1 && AV_LOG_INFO > av_log_get_level()) {
723 fprintf(stderr, "%s %c", buf.str, end);
724 } else
725 8845 av_log(NULL, AV_LOG_INFO, "%s %c", buf.str, end);
726
727 8845 fflush(stderr);
728 }
729 8845 av_bprint_finalize(&buf, NULL);
730
731
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 8845 times.
8845 if (progress_avio) {
732 av_bprintf(&buf_script, "progress=%s\n",
733 is_last_report ? "end" : "continue");
734 avio_write(progress_avio, buf_script.str,
735 FFMIN(buf_script.len, buf_script.size - 1));
736 avio_flush(progress_avio);
737 av_bprint_finalize(&buf_script, NULL);
738 if (is_last_report) {
739 if ((ret = avio_closep(&progress_avio)) < 0)
740 av_log(NULL, AV_LOG_ERROR,
741 "Error closing progress log, loss of information possible: %s\n", av_err2str(ret));
742 }
743 }
744
745 8845 first_report = 0;
746 }
747
748 8813 static void print_stream_maps(void)
749 {
750 8813 av_log(NULL, AV_LOG_INFO, "Stream mapping:\n");
751
2/2
✓ Branch 2 taken 8340 times.
✓ Branch 3 taken 8813 times.
17153 for (InputStream *ist = ist_iter(NULL); ist; ist = ist_iter(ist)) {
752
2/2
✓ Branch 0 taken 7148 times.
✓ Branch 1 taken 8340 times.
15488 for (int j = 0; j < ist->nb_filters; j++) {
753
2/2
✓ Branch 1 taken 176 times.
✓ Branch 2 taken 6972 times.
7148 if (!filtergraph_is_simple(ist->filters[j]->graph)) {
754 av_log(NULL, AV_LOG_INFO, " Stream #%d:%d (%s) -> %s",
755 176 ist->file->index, ist->index, ist->dec ? ist->dec->name : "?",
756
1/2
✓ Branch 0 taken 176 times.
✗ Branch 1 not taken.
176 ist->filters[j]->name);
757
2/2
✓ Branch 0 taken 4 times.
✓ Branch 1 taken 172 times.
176 if (nb_filtergraphs > 1)
758 4 av_log(NULL, AV_LOG_INFO, " (graph %d)", ist->filters[j]->graph->index);
759 176 av_log(NULL, AV_LOG_INFO, "\n");
760 }
761 }
762 }
763
764
2/2
✓ Branch 2 taken 9326 times.
✓ Branch 3 taken 8813 times.
18139 for (OutputStream *ost = ost_iter(NULL); ost; ost = ost_iter(ost)) {
765
2/2
✓ Branch 0 taken 1 times.
✓ Branch 1 taken 9325 times.
9326 if (ost->attachment_filename) {
766 /* an attached file */
767 1 av_log(NULL, AV_LOG_INFO, " File %s -> Stream #%d:%d\n",
768 1 ost->attachment_filename, ost->file->index, ost->index);
769 1 continue;
770 }
771
772
4/4
✓ Branch 0 taken 8378 times.
✓ Branch 1 taken 947 times.
✓ Branch 3 taken 1406 times.
✓ Branch 4 taken 6972 times.
9325 if (ost->filter && !filtergraph_is_simple(ost->filter->graph)) {
773 /* output from a complex graph */
774 1406 av_log(NULL, AV_LOG_INFO, " %s", ost->filter->name);
775
2/2
✓ Branch 0 taken 1 times.
✓ Branch 1 taken 1405 times.
1406 if (nb_filtergraphs > 1)
776 1 av_log(NULL, AV_LOG_INFO, " (graph %d)", ost->filter->graph->index);
777
778 1406 av_log(NULL, AV_LOG_INFO, " -> Stream #%d:%d (%s)\n", ost->file->index,
779 1406 ost->index, ost->enc->enc_ctx->codec->name);
780 1406 continue;
781 }
782
783 7919 av_log(NULL, AV_LOG_INFO, " Stream #%d:%d -> #%d:%d",
784 7919 ost->ist->file->index,
785 7919 ost->ist->index,
786 7919 ost->file->index,
787 ost->index);
788
2/2
✓ Branch 0 taken 7014 times.
✓ Branch 1 taken 905 times.
7919 if (ost->enc) {
789 7014 const AVCodec *in_codec = ost->ist->dec;
790 7014 const AVCodec *out_codec = ost->enc->enc_ctx->codec;
791 7014 const char *decoder_name = "?";
792 7014 const char *in_codec_name = "?";
793 7014 const char *encoder_name = "?";
794 7014 const char *out_codec_name = "?";
795 const AVCodecDescriptor *desc;
796
797
1/2
✓ Branch 0 taken 7014 times.
✗ Branch 1 not taken.
7014 if (in_codec) {
798 7014 decoder_name = in_codec->name;
799 7014 desc = avcodec_descriptor_get(in_codec->id);
800
1/2
✓ Branch 0 taken 7014 times.
✗ Branch 1 not taken.
7014 if (desc)
801 7014 in_codec_name = desc->name;
802
2/2
✓ Branch 0 taken 6829 times.
✓ Branch 1 taken 185 times.
7014 if (!strcmp(decoder_name, in_codec_name))
803 6829 decoder_name = "native";
804 }
805
806
1/2
✓ Branch 0 taken 7014 times.
✗ Branch 1 not taken.
7014 if (out_codec) {
807 7014 encoder_name = out_codec->name;
808 7014 desc = avcodec_descriptor_get(out_codec->id);
809
1/2
✓ Branch 0 taken 7014 times.
✗ Branch 1 not taken.
7014 if (desc)
810 7014 out_codec_name = desc->name;
811
2/2
✓ Branch 0 taken 6896 times.
✓ Branch 1 taken 118 times.
7014 if (!strcmp(encoder_name, out_codec_name))
812 6896 encoder_name = "native";
813 }
814
815 7014 av_log(NULL, AV_LOG_INFO, " (%s (%s) -> %s (%s))",
816 in_codec_name, decoder_name,
817 out_codec_name, encoder_name);
818 } else
819 905 av_log(NULL, AV_LOG_INFO, " (copy)");
820 7919 av_log(NULL, AV_LOG_INFO, "\n");
821 }
822 8813 }
823
824 static void set_tty_echo(int on)
825 {
826 #if HAVE_TERMIOS_H
827 struct termios tty;
828 if (tcgetattr(0, &tty) == 0) {
829 if (on) tty.c_lflag |= ECHO;
830 else tty.c_lflag &= ~ECHO;
831 tcsetattr(0, TCSANOW, &tty);
832 }
833 #endif
834 }
835
836 static int check_keyboard_interaction(int64_t cur_time)
837 {
838 int i, key;
839 static int64_t last_time;
840 /* read_key() returns 0 on EOF */
841 if (cur_time - last_time >= 100000) {
842 key = read_key();
843 last_time = cur_time;
844 }else
845 key = -1;
846 if (key == 'q') {
847 av_log(NULL, AV_LOG_INFO, "\n\n[q] command received. Exiting.\n\n");
848 return AVERROR_EXIT;
849 }
850 if (key == '+') av_log_set_level(av_log_get_level()+10);
851 if (key == '-') av_log_set_level(av_log_get_level()-10);
852 if (key == 'c' || key == 'C'){
853 char buf[4096], target[64], command[256], arg[256] = {0};
854 double time;
855 int k, n = 0;
856 fprintf(stderr, "\nEnter command: <target>|all <time>|-1 <command>[ <argument>]\n");
857 i = 0;
858 set_tty_echo(1);
859 while ((k = read_key()) != '\n' && k != '\r' && i < sizeof(buf)-1)
860 if (k > 0)
861 buf[i++] = k;
862 buf[i] = 0;
863 set_tty_echo(0);
864 fprintf(stderr, "\n");
865 if (k > 0 &&
866 (n = sscanf(buf, "%63[^ ] %lf %255[^ ] %255[^\n]", target, &time, command, arg)) >= 3) {
867 av_log(NULL, AV_LOG_DEBUG, "Processing command target:%s time:%f command:%s arg:%s",
868 target, time, command, arg);
869 for (OutputStream *ost = ost_iter(NULL); ost; ost = ost_iter(ost)) {
870 if (ost->fg_simple)
871 fg_send_command(ost->fg_simple, time, target, command, arg,
872 key == 'C');
873 }
874 for (i = 0; i < nb_filtergraphs; i++)
875 fg_send_command(filtergraphs[i], time, target, command, arg,
876 key == 'C');
877 } else {
878 av_log(NULL, AV_LOG_ERROR,
879 "Parse error, at least 3 arguments were expected, "
880 "only %d given in string '%s'\n", n, buf);
881 }
882 }
883 if (key == '?'){
884 fprintf(stderr, "key function\n"
885 "? show this help\n"
886 "+ increase verbosity\n"
887 "- decrease verbosity\n"
888 "c Send command to first matching filter supporting it\n"
889 "C Send/Queue command to all matching filters\n"
890 "h dump packets/hex press to cycle through the 3 states\n"
891 "q quit\n"
892 "s Show QP histogram\n"
893 );
894 }
895 return 0;
896 }
897
898 /*
899 * The following code is the main loop of the file converter
900 */
901 8813 static int transcode(Scheduler *sch)
902 {
903 8813 int ret = 0;
904 8813 int64_t timer_start, transcode_ts = 0;
905
906 8813 print_stream_maps();
907
908 8813 atomic_store(&transcode_init_done, 1);
909
910 8813 ret = sch_start(sch);
911
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 8813 times.
8813 if (ret < 0)
912 return ret;
913
914
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 8813 times.
8813 if (stdin_interaction) {
915 av_log(NULL, AV_LOG_INFO, "Press [q] to stop, [?] for help\n");
916 }
917
918 8813 timer_start = av_gettime_relative();
919
920
2/2
✓ Branch 1 taken 18970 times.
✓ Branch 2 taken 8812 times.
27782 while (!sch_wait(sch, stats_period, &transcode_ts)) {
921 18970 int64_t cur_time= av_gettime_relative();
922
923
2/2
✓ Branch 0 taken 1 times.
✓ Branch 1 taken 18969 times.
18970 if (received_nb_signals)
924 1 break;
925
926 /* if 'q' pressed, exits */
927
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 18969 times.
18969 if (stdin_interaction)
928 if (check_keyboard_interaction(cur_time) < 0)
929 break;
930
931 /* dump report by using the output first video and audio streams */
932 18969 print_report(0, timer_start, cur_time, transcode_ts);
933 }
934
935 8813 ret = sch_stop(sch, &transcode_ts);
936
937 /* write the trailer if needed */
938
2/2
✓ Branch 0 taken 8817 times.
✓ Branch 1 taken 8813 times.
17630 for (int i = 0; i < nb_output_files; i++) {
939 8817 int err = of_write_trailer(output_files[i]);
940 8817 ret = err_merge(ret, err);
941 }
942
943 8813 term_exit();
944
945 /* dump report by using the first video and audio streams */
946 8813 print_report(1, timer_start, av_gettime_relative(), transcode_ts);
947
948 8813 return ret;
949 }
950
951 8813 static BenchmarkTimeStamps get_benchmark_time_stamps(void)
952 {
953 8813 BenchmarkTimeStamps time_stamps = { av_gettime_relative() };
954 #if HAVE_GETRUSAGE
955 struct rusage rusage;
956
957 8813 getrusage(RUSAGE_SELF, &rusage);
958 8813 time_stamps.user_usec =
959 8813 (rusage.ru_utime.tv_sec * 1000000LL) + rusage.ru_utime.tv_usec;
960 8813 time_stamps.sys_usec =
961 8813 (rusage.ru_stime.tv_sec * 1000000LL) + rusage.ru_stime.tv_usec;
962 #elif HAVE_GETPROCESSTIMES
963 HANDLE proc;
964 FILETIME c, e, k, u;
965 proc = GetCurrentProcess();
966 GetProcessTimes(proc, &c, &e, &k, &u);
967 time_stamps.user_usec =
968 ((int64_t)u.dwHighDateTime << 32 | u.dwLowDateTime) / 10;
969 time_stamps.sys_usec =
970 ((int64_t)k.dwHighDateTime << 32 | k.dwLowDateTime) / 10;
971 #else
972 time_stamps.user_usec = time_stamps.sys_usec = 0;
973 #endif
974 8813 return time_stamps;
975 }
976
977 static int64_t getmaxrss(void)
978 {
979 #if HAVE_GETRUSAGE && HAVE_STRUCT_RUSAGE_RU_MAXRSS
980 struct rusage rusage;
981 getrusage(RUSAGE_SELF, &rusage);
982 return (int64_t)rusage.ru_maxrss * 1024;
983 #elif HAVE_GETPROCESSMEMORYINFO
984 HANDLE proc;
985 PROCESS_MEMORY_COUNTERS memcounters;
986 proc = GetCurrentProcess();
987 memcounters.cb = sizeof(memcounters);
988 GetProcessMemoryInfo(proc, &memcounters, sizeof(memcounters));
989 return memcounters.PeakPagefileUsage;
990 #else
991 return 0;
992 #endif
993 }
994
995 8822 int main(int argc, char **argv)
996 {
997 8822 Scheduler *sch = NULL;
998
999 int ret;
1000 BenchmarkTimeStamps ti;
1001
1002 8822 init_dynload();
1003
1004 8822 setvbuf(stderr,NULL,_IONBF,0); /* win32 runtime needs this */
1005
1006 8822 av_log_set_flags(AV_LOG_SKIP_REPEATED);
1007 8822 parse_loglevel(argc, argv, options);
1008
1009 #if CONFIG_AVDEVICE
1010 8822 avdevice_register_all();
1011 #endif
1012 8822 avformat_network_init();
1013
1014 8822 show_banner(argc, argv, options);
1015
1016 8822 sch = sch_alloc();
1017
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 8822 times.
8822 if (!sch) {
1018 ret = AVERROR(ENOMEM);
1019 goto finish;
1020 }
1021
1022 /* parse options and open all input/output files */
1023 8822 ret = ffmpeg_parse_options(argc, argv, sch);
1024
2/2
✓ Branch 0 taken 9 times.
✓ Branch 1 taken 8813 times.
8822 if (ret < 0)
1025 9 goto finish;
1026
1027
1/4
✗ Branch 0 not taken.
✓ Branch 1 taken 8813 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
8813 if (nb_output_files <= 0 && nb_input_files == 0) {
1028 show_usage();
1029 av_log(NULL, AV_LOG_WARNING, "Use -h to get full help or, even better, run 'man %s'\n", program_name);
1030 ret = 1;
1031 goto finish;
1032 }
1033
1034
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 8813 times.
8813 if (nb_output_files <= 0) {
1035 av_log(NULL, AV_LOG_FATAL, "At least one output file must be specified\n");
1036 ret = 1;
1037 goto finish;
1038 }
1039
1040 #if CONFIG_MEDIACODEC
1041 android_binder_threadpool_init_if_required();
1042 #endif
1043
1044 8813 current_time = ti = get_benchmark_time_stamps();
1045 8813 ret = transcode(sch);
1046
3/4
✓ Branch 0 taken 8811 times.
✓ Branch 1 taken 2 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 8811 times.
8813 if (ret >= 0 && do_benchmark) {
1047 int64_t utime, stime, rtime;
1048 current_time = get_benchmark_time_stamps();
1049 utime = current_time.user_usec - ti.user_usec;
1050 stime = current_time.sys_usec - ti.sys_usec;
1051 rtime = current_time.real_usec - ti.real_usec;
1052 av_log(NULL, AV_LOG_INFO,
1053 "bench: utime=%0.3fs stime=%0.3fs rtime=%0.3fs\n",
1054 utime / 1000000.0, stime / 1000000.0, rtime / 1000000.0);
1055 }
1056
1057
2/2
✓ Branch 0 taken 8812 times.
✓ Branch 1 taken 1 times.
17625 ret = received_nb_signals ? 255 :
1058
2/2
✓ Branch 0 taken 8811 times.
✓ Branch 1 taken 1 times.
8812 (ret == FFMPEG_ERROR_RATE_EXCEEDED) ? 69 : ret;
1059
1060 8822 finish:
1061
2/2
✓ Branch 0 taken 2 times.
✓ Branch 1 taken 8820 times.
8822 if (ret == AVERROR_EXIT)
1062 2 ret = 0;
1063
1064 8822 ffmpeg_cleanup(ret);
1065
1066 8822 sch_free(&sch);
1067
1068 8822 av_log(NULL, AV_LOG_VERBOSE, "\n");
1069 8822 av_log(NULL, AV_LOG_VERBOSE, "Exiting with exit code %d\n", ret);
1070
1071 8822 return ret;
1072 }
1073