FFmpeg
ffmpeg.c
Go to the documentation of this file.
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 
93 
94 typedef struct BenchmarkTimeStamps {
99 
101 static int64_t getmaxrss(void);
102 
104 
107 
110 
113 
116 
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 static void term_exit_sigsafe(void)
128 {
129 #if HAVE_TERMIOS_H
130  if(restore_tty)
131  tcsetattr (0, TCSANOW, &oldtty);
132 #endif
133 }
134 
135 void term_exit(void)
136 {
137  av_log(NULL, AV_LOG_QUIET, "%s", "");
139 }
140 
141 static volatile int received_sigterm = 0;
142 static volatile int received_nb_signals = 0;
144 static volatile int ffmpeg_exited = 0;
146 
147 static void
149 {
150  int ret;
154  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 }
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 void term_init(void)
206 {
207 #if defined __linux__
208  struct sigaction action = {0};
209  action.sa_handler = sigterm_handler;
210 
211  /* block other interrupts while processing this one */
212  sigfillset(&action.sa_mask);
213 
214  /* restart interruptible functions (i.e. don't fail with EINTR) */
215  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  if (stdin_interaction && fcntl(0, F_GETFD) == -1) {
225  "fd 0 is not an open file descriptor, stdin interaction disabled\n");
226  stdin_interaction = 0;
227  }
228 
229  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  SIGNAL(SIGINT , sigterm_handler); /* Interrupt (ANSI). */
251  SIGNAL(SIGTERM, sigterm_handler); /* Termination (ANSI). */
252 #ifdef SIGXCPU
253  SIGNAL(SIGXCPU, sigterm_handler);
254 #endif
255 #ifdef SIGPIPE
256  signal(SIGPIPE, SIG_IGN); /* Broken pipe (POSIX). */
257 #endif
258 #if HAVE_SETCONSOLECTRLHANDLER
259  SetConsoleCtrlHandler((PHANDLER_ROUTINE) CtrlHandler, TRUE);
260 #endif
261 }
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 static int decode_interrupt_cb(void *ctx)
318 {
320 }
321 
323 
324 static void ffmpeg_cleanup(int ret)
325 {
328 
329  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  for (int i = 0; i < nb_filtergraphs; i++)
337 
338  for (int i = 0; i < nb_output_files; i++)
340 
341  for (int i = 0; i < nb_input_files; i++)
343 
344  for (int i = 0; i < nb_decoders; i++)
345  dec_free(&decoders[i]);
346  av_freep(&decoders);
347 
348  if (vstats_file) {
349  if (fclose(vstats_file))
351  "Error closing vstats file, loss of information possible: %s\n",
352  av_err2str(AVERROR(errno)));
353  }
356 
358 
360 
363 
366 
367  uninit_opts();
368 
370 
371  if (received_sigterm) {
372  av_log(NULL, AV_LOG_INFO, "Exiting normally, received signal %d.\n",
373  (int) received_sigterm);
374  } else if (ret && atomic_load(&transcode_init_done)) {
375  av_log(NULL, AV_LOG_INFO, "Conversion failed!\n");
376  }
377  term_exit();
378  ffmpeg_exited = 1;
379 }
380 
382 {
383  int of_idx = prev ? prev->file->index : 0;
384  int ost_idx = prev ? prev->index + 1 : 0;
385 
386  for (; of_idx < nb_output_files; of_idx++) {
387  OutputFile *of = output_files[of_idx];
388  if (ost_idx < of->nb_streams)
389  return of->streams[ost_idx];
390 
391  ost_idx = 0;
392  }
393 
394  return NULL;
395 }
396 
398 {
399  int if_idx = prev ? prev->file->index : 0;
400  int ist_idx = prev ? prev->index + 1 : 0;
401 
402  for (; if_idx < nb_input_files; if_idx++) {
403  InputFile *f = input_files[if_idx];
404  if (ist_idx < f->nb_streams)
405  return f->streams[ist_idx];
406 
407  ist_idx = 0;
408  }
409 
410  return NULL;
411 }
412 
413 static void frame_data_free(void *opaque, uint8_t *data)
414 {
415  FrameData *fd = (FrameData *)data;
416 
419 
420  av_free(data);
421 }
422 
423 static int frame_data_ensure(AVBufferRef **dst, int writable)
424 {
425  AVBufferRef *src = *dst;
426 
427  if (!src || (writable && !av_buffer_is_writable(src))) {
428  FrameData *fd;
429 
430  fd = av_mallocz(sizeof(*fd));
431  if (!fd)
432  return AVERROR(ENOMEM);
433 
434  *dst = av_buffer_create((uint8_t *)fd, sizeof(*fd),
435  frame_data_free, NULL, 0);
436  if (!*dst) {
438  av_freep(&fd);
439  return AVERROR(ENOMEM);
440  }
441 
442  if (src) {
443  const FrameData *fd_src = (const FrameData *)src->data;
444 
445  memcpy(fd, fd_src, sizeof(*fd));
446  fd->par_enc = NULL;
447  fd->side_data = NULL;
448  fd->nb_side_data = 0;
449 
450  if (fd_src->par_enc) {
451  int ret = 0;
452 
453  fd->par_enc = avcodec_parameters_alloc();
454  ret = fd->par_enc ?
455  avcodec_parameters_copy(fd->par_enc, fd_src->par_enc) :
456  AVERROR(ENOMEM);
457  if (ret < 0) {
460  return ret;
461  }
462  }
463 
464  if (fd_src->nb_side_data) {
465  int ret = clone_side_data(&fd->side_data, &fd->nb_side_data,
466  fd_src->side_data, fd_src->nb_side_data, 0);
467  if (ret < 0) {
470  return ret;
471  }
472  }
473 
475  } else {
476  fd->dec.frame_num = UINT64_MAX;
477  fd->dec.pts = AV_NOPTS_VALUE;
478 
479  for (unsigned i = 0; i < FF_ARRAY_ELEMS(fd->wallclock); i++)
480  fd->wallclock[i] = INT64_MIN;
481  }
482  }
483 
484  return 0;
485 }
486 
488 {
489  int ret = frame_data_ensure(&frame->opaque_ref, 1);
490  return ret < 0 ? NULL : (FrameData*)frame->opaque_ref->data;
491 }
492 
494 {
495  int ret = frame_data_ensure(&frame->opaque_ref, 0);
496  return ret < 0 ? NULL : (const FrameData*)frame->opaque_ref->data;
497 }
498 
500 {
501  int ret = frame_data_ensure(&pkt->opaque_ref, 1);
502  return ret < 0 ? NULL : (FrameData*)pkt->opaque_ref->data;
503 }
504 
506 {
507  int ret = frame_data_ensure(&pkt->opaque_ref, 0);
508  return ret < 0 ? NULL : (const FrameData*)pkt->opaque_ref->data;
509 }
510 
511 int check_avoptions_used(const AVDictionary *opts, const AVDictionary *opts_used,
512  void *logctx, int decode)
513 {
514  const AVClass *class = avcodec_get_class();
515  const AVClass *fclass = avformat_get_class();
516 
517  const int flag = decode ? AV_OPT_FLAG_DECODING_PARAM :
519  const AVDictionaryEntry *e = NULL;
520 
521  while ((e = av_dict_iterate(opts, e))) {
522  const AVOption *option, *foption;
523  char *optname, *p;
524 
525  if (av_dict_get(opts_used, e->key, NULL, 0))
526  continue;
527 
528  optname = av_strdup(e->key);
529  if (!optname)
530  return AVERROR(ENOMEM);
531 
532  p = strchr(optname, ':');
533  if (p)
534  *p = 0;
535 
536  option = av_opt_find(&class, optname, NULL, 0,
538  foption = av_opt_find(&fclass, optname, NULL, 0,
540  av_freep(&optname);
541  if (!option || foption)
542  continue;
543 
544  if (!(option->flags & flag)) {
545  av_log(logctx, AV_LOG_ERROR, "Codec AVOption %s (%s) is not a %s "
546  "option.\n", e->key, option->help ? option->help : "",
547  decode ? "decoding" : "encoding");
548  return AVERROR(EINVAL);
549  }
550 
551  av_log(logctx, AV_LOG_WARNING, "Codec AVOption %s (%s) has not been used "
552  "for any stream. The most likely reason is either wrong type "
553  "(e.g. a video option with no video streams) or that it is a "
554  "private option of some decoder which was not actually used "
555  "for any stream.\n", e->key, option->help ? option->help : "");
556  }
557 
558  return 0;
559 }
560 
561 void update_benchmark(const char *fmt, ...)
562 {
563  if (do_benchmark_all) {
565  va_list va;
566  char buf[1024];
567 
568  if (fmt) {
569  va_start(va, fmt);
570  vsnprintf(buf, sizeof(buf), fmt, va);
571  va_end(va);
573  "bench: %8" PRIu64 " user %8" PRIu64 " sys %8" PRIu64 " real %s \n",
576  t.real_usec - current_time.real_usec, buf);
577  }
578  current_time = t;
579  }
580 }
581 
582 static void print_report(int is_last_report, int64_t timer_start, int64_t cur_time, int64_t pts)
583 {
584  AVBPrint buf, buf_script;
585  int64_t total_size = of_filesize(output_files[0]);
586  int vid;
587  double bitrate;
588  double speed;
589  static int64_t last_time = -1;
590  static int first_report = 1;
591  uint64_t nb_frames_dup = 0, nb_frames_drop = 0;
592  int mins, secs, ms, us;
593  int64_t hours;
594  const char *hours_sign;
595  int ret;
596  float t;
597 
598  if (!print_stats && !is_last_report && !progress_avio)
599  return;
600 
601  if (!is_last_report) {
602  if (last_time == -1) {
603  last_time = cur_time;
604  }
605  if (((cur_time - last_time) < stats_period && !first_report) ||
606  (first_report && atomic_load(&nb_output_dumped) < nb_output_files))
607  return;
608  last_time = cur_time;
609  }
610 
611  t = (cur_time-timer_start) / 1000000.0;
612 
613  vid = 0;
615  av_bprint_init(&buf_script, 0, AV_BPRINT_SIZE_AUTOMATIC);
616 
617  for (OutputStream *ost = ost_iter(NULL); ost; ost = ost_iter(ost)) {
618  const float q = ost->enc ? atomic_load(&ost->quality) / (float) FF_QP2LAMBDA : -1;
619 
620  if (vid && ost->type == AVMEDIA_TYPE_VIDEO) {
621  av_bprintf(&buf, "q=%2.1f ", q);
622  av_bprintf(&buf_script, "stream_%d_%d_q=%.1f\n",
623  ost->file->index, ost->index, q);
624  }
625  if (!vid && ost->type == AVMEDIA_TYPE_VIDEO) {
626  float fps;
627  uint64_t frame_number = atomic_load(&ost->packets_written);
628 
629  fps = t > 1 ? frame_number / t : 0;
630  av_bprintf(&buf, "frame=%5"PRId64" fps=%3.*f q=%3.1f ",
631  frame_number, fps < 9.95, fps, q);
632  av_bprintf(&buf_script, "frame=%"PRId64"\n", frame_number);
633  av_bprintf(&buf_script, "fps=%.2f\n", fps);
634  av_bprintf(&buf_script, "stream_%d_%d_q=%.1f\n",
635  ost->file->index, ost->index, q);
636  if (is_last_report)
637  av_bprintf(&buf, "L");
638 
639  if (ost->filter) {
640  nb_frames_dup = atomic_load(&ost->filter->nb_frames_dup);
641  nb_frames_drop = atomic_load(&ost->filter->nb_frames_drop);
642  }
643 
644  vid = 1;
645  }
646  }
647 
648  if (copy_ts) {
649  if (copy_ts_first_pts == AV_NOPTS_VALUE && pts > 1)
653  }
654 
656  secs = FFABS64U(pts) / AV_TIME_BASE % 60;
657  mins = FFABS64U(pts) / AV_TIME_BASE / 60 % 60;
658  hours = FFABS64U(pts) / AV_TIME_BASE / 3600;
659  hours_sign = (pts < 0) ? "-" : "";
660 
661  bitrate = pts != AV_NOPTS_VALUE && pts && total_size >= 0 ? total_size * 8 / (pts / 1000.0) : -1;
662  speed = pts != AV_NOPTS_VALUE && t != 0.0 ? (double)pts / AV_TIME_BASE / t : -1;
663 
664  if (total_size < 0) av_bprintf(&buf, "size=N/A time=");
665  else av_bprintf(&buf, "size=%8.0fKiB time=", total_size / 1024.0);
666  if (pts == AV_NOPTS_VALUE) {
667  av_bprintf(&buf, "N/A ");
668  } else {
669  av_bprintf(&buf, "%s%02"PRId64":%02d:%02d.%02d ",
670  hours_sign, hours, mins, secs, (100 * us) / AV_TIME_BASE);
671  }
672 
673  if (bitrate < 0) {
674  av_bprintf(&buf, "bitrate=N/A");
675  av_bprintf(&buf_script, "bitrate=N/A\n");
676  }else{
677  av_bprintf(&buf, "bitrate=%6.1fkbits/s", bitrate);
678  av_bprintf(&buf_script, "bitrate=%6.1fkbits/s\n", bitrate);
679  }
680 
681  if (total_size < 0) av_bprintf(&buf_script, "total_size=N/A\n");
682  else av_bprintf(&buf_script, "total_size=%"PRId64"\n", total_size);
683  if (pts == AV_NOPTS_VALUE) {
684  av_bprintf(&buf_script, "out_time_us=N/A\n");
685  av_bprintf(&buf_script, "out_time_ms=N/A\n");
686  av_bprintf(&buf_script, "out_time=N/A\n");
687  } else {
688  av_bprintf(&buf_script, "out_time_us=%"PRId64"\n", pts);
689  av_bprintf(&buf_script, "out_time_ms=%"PRId64"\n", pts);
690  av_bprintf(&buf_script, "out_time=%s%02"PRId64":%02d:%02d.%06d\n",
691  hours_sign, hours, mins, secs, us);
692  }
693 
694  if (nb_frames_dup || nb_frames_drop)
695  av_bprintf(&buf, " dup=%"PRId64" drop=%"PRId64, nb_frames_dup, nb_frames_drop);
696  av_bprintf(&buf_script, "dup_frames=%"PRId64"\n", nb_frames_dup);
697  av_bprintf(&buf_script, "drop_frames=%"PRId64"\n", nb_frames_drop);
698 
699  if (speed < 0) {
700  av_bprintf(&buf, " speed=N/A");
701  av_bprintf(&buf_script, "speed=N/A\n");
702  } else {
703  av_bprintf(&buf, " speed=%4.3gx", speed);
704  av_bprintf(&buf_script, "speed=%4.3gx\n", speed);
705  }
706 
707  secs = (int)t;
708  ms = (int)((t - secs) * 1000);
709  mins = secs / 60;
710  secs %= 60;
711  hours = mins / 60;
712  mins %= 60;
713 
714  av_bprintf(&buf, " elapsed=%"PRId64":%02d:%02d.%02d", hours, mins, secs, ms / 10);
715 
716  if (print_stats || is_last_report) {
717  const char end = is_last_report ? '\n' : '\r';
718  if (print_stats==1 && AV_LOG_INFO > av_log_get_level()) {
719  fprintf(stderr, "%s %c", buf.str, end);
720  } else
721  av_log(NULL, AV_LOG_INFO, "%s %c", buf.str, end);
722 
723  fflush(stderr);
724  }
725  av_bprint_finalize(&buf, NULL);
726 
727  if (progress_avio) {
728  av_bprintf(&buf_script, "progress=%s\n",
729  is_last_report ? "end" : "continue");
730  avio_write(progress_avio, buf_script.str,
731  FFMIN(buf_script.len, buf_script.size - 1));
733  av_bprint_finalize(&buf_script, NULL);
734  if (is_last_report) {
735  if ((ret = avio_closep(&progress_avio)) < 0)
737  "Error closing progress log, loss of information possible: %s\n", av_err2str(ret));
738  }
739  }
740 
741  first_report = 0;
742 }
743 
744 static void print_stream_maps(void)
745 {
746  av_log(NULL, AV_LOG_INFO, "Stream mapping:\n");
747  for (InputStream *ist = ist_iter(NULL); ist; ist = ist_iter(ist)) {
748  for (int j = 0; j < ist->nb_filters; j++) {
749  if (!filtergraph_is_simple(ist->filters[j]->graph)) {
750  av_log(NULL, AV_LOG_INFO, " Stream #%d:%d (%s) -> %s",
751  ist->file->index, ist->index, ist->dec ? ist->dec->name : "?",
752  ist->filters[j]->name);
753  if (nb_filtergraphs > 1)
754  av_log(NULL, AV_LOG_INFO, " (graph %d)", ist->filters[j]->graph->index);
755  av_log(NULL, AV_LOG_INFO, "\n");
756  }
757  }
758  }
759 
760  for (OutputStream *ost = ost_iter(NULL); ost; ost = ost_iter(ost)) {
761  if (ost->attachment_filename) {
762  /* an attached file */
763  av_log(NULL, AV_LOG_INFO, " File %s -> Stream #%d:%d\n",
764  ost->attachment_filename, ost->file->index, ost->index);
765  continue;
766  }
767 
768  if (ost->filter && !filtergraph_is_simple(ost->filter->graph)) {
769  /* output from a complex graph */
770  av_log(NULL, AV_LOG_INFO, " %s", ost->filter->name);
771  if (nb_filtergraphs > 1)
772  av_log(NULL, AV_LOG_INFO, " (graph %d)", ost->filter->graph->index);
773 
774  av_log(NULL, AV_LOG_INFO, " -> Stream #%d:%d (%s)\n", ost->file->index,
775  ost->index, ost->enc->enc_ctx->codec->name);
776  continue;
777  }
778 
779  av_log(NULL, AV_LOG_INFO, " Stream #%d:%d -> #%d:%d",
780  ost->ist->file->index,
781  ost->ist->index,
782  ost->file->index,
783  ost->index);
784  if (ost->enc) {
785  const AVCodec *in_codec = ost->ist->dec;
786  const AVCodec *out_codec = ost->enc->enc_ctx->codec;
787  const char *decoder_name = "?";
788  const char *in_codec_name = "?";
789  const char *encoder_name = "?";
790  const char *out_codec_name = "?";
791  const AVCodecDescriptor *desc;
792 
793  if (in_codec) {
794  decoder_name = in_codec->name;
795  desc = avcodec_descriptor_get(in_codec->id);
796  if (desc)
797  in_codec_name = desc->name;
798  if (!strcmp(decoder_name, in_codec_name))
799  decoder_name = "native";
800  }
801 
802  if (out_codec) {
803  encoder_name = out_codec->name;
804  desc = avcodec_descriptor_get(out_codec->id);
805  if (desc)
806  out_codec_name = desc->name;
807  if (!strcmp(encoder_name, out_codec_name))
808  encoder_name = "native";
809  }
810 
811  av_log(NULL, AV_LOG_INFO, " (%s (%s) -> %s (%s))",
812  in_codec_name, decoder_name,
813  out_codec_name, encoder_name);
814  } else
815  av_log(NULL, AV_LOG_INFO, " (copy)");
816  av_log(NULL, AV_LOG_INFO, "\n");
817  }
818 }
819 
820 static void set_tty_echo(int on)
821 {
822 #if HAVE_TERMIOS_H
823  struct termios tty;
824  if (tcgetattr(0, &tty) == 0) {
825  if (on) tty.c_lflag |= ECHO;
826  else tty.c_lflag &= ~ECHO;
827  tcsetattr(0, TCSANOW, &tty);
828  }
829 #endif
830 }
831 
833 {
834  int i, key;
835  static int64_t last_time;
836  /* read_key() returns 0 on EOF */
837  if (cur_time - last_time >= 100000) {
838  key = read_key();
839  last_time = cur_time;
840  }else
841  key = -1;
842  if (key == 'q') {
843  av_log(NULL, AV_LOG_INFO, "\n\n[q] command received. Exiting.\n\n");
844  return AVERROR_EXIT;
845  }
846  if (key == '+') av_log_set_level(av_log_get_level()+10);
847  if (key == '-') av_log_set_level(av_log_get_level()-10);
848  if (key == 'c' || key == 'C'){
849  char buf[4096], target[64], command[256], arg[256] = {0};
850  double time;
851  int k, n = 0;
852  fprintf(stderr, "\nEnter command: <target>|all <time>|-1 <command>[ <argument>]\n");
853  i = 0;
854  set_tty_echo(1);
855  while ((k = read_key()) != '\n' && k != '\r' && i < sizeof(buf)-1)
856  if (k > 0)
857  buf[i++] = k;
858  buf[i] = 0;
859  set_tty_echo(0);
860  fprintf(stderr, "\n");
861  if (k > 0 &&
862  (n = sscanf(buf, "%63[^ ] %lf %255[^ ] %255[^\n]", target, &time, command, arg)) >= 3) {
863  av_log(NULL, AV_LOG_DEBUG, "Processing command target:%s time:%f command:%s arg:%s",
864  target, time, command, arg);
865  for (OutputStream *ost = ost_iter(NULL); ost; ost = ost_iter(ost)) {
866  if (ost->fg_simple)
867  fg_send_command(ost->fg_simple, time, target, command, arg,
868  key == 'C');
869  }
870  for (i = 0; i < nb_filtergraphs; i++)
871  fg_send_command(filtergraphs[i], time, target, command, arg,
872  key == 'C');
873  } else {
875  "Parse error, at least 3 arguments were expected, "
876  "only %d given in string '%s'\n", n, buf);
877  }
878  }
879  if (key == '?'){
880  fprintf(stderr, "key function\n"
881  "? show this help\n"
882  "+ increase verbosity\n"
883  "- decrease verbosity\n"
884  "c Send command to first matching filter supporting it\n"
885  "C Send/Queue command to all matching filters\n"
886  "h dump packets/hex press to cycle through the 3 states\n"
887  "q quit\n"
888  "s Show QP histogram\n"
889  );
890  }
891  return 0;
892 }
893 
894 /*
895  * The following code is the main loop of the file converter
896  */
897 static int transcode(Scheduler *sch)
898 {
899  int ret = 0;
900  int64_t timer_start, transcode_ts = 0;
901 
903 
905 
906  ret = sch_start(sch);
907  if (ret < 0)
908  return ret;
909 
910  if (stdin_interaction) {
911  av_log(NULL, AV_LOG_INFO, "Press [q] to stop, [?] for help\n");
912  }
913 
914  timer_start = av_gettime_relative();
915 
916  while (!sch_wait(sch, stats_period, &transcode_ts)) {
917  int64_t cur_time= av_gettime_relative();
918 
920  break;
921 
922  /* if 'q' pressed, exits */
923  if (stdin_interaction)
924  if (check_keyboard_interaction(cur_time) < 0)
925  break;
926 
927  /* dump report by using the output first video and audio streams */
928  print_report(0, timer_start, cur_time, transcode_ts);
929  }
930 
931  ret = sch_stop(sch, &transcode_ts);
932 
933  /* write the trailer if needed */
934  for (int i = 0; i < nb_output_files; i++) {
935  int err = of_write_trailer(output_files[i]);
936  ret = err_merge(ret, err);
937  }
938 
939  term_exit();
940 
941  /* dump report by using the first video and audio streams */
942  print_report(1, timer_start, av_gettime_relative(), transcode_ts);
943 
944  return ret;
945 }
946 
948 {
949  BenchmarkTimeStamps time_stamps = { av_gettime_relative() };
950 #if HAVE_GETRUSAGE
951  struct rusage rusage;
952 
953  getrusage(RUSAGE_SELF, &rusage);
954  time_stamps.user_usec =
955  (rusage.ru_utime.tv_sec * 1000000LL) + rusage.ru_utime.tv_usec;
956  time_stamps.sys_usec =
957  (rusage.ru_stime.tv_sec * 1000000LL) + rusage.ru_stime.tv_usec;
958 #elif HAVE_GETPROCESSTIMES
959  HANDLE proc;
960  FILETIME c, e, k, u;
961  proc = GetCurrentProcess();
962  GetProcessTimes(proc, &c, &e, &k, &u);
963  time_stamps.user_usec =
964  ((int64_t)u.dwHighDateTime << 32 | u.dwLowDateTime) / 10;
965  time_stamps.sys_usec =
966  ((int64_t)k.dwHighDateTime << 32 | k.dwLowDateTime) / 10;
967 #else
968  time_stamps.user_usec = time_stamps.sys_usec = 0;
969 #endif
970  return time_stamps;
971 }
972 
973 static int64_t getmaxrss(void)
974 {
975 #if HAVE_GETRUSAGE && HAVE_STRUCT_RUSAGE_RU_MAXRSS
976  struct rusage rusage;
977  getrusage(RUSAGE_SELF, &rusage);
978  return (int64_t)rusage.ru_maxrss * 1024;
979 #elif HAVE_GETPROCESSMEMORYINFO
980  HANDLE proc;
981  PROCESS_MEMORY_COUNTERS memcounters;
982  proc = GetCurrentProcess();
983  memcounters.cb = sizeof(memcounters);
984  GetProcessMemoryInfo(proc, &memcounters, sizeof(memcounters));
985  return memcounters.PeakPagefileUsage;
986 #else
987  return 0;
988 #endif
989 }
990 
991 int main(int argc, char **argv)
992 {
993  Scheduler *sch = NULL;
994 
995  int ret;
997 
998  init_dynload();
999 
1000  setvbuf(stderr,NULL,_IONBF,0); /* win32 runtime needs this */
1001 
1003  parse_loglevel(argc, argv, options);
1004 
1005 #if CONFIG_AVDEVICE
1007 #endif
1009 
1010  show_banner(argc, argv, options);
1011 
1012  sch = sch_alloc();
1013  if (!sch) {
1014  ret = AVERROR(ENOMEM);
1015  goto finish;
1016  }
1017 
1018  /* parse options and open all input/output files */
1019  ret = ffmpeg_parse_options(argc, argv, sch);
1020  if (ret < 0)
1021  goto finish;
1022 
1023  if (nb_output_files <= 0 && nb_input_files == 0) {
1024  show_usage();
1025  av_log(NULL, AV_LOG_WARNING, "Use -h to get full help or, even better, run 'man %s'\n", program_name);
1026  ret = 1;
1027  goto finish;
1028  }
1029 
1030  if (nb_output_files <= 0) {
1031  av_log(NULL, AV_LOG_FATAL, "At least one output file must be specified\n");
1032  ret = 1;
1033  goto finish;
1034  }
1035 
1036 #if CONFIG_MEDIACODEC
1038 #endif
1039 
1041  ret = transcode(sch);
1042  if (ret >= 0 && do_benchmark) {
1043  int64_t utime, stime, rtime;
1045  utime = current_time.user_usec - ti.user_usec;
1046  stime = current_time.sys_usec - ti.sys_usec;
1047  rtime = current_time.real_usec - ti.real_usec;
1049  "bench: utime=%0.3fs stime=%0.3fs rtime=%0.3fs\n",
1050  utime / 1000000.0, stime / 1000000.0, rtime / 1000000.0);
1051  }
1052 
1053  ret = received_nb_signals ? 255 :
1054  (ret == FFMPEG_ERROR_RATE_EXCEEDED) ? 69 : ret;
1055 
1056 finish:
1057  if (ret == AVERROR_EXIT)
1058  ret = 0;
1059 
1061 
1062  sch_free(&sch);
1063 
1064  av_log(NULL, AV_LOG_VERBOSE, "\n");
1065  av_log(NULL, AV_LOG_VERBOSE, "Exiting with exit code %d\n", ret);
1066 
1067  return ret;
1068 }
AV_OPT_SEARCH_CHILDREN
#define AV_OPT_SEARCH_CHILDREN
Search in possible children of the given object first.
Definition: opt.h:604
FrameData::par_enc
AVCodecParameters * par_enc
Definition: ffmpeg.h:709
AVCodec
AVCodec.
Definition: codec.h:169
av_gettime_relative
int64_t av_gettime_relative(void)
Get the current time in microseconds since some unspecified starting point.
Definition: time.c:56
AV_LOG_WARNING
#define AV_LOG_WARNING
Something somehow does not look correct.
Definition: log.h:216
atomic_store
#define atomic_store(object, desired)
Definition: stdatomic.h:85
err_merge
static int err_merge(int err0, int err1)
Merge two return codes - return one of the error codes if at least one of them was negative,...
Definition: ffmpeg_utils.h:39
AVERROR
Filter the word “frame” indicates either a video frame or a group of audio as stored in an AVFrame structure Format for each input and each output the list of supported formats For video that means pixel format For audio that means channel sample they are references to shared objects When the negotiation mechanism computes the intersection of the formats supported at each end of a all references to both lists are replaced with a reference to the intersection And when a single format is eventually chosen for a link amongst the remaining all references to the list are updated That means that if a filter requires that its input and output have the same format amongst a supported all it has to do is use a reference to the same list of formats query_formats can leave some formats unset and return AVERROR(EAGAIN) to cause the negotiation mechanism toagain later. That can be used by filters with complex requirements to use the format negotiated on one link to set the formats supported on another. Frame references ownership and permissions
nb_input_files
int nb_input_files
Definition: ffmpeg.c:109
flag
int flag
Definition: cpu.c:40
FrameData::nb_side_data
int nb_side_data
Definition: ffmpeg.h:712
ffmpeg_exited
static volatile int ffmpeg_exited
Definition: ffmpeg.c:144
FrameData
Definition: ffmpeg.h:690
av_bprint_init
void av_bprint_init(AVBPrint *buf, unsigned size_init, unsigned size_max)
Definition: bprint.c:69
clone_side_data
static int clone_side_data(AVFrameSideData ***dst, int *nb_dst, AVFrameSideData *const *src, int nb_src, unsigned int flags)
Wrapper calling av_frame_side_data_clone() in a loop for all source entries.
Definition: ffmpeg_utils.h:50
AV_LOG_QUIET
#define AV_LOG_QUIET
Print no output.
Definition: log.h:192
AVBufferRef::data
uint8_t * data
The data buffer.
Definition: buffer.h:90
fg_free
void fg_free(FilterGraph **pfg)
Definition: ffmpeg_filter.c:1015
int64_t
long long int64_t
Definition: coverity.c:34
BenchmarkTimeStamps::user_usec
int64_t user_usec
Definition: ffmpeg.c:96
frame_data_free
static void frame_data_free(void *opaque, uint8_t *data)
Definition: ffmpeg.c:413
avformat_get_class
const AVClass * avformat_get_class(void)
Get the AVClass for AVFormatContext.
Definition: options.c:192
ist_iter
InputStream * ist_iter(InputStream *prev)
Definition: ffmpeg.c:397
InputFile::index
int index
Definition: ffmpeg.h:507
AVFrame
This structure describes decoded (raw) audio or video data.
Definition: frame.h:466
binder.h
of_filesize
int64_t of_filesize(OutputFile *of)
Definition: ffmpeg_mux.c:883
u
#define u(width, name, range_min, range_max)
Definition: cbs_apv.c:68
current_time
static BenchmarkTimeStamps current_time
Definition: ffmpeg.c:105
AVOption
AVOption.
Definition: opt.h:428
OutputStream::index
int index
Definition: ffmpeg.h:629
data
const char data[16]
Definition: mxf.c:149
atomic_int
intptr_t atomic_int
Definition: stdatomic.h:55
ffmpeg.h
AV_LOG_VERBOSE
#define AV_LOG_VERBOSE
Detailed information.
Definition: log.h:226
BenchmarkTimeStamps::sys_usec
int64_t sys_usec
Definition: ffmpeg.c:97
progress_avio
AVIOContext * progress_avio
Definition: ffmpeg.c:106
show_usage
void show_usage(void)
Definition: ffmpeg_opt.c:1370
nb_streams
static unsigned int nb_streams
Definition: ffprobe.c:352
AVDictionary
Definition: dict.c:32
program_birth_year
const int program_birth_year
program birth year, defined by the program for show_banner()
Definition: ffmpeg.c:90
ost
static AVStream * ost
Definition: vaapi_transcode.c:42
term_exit_sigsafe
static void term_exit_sigsafe(void)
Definition: ffmpeg.c:127
OutputStream::file
struct OutputFile * file
Definition: ffmpeg.h:627
ECHO
#define ECHO(name, type, min, max)
Definition: af_aecho.c:157
AVIOInterruptCB
Callback for checking whether to abort blocking functions.
Definition: avio.h:59
InputStream
Definition: ffmpeg.h:461
filter_nbthreads
char * filter_nbthreads
Definition: ffmpeg_opt.c:73
stats_period
int64_t stats_period
Definition: ffmpeg_opt.c:81
finish
static void finish(void)
Definition: movenc.c:374
sch_stop
int sch_stop(Scheduler *sch, int64_t *finish_ts)
Definition: ffmpeg_sched.c:2820
AVPacket::opaque_ref
AVBufferRef * opaque_ref
AVBufferRef for free use by the API user.
Definition: packet.h:639
AV_BPRINT_SIZE_AUTOMATIC
#define AV_BPRINT_SIZE_AUTOMATIC
packet_data_c
const FrameData * packet_data_c(AVPacket *pkt)
Definition: ffmpeg.c:505
update_benchmark
void update_benchmark(const char *fmt,...)
Definition: ffmpeg.c:561
pts
static int64_t pts
Definition: transcode_aac.c:649
fg_send_command
void fg_send_command(FilterGraph *fg, double time, const char *target, const char *command, const char *arg, int all_filters)
Definition: ffmpeg_filter.c:3410
avformat_network_init
int avformat_network_init(void)
Do global initialization of network libraries.
Definition: utils.c:561
InputFile
Definition: ffmpeg.h:504
transcode
static int transcode(Scheduler *sch)
Definition: ffmpeg.c:897
sig
static volatile sig_atomic_t sig
Definition: signal.c:48
ffmpeg_cleanup
static void ffmpeg_cleanup(int ret)
Definition: ffmpeg.c:324
AV_LOG_ERROR
#define AV_LOG_ERROR
Something went wrong and cannot losslessly be recovered.
Definition: log.h:210
sch_free
void sch_free(Scheduler **psch)
Definition: ffmpeg_sched.c:502
FF_ARRAY_ELEMS
#define FF_ARRAY_ELEMS(a)
Definition: sinewin_tablegen.c:29
BenchmarkTimeStamps::real_usec
int64_t real_usec
Definition: ffmpeg.c:95
av_dict_get
AVDictionaryEntry * av_dict_get(const AVDictionary *m, const char *key, const AVDictionaryEntry *prev, int flags)
Get a dictionary entry with matching key.
Definition: dict.c:60
float
float
Definition: af_crystalizer.c:122
decode
static void decode(AVCodecContext *dec_ctx, AVPacket *pkt, AVFrame *frame, FILE *outfile)
Definition: decode_audio.c:72
of_free
void of_free(OutputFile **pof)
Definition: ffmpeg_mux.c:856
AVCodecDescriptor
This struct describes the properties of a single codec described by an AVCodecID.
Definition: codec_desc.h:38
get_benchmark_time_stamps
static BenchmarkTimeStamps get_benchmark_time_stamps(void)
Definition: ffmpeg.c:947
vstats_filename
char * vstats_filename
Definition: ffmpeg_opt.c:54
sch_alloc
Scheduler * sch_alloc(void)
Definition: ffmpeg_sched.c:623
copy_ts_first_pts
static int64_t copy_ts_first_pts
Definition: ffmpeg.c:145
print_filtergraphs
int print_filtergraphs(FilterGraph **graphs, int nb_graphs, InputFile **ifiles, int nb_ifiles, OutputFile **ofiles, int nb_ofiles)
Definition: graphprint.c:1074
bitrate
int64_t bitrate
Definition: av1_levels.c:47
AVDictionaryEntry::key
char * key
Definition: dict.h:91
term_init
void term_init(void)
Definition: ffmpeg.c:205
AV_LOG_DEBUG
#define AV_LOG_DEBUG
Stuff which is only useful for libav* developers.
Definition: log.h:231
ctx
static AVFormatContext * ctx
Definition: movenc.c:49
limits.h
print_graphs_file
char * print_graphs_file
Definition: ffmpeg_opt.c:78
on
s EdgeDetect Foobar g libavfilter vf_edgedetect c libavfilter vf_foobar c edit libavfilter and add an entry for foobar following the pattern of the other filters edit libavfilter allfilters and add an entry for foobar following the pattern of the other filters configure make j< whatever > ffmpeg ffmpeg i you should get a foobar png with Lena edge detected That s your new playground is ready Some little details about what s going on
Definition: writing_filters.txt:34
term_exit
void term_exit(void)
Definition: ffmpeg.c:135
ffmpeg_utils.h
key
const char * key
Definition: hwcontext_opencl.c:189
av_mallocz
#define av_mallocz(s)
Definition: tableprint_vlc.h:31
atomic_load
#define atomic_load(object)
Definition: stdatomic.h:93
command
static int command(AVFilterContext *ctx, const char *cmd, const char *arg, char *res, int res_len, int flags)
Definition: vf_drawtext.c:1196
arg
const char * arg
Definition: jacosubdec.c:65
of_enc_stats_close
void of_enc_stats_close(void)
Definition: ffmpeg_mux_init.c:197
option
option
Definition: libkvazaar.c:312
avio_flush
void avio_flush(AVIOContext *s)
Force flushing of buffered data.
Definition: aviobuf.c:228
av_log_get_level
int av_log_get_level(void)
Get the current log level.
Definition: log.c:472
init_dynload
void init_dynload(void)
Initialize dynamic library loading.
Definition: cmdutils.c:75
opts
static AVDictionary * opts
Definition: movenc.c:51
AVClass
Describe the class of an AVClass context structure.
Definition: log.h:76
avcodec_get_class
const AVClass * avcodec_get_class(void)
Get the AVClass for AVCodecContext.
Definition: options.c:184
NULL
#define NULL
Definition: coverity.c:32
av_buffer_unref
void av_buffer_unref(AVBufferRef **buf)
Free a given reference and automatically free the buffer if there are no more references to it.
Definition: buffer.c:139
main
int main(int argc, char **argv)
Definition: ffmpeg.c:991
Decoder
Definition: ffmpeg.h:447
nb_output_dumped
atomic_uint nb_output_dumped
Definition: ffmpeg.c:103
getmaxrss
static int64_t getmaxrss(void)
Definition: ffmpeg.c:973
check_keyboard_interaction
static int check_keyboard_interaction(int64_t cur_time)
Definition: ffmpeg.c:832
av_log_set_flags
void av_log_set_flags(int arg)
Definition: log.c:482
print_stream_maps
static void print_stream_maps(void)
Definition: ffmpeg.c:744
options
Definition: swscale.c:50
vstats_file
FILE * vstats_file
Definition: ffmpeg.c:92
AV_OPT_SEARCH_FAKE_OBJ
#define AV_OPT_SEARCH_FAKE_OBJ
The obj passed to av_opt_find() is fake – only a double pointer to AVClass instead of a required poin...
Definition: opt.h:612
ost_iter
OutputStream * ost_iter(OutputStream *prev)
Definition: ffmpeg.c:381
double
double
Definition: af_crystalizer.c:132
time.h
received_nb_signals
static volatile int received_nb_signals
Definition: ffmpeg.c:142
do_benchmark_all
int do_benchmark_all
Definition: ffmpeg_opt.c:61
OutputFile::index
int index
Definition: ffmpeg.h:676
AV_OPT_FLAG_ENCODING_PARAM
#define AV_OPT_FLAG_ENCODING_PARAM
A generic parameter which can be set by the user for muxing or encoding.
Definition: opt.h:351
c
Undefined Behavior In the C some operations are like signed integer dereferencing freed accessing outside allocated Undefined Behavior must not occur in a C it is not safe even if the output of undefined operations is unused The unsafety may seem nit picking but Optimizing compilers have in fact optimized code on the assumption that no undefined Behavior occurs Optimizing code based on wrong assumptions can and has in some cases lead to effects beyond the output of computations The signed integer overflow problem in speed critical code Code which is highly optimized and works with signed integers sometimes has the problem that often the output of the computation does not c
Definition: undefined.txt:32
av_buffer_create
AVBufferRef * av_buffer_create(uint8_t *data, size_t size, void(*free)(void *opaque, uint8_t *data), void *opaque, int flags)
Create an AVBuffer from an existing array.
Definition: buffer.c:55
input_files
InputFile ** input_files
Definition: ffmpeg.c:108
print_graphs_format
char * print_graphs_format
Definition: ffmpeg_opt.c:79
OutputFile::streams
OutputStream ** streams
Definition: ffmpeg.h:680
Scheduler
Definition: ffmpeg_sched.c:278
FilterGraph
Definition: ffmpeg.h:395
print_stats
int print_stats
Definition: ffmpeg_opt.c:70
decode_interrupt_cb
static int decode_interrupt_cb(void *ctx)
Definition: ffmpeg.c:317
print_report
static void print_report(int is_last_report, int64_t timer_start, int64_t cur_time, int64_t pts)
Definition: ffmpeg.c:582
av_opt_find
const AVOption * av_opt_find(void *obj, const char *name, const char *unit, int opt_flags, int search_flags)
Look for an option in an object.
Definition: opt.c:1984
FrameData::side_data
AVFrameSideData ** side_data
Definition: ffmpeg.h:711
f
f
Definition: af_crystalizer.c:122
AVIOContext
Bytestream IO Context.
Definition: avio.h:160
av_bprint_finalize
int av_bprint_finalize(AVBPrint *buf, char **ret_str)
Finalize a print buffer.
Definition: bprint.c:235
dst
uint8_t ptrdiff_t const uint8_t ptrdiff_t int intptr_t intptr_t int int16_t * dst
Definition: dsp.h:87
output_files
OutputFile ** output_files
Definition: ffmpeg.c:111
SIGNAL
#define SIGNAL(sig, func)
Definition: ffmpeg.c:201
i
#define i(width, name, range_min, range_max)
Definition: cbs_h264.c:63
av_err2str
#define av_err2str(errnum)
Convenience macro, the return value should be used only directly in function arguments but never stan...
Definition: error.h:122
received_sigterm
static volatile int received_sigterm
Definition: ffmpeg.c:141
filtergraph_is_simple
int filtergraph_is_simple(const FilterGraph *fg)
Definition: ffmpeg_filter.c:2315
uninit_opts
void uninit_opts(void)
Uninitialize the cmdutils option system, in particular free the *_opts contexts and their contents.
Definition: cmdutils.c:62
copy_ts
int copy_ts
Definition: ffmpeg_opt.c:64
AV_NOPTS_VALUE
#define AV_NOPTS_VALUE
Undefined timestamp value.
Definition: avutil.h:247
frame_data
FrameData * frame_data(AVFrame *frame)
Get our axiliary frame data attached to the frame, allocating it if needed.
Definition: ffmpeg.c:487
avdevice.h
show_banner
void show_banner(int argc, char **argv, const OptionDef *options)
Print the program banner to stderr.
Definition: opt_common.c:240
avio_write
void avio_write(AVIOContext *s, const unsigned char *buf, int size)
Definition: aviobuf.c:206
do_benchmark
int do_benchmark
Definition: ffmpeg_opt.c:60
AVCodecParameters::avcodec_parameters_alloc
AVCodecParameters * avcodec_parameters_alloc(void)
Allocate a new AVCodecParameters and set its fields to default values (unknown/invalid/0).
Definition: codec_par.c:57
decoders
Decoder ** decoders
Definition: ffmpeg.c:117
nb_decoders
int nb_decoders
Definition: ffmpeg.c:118
AV_LOG_INFO
#define AV_LOG_INFO
Standard information.
Definition: log.h:221
AVCodec::id
enum AVCodecID id
Definition: codec.h:183
av_log_set_level
void av_log_set_level(int level)
Set the log level.
Definition: log.c:477
bprint.h
av_frame_side_data_free
void av_frame_side_data_free(AVFrameSideData ***sd, int *nb_sd)
Free all side data entries and their contents, then zeroes out the values which the pointers are poin...
Definition: side_data.c:138
AV_TIME_BASE
#define AV_TIME_BASE
Internal time base represented as integer.
Definition: avutil.h:253
vsnprintf
#define vsnprintf
Definition: snprintf.h:36
sigterm_handler
static void sigterm_handler(int sig)
Definition: ffmpeg.c:148
print_graphs
int print_graphs
Definition: ffmpeg_opt.c:77
FFMIN
#define FFMIN(a, b)
Definition: macros.h:49
AVCodec::name
const char * name
Name of the codec implementation.
Definition: codec.h:176
filtergraphs
FilterGraph ** filtergraphs
Definition: ffmpeg.c:114
int_cb
const AVIOInterruptCB int_cb
Definition: ffmpeg.c:322
nb_output_files
int nb_output_files
Definition: ffmpeg.c:112
frame_data_ensure
static int frame_data_ensure(AVBufferRef **dst, int writable)
Definition: ffmpeg.c:423
av_buffer_is_writable
int av_buffer_is_writable(const AVBufferRef *buf)
Definition: buffer.c:147
parse_loglevel
void parse_loglevel(int argc, char **argv, const OptionDef *options)
Find the '-loglevel' option in the command line args and apply it.
Definition: cmdutils.c:556
AVCodecParameters::avcodec_parameters_copy
int avcodec_parameters_copy(AVCodecParameters *dst, const AVCodecParameters *src)
Copy the contents of src to dst.
Definition: codec_par.c:107
ret
ret
Definition: filter_design.txt:187
AV_LOG_FATAL
#define AV_LOG_FATAL
Something went wrong and recovery is not possible.
Definition: log.h:204
dec_free
void dec_free(Decoder **pdec)
Definition: ffmpeg_dec.c:118
frame
these buffered frames must be flushed immediately if a new input produces new the filter must not call request_frame to get more It must just process the frame or queue it The task of requesting more frames is left to the filter s request_frame method or the application If a filter has several the filter must be ready for frames arriving randomly on any input any filter with several inputs will most likely require some kind of queuing mechanism It is perfectly acceptable to have a limited queue and to drop frames when the inputs are too unbalanced request_frame For filters that do not use the this method is called when a frame is wanted on an output For a it should directly call filter_frame on the corresponding output For a if there are queued frames already one of these frames should be pushed If the filter should request a frame on one of its repeatedly until at least one frame has been pushed Return or at least make progress towards producing a frame
Definition: filter_design.txt:265
hw_device_free_all
void hw_device_free_all(void)
Definition: ffmpeg_hw.c:286
avformat.h
av_bprintf
void av_bprintf(AVBPrint *buf, const char *fmt,...)
Definition: bprint.c:122
dict.h
check_avoptions_used
int check_avoptions_used(const AVDictionary *opts, const AVDictionary *opts_used, void *logctx, int decode)
Definition: ffmpeg.c:511
AV_LOG_SKIP_REPEATED
#define AV_LOG_SKIP_REPEATED
Skip repeated messages, this requires the user app to use av_log() instead of (f)printf as the 2 woul...
Definition: log.h:400
AVCodecParameters::avcodec_parameters_free
void avcodec_parameters_free(AVCodecParameters **par)
Free an AVCodecParameters instance and everything associated with it and write NULL to the supplied p...
Definition: codec_par.c:67
ifile_close
void ifile_close(InputFile **f)
Definition: ffmpeg_demux.c:925
avformat_network_deinit
int avformat_network_deinit(void)
Undo the initialization done by avformat_network_init.
Definition: utils.c:573
AVStream::index
int index
stream index in AVFormatContext
Definition: avformat.h:753
transcode_init_done
static atomic_int transcode_init_done
Definition: ffmpeg.c:143
BenchmarkTimeStamps
Definition: ffmpeg.c:94
android_binder_threadpool_init_if_required
void android_binder_threadpool_init_if_required(void)
Initialize Android Binder thread pool.
InputStream::file
struct InputFile * file
Definition: ffmpeg.h:465
atomic_uint
intptr_t atomic_uint
Definition: stdatomic.h:56
program_name
const char program_name[]
program name, defined by the program for show_version().
Definition: ffmpeg.c:89
ffmpeg_parse_options
int ffmpeg_parse_options(int argc, char **argv, Scheduler *sch)
Windows::Graphics::DirectX::Direct3D11::p
IDirect3DDxgiInterfaceAccess _COM_Outptr_ void ** p
Definition: vsrc_gfxcapture_winrt.hpp:53
AV_OPT_FLAG_DECODING_PARAM
#define AV_OPT_FLAG_DECODING_PARAM
A generic parameter which can be set by the user for demuxing or decoding.
Definition: opt.h:355
desc
const char * desc
Definition: libsvtav1.c:83
AVMEDIA_TYPE_VIDEO
@ AVMEDIA_TYPE_VIDEO
Definition: avutil.h:200
us
#define us(width, name, range_min, range_max, subs,...)
Definition: cbs_apv.c:70
mem.h
AVBufferRef
A reference to a data buffer.
Definition: buffer.h:82
av_strdup
#define av_strdup(s)
Definition: ops_asmgen.c:47
InputStream::index
int index
Definition: ffmpeg.h:467
ffmpeg_sched.h
sch_wait
int sch_wait(Scheduler *sch, uint64_t timeout_us, int64_t *transcode_ts)
Wait until transcoding terminates or the specified timeout elapses.
Definition: ffmpeg_sched.c:1836
FFMPEG_ERROR_RATE_EXCEEDED
#define FFMPEG_ERROR_RATE_EXCEEDED
Definition: ffmpeg.h:54
av_free
#define av_free(p)
Definition: tableprint_vlc.h:34
AVDictionaryEntry
Definition: dict.h:90
stdin_interaction
int stdin_interaction
Definition: ffmpeg_opt.c:71
AVPacket
This structure stores compressed data.
Definition: packet.h:580
avio_closep
int avio_closep(AVIOContext **s)
Close the resource accessed by the AVIOContext *s, free it and set the pointer pointing to it to NULL...
Definition: avio.c:655
av_freep
#define av_freep(p)
Definition: tableprint_vlc.h:35
cmdutils.h
packet_data
FrameData * packet_data(AVPacket *pkt)
Definition: ffmpeg.c:499
nb_filtergraphs
int nb_filtergraphs
Definition: ffmpeg.c:115
sch_start
int sch_start(Scheduler *sch)
Definition: ffmpeg_sched.c:1770
OutputStream
Definition: mux.c:53
av_log
#define av_log(a,...)
Definition: tableprint_vlc.h:27
graphprint.h
FFABS64U
#define FFABS64U(a)
Definition: common.h:92
AVERROR_EXIT
#define AVERROR_EXIT
Immediate exit was requested; the called function should not be restarted.
Definition: error.h:58
avcodec_descriptor_get
const AVCodecDescriptor * avcodec_descriptor_get(enum AVCodecID id)
Definition: codec_desc.c:3878
pkt
static AVPacket * pkt
Definition: demux_decode.c:55
set_tty_echo
static void set_tty_echo(int on)
Definition: ffmpeg.c:820
FF_QP2LAMBDA
#define FF_QP2LAMBDA
factor to convert from H.263 QP to lambda
Definition: avutil.h:226
frame_data_c
const FrameData * frame_data_c(AVFrame *frame)
Definition: ffmpeg.c:493
read_key
static int read_key(void)
Definition: ffmpeg.c:264
of_write_trailer
int of_write_trailer(OutputFile *of)
Definition: ffmpeg_mux.c:752
av_dict_iterate
const AVDictionaryEntry * av_dict_iterate(const AVDictionary *m, const AVDictionaryEntry *prev)
Iterate over a dictionary.
Definition: dict.c:42
src
#define src
Definition: vp8dsp.c:248
read
static uint32_t BS_FUNC() read(BSCTX *bc, unsigned int n)
Return n bits from the buffer, n has to be in the 0-32 range.
Definition: bitstream_template.h:239
OutputFile
Definition: ffmpeg.h:673
avdevice_register_all
FF_VISIBILITY_POP_HIDDEN av_cold void avdevice_register_all(void)
Initialize libavdevice and register all the input and output devices.
Definition: alldevices.c:67