FFmpeg coverage


Directory: ../../../ffmpeg/
File: src/fftools/ffmpeg.c
Date: 2025-08-19 23:55:23
Exec Total Coverage
Lines: 326 468 69.7%
Functions: 19 25 76.0%
Branches: 195 312 62.5%

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