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