FFmpeg
ffmpeg_demux.c
Go to the documentation of this file.
1 /*
2  * This file is part of FFmpeg.
3  *
4  * FFmpeg is free software; you can redistribute it and/or
5  * modify it under the terms of the GNU Lesser General Public
6  * License as published by the Free Software Foundation; either
7  * version 2.1 of the License, or (at your option) any later version.
8  *
9  * FFmpeg is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12  * Lesser General Public License for more details.
13  *
14  * You should have received a copy of the GNU Lesser General Public
15  * License along with FFmpeg; if not, write to the Free Software
16  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
17  */
18 
19 #include <float.h>
20 #include <stdint.h>
21 
22 #include "ffmpeg.h"
23 
24 #include "libavutil/avassert.h"
25 #include "libavutil/avstring.h"
26 #include "libavutil/display.h"
27 #include "libavutil/error.h"
28 #include "libavutil/intreadwrite.h"
29 #include "libavutil/opt.h"
30 #include "libavutil/parseutils.h"
31 #include "libavutil/pixdesc.h"
32 #include "libavutil/time.h"
33 #include "libavutil/timestamp.h"
34 #include "libavutil/thread.h"
36 
37 #include "libavcodec/packet.h"
38 
39 #include "libavformat/avformat.h"
40 
41 static const char *const opt_name_discard[] = {"discard", NULL};
42 static const char *const opt_name_reinit_filters[] = {"reinit_filter", NULL};
43 static const char *const opt_name_fix_sub_duration[] = {"fix_sub_duration", NULL};
44 static const char *const opt_name_canvas_sizes[] = {"canvas_size", NULL};
45 static const char *const opt_name_guess_layout_max[] = {"guess_layout_max", NULL};
46 static const char *const opt_name_ts_scale[] = {"itsscale", NULL};
47 static const char *const opt_name_hwaccels[] = {"hwaccel", NULL};
48 static const char *const opt_name_hwaccel_devices[] = {"hwaccel_device", NULL};
49 static const char *const opt_name_hwaccel_output_formats[] = {"hwaccel_output_format", NULL};
50 static const char *const opt_name_autorotate[] = {"autorotate", NULL};
51 static const char *const opt_name_display_rotations[] = {"display_rotation", NULL};
52 static const char *const opt_name_display_hflips[] = {"display_hflip", NULL};
53 static const char *const opt_name_display_vflips[] = {"display_vflip", NULL};
54 
55 typedef struct DemuxStream {
57 
58  // name used for logging
59  char log_name[32];
60 
61  double ts_scale;
62 
63  int64_t min_pts; /* pts with the smallest value in a current stream */
64  int64_t max_pts; /* pts with the higher value in a current stream */
65 } DemuxStream;
66 
67 typedef struct Demuxer {
69 
70  // name used for logging
71  char log_name[32];
72 
73  /* number of times input stream should be looped */
74  int loop;
75  /* actual duration of the longest stream in a file at the moment when
76  * looping happens */
77  int64_t duration;
78  /* time base of the duration */
80 
81  /* number of streams that the user was warned of */
83 
88 } Demuxer;
89 
90 typedef struct DemuxMsg {
92  int looping;
93 
94  // repeat_pict from the demuxer-internal parser
96 } DemuxMsg;
97 
99 {
100  return (DemuxStream*)ist;
101 }
102 
104 {
105  return (Demuxer*)f;
106 }
107 
108 static void report_new_stream(Demuxer *d, const AVPacket *pkt)
109 {
110  AVStream *st = d->f.ctx->streams[pkt->stream_index];
111 
112  if (pkt->stream_index < d->nb_streams_warn)
113  return;
115  "New %s stream with index %d at pos:%"PRId64" and DTS:%ss\n",
118  d->nb_streams_warn = pkt->stream_index + 1;
119 }
120 
122  int64_t last_duration)
123 {
124  /* the total duration of the stream, max_pts - min_pts is
125  * the duration of the stream without the last frame */
126  if (ds->max_pts > ds->min_pts &&
127  ds->max_pts - (uint64_t)ds->min_pts < INT64_MAX - last_duration)
128  last_duration += ds->max_pts - ds->min_pts;
129 
130  if (!d->duration ||
131  av_compare_ts(d->duration, d->time_base,
132  last_duration, ds->ist.st->time_base) < 0) {
133  d->duration = last_duration;
134  d->time_base = ds->ist.st->time_base;
135  }
136 }
137 
138 static int seek_to_start(Demuxer *d)
139 {
140  InputFile *ifile = &d->f;
141  AVFormatContext *is = ifile->ctx;
142  int ret;
143 
144  ret = avformat_seek_file(is, -1, INT64_MIN, is->start_time, is->start_time, 0);
145  if (ret < 0)
146  return ret;
147 
148  if (ifile->audio_duration_queue_size) {
149  /* duration is the length of the last frame in a stream
150  * when audio stream is present we don't care about
151  * last video frame length because it's not defined exactly */
152  int got_durations = 0;
153 
154  while (got_durations < ifile->audio_duration_queue_size) {
155  DemuxStream *ds;
156  LastFrameDuration dur;
157  ret = av_thread_message_queue_recv(ifile->audio_duration_queue, &dur, 0);
158  if (ret < 0)
159  return ret;
160  got_durations++;
161 
162  ds = ds_from_ist(ifile->streams[dur.stream_idx]);
163  ifile_duration_update(d, ds, dur.duration);
164  }
165  } else {
166  for (int i = 0; i < ifile->nb_streams; i++) {
167  int64_t duration = 0;
168  InputStream *ist = ifile->streams[i];
169  DemuxStream *ds = ds_from_ist(ist);
170 
171  if (ist->framerate.num) {
172  duration = av_rescale_q(1, av_inv_q(ist->framerate), ist->st->time_base);
173  } else if (ist->st->avg_frame_rate.num) {
175  } else {
176  duration = 1;
177  }
178 
180  }
181  }
182 
183  if (d->loop > 0)
184  d->loop--;
185 
186  return ret;
187 }
188 
189 static void ts_fixup(Demuxer *d, AVPacket *pkt, int *repeat_pict)
190 {
191  InputFile *ifile = &d->f;
192  InputStream *ist = ifile->streams[pkt->stream_index];
193  DemuxStream *ds = ds_from_ist(ist);
194  const int64_t start_time = ifile->start_time_effective;
195  int64_t duration;
196 
197 #define SHOW_TS_DEBUG(tag_) \
198  if (debug_ts) { \
199  av_log(ist, AV_LOG_INFO, "%s -> ist_index:%d:%d type:%s " \
200  "pkt_pts:%s pkt_pts_time:%s pkt_dts:%s pkt_dts_time:%s duration:%s duration_time:%s\n", \
201  tag_, ifile->index, pkt->stream_index, \
202  av_get_media_type_string(ist->st->codecpar->codec_type), \
203  av_ts2str(pkt->pts), av_ts2timestr(pkt->pts, &ist->st->time_base), \
204  av_ts2str(pkt->dts), av_ts2timestr(pkt->dts, &ist->st->time_base), \
205  av_ts2str(pkt->duration), av_ts2timestr(pkt->duration, &ist->st->time_base)); \
206  }
207 
208  SHOW_TS_DEBUG("demuxer");
209 
211  ist->st->pts_wrap_bits < 64) {
212  int64_t stime, stime2;
213 
215  stime2= stime + (1ULL<<ist->st->pts_wrap_bits);
216  ist->wrap_correction_done = 1;
217 
218  if(stime2 > stime && pkt->dts != AV_NOPTS_VALUE && pkt->dts > stime + (1LL<<(ist->st->pts_wrap_bits-1))) {
219  pkt->dts -= 1ULL<<ist->st->pts_wrap_bits;
220  ist->wrap_correction_done = 0;
221  }
222  if(stime2 > stime && pkt->pts != AV_NOPTS_VALUE && pkt->pts > stime + (1LL<<(ist->st->pts_wrap_bits-1))) {
223  pkt->pts -= 1ULL<<ist->st->pts_wrap_bits;
224  ist->wrap_correction_done = 0;
225  }
226  }
227 
228  if (pkt->dts != AV_NOPTS_VALUE)
229  pkt->dts += av_rescale_q(ifile->ts_offset, AV_TIME_BASE_Q, ist->st->time_base);
230  if (pkt->pts != AV_NOPTS_VALUE)
231  pkt->pts += av_rescale_q(ifile->ts_offset, AV_TIME_BASE_Q, ist->st->time_base);
232 
233  if (pkt->pts != AV_NOPTS_VALUE)
234  pkt->pts *= ds->ts_scale;
235  if (pkt->dts != AV_NOPTS_VALUE)
236  pkt->dts *= ds->ts_scale;
237 
238  duration = av_rescale_q(d->duration, d->time_base, ist->st->time_base);
239  if (pkt->pts != AV_NOPTS_VALUE) {
240  pkt->pts += duration;
241  ds->max_pts = FFMAX(pkt->pts, ds->max_pts);
242  ds->min_pts = FFMIN(pkt->pts, ds->min_pts);
243  }
244 
245  if (pkt->dts != AV_NOPTS_VALUE)
246  pkt->dts += duration;
247 
248  *repeat_pict = -1;
249  if (ist->st->codecpar->codec_type == AVMEDIA_TYPE_VIDEO &&
250  av_stream_get_parser(ist->st))
251  *repeat_pict = av_stream_get_parser(ist->st)->repeat_pict;
252 
253  SHOW_TS_DEBUG("demuxer+tsfixup");
254 }
255 
257 {
258  char name[16];
259  snprintf(name, sizeof(name), "dmx%d:%s", f->index, f->ctx->iformat->name);
261 }
262 
263 static void *input_thread(void *arg)
264 {
265  Demuxer *d = arg;
266  InputFile *f = &d->f;
267  AVPacket *pkt;
268  unsigned flags = d->non_blocking ? AV_THREAD_MESSAGE_NONBLOCK : 0;
269  int ret = 0;
270 
271  pkt = av_packet_alloc();
272  if (!pkt) {
273  ret = AVERROR(ENOMEM);
274  goto finish;
275  }
276 
278 
279  while (1) {
280  DemuxMsg msg = { NULL };
281 
282  ret = av_read_frame(f->ctx, pkt);
283 
284  if (ret == AVERROR(EAGAIN)) {
285  av_usleep(10000);
286  continue;
287  }
288  if (ret < 0) {
289  if (d->loop) {
290  /* signal looping to the consumer thread */
291  msg.looping = 1;
292  ret = av_thread_message_queue_send(d->in_thread_queue, &msg, 0);
293  if (ret >= 0)
294  ret = seek_to_start(d);
295  if (ret >= 0)
296  continue;
297 
298  /* fallthrough to the error path */
299  }
300 
301  if (ret == AVERROR_EOF)
302  av_log(d, AV_LOG_VERBOSE, "EOF while reading input\n");
303  else
304  av_log(d, AV_LOG_ERROR, "Error during demuxing: %s\n",
305  av_err2str(ret));
306 
307  break;
308  }
309 
310  if (do_pkt_dump) {
312  f->ctx->streams[pkt->stream_index]);
313  }
314 
315  /* the following test is needed in case new streams appear
316  dynamically in stream : we ignore them */
317  if (pkt->stream_index >= f->nb_streams) {
320  continue;
321  }
322 
323  if (pkt->flags & AV_PKT_FLAG_CORRUPT) {
325  "corrupt input packet in stream %d\n",
326  pkt->stream_index);
327  if (exit_on_error) {
330  break;
331  }
332  }
333 
334  ts_fixup(d, pkt, &msg.repeat_pict);
335 
336  msg.pkt = av_packet_alloc();
337  if (!msg.pkt) {
339  ret = AVERROR(ENOMEM);
340  break;
341  }
342  av_packet_move_ref(msg.pkt, pkt);
343  ret = av_thread_message_queue_send(d->in_thread_queue, &msg, flags);
344  if (flags && ret == AVERROR(EAGAIN)) {
345  flags = 0;
346  ret = av_thread_message_queue_send(d->in_thread_queue, &msg, flags);
347  av_log(f->ctx, AV_LOG_WARNING,
348  "Thread message queue blocking; consider raising the "
349  "thread_queue_size option (current value: %d)\n",
350  d->thread_queue_size);
351  }
352  if (ret < 0) {
353  if (ret != AVERROR_EOF)
354  av_log(f->ctx, AV_LOG_ERROR,
355  "Unable to send packet to main thread: %s\n",
356  av_err2str(ret));
357  av_packet_free(&msg.pkt);
358  break;
359  }
360  }
361 
362 finish:
363  av_assert0(ret < 0);
364  av_thread_message_queue_set_err_recv(d->in_thread_queue, ret);
365 
367 
368  av_log(d, AV_LOG_VERBOSE, "Terminating demuxer thread\n");
369 
370  return NULL;
371 }
372 
373 static void thread_stop(Demuxer *d)
374 {
375  InputFile *f = &d->f;
376  DemuxMsg msg;
377 
378  if (!d->in_thread_queue)
379  return;
381  while (av_thread_message_queue_recv(d->in_thread_queue, &msg, 0) >= 0)
382  av_packet_free(&msg.pkt);
383 
384  pthread_join(d->thread, NULL);
385  av_thread_message_queue_free(&d->in_thread_queue);
386  av_thread_message_queue_free(&f->audio_duration_queue);
387 }
388 
389 static int thread_start(Demuxer *d)
390 {
391  int ret;
392  InputFile *f = &d->f;
393 
394  if (d->thread_queue_size <= 0)
395  d->thread_queue_size = (nb_input_files > 1 ? 8 : 1);
396 
397  if (nb_input_files > 1 &&
398  (f->ctx->pb ? !f->ctx->pb->seekable :
399  strcmp(f->ctx->iformat->name, "lavfi")))
400  d->non_blocking = 1;
401  ret = av_thread_message_queue_alloc(&d->in_thread_queue,
402  d->thread_queue_size, sizeof(DemuxMsg));
403  if (ret < 0)
404  return ret;
405 
406  if (d->loop) {
407  int nb_audio_dec = 0;
408 
409  for (int i = 0; i < f->nb_streams; i++) {
410  InputStream *ist = f->streams[i];
411  nb_audio_dec += !!(ist->decoding_needed &&
413  }
414 
415  if (nb_audio_dec) {
416  ret = av_thread_message_queue_alloc(&f->audio_duration_queue,
417  nb_audio_dec, sizeof(LastFrameDuration));
418  if (ret < 0)
419  goto fail;
420  f->audio_duration_queue_size = nb_audio_dec;
421  }
422  }
423 
424  if ((ret = pthread_create(&d->thread, NULL, input_thread, d))) {
425  av_log(d, AV_LOG_ERROR, "pthread_create failed: %s. Try to increase `ulimit -v` or decrease `ulimit -s`.\n", strerror(ret));
426  ret = AVERROR(ret);
427  goto fail;
428  }
429 
430  return 0;
431 fail:
432  av_thread_message_queue_free(&d->in_thread_queue);
433  return ret;
434 }
435 
437 {
439  InputStream *ist;
440  DemuxMsg msg;
441  int ret;
442 
443  if (!d->in_thread_queue) {
444  ret = thread_start(d);
445  if (ret < 0)
446  return ret;
447  }
448 
449  if (f->readrate || f->rate_emu) {
450  int i;
451  int64_t file_start = copy_ts * (
452  (f->start_time_effective != AV_NOPTS_VALUE ? f->start_time_effective * !start_at_zero : 0) +
453  (f->start_time != AV_NOPTS_VALUE ? f->start_time : 0)
454  );
455  float scale = f->rate_emu ? 1.0 : f->readrate;
456  for (i = 0; i < f->nb_streams; i++) {
457  InputStream *ist = f->streams[i];
458  int64_t stream_ts_offset, pts, now;
459  if (!ist->nb_packets || (ist->decoding_needed && !ist->got_output)) continue;
460  stream_ts_offset = FFMAX(ist->first_dts != AV_NOPTS_VALUE ? ist->first_dts : 0, file_start);
461  pts = av_rescale(ist->dts, 1000000, AV_TIME_BASE);
462  now = (av_gettime_relative() - ist->start) * scale + stream_ts_offset;
463  if (pts > now)
464  return AVERROR(EAGAIN);
465  }
466  }
467 
468  ret = av_thread_message_queue_recv(d->in_thread_queue, &msg,
469  d->non_blocking ?
471  if (ret < 0)
472  return ret;
473  if (msg.looping)
474  return 1;
475 
476  ist = f->streams[msg.pkt->stream_index];
478 
479  *pkt = msg.pkt;
480  return 0;
481 }
482 
483 static void ist_free(InputStream **pist)
484 {
485  InputStream *ist = *pist;
486 
487  if (!ist)
488  return;
489 
491  av_packet_free(&ist->pkt);
492  av_dict_free(&ist->decoder_opts);
495  av_freep(&ist->filters);
496  av_freep(&ist->hwaccel_device);
497  av_freep(&ist->dts_buffer);
498 
501 
502  av_freep(pist);
503 }
504 
506 {
507  InputFile *f = *pf;
509 
510  if (!f)
511  return;
512 
513  thread_stop(d);
514 
515  for (int i = 0; i < f->nb_streams; i++)
516  ist_free(&f->streams[i]);
517  av_freep(&f->streams);
518 
519  avformat_close_input(&f->ctx);
520 
521  av_freep(pf);
522 }
523 
525  enum HWAccelID hwaccel_id, enum AVHWDeviceType hwaccel_device_type)
526 
527 {
528  char *codec_name = NULL;
529 
530  MATCH_PER_STREAM_OPT(codec_names, str, codec_name, s, st);
531  if (codec_name) {
532  const AVCodec *codec = find_codec_or_die(NULL, codec_name, st->codecpar->codec_type, 0);
533  st->codecpar->codec_id = codec->id;
534  if (recast_media && st->codecpar->codec_type != codec->type)
535  st->codecpar->codec_type = codec->type;
536  return codec;
537  } else {
538  if (st->codecpar->codec_type == AVMEDIA_TYPE_VIDEO &&
539  hwaccel_id == HWACCEL_GENERIC &&
540  hwaccel_device_type != AV_HWDEVICE_TYPE_NONE) {
541  const AVCodec *c;
542  void *i = NULL;
543 
544  while ((c = av_codec_iterate(&i))) {
545  const AVCodecHWConfig *config;
546 
547  if (c->id != st->codecpar->codec_id ||
549  continue;
550 
551  for (int j = 0; config = avcodec_get_hw_config(c, j); j++) {
552  if (config->device_type == hwaccel_device_type) {
553  av_log(NULL, AV_LOG_VERBOSE, "Selecting decoder '%s' because of requested hwaccel method %s\n",
554  c->name, av_hwdevice_get_type_name(hwaccel_device_type));
555  return c;
556  }
557  }
558  }
559  }
560 
562  }
563 }
564 
565 static int guess_input_channel_layout(InputStream *ist, int guess_layout_max)
566 {
567  AVCodecContext *dec = ist->dec_ctx;
568 
570  char layout_name[256];
571 
572  if (dec->ch_layout.nb_channels > guess_layout_max)
573  return 0;
576  return 0;
577  av_channel_layout_describe(&dec->ch_layout, layout_name, sizeof(layout_name));
578  av_log(ist, AV_LOG_WARNING, "Guessed Channel Layout: %s\n", layout_name);
579  }
580  return 1;
581 }
582 
585 {
586  AVStream *st = ist->st;
587  double rotation = DBL_MAX;
588  int hflip = -1, vflip = -1;
589  int hflip_set = 0, vflip_set = 0, rotation_set = 0;
590  int32_t *buf;
591 
592  MATCH_PER_STREAM_OPT(display_rotations, dbl, rotation, ctx, st);
593  MATCH_PER_STREAM_OPT(display_hflips, i, hflip, ctx, st);
594  MATCH_PER_STREAM_OPT(display_vflips, i, vflip, ctx, st);
595 
596  rotation_set = rotation != DBL_MAX;
597  hflip_set = hflip != -1;
598  vflip_set = vflip != -1;
599 
600  if (!rotation_set && !hflip_set && !vflip_set)
601  return;
602 
604  if (!buf) {
605  av_log(ist, AV_LOG_FATAL, "Failed to generate a display matrix!\n");
606  exit_program(1);
607  }
608 
610  rotation_set ? -(rotation) : -0.0f);
611 
613  hflip_set ? hflip : 0,
614  vflip_set ? vflip : 0);
615 }
616 
617 static const char *input_stream_item_name(void *obj)
618 {
619  const DemuxStream *ds = obj;
620 
621  return ds->log_name;
622 }
623 
624 static const AVClass input_stream_class = {
625  .class_name = "InputStream",
626  .version = LIBAVUTIL_VERSION_INT,
627  .item_name = input_stream_item_name,
628  .category = AV_CLASS_CATEGORY_DEMUXER,
629 };
630 
632 {
633  const char *type_str = av_get_media_type_string(st->codecpar->codec_type);
634  InputFile *f = &d->f;
635  DemuxStream *ds = allocate_array_elem(&f->streams, sizeof(*ds),
636  &f->nb_streams);
637 
638  ds->ist.st = st;
639  ds->ist.file_index = f->index;
641 
642  snprintf(ds->log_name, sizeof(ds->log_name), "%cist#%d:%d/%s",
643  type_str ? *type_str : '?', d->f.index, st->index,
645 
646  return ds;
647 }
648 
649 /* Add all the streams from the given input file to the demuxer */
650 static void add_input_streams(const OptionsContext *o, Demuxer *d)
651 {
652  InputFile *f = &d->f;
653  AVFormatContext *ic = f->ctx;
654  int i, ret;
655 
656  for (i = 0; i < ic->nb_streams; i++) {
657  AVStream *st = ic->streams[i];
658  AVCodecParameters *par = st->codecpar;
659  DemuxStream *ds;
660  InputStream *ist;
661  char *framerate = NULL, *hwaccel_device = NULL;
662  const char *hwaccel = NULL;
663  char *hwaccel_output_format = NULL;
664  char *codec_tag = NULL;
665  char *next;
666  char *discard_str = NULL;
667  const AVClass *cc = avcodec_get_class();
668  const AVOption *discard_opt = av_opt_find(&cc, "skip_frame", NULL,
670 
671  ds = demux_stream_alloc(d, st);
672  ist = &ds->ist;
673 
674  ist->discard = 1;
675  st->discard = AVDISCARD_ALL;
676  ist->nb_samples = 0;
677  ist->first_dts = AV_NOPTS_VALUE;
678  ds->min_pts = INT64_MAX;
679  ds->max_pts = INT64_MIN;
680 
681  ds->ts_scale = 1.0;
682  MATCH_PER_STREAM_OPT(ts_scale, dbl, ds->ts_scale, ic, st);
683 
684  ist->autorotate = 1;
686 
687  MATCH_PER_STREAM_OPT(codec_tags, str, codec_tag, ic, st);
688  if (codec_tag) {
689  uint32_t tag = strtol(codec_tag, &next, 0);
690  if (*next)
691  tag = AV_RL32(codec_tag);
692  st->codecpar->codec_tag = tag;
693  }
694 
695  if (st->codecpar->codec_type == AVMEDIA_TYPE_VIDEO) {
696  add_display_matrix_to_stream(o, ic, ist);
697 
698  MATCH_PER_STREAM_OPT(hwaccels, str, hwaccel, ic, st);
699  MATCH_PER_STREAM_OPT(hwaccel_output_formats, str,
700  hwaccel_output_format, ic, st);
701 
702  if (!hwaccel_output_format && hwaccel && !strcmp(hwaccel, "cuvid")) {
703  av_log(ist, AV_LOG_WARNING,
704  "WARNING: defaulting hwaccel_output_format to cuda for compatibility "
705  "with old commandlines. This behaviour is DEPRECATED and will be removed "
706  "in the future. Please explicitly set \"-hwaccel_output_format cuda\".\n");
708  } else if (!hwaccel_output_format && hwaccel && !strcmp(hwaccel, "qsv")) {
709  av_log(ist, AV_LOG_WARNING,
710  "WARNING: defaulting hwaccel_output_format to qsv for compatibility "
711  "with old commandlines. This behaviour is DEPRECATED and will be removed "
712  "in the future. Please explicitly set \"-hwaccel_output_format qsv\".\n");
714  } else if (!hwaccel_output_format && hwaccel && !strcmp(hwaccel, "mediacodec")) {
715  // There is no real AVHWFrameContext implementation. Set
716  // hwaccel_output_format to avoid av_hwframe_transfer_data error.
718  } else if (hwaccel_output_format) {
719  ist->hwaccel_output_format = av_get_pix_fmt(hwaccel_output_format);
721  av_log(ist, AV_LOG_FATAL, "Unrecognised hwaccel output "
722  "format: %s", hwaccel_output_format);
723  }
724  } else {
726  }
727 
728  if (hwaccel) {
729  // The NVDEC hwaccels use a CUDA device, so remap the name here.
730  if (!strcmp(hwaccel, "nvdec") || !strcmp(hwaccel, "cuvid"))
731  hwaccel = "cuda";
732 
733  if (!strcmp(hwaccel, "none"))
734  ist->hwaccel_id = HWACCEL_NONE;
735  else if (!strcmp(hwaccel, "auto"))
736  ist->hwaccel_id = HWACCEL_AUTO;
737  else {
739  if (type != AV_HWDEVICE_TYPE_NONE) {
741  ist->hwaccel_device_type = type;
742  }
743 
744  if (!ist->hwaccel_id) {
745  av_log(ist, AV_LOG_FATAL, "Unrecognized hwaccel: %s.\n",
746  hwaccel);
747  av_log(ist, AV_LOG_FATAL, "Supported hwaccels: ");
749  while ((type = av_hwdevice_iterate_types(type)) !=
751  av_log(ist, AV_LOG_FATAL, "%s ",
753  av_log(ist, AV_LOG_FATAL, "\n");
754  exit_program(1);
755  }
756  }
757  }
758 
759  MATCH_PER_STREAM_OPT(hwaccel_devices, str, hwaccel_device, ic, st);
760  if (hwaccel_device) {
761  ist->hwaccel_device = av_strdup(hwaccel_device);
762  if (!ist->hwaccel_device)
763  report_and_exit(AVERROR(ENOMEM));
764  }
765 
767  }
768 
769  ist->dec = choose_decoder(o, ic, st, ist->hwaccel_id, ist->hwaccel_device_type);
770  ist->decoder_opts = filter_codec_opts(o->g->codec_opts, ist->st->codecpar->codec_id, ic, st, ist->dec);
771 
772  ist->reinit_filters = -1;
773  MATCH_PER_STREAM_OPT(reinit_filters, i, ist->reinit_filters, ic, st);
774 
775  MATCH_PER_STREAM_OPT(discard, str, discard_str, ic, st);
777 
778  if ((o->video_disable && ist->st->codecpar->codec_type == AVMEDIA_TYPE_VIDEO) ||
783 
784  if (discard_str && av_opt_eval_int(&cc, discard_opt, discard_str, &ist->user_set_discard) < 0) {
785  av_log(ist, AV_LOG_ERROR, "Error parsing discard %s.\n",
786  discard_str);
787  exit_program(1);
788  }
789 
792 
793  ist->dec_ctx = avcodec_alloc_context3(ist->dec);
794  if (!ist->dec_ctx)
795  report_and_exit(AVERROR(ENOMEM));
796 
798  if (ret < 0) {
799  av_log(ist, AV_LOG_ERROR, "Error initializing the decoder context.\n");
800  exit_program(1);
801  }
802 
803  ist->decoded_frame = av_frame_alloc();
804  if (!ist->decoded_frame)
805  report_and_exit(AVERROR(ENOMEM));
806 
807  ist->pkt = av_packet_alloc();
808  if (!ist->pkt)
809  report_and_exit(AVERROR(ENOMEM));
810 
811  if (o->bitexact)
813 
814  switch (par->codec_type) {
815  case AVMEDIA_TYPE_VIDEO:
816  // avformat_find_stream_info() doesn't set this for us anymore.
817  ist->dec_ctx->framerate = st->avg_frame_rate;
818 
819  MATCH_PER_STREAM_OPT(frame_rates, str, framerate, ic, st);
821  framerate) < 0) {
822  av_log(ist, AV_LOG_ERROR, "Error parsing framerate %s.\n",
823  framerate);
824  exit_program(1);
825  }
826 
827  ist->top_field_first = -1;
828  MATCH_PER_STREAM_OPT(top_field_first, i, ist->top_field_first, ic, st);
829 
831 
832  break;
833  case AVMEDIA_TYPE_AUDIO: {
834  int guess_layout_max = INT_MAX;
835  MATCH_PER_STREAM_OPT(guess_layout_max, i, guess_layout_max, ic, st);
836  guess_input_channel_layout(ist, guess_layout_max);
837  break;
838  }
839  case AVMEDIA_TYPE_DATA:
840  case AVMEDIA_TYPE_SUBTITLE: {
841  char *canvas_size = NULL;
842  MATCH_PER_STREAM_OPT(fix_sub_duration, i, ist->fix_sub_duration, ic, st);
843  MATCH_PER_STREAM_OPT(canvas_sizes, str, canvas_size, ic, st);
844  if (canvas_size &&
845  av_parse_video_size(&ist->dec_ctx->width, &ist->dec_ctx->height, canvas_size) < 0) {
846  av_log(ist, AV_LOG_FATAL, "Invalid canvas size: %s.\n", canvas_size);
847  exit_program(1);
848  }
849  break;
850  }
853  break;
854  default:
855  abort();
856  }
857 
858  ist->par = avcodec_parameters_alloc();
859  if (!ist->par)
860  report_and_exit(AVERROR(ENOMEM));
861 
863  if (ret < 0) {
864  av_log(ist, AV_LOG_ERROR, "Error initializing the decoder context.\n");
865  exit_program(1);
866  }
867  }
868 }
869 
870 static void dump_attachment(InputStream *ist, const char *filename)
871 {
872  AVStream *st = ist->st;
873  int ret;
874  AVIOContext *out = NULL;
875  const AVDictionaryEntry *e;
876 
877  if (!st->codecpar->extradata_size) {
878  av_log(ist, AV_LOG_WARNING, "No extradata to dump.\n");
879  return;
880  }
881  if (!*filename && (e = av_dict_get(st->metadata, "filename", NULL, 0)))
882  filename = e->value;
883  if (!*filename) {
884  av_log(ist, AV_LOG_FATAL, "No filename specified and no 'filename' tag");
885  exit_program(1);
886  }
887 
888  assert_file_overwrite(filename);
889 
890  if ((ret = avio_open2(&out, filename, AVIO_FLAG_WRITE, &int_cb, NULL)) < 0) {
891  av_log(ist, AV_LOG_FATAL, "Could not open file %s for writing.\n",
892  filename);
893  exit_program(1);
894  }
895 
897  avio_flush(out);
898  avio_close(out);
899 }
900 
901 static const char *input_file_item_name(void *obj)
902 {
903  const Demuxer *d = obj;
904 
905  return d->log_name;
906 }
907 
908 static const AVClass input_file_class = {
909  .class_name = "InputFile",
910  .version = LIBAVUTIL_VERSION_INT,
911  .item_name = input_file_item_name,
912  .category = AV_CLASS_CATEGORY_DEMUXER,
913 };
914 
915 static Demuxer *demux_alloc(void)
916 {
918 
919  d->f.class = &input_file_class;
920  d->f.index = nb_input_files - 1;
921 
922  snprintf(d->log_name, sizeof(d->log_name), "in#%d", d->f.index);
923 
924  return d;
925 }
926 
927 int ifile_open(const OptionsContext *o, const char *filename)
928 {
929  Demuxer *d;
930  InputFile *f;
931  AVFormatContext *ic;
933  int err, i, ret;
934  int64_t timestamp;
935  AVDictionary *unused_opts = NULL;
936  const AVDictionaryEntry *e = NULL;
937  char * video_codec_name = NULL;
938  char * audio_codec_name = NULL;
939  char *subtitle_codec_name = NULL;
940  char * data_codec_name = NULL;
941  int scan_all_pmts_set = 0;
942 
943  int64_t start_time = o->start_time;
944  int64_t start_time_eof = o->start_time_eof;
945  int64_t stop_time = o->stop_time;
946  int64_t recording_time = o->recording_time;
947 
948  d = demux_alloc();
949  f = &d->f;
950 
951  if (stop_time != INT64_MAX && recording_time != INT64_MAX) {
952  stop_time = INT64_MAX;
953  av_log(d, AV_LOG_WARNING, "-t and -to cannot be used together; using -t.\n");
954  }
955 
956  if (stop_time != INT64_MAX && recording_time == INT64_MAX) {
957  int64_t start = start_time == AV_NOPTS_VALUE ? 0 : start_time;
958  if (stop_time <= start) {
959  av_log(d, AV_LOG_ERROR, "-to value smaller than -ss; aborting.\n");
960  exit_program(1);
961  } else {
962  recording_time = stop_time - start;
963  }
964  }
965 
966  if (o->format) {
968  av_log(d, AV_LOG_FATAL, "Unknown input format: '%s'\n", o->format);
969  exit_program(1);
970  }
971  }
972 
973  if (!strcmp(filename, "-"))
974  filename = "fd:";
975 
976  stdin_interaction &= strncmp(filename, "pipe:", 5) &&
977  strcmp(filename, "fd:") &&
978  strcmp(filename, "/dev/stdin");
979 
980  /* get default parameters from command line */
981  ic = avformat_alloc_context();
982  if (!ic)
983  report_and_exit(AVERROR(ENOMEM));
984  if (o->nb_audio_sample_rate) {
985  av_dict_set_int(&o->g->format_opts, "sample_rate", o->audio_sample_rate[o->nb_audio_sample_rate - 1].u.i, 0);
986  }
987  if (o->nb_audio_channels) {
988  const AVClass *priv_class;
989  if (file_iformat && (priv_class = file_iformat->priv_class) &&
990  av_opt_find(&priv_class, "ch_layout", NULL, 0,
992  char buf[32];
993  snprintf(buf, sizeof(buf), "%dC", o->audio_channels[o->nb_audio_channels - 1].u.i);
994  av_dict_set(&o->g->format_opts, "ch_layout", buf, 0);
995  }
996  }
997  if (o->nb_audio_ch_layouts) {
998  const AVClass *priv_class;
999  if (file_iformat && (priv_class = file_iformat->priv_class) &&
1000  av_opt_find(&priv_class, "ch_layout", NULL, 0,
1002  av_dict_set(&o->g->format_opts, "ch_layout", o->audio_ch_layouts[o->nb_audio_ch_layouts - 1].u.str, 0);
1003  }
1004  }
1005  if (o->nb_frame_rates) {
1006  const AVClass *priv_class;
1007  /* set the format-level framerate option;
1008  * this is important for video grabbers, e.g. x11 */
1009  if (file_iformat && (priv_class = file_iformat->priv_class) &&
1010  av_opt_find(&priv_class, "framerate", NULL, 0,
1012  av_dict_set(&o->g->format_opts, "framerate",
1013  o->frame_rates[o->nb_frame_rates - 1].u.str, 0);
1014  }
1015  }
1016  if (o->nb_frame_sizes) {
1017  av_dict_set(&o->g->format_opts, "video_size", o->frame_sizes[o->nb_frame_sizes - 1].u.str, 0);
1018  }
1019  if (o->nb_frame_pix_fmts)
1020  av_dict_set(&o->g->format_opts, "pixel_format", o->frame_pix_fmts[o->nb_frame_pix_fmts - 1].u.str, 0);
1021 
1022  MATCH_PER_TYPE_OPT(codec_names, str, video_codec_name, ic, "v");
1023  MATCH_PER_TYPE_OPT(codec_names, str, audio_codec_name, ic, "a");
1024  MATCH_PER_TYPE_OPT(codec_names, str, subtitle_codec_name, ic, "s");
1025  MATCH_PER_TYPE_OPT(codec_names, str, data_codec_name, ic, "d");
1026 
1027  if (video_codec_name)
1029  if (audio_codec_name)
1031  if (subtitle_codec_name)
1033  if (data_codec_name)
1034  ic->data_codec = find_codec_or_die(NULL, data_codec_name , AVMEDIA_TYPE_DATA , 0);
1035 
1039  ic->data_codec_id = data_codec_name ? ic->data_codec->id : AV_CODEC_ID_NONE;
1040 
1041  ic->flags |= AVFMT_FLAG_NONBLOCK;
1042  if (o->bitexact)
1043  ic->flags |= AVFMT_FLAG_BITEXACT;
1044  ic->interrupt_callback = int_cb;
1045 
1046  if (!av_dict_get(o->g->format_opts, "scan_all_pmts", NULL, AV_DICT_MATCH_CASE)) {
1047  av_dict_set(&o->g->format_opts, "scan_all_pmts", "1", AV_DICT_DONT_OVERWRITE);
1048  scan_all_pmts_set = 1;
1049  }
1050  /* open the input file with generic avformat function */
1051  err = avformat_open_input(&ic, filename, file_iformat, &o->g->format_opts);
1052  if (err < 0) {
1053  print_error(filename, err);
1054  if (err == AVERROR_PROTOCOL_NOT_FOUND)
1055  av_log(d, AV_LOG_ERROR, "Did you mean file:%s?\n", filename);
1056  exit_program(1);
1057  }
1058 
1059  av_strlcat(d->log_name, "/", sizeof(d->log_name));
1060  av_strlcat(d->log_name, ic->iformat->name, sizeof(d->log_name));
1061 
1062  if (scan_all_pmts_set)
1063  av_dict_set(&o->g->format_opts, "scan_all_pmts", NULL, AV_DICT_MATCH_CASE);
1066 
1067  /* apply forced codec ids */
1068  for (i = 0; i < ic->nb_streams; i++)
1070 
1071  if (o->find_stream_info) {
1073  int orig_nb_streams = ic->nb_streams;
1074 
1075  /* If not enough info to get the stream parameters, we decode the
1076  first frames to get it. (used in mpeg case for example) */
1078 
1079  for (i = 0; i < orig_nb_streams; i++)
1080  av_dict_free(&opts[i]);
1081  av_freep(&opts);
1082 
1083  if (ret < 0) {
1084  av_log(d, AV_LOG_FATAL, "could not find codec parameters\n");
1085  if (ic->nb_streams == 0) {
1086  avformat_close_input(&ic);
1087  exit_program(1);
1088  }
1089  }
1090  }
1091 
1092  if (start_time != AV_NOPTS_VALUE && start_time_eof != AV_NOPTS_VALUE) {
1093  av_log(d, AV_LOG_WARNING, "Cannot use -ss and -sseof both, using -ss\n");
1094  start_time_eof = AV_NOPTS_VALUE;
1095  }
1096 
1097  if (start_time_eof != AV_NOPTS_VALUE) {
1098  if (start_time_eof >= 0) {
1099  av_log(d, AV_LOG_ERROR, "-sseof value must be negative; aborting\n");
1100  exit_program(1);
1101  }
1102  if (ic->duration > 0) {
1103  start_time = start_time_eof + ic->duration;
1104  if (start_time < 0) {
1105  av_log(d, AV_LOG_WARNING, "-sseof value seeks to before start of file; ignored\n");
1107  }
1108  } else
1109  av_log(d, AV_LOG_WARNING, "Cannot use -sseof, file duration not known\n");
1110  }
1111  timestamp = (start_time == AV_NOPTS_VALUE) ? 0 : start_time;
1112  /* add the stream start time */
1113  if (!o->seek_timestamp && ic->start_time != AV_NOPTS_VALUE)
1114  timestamp += ic->start_time;
1115 
1116  /* if seeking requested, we execute it */
1117  if (start_time != AV_NOPTS_VALUE) {
1118  int64_t seek_timestamp = timestamp;
1119 
1120  if (!(ic->iformat->flags & AVFMT_SEEK_TO_PTS)) {
1121  int dts_heuristic = 0;
1122  for (i=0; i<ic->nb_streams; i++) {
1123  const AVCodecParameters *par = ic->streams[i]->codecpar;
1124  if (par->video_delay) {
1125  dts_heuristic = 1;
1126  break;
1127  }
1128  }
1129  if (dts_heuristic) {
1130  seek_timestamp -= 3*AV_TIME_BASE / 23;
1131  }
1132  }
1133  ret = avformat_seek_file(ic, -1, INT64_MIN, seek_timestamp, seek_timestamp, 0);
1134  if (ret < 0) {
1135  av_log(d, AV_LOG_WARNING, "could not seek to position %0.3f\n",
1136  (double)timestamp / AV_TIME_BASE);
1137  }
1138  }
1139 
1140  f->ctx = ic;
1141  f->start_time = start_time;
1142  f->recording_time = recording_time;
1143  f->input_sync_ref = o->input_sync_ref;
1144  f->input_ts_offset = o->input_ts_offset;
1145  f->ts_offset = o->input_ts_offset - (copy_ts ? (start_at_zero && ic->start_time != AV_NOPTS_VALUE ? ic->start_time : 0) : timestamp);
1146  f->rate_emu = o->rate_emu;
1147  f->accurate_seek = o->accurate_seek;
1148  d->loop = o->loop;
1149  d->duration = 0;
1150  d->time_base = (AVRational){ 1, 1 };
1151 
1152  f->readrate = o->readrate ? o->readrate : 0.0;
1153  if (f->readrate < 0.0f) {
1154  av_log(d, AV_LOG_ERROR, "Option -readrate is %0.3f; it must be non-negative.\n", f->readrate);
1155  exit_program(1);
1156  }
1157  if (f->readrate && f->rate_emu) {
1158  av_log(d, AV_LOG_WARNING, "Both -readrate and -re set. Using -readrate %0.3f.\n", f->readrate);
1159  f->rate_emu = 0;
1160  }
1161 
1162  d->thread_queue_size = o->thread_queue_size;
1163 
1164  /* update the current parameters so that they match the one of the input stream */
1165  add_input_streams(o, d);
1166 
1167  /* dump the file content */
1168  av_dump_format(ic, f->index, filename, 0);
1169 
1170  /* check if all codec options have been used */
1171  unused_opts = strip_specifiers(o->g->codec_opts);
1172  for (i = 0; i < f->nb_streams; i++) {
1173  e = NULL;
1174  while ((e = av_dict_iterate(f->streams[i]->decoder_opts, e)))
1175  av_dict_set(&unused_opts, e->key, NULL, 0);
1176  }
1177 
1178  e = NULL;
1179  while ((e = av_dict_iterate(unused_opts, e))) {
1180  const AVClass *class = avcodec_get_class();
1181  const AVOption *option = av_opt_find(&class, e->key, NULL, 0,
1183  const AVClass *fclass = avformat_get_class();
1184  const AVOption *foption = av_opt_find(&fclass, e->key, NULL, 0,
1186  if (!option || foption)
1187  continue;
1188 
1189 
1190  if (!(option->flags & AV_OPT_FLAG_DECODING_PARAM)) {
1191  av_log(d, AV_LOG_ERROR, "Codec AVOption %s (%s) is not a decoding "
1192  "option.\n", e->key, option->help ? option->help : "");
1193  exit_program(1);
1194  }
1195 
1196  av_log(d, AV_LOG_WARNING, "Codec AVOption %s (%s) has not been used "
1197  "for any stream. The most likely reason is either wrong type "
1198  "(e.g. a video option with no video streams) or that it is a "
1199  "private option of some decoder which was not actually used "
1200  "for any stream.\n", e->key, option->help ? option->help : "");
1201  }
1202  av_dict_free(&unused_opts);
1203 
1204  for (i = 0; i < o->nb_dump_attachment; i++) {
1205  int j;
1206 
1207  for (j = 0; j < f->nb_streams; j++) {
1208  InputStream *ist = f->streams[j];
1209 
1210  if (check_stream_specifier(ic, ist->st, o->dump_attachment[i].specifier) == 1)
1212  }
1213  }
1214 
1215  return 0;
1216 }
OptionsContext::readrate
float readrate
Definition: ffmpeg.h:126
input_thread
static void * input_thread(void *arg)
Definition: ffmpeg_demux.c:263
av_packet_unref
void av_packet_unref(AVPacket *pkt)
Wipe the packet.
Definition: avpacket.c:422
AVCodec
AVCodec.
Definition: codec.h:184
OptionsContext::input_ts_offset
int64_t input_ts_offset
Definition: ffmpeg.h:123
pthread_join
static av_always_inline int pthread_join(pthread_t thread, void **value_ptr)
Definition: os2threads.h:94
AVMEDIA_TYPE_SUBTITLE
@ AVMEDIA_TYPE_SUBTITLE
Definition: avutil.h:204
DemuxStream::ist
InputStream ist
Definition: ffmpeg_demux.c:56
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
AV_PIX_FMT_CUDA
@ AV_PIX_FMT_CUDA
HW acceleration through CUDA.
Definition: pixfmt.h:253
AVCodecParameters::extradata
uint8_t * extradata
Extra binary data needed for initializing the decoder, codec-dependent.
Definition: codec_par.h:76
name
it s the only field you need to keep assuming you have a context There is some magic you don t need to care about around this just let it vf default minimum maximum flags name is the option name
Definition: writing_filters.txt:88
OptionsContext::stop_time
int64_t stop_time
Definition: ffmpeg.h:158
InputStream::hwaccel_device
char * hwaccel_device
Definition: ffmpeg.h:421
OptionsContext::dump_attachment
SpecifierOpt * dump_attachment
Definition: ffmpeg.h:134
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:144
opt.h
OptionsContext::nb_audio_sample_rate
int nb_audio_sample_rate
Definition: ffmpeg.h:112
MATCH_PER_STREAM_OPT
#define MATCH_PER_STREAM_OPT(name, type, outvar, fmtctx, st)
Definition: ffmpeg.h:877
AVCodecParameters::codec_type
enum AVMediaType codec_type
General type of the encoded data.
Definition: codec_par.h:58
input_stream_class
static const AVClass input_stream_class
Definition: ffmpeg_demux.c:624
av_compare_ts
int av_compare_ts(int64_t ts_a, AVRational tb_a, int64_t ts_b, AVRational tb_b)
Compare two timestamps each in its own time base.
Definition: mathematics.c:147
InputStream::framerate_guessed
AVRational framerate_guessed
Definition: ffmpeg.h:360
avio_close
int avio_close(AVIOContext *s)
Close the resource accessed by the AVIOContext s and free it.
Definition: aviobuf.c:1247
out
FILE * out
Definition: movenc.c:54
ifile_open
int ifile_open(const OptionsContext *o, const char *filename)
Definition: ffmpeg_demux.c:927
is
The official guide to swscale for confused that is
Definition: swscale.txt:28
OptionsContext::nb_audio_ch_layouts
int nb_audio_ch_layouts
Definition: ffmpeg.h:108
AVCodecParameters
This struct describes the properties of an encoded stream.
Definition: codec_par.h:54
thread.h
AVERROR_EOF
#define AVERROR_EOF
End of file.
Definition: error.h:57
AVStream::discard
enum AVDiscard discard
Selects which packets can be discarded at will and do not need to be demuxed.
Definition: avformat.h:909
MATCH_PER_TYPE_OPT
#define MATCH_PER_TYPE_OPT(name, type, outvar, fmtctx, mediatype)
Definition: ffmpeg.h:894
avcodec_parameters_from_context
int avcodec_parameters_from_context(AVCodecParameters *par, const AVCodecContext *codec)
Fill the parameters struct based on the values from the supplied codec context.
Definition: codec_par.c:99
remove_avoptions
void remove_avoptions(AVDictionary **a, AVDictionary *b)
Definition: ffmpeg.c:620
InputStream::dec_ctx
AVCodecContext * dec_ctx
Definition: ffmpeg.h:355
AV_TIME_BASE_Q
#define AV_TIME_BASE_Q
Internal time base represented as fractional value.
Definition: avutil.h:260
InputStream::user_set_discard
int user_set_discard
Definition: ffmpeg.h:341
avformat_get_class
const AVClass * avformat_get_class(void)
Get the AVClass for AVFormatContext.
Definition: options.c:203
av_frame_free
void av_frame_free(AVFrame **frame)
Free the frame and any dynamically allocated objects in it, e.g.
Definition: frame.c:101
AV_THREAD_MESSAGE_NONBLOCK
@ AV_THREAD_MESSAGE_NONBLOCK
Perform non-blocking operation.
Definition: threadmessage.h:31
pixdesc.h
AVFormatContext::streams
AVStream ** streams
A list of all streams in the file.
Definition: avformat.h:1172
ifile_close
void ifile_close(InputFile **pf)
Definition: ffmpeg_demux.c:505
av_display_matrix_flip
void av_display_matrix_flip(int32_t matrix[9], int hflip, int vflip)
Flip the input matrix horizontally and/or vertically.
Definition: display.c:66
subtitle_codec_name
static const char * subtitle_codec_name
Definition: ffplay.c:340
AV_HWDEVICE_TYPE_NONE
@ AV_HWDEVICE_TYPE_NONE
Definition: hwcontext.h:28
LastFrameDuration::stream_idx
int stream_idx
Definition: ffmpeg.h:443
OptionsContext::subtitle_disable
int subtitle_disable
Definition: ffmpeg.h:168
demux_stream_alloc
static DemuxStream * demux_stream_alloc(Demuxer *d, AVStream *st)
Definition: ffmpeg_demux.c:631
AVOption
AVOption.
Definition: opt.h:251
ts_fixup
static void ts_fixup(Demuxer *d, AVPacket *pkt, int *repeat_pict)
Definition: ffmpeg_demux.c:189
AVStream::avg_frame_rate
AVRational avg_frame_rate
Average framerate.
Definition: avformat.h:927
dump_attachment
static void dump_attachment(InputStream *ist, const char *filename)
Definition: ffmpeg_demux.c:870
av_hwdevice_find_type_by_name
enum AVHWDeviceType av_hwdevice_find_type_by_name(const char *name)
Look up an AVHWDeviceType by name.
Definition: hwcontext.c:83
ffmpeg.h
AV_LOG_VERBOSE
#define AV_LOG_VERBOSE
Detailed information.
Definition: log.h:196
float.h
av_hwdevice_iterate_types
enum AVHWDeviceType av_hwdevice_iterate_types(enum AVHWDeviceType prev)
Iterate over supported device types.
Definition: hwcontext.c:102
OptionsContext::bitexact
int bitexact
Definition: ffmpeg.h:164
autorotate
static int autorotate
Definition: ffplay.c:348
av_display_rotation_set
void av_display_rotation_set(int32_t matrix[9], double angle)
Initialize a transformation matrix describing a pure clockwise rotation by the specified angle (in de...
Definition: display.c:51
OptionsContext::audio_channels
SpecifierOpt * audio_channels
Definition: ffmpeg.h:109
DemuxMsg::pkt
AVPacket * pkt
Definition: ffmpeg_demux.c:91
OptionsContext::nb_frame_rates
int nb_frame_rates
Definition: ffmpeg.h:114
AVCodecParameters::codec_tag
uint32_t codec_tag
Additional information about the codec (corresponds to the AVI FOURCC).
Definition: codec_par.h:66
AVDictionary
Definition: dict.c:32
AVChannelLayout::order
enum AVChannelOrder order
Channel order used in this layout.
Definition: channel_layout.h:306
FFMAX
#define FFMAX(a, b)
Definition: macros.h:47
av_read_frame
int av_read_frame(AVFormatContext *s, AVPacket *pkt)
Return the next frame of a stream.
Definition: demux.c:1439
AVFormatContext::video_codec_id
enum AVCodecID video_codec_id
Forced video codec_id.
Definition: avformat.h:1276
InputStream::decoding_needed
int decoding_needed
Definition: ffmpeg.h:342
LastFrameDuration
Definition: ffmpeg.h:442
OptionsContext::format
const char * format
Definition: ffmpeg.h:103
AVChannelLayout::nb_channels
int nb_channels
Number of channels in this layout.
Definition: channel_layout.h:311
tf_sess_config.config
config
Definition: tf_sess_config.py:33
file_iformat
static const AVInputFormat * file_iformat
Definition: ffplay.c:305
av_packet_free
void av_packet_free(AVPacket **pkt)
Free the packet, if the packet is reference counted, it will be unreferenced first.
Definition: avpacket.c:73
choose_decoder
static const AVCodec * choose_decoder(const OptionsContext *o, AVFormatContext *s, AVStream *st, enum HWAccelID hwaccel_id, enum AVHWDeviceType hwaccel_device_type)
Definition: ffmpeg_demux.c:524
exit_program
void exit_program(int ret)
Wraps exit with a program-specific cleanup routine.
Definition: cmdutils.c:99
SpecifierOpt::i
int i
Definition: cmdutils.h:138
InputStream
Definition: ffmpeg.h:335
AVCodecContext::framerate
AVRational framerate
Definition: avcodec.h:1771
framerate
int framerate
Definition: h264_levels.c:65
avformat_close_input
void avformat_close_input(AVFormatContext **s)
Close an opened input AVFormatContext.
Definition: demux.c:369
AVFormatContext::interrupt_callback
AVIOInterruptCB interrupt_callback
Custom interrupt callbacks for the I/O layer.
Definition: avformat.h:1368
Demuxer
Definition: ffmpeg_demux.c:67
OptionsContext::rate_emu
int rate_emu
Definition: ffmpeg.h:125
opt_name_fix_sub_duration
static const char *const opt_name_fix_sub_duration[]
Definition: ffmpeg_demux.c:43
print_error
void print_error(const char *filename, int err)
Print an error message to stderr, indicating filename and a human readable description of the error c...
Definition: cmdutils.c:799
avio_open2
int avio_open2(AVIOContext **s, const char *url, int flags, const AVIOInterruptCB *int_cb, AVDictionary **options)
Create and initialize a AVIOContext for accessing the resource indicated by url.
Definition: aviobuf.c:1241
finish
static void finish(void)
Definition: movenc.c:342
assert_file_overwrite
void assert_file_overwrite(const char *filename)
Definition: ffmpeg_opt.c:656
AVFMT_SEEK_TO_PTS
#define AVFMT_SEEK_TO_PTS
Seeking is based on PTS.
Definition: avformat.h:501
opt_name_display_vflips
static const char *const opt_name_display_vflips[]
Definition: ffmpeg_demux.c:53
OptionsContext::nb_dump_attachment
int nb_dump_attachment
Definition: ffmpeg.h:135
OptionsContext::g
OptionGroup * g
Definition: ffmpeg.h:97
AVCodecContext::ch_layout
AVChannelLayout ch_layout
Audio channel layout.
Definition: avcodec.h:2075
report_and_exit
void report_and_exit(int ret)
Reports an error corresponding to the provided AVERROR code and calls exit_program() with the corresp...
Definition: cmdutils.c:93
InputStream::sub2video
struct InputStream::sub2video sub2video
Demuxer::log_name
char log_name[32]
Definition: ffmpeg_demux.c:71
fail
#define fail()
Definition: checkasm.h:135
opt_name_hwaccel_output_formats
static const char *const opt_name_hwaccel_output_formats[]
Definition: ffmpeg_demux.c:49
InputStream::decoder_opts
AVDictionary * decoder_opts
Definition: ffmpeg.h:389
opt_name_autorotate
static const char *const opt_name_autorotate[]
Definition: ffmpeg_demux.c:50
InputStream::filter_in_rescale_delta_last
int64_t filter_in_rescale_delta_last
Definition: ffmpeg.h:380
input_file_item_name
static const char * input_file_item_name(void *obj)
Definition: ffmpeg_demux.c:901
AVDISCARD_NONE
@ AVDISCARD_NONE
discard nothing
Definition: defs.h:70
AVCodecContext::flags
int flags
AV_CODEC_FLAG_*.
Definition: avcodec.h:515
InputStream::nb_packets
uint64_t nb_packets
Definition: ffmpeg.h:431
type
it s the only field you need to keep assuming you have a context There is some magic you don t need to care about around this just let it vf type
Definition: writing_filters.txt:86
opt_name_display_hflips
static const char *const opt_name_display_hflips[]
Definition: ffmpeg_demux.c:52
scale
static av_always_inline float scale(float x, float s)
Definition: vf_v360.c:1389
pts
static int64_t pts
Definition: transcode_aac.c:653
av_thread_message_queue_recv
int av_thread_message_queue_recv(AVThreadMessageQueue *mq, void *msg, unsigned flags)
Receive a message from the queue.
Definition: threadmessage.c:174
OptionsContext
Definition: ffmpeg.h:96
AV_PKT_DATA_DISPLAYMATRIX
@ AV_PKT_DATA_DISPLAYMATRIX
This side data contains a 3x3 transformation matrix describing an affine transformation that needs to...
Definition: packet.h:109
do_pkt_dump
int do_pkt_dump
Definition: ffmpeg_opt.c:75
AVRational::num
int num
Numerator.
Definition: rational.h:59
Demuxer::f
InputFile f
Definition: ffmpeg_demux.c:68
InputFile
Definition: ffmpeg.h:447
avsubtitle_free
void avsubtitle_free(AVSubtitle *sub)
Free all allocated data in the given subtitle struct.
Definition: avcodec.c:409
ifile_get_packet
int ifile_get_packet(InputFile *f, AVPacket **pkt)
Get next input packet from the demuxer.
Definition: ffmpeg_demux.c:436
OptionsContext::recording_time
int64_t recording_time
Definition: ffmpeg.h:157
av_frame_alloc
AVFrame * av_frame_alloc(void)
Allocate an AVFrame and set its fields to default values.
Definition: frame.c:89
InputStream::last_pkt_repeat_pict
int last_pkt_repeat_pict
Definition: ffmpeg.h:378
OptionsContext::audio_disable
int audio_disable
Definition: ffmpeg.h:167
check_stream_specifier
int check_stream_specifier(AVFormatContext *s, AVStream *st, const char *spec)
Check if the given stream matches a stream specifier.
Definition: cmdutils.c:887
InputStream::first_dts
int64_t first_dts
dts of the first packet read for this stream (in AV_TIME_BASE units)
Definition: ffmpeg.h:367
InputStream::hwaccel_pix_fmt
enum AVPixelFormat hwaccel_pix_fmt
Definition: ffmpeg.h:425
avassert.h
InputStream::dts
int64_t dts
dts of the last packet read for this stream (in AV_TIME_BASE units)
Definition: ffmpeg.h:368
pkt
AVPacket * pkt
Definition: movenc.c:59
AV_LOG_ERROR
#define AV_LOG_ERROR
Something went wrong and cannot losslessly be recovered.
Definition: log.h:180
opt_name_display_rotations
static const char *const opt_name_display_rotations[]
Definition: ffmpeg_demux.c:51
AVInputFormat
Definition: avformat.h:546
AVFormatContext::subtitle_codec
const AVCodec * subtitle_codec
Forced subtitle codec.
Definition: avformat.h:1586
AV_PKT_FLAG_CORRUPT
#define AV_PKT_FLAG_CORRUPT
The packet content is corrupted.
Definition: packet.h:430
OptionGroup::codec_opts
AVDictionary * codec_opts
Definition: cmdutils.h:257
av_dump_format
void av_dump_format(AVFormatContext *ic, int index, const char *url, int is_output)
Print detailed information about the input or output format, such as duration, bitrate,...
Definition: dump.c:629
av_thread_message_queue_send
int av_thread_message_queue_send(AVThreadMessageQueue *mq, void *msg, unsigned flags)
Send a message on the queue.
Definition: threadmessage.c:158
duration
int64_t duration
Definition: movenc.c:64
avformat_open_input
int avformat_open_input(AVFormatContext **ps, const char *url, const AVInputFormat *fmt, AVDictionary **options)
Open an input stream and read the header.
Definition: demux.c:221
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
av_channel_layout_describe
int av_channel_layout_describe(const AVChannelLayout *channel_layout, char *buf, size_t buf_size)
Get a human-readable string describing the channel layout properties.
Definition: channel_layout.c:778
HWACCEL_GENERIC
@ HWACCEL_GENERIC
Definition: ffmpeg.h:72
avcodec_alloc_context3
AVCodecContext * avcodec_alloc_context3(const AVCodec *codec)
Allocate an AVCodecContext and set its fields to default values.
Definition: options.c:153
opt_name_discard
static const char *const opt_name_discard[]
Definition: ffmpeg_demux.c:41
SpecifierOpt::specifier
char * specifier
stream/chapter/program/...
Definition: cmdutils.h:135
intreadwrite.h
s
#define s(width, name)
Definition: cbs_vp9.c:256
InputStream::framerate
AVRational framerate
Definition: ffmpeg.h:390
opt_name_hwaccel_devices
static const char *const opt_name_hwaccel_devices[]
Definition: ffmpeg_demux.c:48
AVFormatContext::flags
int flags
Flags modifying the (de)muxer behaviour.
Definition: avformat.h:1222
AVInputFormat::name
const char * name
A comma separated list of short names for the format.
Definition: avformat.h:551
AVFormatContext::iformat
const struct AVInputFormat * iformat
The input container format.
Definition: avformat.h:1116
AVDictionaryEntry::key
char * key
Definition: dict.h:90
AVMEDIA_TYPE_AUDIO
@ AVMEDIA_TYPE_AUDIO
Definition: avutil.h:202
AV_CHANNEL_ORDER_UNSPEC
@ AV_CHANNEL_ORDER_UNSPEC
Only the channel count is specified, without any further information about the channel order.
Definition: channel_layout.h:112
DemuxStream::ts_scale
double ts_scale
Definition: ffmpeg_demux.c:61
OptionsContext::audio_ch_layouts
SpecifierOpt * audio_ch_layouts
Definition: ffmpeg.h:107
av_assert0
#define av_assert0(cond)
assert() equivalent, that is always enabled.
Definition: avassert.h:37
AVHWDeviceType
AVHWDeviceType
Definition: hwcontext.h:27
AVIO_FLAG_WRITE
#define AVIO_FLAG_WRITE
write-only
Definition: avio.h:624
ctx
AVFormatContext * ctx
Definition: movenc.c:48
InputStream::filters
InputFilter ** filters
Definition: ffmpeg.h:413
Demuxer::nb_streams_warn
int nb_streams_warn
Definition: ffmpeg_demux.c:82
av_rescale_q
int64_t av_rescale_q(int64_t a, AVRational bq, AVRational cq)
Rescale a 64-bit integer by 2 rational numbers.
Definition: mathematics.c:142
input_stream_item_name
static const char * input_stream_item_name(void *obj)
Definition: ffmpeg_demux.c:617
opt_name_canvas_sizes
static const char *const opt_name_canvas_sizes[]
Definition: ffmpeg_demux.c:44
av_hwdevice_get_type_name
const char * av_hwdevice_get_type_name(enum AVHWDeviceType type)
Get the string name of an AVHWDeviceType.
Definition: hwcontext.c:93
AVThreadMessageQueue
Definition: threadmessage.c:27
OptionsContext::accurate_seek
int accurate_seek
Definition: ffmpeg.h:127
av_usleep
int av_usleep(unsigned usec)
Sleep for a period of time.
Definition: time.c:84
AVMEDIA_TYPE_DATA
@ AVMEDIA_TYPE_DATA
Opaque data information usually continuous.
Definition: avutil.h:203
opt_name_ts_scale
static const char *const opt_name_ts_scale[]
Definition: ffmpeg_demux.c:46
assert_avoptions
void assert_avoptions(AVDictionary *m)
Definition: ffmpeg.c:629
AV_PIX_FMT_MEDIACODEC
@ AV_PIX_FMT_MEDIACODEC
hardware decoding through MediaCodec
Definition: pixfmt.h:313
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:1772
arg
const char * arg
Definition: jacosubdec.c:67
pthread_create
static av_always_inline int pthread_create(pthread_t *thread, const pthread_attr_t *attr, void *(*start_routine)(void *), void *arg)
Definition: os2threads.h:80
AV_CLASS_CATEGORY_DEMUXER
@ AV_CLASS_CATEGORY_DEMUXER
Definition: log.h:33
option
option
Definition: libkvazaar.c:312
avio_flush
void avio_flush(AVIOContext *s)
Force flushing of buffered data.
Definition: aviobuf.c:244
AVCodecParserContext::repeat_pict
int repeat_pict
This field is used for proper frame duration computation in lavf.
Definition: avcodec.h:2877
OptionsContext::start_time
int64_t start_time
Definition: ffmpeg.h:100
AVDISCARD_ALL
@ AVDISCARD_ALL
discard all
Definition: defs.h:76
AVFormatContext
Format I/O context.
Definition: avformat.h:1104
AVFormatContext::audio_codec_id
enum AVCodecID audio_codec_id
Forced audio codec_id.
Definition: avformat.h:1282
opts
AVDictionary * opts
Definition: movenc.c:50
OptionGroup::format_opts
AVDictionary * format_opts
Definition: cmdutils.h:258
opt_name_guess_layout_max
static const char *const opt_name_guess_layout_max[]
Definition: ffmpeg_demux.c:45
AVStream::codecpar
AVCodecParameters * codecpar
Codec parameters associated with this stream.
Definition: avformat.h:861
LIBAVUTIL_VERSION_INT
#define LIBAVUTIL_VERSION_INT
Definition: version.h:85
demuxer_from_ifile
static Demuxer * demuxer_from_ifile(InputFile *f)
Definition: ffmpeg_demux.c:103
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:187
ifile_duration_update
static void ifile_duration_update(Demuxer *d, DemuxStream *ds, int64_t last_duration)
Definition: ffmpeg_demux.c:121
AVStream::time_base
AVRational time_base
This is the fundamental unit of time (in seconds) in terms of which frame timestamps are represented.
Definition: avformat.h:877
NULL
#define NULL
Definition: coverity.c:32
InputStream::top_field_first
int top_field_first
Definition: ffmpeg.h:391
InputStream::st
AVStream * st
Definition: ffmpeg.h:339
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:63
OptionsContext::frame_sizes
SpecifierOpt * frame_sizes
Definition: ffmpeg.h:117
AVCodec::type
enum AVMediaType type
Definition: codec.h:197
avcodec_free_context
void avcodec_free_context(AVCodecContext **avctx)
Free the codec context and everything associated with it and write NULL to the provided pointer.
Definition: options.c:168
AVRational
Rational number (pair of numerator and denominator).
Definition: rational.h:58
DemuxStream::max_pts
int64_t max_pts
Definition: ffmpeg_demux.c:64
parseutils.h
InputStream::hwaccel_id
enum HWAccelID hwaccel_id
Definition: ffmpeg.h:419
AVStream::metadata
AVDictionary * metadata
Definition: avformat.h:918
InputStream::fix_sub_duration
int fix_sub_duration
Definition: ffmpeg.h:395
InputStream::hwaccel_output_format
enum AVPixelFormat hwaccel_output_format
Definition: ffmpeg.h:422
AV_DICT_DONT_OVERWRITE
#define AV_DICT_DONT_OVERWRITE
Don't overwrite existing entries.
Definition: dict.h:81
time.h
AV_PIX_FMT_QSV
@ AV_PIX_FMT_QSV
HW acceleration through QSV, data[3] contains a pointer to the mfxFrameSurface1 structure.
Definition: pixfmt.h:240
AVFormatContext::audio_codec
const AVCodec * audio_codec
Forced audio codec.
Definition: avformat.h:1578
OptionsContext::input_sync_ref
int input_sync_ref
Definition: ffmpeg.h:129
av_packet_move_ref
void av_packet_move_ref(AVPacket *dst, AVPacket *src)
Move every field in src to dst and reset src.
Definition: avpacket.c:479
report_new_stream
static void report_new_stream(Demuxer *d, const AVPacket *pkt)
Definition: ffmpeg_demux.c:108
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
InputStream::par
AVCodecParameters * par
Codec parameters - to be used by the decoding/streamcopy code.
Definition: ffmpeg.h:354
input_files
InputFile ** input_files
Definition: ffmpeg.c:143
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:571
error.h
avcodec_find_decoder
const AVCodec * avcodec_find_decoder(enum AVCodecID id)
Find a registered decoder with a matching codec ID.
Definition: allcodecs.c:966
recast_media
int recast_media
Definition: ffmpeg_opt.c:100
AVCodecParameters::extradata_size
int extradata_size
Size of the extradata content in bytes.
Definition: codec_par.h:80
AVFormatContext::nb_streams
unsigned int nb_streams
Number of elements in AVFormatContext.streams.
Definition: avformat.h:1160
av_codec_is_decoder
int av_codec_is_decoder(const AVCodec *codec)
Definition: utils.c:83
AVFormatContext::data_codec
const AVCodec * data_codec
Forced data codec.
Definition: avformat.h:1594
avformat_find_stream_info
int avformat_find_stream_info(AVFormatContext *ic, AVDictionary **options)
Read packets of a media file to get stream information.
Definition: demux.c:2425
f
f
Definition: af_crystalizer.c:122
AVIOContext
Bytestream IO Context.
Definition: avio.h:166
av_ts2timestr
#define av_ts2timestr(ts, tb)
Convenience macro, the return value should be used only directly in function arguments but never stan...
Definition: timestamp.h:76
InputStream::hwaccel_device_type
enum AVHWDeviceType hwaccel_device_type
Definition: ffmpeg.h:420
OptionsContext::thread_queue_size
int thread_queue_size
Definition: ffmpeg.h:128
InputStream::decoded_frame
AVFrame * decoded_frame
Definition: ffmpeg.h:357
InputStream::wrap_correction_done
int wrap_correction_done
Definition: ffmpeg.h:372
InputStream::start
int64_t start
Definition: ffmpeg.h:363
avformat_alloc_context
AVFormatContext * avformat_alloc_context(void)
Allocate an AVFormatContext.
Definition: options.c:166
threadmessage.h
InputStream::file_index
int file_index
Definition: ffmpeg.h:338
opt_name_hwaccels
static const char *const opt_name_hwaccels[]
Definition: ffmpeg_demux.c:47
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:121
start_time
static int64_t start_time
Definition: ffplay.c:326
InputStream::pkt
AVPacket * pkt
Definition: ffmpeg.h:358
InputStream::got_output
int got_output
Definition: ffmpeg.h:397
copy_ts
int copy_ts
Definition: ffmpeg_opt.c:76
avformat_seek_file
int avformat_seek_file(AVFormatContext *s, int stream_index, int64_t min_ts, int64_t ts, int64_t max_ts, int flags)
Seek to timestamp ts.
Definition: seek.c:659
AV_NOPTS_VALUE
#define AV_NOPTS_VALUE
Undefined timestamp value.
Definition: avutil.h:248
OptionsContext::seek_timestamp
int seek_timestamp
Definition: ffmpeg.h:102
av_guess_frame_rate
AVRational av_guess_frame_rate(AVFormatContext *format, AVStream *st, AVFrame *frame)
Guess the frame rate, based on both the container and codec information.
Definition: avformat.c:679
add_display_matrix_to_stream
static void add_display_matrix_to_stream(const OptionsContext *o, AVFormatContext *ctx, InputStream *ist)
Definition: ffmpeg_demux.c:583
input_file_class
static const AVClass input_file_class
Definition: ffmpeg_demux.c:908
setup_find_stream_info_opts
AVDictionary ** setup_find_stream_info_opts(AVFormatContext *s, AVDictionary *codec_opts)
Setup AVCodecContext options for avformat_find_stream_info().
Definition: cmdutils.c:953
Demuxer::thread
pthread_t thread
Definition: ffmpeg_demux.c:86
AVMEDIA_TYPE_UNKNOWN
@ AVMEDIA_TYPE_UNKNOWN
Usually treated as AVMEDIA_TYPE_DATA.
Definition: avutil.h:200
Demuxer::thread_queue_size
int thread_queue_size
Definition: ffmpeg_demux.c:85
allocate_array_elem
void * allocate_array_elem(void *ptr, size_t elem_size, int *nb_elems)
Atomically add a new element to an array of pointers, i.e.
Definition: cmdutils.c:987
AV_OPT_SEARCH_CHILDREN
#define AV_OPT_SEARCH_CHILDREN
Search in possible children of the given object first.
Definition: opt.h:563
AVPacket::dts
int64_t dts
Decompression timestamp in AVStream->time_base units; the time at which the packet is decompressed.
Definition: packet.h:373
avio_write
void avio_write(AVIOContext *s, const unsigned char *buf, int size)
Definition: aviobuf.c:222
OptionsContext::find_stream_info
int find_stream_info
Definition: ffmpeg.h:130
DemuxStream::min_pts
int64_t min_pts
Definition: ffmpeg_demux.c:63
strip_specifiers
AVDictionary * strip_specifiers(const AVDictionary *dict)
Definition: ffmpeg_opt.c:167
AVPacket::flags
int flags
A combination of AV_PKT_FLAG values.
Definition: packet.h:380
av_packet_alloc
AVPacket * av_packet_alloc(void)
Allocate an AVPacket and set its fields to default values.
Definition: avpacket.c:62
av_dict_free
void av_dict_free(AVDictionary **pm)
Free all the memory allocated for an AVDictionary struct and all keys and values.
Definition: dict.c:223
guess_input_channel_layout
static int guess_input_channel_layout(InputStream *ist, int guess_layout_max)
Definition: ffmpeg_demux.c:565
av_parse_video_size
int av_parse_video_size(int *width_ptr, int *height_ptr, const char *str)
Parse str and put in width_ptr and height_ptr the detected values.
Definition: parseutils.c:150
pthread_t
Definition: os2threads.h:44
OptionsContext::frame_rates
SpecifierOpt * frame_rates
Definition: ffmpeg.h:113
AV_LOG_INFO
#define AV_LOG_INFO
Standard information.
Definition: log.h:191
video_codec_name
static const char * video_codec_name
Definition: ffplay.c:341
av_thread_message_queue_alloc
int av_thread_message_queue_alloc(AVThreadMessageQueue **mq, unsigned nelem, unsigned elsize)
Allocate a new message queue.
Definition: threadmessage.c:42
AVCodec::id
enum AVCodecID id
Definition: codec.h:198
av_channel_layout_default
void av_channel_layout_default(AVChannelLayout *ch_layout, int nb_channels)
Get the default channel layout for a given number of channels.
Definition: channel_layout.c:962
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:53
Demuxer::non_blocking
int non_blocking
Definition: ffmpeg_demux.c:87
avcodec_get_name
const char * avcodec_get_name(enum AVCodecID id)
Get the name of a codec.
Definition: utils.c:442
HWACCEL_AUTO
@ HWACCEL_AUTO
Definition: ffmpeg.h:71
DemuxStream
Definition: ffmpeg_demux.c:55
av_parse_video_rate
int av_parse_video_rate(AVRational *rate, const char *arg)
Parse str and store the detected values in *rate.
Definition: parseutils.c:181
DemuxMsg::looping
int looping
Definition: ffmpeg_demux.c:92
AV_CODEC_ID_NONE
@ AV_CODEC_ID_NONE
Definition: codec_id.h:50
i
#define i(width, name, range_min, range_max)
Definition: cbs_h2645.c:269
AVPacket::pts
int64_t pts
Presentation timestamp in AVStream->time_base units; the time at which the decompressed packet will b...
Definition: packet.h:367
packet.h
avcodec_parameters_to_context
int avcodec_parameters_to_context(AVCodecContext *codec, const AVCodecParameters *par)
Fill the codec context based on the values from the supplied codec parameters.
Definition: codec_par.c:182
AV_TIME_BASE
#define AV_TIME_BASE
Internal time base represented as integer.
Definition: avutil.h:254
find_codec_or_die
const AVCodec * find_codec_or_die(void *logctx, const char *name, enum AVMediaType type, int encoder)
Definition: ffmpeg_opt.c:626
SHOW_TS_DEBUG
#define SHOW_TS_DEBUG(tag_)
OptionsContext::audio_sample_rate
SpecifierOpt * audio_sample_rate
Definition: ffmpeg.h:111
OptionsContext::start_time_eof
int64_t start_time_eof
Definition: ffmpeg.h:101
display.h
av_thread_message_queue_set_err_send
void av_thread_message_queue_set_err_send(AVThreadMessageQueue *mq, int err)
Set the sending error code.
Definition: threadmessage.c:190
exit_on_error
int exit_on_error
Definition: ffmpeg_opt.c:80
OptionsContext::nb_frame_pix_fmts
int nb_frame_pix_fmts
Definition: ffmpeg.h:120
filter_codec_opts
AVDictionary * filter_codec_opts(AVDictionary *opts, enum AVCodecID codec_id, AVFormatContext *s, AVStream *st, const AVCodec *codec)
Filter out options for given codec.
Definition: cmdutils.c:895
AVMEDIA_TYPE_ATTACHMENT
@ AVMEDIA_TYPE_ATTACHMENT
Opaque data information usually sparse.
Definition: avutil.h:205
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:282
FFMIN
#define FFMIN(a, b)
Definition: macros.h:49
thread_start
static int thread_start(Demuxer *d)
Definition: ffmpeg_demux.c:389
av_inv_q
static av_always_inline AVRational av_inv_q(AVRational q)
Invert a rational.
Definition: rational.h:159
av_rescale
int64_t av_rescale(int64_t a, int64_t b, int64_t c)
Rescale a 64-bit integer with rounding to nearest.
Definition: mathematics.c:129
int_cb
const AVIOInterruptCB int_cb
Definition: ffmpeg.c:500
AVCodecContext::height
int height
Definition: avcodec.h:607
AVFMT_FLAG_NONBLOCK
#define AVFMT_FLAG_NONBLOCK
Do not block when reading packets from input.
Definition: avformat.h:1225
av_codec_iterate
const AVCodec * av_codec_iterate(void **opaque)
Iterate over all registered codecs.
Definition: allcodecs.c:917
add_input_streams
static void add_input_streams(const OptionsContext *o, Demuxer *d)
Definition: ffmpeg_demux.c:650
tag
uint32_t tag
Definition: movenc.c:1709
AVFMT_FLAG_BITEXACT
#define AVFMT_FLAG_BITEXACT
When muxing, try to avoid writing any random/volatile data to the output.
Definition: avformat.h:1239
ret
ret
Definition: filter_design.txt:187
AVStream
Stream structure.
Definition: avformat.h:838
AV_LOG_FATAL
#define AV_LOG_FATAL
Something went wrong and recovery is not possible.
Definition: log.h:174
AVClass::class_name
const char * class_name
The name of the class; usually it is the same name as the context structure type to which the AVClass...
Definition: log.h:71
av_strlcat
size_t av_strlcat(char *dst, const char *src, size_t size)
Append the string src to the string dst, but to a total length of no more than size - 1 bytes,...
Definition: avstring.c:96
normalize.ifile
ifile
Definition: normalize.py:6
av_opt_eval_int
int av_opt_eval_int(void *obj, const AVOption *o, const char *val, int *int_out)
Demuxer::loop
int loop
Definition: ffmpeg_demux.c:74
InputStream::reinit_filters
int reinit_filters
Definition: ffmpeg.h:416
avformat.h
HWAccelID
HWAccelID
Definition: ffmpeg.h:69
Demuxer::duration
int64_t duration
Definition: ffmpeg_demux.c:77
AV_DICT_MATCH_CASE
#define AV_DICT_MATCH_CASE
Only get an entry with exact-case key match.
Definition: dict.h:74
AV_RL32
uint64_t_TMPL AV_WL64 unsigned int_TMPL AV_RL32
Definition: bytestream.h:92
av_get_pix_fmt
enum AVPixelFormat av_get_pix_fmt(const char *name)
Return the pixel format corresponding to name.
Definition: pixdesc.c:2820
AVFormatContext::data_codec_id
enum AVCodecID data_codec_id
Forced Data codec_id.
Definition: avformat.h:1632
av_get_media_type_string
const char * av_get_media_type_string(enum AVMediaType media_type)
Return a string describing the media_type enum, NULL if media_type is unknown.
Definition: utils.c:28
AVCodecContext
main external API structure.
Definition: avcodec.h:435
AVStream::index
int index
stream index in AVFormatContext
Definition: avformat.h:844
Demuxer::in_thread_queue
AVThreadMessageQueue * in_thread_queue
Definition: ffmpeg_demux.c:84
audio_codec_name
static const char * audio_codec_name
Definition: ffplay.c:339
OptionsContext::nb_audio_channels
int nb_audio_channels
Definition: ffmpeg.h:110
InputStream::prev_pkt_pts
int64_t prev_pkt_pts
Definition: ffmpeg.h:362
AVInputFormat::flags
int flags
Can use flags: AVFMT_NOFILE, AVFMT_NEEDNUMBER, AVFMT_SHOW_IDS, AVFMT_NOTIMESTAMPS,...
Definition: avformat.h:565
SpecifierOpt::str
uint8_t * str
Definition: cmdutils.h:137
AV_PIX_FMT_NONE
@ AV_PIX_FMT_NONE
Definition: pixfmt.h:65
OptionsContext::video_disable
int video_disable
Definition: ffmpeg.h:166
InputStream::prev_sub
struct InputStream::@3 prev_sub
ds_from_ist
static DemuxStream * ds_from_ist(InputStream *ist)
Definition: ffmpeg_demux.c:98
InputStream::nb_samples
int64_t nb_samples
Definition: ffmpeg.h:386
OptionsContext::frame_pix_fmts
SpecifierOpt * frame_pix_fmts
Definition: ffmpeg.h:119
av_find_input_format
const AVInputFormat * av_find_input_format(const char *short_name)
Find AVInputFormat based on the short name of the input format.
Definition: format.c:118
demux_alloc
static Demuxer * demux_alloc(void)
Definition: ffmpeg_demux.c:915
AVFormatContext::duration
int64_t duration
Duration of the stream, in AV_TIME_BASE fractional seconds.
Definition: avformat.h:1206
AVPacket::stream_index
int stream_index
Definition: packet.h:376
HWACCEL_NONE
@ HWACCEL_NONE
Definition: ffmpeg.h:70
seek_to_start
static int seek_to_start(Demuxer *d)
Definition: ffmpeg_demux.c:138
avcodec_get_hw_config
const AVCodecHWConfig * avcodec_get_hw_config(const AVCodec *codec, int index)
Retrieve supported hardware configurations for a codec.
Definition: utils.c:884
OptionsContext::nb_frame_sizes
int nb_frame_sizes
Definition: ffmpeg.h:118
InputStream::discard
int discard
Definition: ffmpeg.h:340
InputStream::sub2video::frame
AVFrame * frame
Definition: ffmpeg.h:406
av_dict_set_int
int av_dict_set_int(AVDictionary **pm, const char *key, int64_t value, int flags)
Convenience wrapper for av_dict_set() that converts the value to a string and stores it.
Definition: dict.c:167
av_strdup
char * av_strdup(const char *s)
Duplicate a string.
Definition: mem.c:270
AVMEDIA_TYPE_VIDEO
@ AVMEDIA_TYPE_VIDEO
Definition: avutil.h:201
start_at_zero
int start_at_zero
Definition: ffmpeg_opt.c:77
SpecifierOpt::u
union SpecifierOpt::@0 u
AV_CODEC_FLAG_BITEXACT
#define AV_CODEC_FLAG_BITEXACT
Use only bitexact stuff (except (I)DCT).
Definition: avcodec.h:330
AVCodecParameters::video_delay
int video_delay
Video only.
Definition: codec_par.h:157
DemuxStream::log_name
char log_name[32]
Definition: ffmpeg_demux.c:59
thread_stop
static void thread_stop(Demuxer *d)
Definition: ffmpeg_demux.c:373
InputStream::class
const AVClass * class
Definition: ffmpeg.h:336
AVDictionaryEntry
Definition: dict.h:89
stdin_interaction
int stdin_interaction
Definition: ffmpeg_opt.c:84
do_hex_dump
int do_hex_dump
Definition: ffmpeg_opt.c:74
AVCodecParameters::codec_id
enum AVCodecID codec_id
Specific type of the encoded data (the codec used).
Definition: codec_par.h:62
LastFrameDuration::duration
int64_t duration
Definition: ffmpeg.h:444
AVPacket
This structure stores compressed data.
Definition: packet.h:351
DemuxMsg
Definition: ffmpeg_demux.c:90
av_thread_message_queue_free
void av_thread_message_queue_free(AVThreadMessageQueue **mq)
Free a message queue.
Definition: threadmessage.c:93
av_freep
#define av_freep(p)
Definition: tableprint_vlc.h:34
av_dict_set
int av_dict_set(AVDictionary **pm, const char *key, const char *value, int flags)
Set the given entry in *pm, overwriting an existing entry.
Definition: dict.c:86
AVPacket::pos
int64_t pos
byte position in stream, -1 if unknown
Definition: packet.h:394
opt_name_reinit_filters
static const char *const opt_name_reinit_filters[]
Definition: ffmpeg_demux.c:42
OptionsContext::data_disable
int data_disable
Definition: ffmpeg.h:169
InputStream::dts_buffer
int64_t * dts_buffer
Definition: ffmpeg.h:436
av_stream_new_side_data
uint8_t * av_stream_new_side_data(AVStream *st, enum AVPacketSideDataType type, size_t size)
Allocate new information from stream.
Definition: avformat.c:191
d
d
Definition: ffmpeg_filter.c:156
AVCodecContext::width
int width
picture width / height.
Definition: avcodec.h:607
int32_t
int32_t
Definition: audioconvert.c:56
ist_free
static void ist_free(InputStream **pist)
Definition: ffmpeg_demux.c:483
convert_header.str
string str
Definition: convert_header.py:20
timestamp.h
flags
#define flags(name, subs,...)
Definition: cbs_av1.c:561
av_thread_message_queue_set_err_recv
void av_thread_message_queue_set_err_recv(AVThreadMessageQueue *mq, int err)
Set the receiving error code.
Definition: threadmessage.c:201
av_log
#define av_log(a,...)
Definition: tableprint_vlc.h:27
AVFormatContext::start_time
int64_t start_time
Position of the first frame of the component, in AV_TIME_BASE fractional seconds.
Definition: avformat.h:1196
AVERROR_INVALIDDATA
#define AVERROR_INVALIDDATA
Invalid data found when processing input.
Definition: error.h:61
av_stream_get_parser
struct AVCodecParserContext * av_stream_get_parser(const AVStream *s)
Definition: demux_utils.c:32
AVCodecHWConfig
Definition: codec.h:338
av_pkt_dump_log2
void av_pkt_dump_log2(void *avcl, int level, const AVPacket *pkt, int dump_payload, const AVStream *st)
Send a nice dump of a packet to the log.
Definition: dump.c:117
AVDictionaryEntry::value
char * value
Definition: dict.h:91
avstring.h
AVStream::pts_wrap_bits
int pts_wrap_bits
Number of bits in timestamps.
Definition: avformat.h:1005
AVERROR_PROTOCOL_NOT_FOUND
#define AVERROR_PROTOCOL_NOT_FOUND
Protocol not found.
Definition: error.h:65
InputStream::dec
const AVCodec * dec
Definition: ffmpeg.h:356
snprintf
#define snprintf
Definition: snprintf.h:34
Demuxer::time_base
AVRational time_base
Definition: ffmpeg_demux.c:79
InputStream::subtitle
AVSubtitle subtitle
Definition: ffmpeg.h:399
av_dict_iterate
const AVDictionaryEntry * av_dict_iterate(const AVDictionary *m, const AVDictionaryEntry *prev)
Iterate over a dictionary.
Definition: dict.c:42
AVInputFormat::priv_class
const AVClass * priv_class
AVClass for the private context.
Definition: avformat.h:576
DemuxMsg::repeat_pict
int repeat_pict
Definition: ffmpeg_demux.c:95
OptionsContext::loop
int loop
Definition: ffmpeg.h:124
InputStream::autorotate
int autorotate
Definition: ffmpeg.h:393
AVFormatContext::video_codec
const AVCodec * video_codec
Forced video codec.
Definition: avformat.h:1570
thread_set_name
static void thread_set_name(InputFile *f)
Definition: ffmpeg_demux.c:256
ff_thread_setname
static int ff_thread_setname(const char *name)
Definition: thread.h:195
AVFormatContext::subtitle_codec_id
enum AVCodecID subtitle_codec_id
Forced subtitle codec_id.
Definition: avformat.h:1288