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 #include "ffmpeg_sched.h"
24 #include "ffmpeg_utils.h"
25 
26 #include "libavutil/avassert.h"
27 #include "libavutil/avstring.h"
28 #include "libavutil/display.h"
29 #include "libavutil/error.h"
30 #include "libavutil/intreadwrite.h"
31 #include "libavutil/mem.h"
32 #include "libavutil/opt.h"
33 #include "libavutil/parseutils.h"
34 #include "libavutil/pixdesc.h"
35 #include "libavutil/time.h"
36 #include "libavutil/timestamp.h"
37 
38 #include "libavcodec/bsf.h"
39 #include "libavcodec/packet.h"
40 
41 #include "libavformat/avformat.h"
42 
43 typedef struct DemuxStream {
45 
46  // name used for logging
47  char log_name[32];
48 
51 
52  double ts_scale;
53 
54  /* non zero if the packets must be decoded in 'raw_fifo', see DECODING_FOR_* */
56 #define DECODING_FOR_OST 1
57 #define DECODING_FOR_FILTER 2
58 
59  /* true if stream data should be discarded */
60  int discard;
61 
62  // scheduler returned EOF for this stream
63  int finished;
64 
72 
73 
76  /// dts of the first packet read for this stream (in AV_TIME_BASE units)
78 
79  /* predicted dts of the next packet read for this stream or (when there are
80  * several frames in a packet) of the next frame in current packet (in AV_TIME_BASE units) */
82  /// dts of the last packet read for this stream (in AV_TIME_BASE units)
84 
86 
89  char dec_name[16];
90  // decoded media properties, as estimated by opening the decoder
92 
94 
95  /* number of packets successfully read for this stream */
96  uint64_t nb_packets;
97  // combined size of all the packets read
98  uint64_t data_size;
99  // latest wallclock time at which packet reading resumed after a stall - used for readrate
101  // timestamp of first packet sent after the latest stall - used for readrate
103  // measure of how far behind packet reading is against spceified readrate
105 } DemuxStream;
106 
107 typedef struct DemuxStreamGroup {
109 
110  // name used for logging
111  char log_name[32];
113 
114 typedef struct Demuxer {
116 
117  // name used for logging
118  char log_name[32];
119 
121 
122  /**
123  * Extra timestamp offset added by discontinuity handling.
124  */
127 
130 
131  /* number of times input stream should be looped */
132  int loop;
134  /* duration of the looped segment of the input file */
136  /* pts with the smallest/largest values ever seen */
139 
140  /* number of streams that the user was warned of */
142 
143  float readrate;
146 
148 
150 
154 } Demuxer;
155 
156 typedef struct DemuxThreadContext {
157  // packet used for reading from the demuxer
159  // packet for reading from BSFs
162 
164 {
165  return (DemuxStream*)ist;
166 }
167 
169 {
170  return (Demuxer*)f;
171 }
172 
174 {
175  for (InputStream *ist = ist_iter(NULL); ist; ist = ist_iter(ist)) {
176  DemuxStream *ds = ds_from_ist(ist);
177  if (ist->par->codec_type == type && ds->discard &&
178  ist->user_set_discard != AVDISCARD_ALL)
179  return ist;
180  }
181  return NULL;
182 }
183 
184 static void report_new_stream(Demuxer *d, const AVPacket *pkt)
185 {
186  const AVStream *st = d->f.ctx->streams[pkt->stream_index];
187 
188  if (pkt->stream_index < d->nb_streams_warn)
189  return;
191  "New %s stream with index %d at pos:%"PRId64" and DTS:%ss\n",
194  d->nb_streams_warn = pkt->stream_index + 1;
195 }
196 
197 static int seek_to_start(Demuxer *d, Timestamp end_pts)
198 {
199  InputFile *ifile = &d->f;
200  AVFormatContext *is = ifile->ctx;
201  int ret;
202 
203  ret = avformat_seek_file(is, -1, INT64_MIN, is->start_time, is->start_time, 0);
204  if (ret < 0)
205  return ret;
206 
207  if (end_pts.ts != AV_NOPTS_VALUE &&
208  (d->max_pts.ts == AV_NOPTS_VALUE ||
209  av_compare_ts(d->max_pts.ts, d->max_pts.tb, end_pts.ts, end_pts.tb) < 0))
210  d->max_pts = end_pts;
211 
212  if (d->max_pts.ts != AV_NOPTS_VALUE) {
213  int64_t min_pts = d->min_pts.ts == AV_NOPTS_VALUE ? 0 : d->min_pts.ts;
214  d->duration.ts = d->max_pts.ts - av_rescale_q(min_pts, d->min_pts.tb, d->max_pts.tb);
215  }
216  d->duration.tb = d->max_pts.tb;
217 
218  if (d->loop > 0)
219  d->loop--;
220 
221  return ret;
222 }
223 
225  AVPacket *pkt)
226 {
227  InputFile *ifile = &d->f;
228  DemuxStream *ds = ds_from_ist(ist);
229  const int fmt_is_discont = ifile->ctx->iformat->flags & AVFMT_TS_DISCONT;
230  int disable_discontinuity_correction = copy_ts;
233 
234  if (copy_ts && ds->next_dts != AV_NOPTS_VALUE &&
235  fmt_is_discont && ist->st->pts_wrap_bits < 60) {
236  int64_t wrap_dts = av_rescale_q_rnd(pkt->dts + (1LL<<ist->st->pts_wrap_bits),
239  if (FFABS(wrap_dts - ds->next_dts) < FFABS(pkt_dts - ds->next_dts)/10)
240  disable_discontinuity_correction = 0;
241  }
242 
243  if (ds->next_dts != AV_NOPTS_VALUE && !disable_discontinuity_correction) {
244  int64_t delta = pkt_dts - ds->next_dts;
245  if (fmt_is_discont) {
246  if (FFABS(delta) > 1LL * dts_delta_threshold * AV_TIME_BASE ||
247  pkt_dts + AV_TIME_BASE/10 < ds->dts) {
248  d->ts_offset_discont -= delta;
249  av_log(ist, AV_LOG_WARNING,
250  "timestamp discontinuity "
251  "(stream id=%d): %"PRId64", new offset= %"PRId64"\n",
252  ist->st->id, delta, d->ts_offset_discont);
254  if (pkt->pts != AV_NOPTS_VALUE)
256  }
257  } else {
258  if (FFABS(delta) > 1LL * dts_error_threshold * AV_TIME_BASE) {
259  av_log(ist, AV_LOG_WARNING,
260  "DTS %"PRId64", next:%"PRId64" st:%d invalid dropping\n",
261  pkt->dts, ds->next_dts, pkt->stream_index);
263  }
264  if (pkt->pts != AV_NOPTS_VALUE){
266  delta = pkt_pts - ds->next_dts;
267  if (FFABS(delta) > 1LL * dts_error_threshold * AV_TIME_BASE) {
268  av_log(ist, AV_LOG_WARNING,
269  "PTS %"PRId64", next:%"PRId64" invalid dropping st:%d\n",
270  pkt->pts, ds->next_dts, pkt->stream_index);
272  }
273  }
274  }
275  } else if (ds->next_dts == AV_NOPTS_VALUE && !copy_ts &&
276  fmt_is_discont && d->last_ts != AV_NOPTS_VALUE) {
277  int64_t delta = pkt_dts - d->last_ts;
278  if (FFABS(delta) > 1LL * dts_delta_threshold * AV_TIME_BASE) {
279  d->ts_offset_discont -= delta;
280  av_log(ist, AV_LOG_DEBUG,
281  "Inter stream timestamp discontinuity %"PRId64", new offset= %"PRId64"\n",
284  if (pkt->pts != AV_NOPTS_VALUE)
286  }
287  }
288 
290 }
291 
293  AVPacket *pkt)
294 {
296  pkt->time_base);
297 
298  // apply previously-detected timestamp-discontinuity offset
299  // (to all streams, not just audio/video)
300  if (pkt->dts != AV_NOPTS_VALUE)
301  pkt->dts += offset;
302  if (pkt->pts != AV_NOPTS_VALUE)
303  pkt->pts += offset;
304 
305  // detect timestamp discontinuities for audio/video
306  if ((ist->par->codec_type == AVMEDIA_TYPE_VIDEO ||
307  ist->par->codec_type == AVMEDIA_TYPE_AUDIO) &&
308  pkt->dts != AV_NOPTS_VALUE)
309  ts_discontinuity_detect(d, ist, pkt);
310 }
311 
313 {
314  InputStream *ist = &ds->ist;
315  const AVCodecParameters *par = ist->par;
316 
317  if (!ds->saw_first_ts) {
318  ds->first_dts =
319  ds->dts = ist->st->avg_frame_rate.num ? - ist->par->video_delay * AV_TIME_BASE / av_q2d(ist->st->avg_frame_rate) : 0;
320  if (pkt->pts != AV_NOPTS_VALUE) {
321  ds->first_dts =
323  }
324  ds->saw_first_ts = 1;
325  }
326 
327  if (ds->next_dts == AV_NOPTS_VALUE)
328  ds->next_dts = ds->dts;
329 
330  if (pkt->dts != AV_NOPTS_VALUE)
332 
333  ds->dts = ds->next_dts;
334  switch (par->codec_type) {
335  case AVMEDIA_TYPE_AUDIO:
336  av_assert1(pkt->duration >= 0);
337  if (par->sample_rate) {
338  ds->next_dts += ((int64_t)AV_TIME_BASE * par->frame_size) /
339  par->sample_rate;
340  } else {
342  }
343  break;
344  case AVMEDIA_TYPE_VIDEO:
345  if (ist->framerate.num) {
346  // TODO: Remove work-around for c99-to-c89 issue 7
347  AVRational time_base_q = AV_TIME_BASE_Q;
348  int64_t next_dts = av_rescale_q(ds->next_dts, time_base_q, av_inv_q(ist->framerate));
349  ds->next_dts = av_rescale_q(next_dts + 1, av_inv_q(ist->framerate), time_base_q);
350  } else if (pkt->duration) {
352  } else if (ist->par->framerate.num != 0) {
353  AVRational field_rate = av_mul_q(ist->par->framerate,
354  (AVRational){ 2, 1 });
355  int fields = 2;
356 
357  if (ds->codec_desc &&
359  av_stream_get_parser(ist->st))
361 
362  ds->next_dts += av_rescale_q(fields, av_inv_q(field_rate), AV_TIME_BASE_Q);
363  }
364  break;
365  }
366 
367  fd->dts_est = ds->dts;
368 
369  return 0;
370 }
371 
372 static int ts_fixup(Demuxer *d, AVPacket *pkt, FrameData *fd)
373 {
374  InputFile *ifile = &d->f;
375  InputStream *ist = ifile->streams[pkt->stream_index];
376  DemuxStream *ds = ds_from_ist(ist);
377  const int64_t start_time = ifile->start_time_effective;
379  int ret;
380 
381  pkt->time_base = ist->st->time_base;
382 
383 #define SHOW_TS_DEBUG(tag_) \
384  if (debug_ts) { \
385  av_log(ist, AV_LOG_INFO, "%s -> ist_index:%d:%d type:%s " \
386  "pkt_pts:%s pkt_pts_time:%s pkt_dts:%s pkt_dts_time:%s duration:%s duration_time:%s\n", \
387  tag_, ifile->index, pkt->stream_index, \
388  av_get_media_type_string(ist->st->codecpar->codec_type), \
389  av_ts2str(pkt->pts), av_ts2timestr(pkt->pts, &pkt->time_base), \
390  av_ts2str(pkt->dts), av_ts2timestr(pkt->dts, &pkt->time_base), \
391  av_ts2str(pkt->duration), av_ts2timestr(pkt->duration, &pkt->time_base)); \
392  }
393 
394  SHOW_TS_DEBUG("demuxer");
395 
397  ist->st->pts_wrap_bits < 64) {
398  int64_t stime, stime2;
399 
401  stime2= stime + (1ULL<<ist->st->pts_wrap_bits);
402  ds->wrap_correction_done = 1;
403 
404  if(stime2 > stime && pkt->dts != AV_NOPTS_VALUE && pkt->dts > stime + (1LL<<(ist->st->pts_wrap_bits-1))) {
405  pkt->dts -= 1ULL<<ist->st->pts_wrap_bits;
406  ds->wrap_correction_done = 0;
407  }
408  if(stime2 > stime && pkt->pts != AV_NOPTS_VALUE && pkt->pts > stime + (1LL<<(ist->st->pts_wrap_bits-1))) {
409  pkt->pts -= 1ULL<<ist->st->pts_wrap_bits;
410  ds->wrap_correction_done = 0;
411  }
412  }
413 
414  if (pkt->dts != AV_NOPTS_VALUE)
416  if (pkt->pts != AV_NOPTS_VALUE)
418 
419  if (pkt->pts != AV_NOPTS_VALUE)
420  pkt->pts *= ds->ts_scale;
421  if (pkt->dts != AV_NOPTS_VALUE)
422  pkt->dts *= ds->ts_scale;
423 
425  if (pkt->pts != AV_NOPTS_VALUE) {
426  // audio decoders take precedence for estimating total file duration
427  int64_t pkt_duration = d->have_audio_dec ? 0 : pkt->duration;
428 
429  pkt->pts += duration;
430 
431  // update max/min pts that will be used to compute total file duration
432  // when using -stream_loop
433  if (d->max_pts.ts == AV_NOPTS_VALUE ||
435  pkt->pts + pkt_duration, pkt->time_base) < 0) {
436  d->max_pts = (Timestamp){ .ts = pkt->pts + pkt_duration,
437  .tb = pkt->time_base };
438  }
439  if (d->min_pts.ts == AV_NOPTS_VALUE ||
441  pkt->pts, pkt->time_base) > 0) {
442  d->min_pts = (Timestamp){ .ts = pkt->pts,
443  .tb = pkt->time_base };
444  }
445  }
446 
447  if (pkt->dts != AV_NOPTS_VALUE)
448  pkt->dts += duration;
449 
450  SHOW_TS_DEBUG("demuxer+tsfixup");
451 
452  // detect and try to correct for timestamp discontinuities
453  ts_discontinuity_process(d, ist, pkt);
454 
455  // update estimated/predicted dts
456  ret = ist_dts_update(ds, pkt, fd);
457  if (ret < 0)
458  return ret;
459 
460  return 0;
461 }
462 
463 static int input_packet_process(Demuxer *d, AVPacket *pkt, unsigned *send_flags)
464 {
465  InputFile *f = &d->f;
466  InputStream *ist = f->streams[pkt->stream_index];
467  DemuxStream *ds = ds_from_ist(ist);
468  FrameData *fd;
469  int ret = 0;
470 
471  fd = packet_data(pkt);
472  if (!fd)
473  return AVERROR(ENOMEM);
474 
475  ret = ts_fixup(d, pkt, fd);
476  if (ret < 0)
477  return ret;
478 
479  if (d->recording_time != INT64_MAX) {
480  int64_t start_time = 0;
481  if (copy_ts) {
482  start_time += f->start_time != AV_NOPTS_VALUE ? f->start_time : 0;
483  start_time += start_at_zero ? 0 : f->start_time_effective;
484  }
485  if (ds->dts >= d->recording_time + start_time)
486  *send_flags |= DEMUX_SEND_STREAMCOPY_EOF;
487  }
488 
489  ds->data_size += pkt->size;
490  ds->nb_packets++;
491 
493 
494  if (debug_ts) {
495  av_log(ist, AV_LOG_INFO, "demuxer+ffmpeg -> ist_index:%d:%d type:%s pkt_pts:%s pkt_pts_time:%s pkt_dts:%s pkt_dts_time:%s duration:%s duration_time:%s off:%s off_time:%s\n",
496  f->index, pkt->stream_index,
501  av_ts2str(f->ts_offset), av_ts2timestr(f->ts_offset, &AV_TIME_BASE_Q));
502  }
503 
504  return 0;
505 }
506 
507 static void readrate_sleep(Demuxer *d)
508 {
509  InputFile *f = &d->f;
510  int64_t file_start = copy_ts * (
511  (f->start_time_effective != AV_NOPTS_VALUE ? f->start_time_effective * !start_at_zero : 0) +
512  (f->start_time != AV_NOPTS_VALUE ? f->start_time : 0)
513  );
514  int64_t initial_burst = AV_TIME_BASE * d->readrate_initial_burst;
515  int resume_warn = 0;
516 
517  for (int i = 0; i < f->nb_streams; i++) {
518  InputStream *ist = f->streams[i];
519  DemuxStream *ds = ds_from_ist(ist);
520  int64_t stream_ts_offset, pts, now, wc_elapsed, elapsed, lag, max_pts, limit_pts;
521 
522  if (ds->discard) continue;
523 
524  stream_ts_offset = FFMAX(ds->first_dts != AV_NOPTS_VALUE ? ds->first_dts : 0, file_start);
525  pts = av_rescale(ds->dts, 1000000, AV_TIME_BASE);
526  now = av_gettime_relative();
527  wc_elapsed = now - d->wallclock_start;
528 
529  if (pts <= stream_ts_offset + initial_burst) continue;
530 
531  max_pts = stream_ts_offset + initial_burst + (int64_t)(wc_elapsed * d->readrate);
532  lag = FFMAX(max_pts - pts, 0);
533  if ( (!ds->lag && lag > 0.3 * AV_TIME_BASE) || ( lag > ds->lag + 0.3 * AV_TIME_BASE) ) {
534  ds->lag = lag;
535  ds->resume_wc = now;
536  ds->resume_pts = pts;
537  av_log_once(ds, AV_LOG_WARNING, AV_LOG_DEBUG, &resume_warn,
538  "Resumed reading at pts %0.3f with rate %0.3f after a lag of %0.3fs\n",
539  (float)pts/AV_TIME_BASE, d->readrate_catchup, (float)lag/AV_TIME_BASE);
540  }
541  if (ds->lag && !lag)
542  ds->lag = ds->resume_wc = ds->resume_pts = 0;
543  if (ds->resume_wc) {
544  elapsed = now - ds->resume_wc;
545  limit_pts = ds->resume_pts + (int64_t)(elapsed * d->readrate_catchup);
546  } else {
547  elapsed = wc_elapsed;
548  limit_pts = max_pts;
549  }
550 
551  if (pts > limit_pts)
552  av_usleep(pts - limit_pts);
553  }
554 }
555 
556 static int do_send(Demuxer *d, DemuxStream *ds, AVPacket *pkt, unsigned flags,
557  const char *pkt_desc)
558 {
559  int ret;
560 
562 
563  ret = sch_demux_send(d->sch, d->f.index, pkt, flags);
564  if (ret == AVERROR_EOF) {
566 
567  av_log(ds, AV_LOG_VERBOSE, "All consumers of this stream are done\n");
568  ds->finished = 1;
569 
570  if (++d->nb_streams_finished == d->nb_streams_used) {
571  av_log(d, AV_LOG_VERBOSE, "All consumers are done\n");
572  return AVERROR_EOF;
573  }
574  } else if (ret < 0) {
575  if (ret != AVERROR_EXIT)
576  av_log(d, AV_LOG_ERROR,
577  "Unable to send %s packet to consumers: %s\n",
578  pkt_desc, av_err2str(ret));
579  return ret;
580  }
581 
582  return 0;
583 }
584 
586  AVPacket *pkt, unsigned flags)
587 {
588  InputFile *f = &d->f;
589  int ret;
590 
591  // pkt can be NULL only when flushing BSFs
592  av_assert0(ds->bsf || pkt);
593 
594  // send heartbeat for sub2video streams
595  if (d->pkt_heartbeat && pkt && pkt->pts != AV_NOPTS_VALUE) {
596  for (int i = 0; i < f->nb_streams; i++) {
597  DemuxStream *ds1 = ds_from_ist(f->streams[i]);
598 
599  if (ds1->finished || !ds1->have_sub2video)
600  continue;
601 
602  d->pkt_heartbeat->pts = pkt->pts;
604  d->pkt_heartbeat->opaque = (void*)(intptr_t)PKT_OPAQUE_SUB_HEARTBEAT;
605 
606  ret = do_send(d, ds1, d->pkt_heartbeat, 0, "heartbeat");
607  if (ret < 0)
608  return ret;
609  }
610  }
611 
612  if (ds->bsf) {
613  if (pkt)
615 
616  ret = av_bsf_send_packet(ds->bsf, pkt);
617  if (ret < 0) {
618  if (pkt)
620  av_log(ds, AV_LOG_ERROR, "Error submitting a packet for filtering: %s\n",
621  av_err2str(ret));
622  return ret;
623  }
624 
625  while (1) {
626  ret = av_bsf_receive_packet(ds->bsf, dt->pkt_bsf);
627  if (ret == AVERROR(EAGAIN))
628  return 0;
629  else if (ret < 0) {
630  if (ret != AVERROR_EOF)
631  av_log(ds, AV_LOG_ERROR,
632  "Error applying bitstream filters to a packet: %s\n",
633  av_err2str(ret));
634  return ret;
635  }
636 
637  dt->pkt_bsf->time_base = ds->bsf->time_base_out;
638 
639  ret = do_send(d, ds, dt->pkt_bsf, 0, "filtered");
640  if (ret < 0) {
642  return ret;
643  }
644  }
645  } else {
646  ret = do_send(d, ds, pkt, flags, "demuxed");
647  if (ret < 0)
648  return ret;
649  }
650 
651  return 0;
652 }
653 
655 {
656  InputFile *f = &d->f;
657  int ret;
658 
659  for (unsigned i = 0; i < f->nb_streams; i++) {
660  DemuxStream *ds = ds_from_ist(f->streams[i]);
661 
662  if (!ds->bsf)
663  continue;
664 
665  ret = demux_send(d, dt, ds, NULL, 0);
666  ret = (ret == AVERROR_EOF) ? 0 : (ret < 0) ? ret : AVERROR_BUG;
667  if (ret < 0) {
668  av_log(ds, AV_LOG_ERROR, "Error flushing BSFs: %s\n",
669  av_err2str(ret));
670  return ret;
671  }
672 
673  av_bsf_flush(ds->bsf);
674  }
675 
676  return 0;
677 }
678 
680 {
681  for (int j = 0; j < ifile->ctx->nb_programs; j++) {
682  AVProgram *p = ifile->ctx->programs[j];
683  int discard = AVDISCARD_ALL;
684 
685  for (int k = 0; k < p->nb_stream_indexes; k++) {
686  DemuxStream *ds = ds_from_ist(ifile->streams[p->stream_index[k]]);
687 
688  if (!ds->discard) {
689  discard = AVDISCARD_DEFAULT;
690  break;
691  }
692  }
693  p->discard = discard;
694  }
695 }
696 
698 {
699  char name[16];
700  snprintf(name, sizeof(name), "dmx%d:%s", f->index, f->ctx->iformat->name);
702 }
703 
705 {
707  av_packet_free(&dt->pkt_bsf);
708 
709  memset(dt, 0, sizeof(*dt));
710 }
711 
713 {
714  memset(dt, 0, sizeof(*dt));
715 
716  dt->pkt_demux = av_packet_alloc();
717  if (!dt->pkt_demux)
718  return AVERROR(ENOMEM);
719 
720  dt->pkt_bsf = av_packet_alloc();
721  if (!dt->pkt_bsf)
722  return AVERROR(ENOMEM);
723 
724  return 0;
725 }
726 
727 static int input_thread(void *arg)
728 {
729  Demuxer *d = arg;
730  InputFile *f = &d->f;
731 
733 
734  int ret = 0;
735 
736  ret = demux_thread_init(&dt);
737  if (ret < 0)
738  goto finish;
739 
741 
743 
744  d->read_started = 1;
746 
747  while (1) {
748  DemuxStream *ds;
749  unsigned send_flags = 0;
750 
751  ret = av_read_frame(f->ctx, dt.pkt_demux);
752 
753  if (ret == AVERROR(EAGAIN)) {
754  av_usleep(10000);
755  continue;
756  }
757  if (ret < 0) {
758  int ret_bsf;
759 
760  if (ret == AVERROR_EOF)
761  av_log(d, AV_LOG_VERBOSE, "EOF while reading input\n");
762  else {
763  av_log(d, AV_LOG_ERROR, "Error during demuxing: %s\n",
764  av_err2str(ret));
765  ret = exit_on_error ? ret : 0;
766  }
767 
768  ret_bsf = demux_bsf_flush(d, &dt);
769  ret = err_merge(ret == AVERROR_EOF ? 0 : ret, ret_bsf);
770 
771  if (d->loop) {
772  /* signal looping to our consumers */
773  dt.pkt_demux->stream_index = -1;
774  ret = sch_demux_send(d->sch, f->index, dt.pkt_demux, 0);
775  if (ret >= 0)
776  ret = seek_to_start(d, (Timestamp){ .ts = dt.pkt_demux->pts,
777  .tb = dt.pkt_demux->time_base });
778  if (ret >= 0)
779  continue;
780 
781  /* fallthrough to the error path */
782  }
783 
784  break;
785  }
786 
787  if (do_pkt_dump) {
789  f->ctx->streams[dt.pkt_demux->stream_index]);
790  }
791 
792  /* the following test is needed in case new streams appear
793  dynamically in stream : we ignore them */
794  ds = dt.pkt_demux->stream_index < f->nb_streams ?
795  ds_from_ist(f->streams[dt.pkt_demux->stream_index]) : NULL;
796  if (!ds || ds->discard || ds->finished) {
799  continue;
800  }
801 
802  if (dt.pkt_demux->flags & AV_PKT_FLAG_CORRUPT) {
804  "corrupt input packet in stream %d\n",
805  dt.pkt_demux->stream_index);
806  if (exit_on_error) {
809  break;
810  }
811  }
812 
813  ret = input_packet_process(d, dt.pkt_demux, &send_flags);
814  if (ret < 0)
815  break;
816 
817  if (d->readrate)
818  readrate_sleep(d);
819 
820  ret = demux_send(d, &dt, ds, dt.pkt_demux, send_flags);
821  if (ret < 0)
822  break;
823  }
824 
825  // EOF/EXIT is normal termination
826  if (ret == AVERROR_EOF || ret == AVERROR_EXIT)
827  ret = 0;
828 
829 finish:
830  demux_thread_uninit(&dt);
831 
832  return ret;
833 }
834 
835 static void demux_final_stats(Demuxer *d)
836 {
837  InputFile *f = &d->f;
838  uint64_t total_packets = 0, total_size = 0;
839 
840  av_log(f, AV_LOG_VERBOSE, "Input file #%d (%s):\n",
841  f->index, f->ctx->url);
842 
843  for (int j = 0; j < f->nb_streams; j++) {
844  InputStream *ist = f->streams[j];
845  DemuxStream *ds = ds_from_ist(ist);
846  enum AVMediaType type = ist->par->codec_type;
847 
848  if (ds->discard || type == AVMEDIA_TYPE_ATTACHMENT)
849  continue;
850 
851  total_size += ds->data_size;
852  total_packets += ds->nb_packets;
853 
854  av_log(f, AV_LOG_VERBOSE, " Input stream #%d:%d (%s): ",
855  f->index, j, av_get_media_type_string(type));
856  av_log(f, AV_LOG_VERBOSE, "%"PRIu64" packets read (%"PRIu64" bytes); ",
857  ds->nb_packets, ds->data_size);
858 
859  if (ds->decoding_needed) {
861  "%"PRIu64" frames decoded; %"PRIu64" decode errors",
863  if (type == AVMEDIA_TYPE_AUDIO)
864  av_log(f, AV_LOG_VERBOSE, " (%"PRIu64" samples)", ist->decoder->samples_decoded);
865  av_log(f, AV_LOG_VERBOSE, "; ");
866  }
867 
868  av_log(f, AV_LOG_VERBOSE, "\n");
869  }
870 
871  av_log(f, AV_LOG_VERBOSE, " Total: %"PRIu64" packets (%"PRIu64" bytes) demuxed\n",
872  total_packets, total_size);
873 }
874 
875 static void ist_free(InputStream **pist)
876 {
877  InputStream *ist = *pist;
878  DemuxStream *ds;
879 
880  if (!ist)
881  return;
882  ds = ds_from_ist(ist);
883 
884  dec_free(&ist->decoder);
885 
887  av_freep(&ist->filters);
889 
891 
893 
894  av_bsf_free(&ds->bsf);
895 
896  av_freep(pist);
897 }
898 
899 static void istg_free(InputStreamGroup **pistg)
900 {
901  InputStreamGroup *istg = *pistg;
902 
903  if (!istg)
904  return;
905 
906  av_freep(pistg);
907 }
908 
910 {
911  InputFile *f = *pf;
913 
914  if (!f)
915  return;
916 
917  if (d->read_started)
919 
920  for (int i = 0; i < f->nb_streams; i++)
921  ist_free(&f->streams[i]);
922  av_freep(&f->streams);
923 
924  for (int i = 0; i < f->nb_stream_groups; i++)
925  istg_free(&f->stream_groups[i]);
926  av_freep(&f->stream_groups);
927 
928  avformat_close_input(&f->ctx);
929 
931 
932  av_freep(pf);
933 }
934 
935 int ist_use(InputStream *ist, int decoding_needed,
936  const ViewSpecifier *vs, SchedulerNode *src)
937 {
938  Demuxer *d = demuxer_from_ifile(ist->file);
939  DemuxStream *ds = ds_from_ist(ist);
940  int ret;
941 
942  if (ist->user_set_discard == AVDISCARD_ALL) {
943  av_log(ist, AV_LOG_ERROR, "Cannot %s a disabled input stream\n",
944  decoding_needed ? "decode" : "streamcopy");
945  return AVERROR(EINVAL);
946  }
947 
948  if (decoding_needed && !ist->dec) {
949  av_log(ist, AV_LOG_ERROR,
950  "Decoding requested, but no decoder found for: %s\n",
951  avcodec_get_name(ist->par->codec_id));
952  return AVERROR(EINVAL);
953  }
954 
955  if (ds->sch_idx_stream < 0) {
956  ret = sch_add_demux_stream(d->sch, d->f.index);
957  if (ret < 0)
958  return ret;
959  ds->sch_idx_stream = ret;
960  }
961 
962  if (ds->discard) {
963  ds->discard = 0;
964  d->nb_streams_used++;
965  }
966 
967  ist->st->discard = ist->user_set_discard;
968  ds->decoding_needed |= decoding_needed;
969  ds->streamcopy_needed |= !decoding_needed;
970 
971  if (decoding_needed && ds->sch_idx_dec < 0) {
972  int is_audio = ist->st->codecpar->codec_type == AVMEDIA_TYPE_AUDIO;
973  int is_unreliable = !!(d->f.ctx->iformat->flags & AVFMT_NOTIMESTAMPS);
974  int64_t use_wallclock_as_timestamps;
975 
976  ret = av_opt_get_int(d->f.ctx, "use_wallclock_as_timestamps", 0, &use_wallclock_as_timestamps);
977  if (ret < 0)
978  return ret;
979 
980  if (use_wallclock_as_timestamps)
981  is_unreliable = 0;
982 
984  (!!is_unreliable * DECODER_FLAG_TS_UNRELIABLE) |
985  (!!(d->loop && is_audio) * DECODER_FLAG_SEND_END_TS)
986 #if FFMPEG_OPT_TOP
988 #endif
989  ;
990 
991  if (ist->framerate.num) {
993  ds->dec_opts.framerate = ist->framerate;
994  } else
995  ds->dec_opts.framerate = ist->st->avg_frame_rate;
996 
997  if (ist->dec->id == AV_CODEC_ID_DVB_SUBTITLE &&
999  av_dict_set(&ds->decoder_opts, "compute_edt", "1", AV_DICT_DONT_OVERWRITE);
1001  av_log(ist, AV_LOG_WARNING,
1002  "Warning using DVB subtitles for filtering and output at the "
1003  "same time is not fully supported, also see -compute_edt [0|1]\n");
1004  }
1005 
1006  snprintf(ds->dec_name, sizeof(ds->dec_name), "%d:%d", ist->file->index, ist->index);
1007  ds->dec_opts.name = ds->dec_name;
1008 
1009  ds->dec_opts.codec = ist->dec;
1010  ds->dec_opts.par = ist->par;
1011 
1012  ds->dec_opts.log_parent = ist;
1013 
1015  if (!ds->decoded_params)
1016  return AVERROR(ENOMEM);
1017 
1018  ret = dec_init(&ist->decoder, d->sch,
1019  &ds->decoder_opts, &ds->dec_opts, ds->decoded_params);
1020  if (ret < 0)
1021  return ret;
1022  ds->sch_idx_dec = ret;
1023 
1025  SCH_DEC_IN(ds->sch_idx_dec));
1026  if (ret < 0)
1027  return ret;
1028 
1029  d->have_audio_dec |= is_audio;
1030  }
1031 
1032  if (decoding_needed && ist->par->codec_type == AVMEDIA_TYPE_VIDEO) {
1033  ret = dec_request_view(ist->decoder, vs, src);
1034  if (ret < 0)
1035  return ret;
1036  } else {
1037  *src = decoding_needed ?
1038  SCH_DEC_OUT(ds->sch_idx_dec, 0) :
1039  SCH_DSTREAM(d->f.index, ds->sch_idx_stream);
1040  }
1041 
1042  return 0;
1043 }
1044 
1045 int ist_filter_add(InputStream *ist, InputFilter *ifilter, int is_simple,
1047  SchedulerNode *src)
1048 {
1049  Demuxer *d = demuxer_from_ifile(ist->file);
1050  DemuxStream *ds = ds_from_ist(ist);
1051  int64_t tsoffset = 0;
1052  int ret;
1053 
1054  ret = ist_use(ist, is_simple ? DECODING_FOR_OST : DECODING_FOR_FILTER,
1055  vs, src);
1056  if (ret < 0)
1057  return ret;
1058 
1059  ret = GROW_ARRAY(ist->filters, ist->nb_filters);
1060  if (ret < 0)
1061  return ret;
1062 
1063  ist->filters[ist->nb_filters - 1] = ifilter;
1064 
1065  if (ist->par->codec_type == AVMEDIA_TYPE_VIDEO) {
1067  ist->par->nb_coded_side_data,
1069  if (ist->framerate.num > 0 && ist->framerate.den > 0) {
1070  opts->framerate = ist->framerate;
1071  opts->flags |= IFILTER_FLAG_CFR;
1072  } else
1073  opts->framerate = av_guess_frame_rate(d->f.ctx, ist->st, NULL);
1074  if (sd && sd->size >= sizeof(uint32_t) * 4) {
1075  opts->crop_top = AV_RL32(sd->data + 0);
1076  opts->crop_bottom = AV_RL32(sd->data + 4);
1077  opts->crop_left = AV_RL32(sd->data + 8);
1078  opts->crop_right = AV_RL32(sd->data + 12);
1079  if (ds->apply_cropping && ds->apply_cropping != CROP_CODEC &&
1080  (opts->crop_top | opts->crop_bottom | opts->crop_left | opts->crop_right))
1081  opts->flags |= IFILTER_FLAG_CROP;
1082  }
1083  } else if (ist->par->codec_type == AVMEDIA_TYPE_SUBTITLE) {
1084  /* Compute the size of the canvas for the subtitles stream.
1085  If the subtitles codecpar has set a size, use it. Otherwise use the
1086  maximum dimensions of the video streams in the same file. */
1087  opts->sub2video_width = ist->par->width;
1088  opts->sub2video_height = ist->par->height;
1089  if (!(opts->sub2video_width && opts->sub2video_height)) {
1090  for (int j = 0; j < d->f.nb_streams; j++) {
1091  AVCodecParameters *par1 = d->f.streams[j]->par;
1092  if (par1->codec_type == AVMEDIA_TYPE_VIDEO) {
1093  opts->sub2video_width = FFMAX(opts->sub2video_width, par1->width);
1094  opts->sub2video_height = FFMAX(opts->sub2video_height, par1->height);
1095  }
1096  }
1097  }
1098 
1099  if (!(opts->sub2video_width && opts->sub2video_height)) {
1100  opts->sub2video_width = FFMAX(opts->sub2video_width, 720);
1101  opts->sub2video_height = FFMAX(opts->sub2video_height, 576);
1102  }
1103 
1104  if (!d->pkt_heartbeat) {
1106  if (!d->pkt_heartbeat)
1107  return AVERROR(ENOMEM);
1108  }
1109  ds->have_sub2video = 1;
1110  }
1111 
1112  ret = av_frame_copy_props(opts->fallback, ds->decoded_params);
1113  if (ret < 0)
1114  return ret;
1115  opts->fallback->format = ds->decoded_params->format;
1116  opts->fallback->width = ds->decoded_params->width;
1117  opts->fallback->height = ds->decoded_params->height;
1118 
1119  ret = av_channel_layout_copy(&opts->fallback->ch_layout, &ds->decoded_params->ch_layout);
1120  if (ret < 0)
1121  return ret;
1122 
1123  if (copy_ts) {
1124  tsoffset = d->f.start_time == AV_NOPTS_VALUE ? 0 : d->f.start_time;
1125  if (!start_at_zero && d->f.ctx->start_time != AV_NOPTS_VALUE)
1126  tsoffset += d->f.ctx->start_time;
1127  }
1128  opts->trim_start_us = ((d->f.start_time == AV_NOPTS_VALUE) || !d->accurate_seek) ?
1129  AV_NOPTS_VALUE : tsoffset;
1130  opts->trim_end_us = d->recording_time;
1131 
1132  opts->name = av_strdup(ds->dec_name);
1133  if (!opts->name)
1134  return AVERROR(ENOMEM);
1135 
1136  opts->flags |= IFILTER_FLAG_AUTOROTATE * !!(ds->autorotate) |
1139 
1140  return 0;
1141 }
1142 
1143 static int choose_decoder(const OptionsContext *o, void *logctx,
1144  AVFormatContext *s, AVStream *st,
1145  enum HWAccelID hwaccel_id, enum AVHWDeviceType hwaccel_device_type,
1146  const AVCodec **pcodec)
1147 
1148 {
1149  const char *codec_name = NULL;
1150 
1151  opt_match_per_stream_str(logctx, &o->codec_names, s, st, &codec_name);
1152  if (codec_name) {
1153  int ret = find_codec(NULL, codec_name, st->codecpar->codec_type, 0, pcodec);
1154  if (ret < 0)
1155  return ret;
1156  st->codecpar->codec_id = (*pcodec)->id;
1157  if (recast_media && st->codecpar->codec_type != (*pcodec)->type)
1158  st->codecpar->codec_type = (*pcodec)->type;
1159  return 0;
1160  } else {
1161  if (st->codecpar->codec_type == AVMEDIA_TYPE_VIDEO &&
1162  hwaccel_id == HWACCEL_GENERIC &&
1163  hwaccel_device_type != AV_HWDEVICE_TYPE_NONE) {
1164  const AVCodec *c;
1165  void *i = NULL;
1166 
1167  while ((c = av_codec_iterate(&i))) {
1168  const AVCodecHWConfig *config;
1169 
1170  if (c->id != st->codecpar->codec_id ||
1172  continue;
1173 
1174  for (int j = 0; config = avcodec_get_hw_config(c, j); j++) {
1175  if (config->device_type == hwaccel_device_type) {
1176  av_log(logctx, AV_LOG_VERBOSE, "Selecting decoder '%s' because of requested hwaccel method %s\n",
1177  c->name, av_hwdevice_get_type_name(hwaccel_device_type));
1178  *pcodec = c;
1179  return 0;
1180  }
1181  }
1182  }
1183  }
1184 
1185  *pcodec = avcodec_find_decoder(st->codecpar->codec_id);
1186  return 0;
1187  }
1188 }
1189 
1191  int guess_layout_max)
1192 {
1193  if (par->ch_layout.order == AV_CHANNEL_ORDER_UNSPEC) {
1194  char layout_name[256];
1195 
1196  if (par->ch_layout.nb_channels > guess_layout_max)
1197  return 0;
1200  return 0;
1201  av_channel_layout_describe(&par->ch_layout, layout_name, sizeof(layout_name));
1202  av_log(ist, AV_LOG_WARNING, "Guessed Channel Layout: %s\n", layout_name);
1203  }
1204  return 1;
1205 }
1206 
1209 {
1210  AVStream *st = ist->st;
1211  DemuxStream *ds = ds_from_ist(ist);
1212  AVPacketSideData *sd;
1213  double rotation = DBL_MAX;
1214  int hflip = -1, vflip = -1;
1215  int hflip_set = 0, vflip_set = 0, rotation_set = 0;
1216  int32_t *buf;
1217 
1218  opt_match_per_stream_dbl(ist, &o->display_rotations, ctx, st, &rotation);
1219  opt_match_per_stream_int(ist, &o->display_hflips, ctx, st, &hflip);
1220  opt_match_per_stream_int(ist, &o->display_vflips, ctx, st, &vflip);
1221 
1222  rotation_set = rotation != DBL_MAX;
1223  hflip_set = hflip != -1;
1224  vflip_set = vflip != -1;
1225 
1226  if (!rotation_set && !hflip_set && !vflip_set)
1227  return 0;
1228 
1232  sizeof(int32_t) * 9, 0);
1233  if (!sd) {
1234  av_log(ist, AV_LOG_FATAL, "Failed to generate a display matrix!\n");
1235  return AVERROR(ENOMEM);
1236  }
1237 
1238  buf = (int32_t *)sd->data;
1240  rotation_set ? -(rotation) : -0.0f);
1241 
1243  hflip_set ? hflip : 0,
1244  vflip_set ? vflip : 0);
1245 
1246  ds->force_display_matrix = 1;
1247 
1248  return 0;
1249 }
1250 
1251 static const char *input_stream_item_name(void *obj)
1252 {
1253  const DemuxStream *ds = obj;
1254 
1255  return ds->log_name;
1256 }
1257 
1258 static const AVClass input_stream_class = {
1259  .class_name = "InputStream",
1260  .version = LIBAVUTIL_VERSION_INT,
1261  .item_name = input_stream_item_name,
1262  .category = AV_CLASS_CATEGORY_DEMUXER,
1263 };
1264 
1266 {
1267  const char *type_str = av_get_media_type_string(st->codecpar->codec_type);
1268  InputFile *f = &d->f;
1269  DemuxStream *ds;
1270 
1271  ds = allocate_array_elem(&f->streams, sizeof(*ds), &f->nb_streams);
1272  if (!ds)
1273  return NULL;
1274 
1275  ds->sch_idx_stream = -1;
1276  ds->sch_idx_dec = -1;
1277 
1278  ds->ist.st = st;
1279  ds->ist.file = f;
1280  ds->ist.index = st->index;
1281  ds->ist.class = &input_stream_class;
1282 
1283  snprintf(ds->log_name, sizeof(ds->log_name), "%cist#%d:%d/%s",
1284  type_str ? *type_str : '?', d->f.index, st->index,
1286 
1287  return ds;
1288 }
1289 
1290 static int ist_add(const OptionsContext *o, Demuxer *d, AVStream *st, AVDictionary **opts_used)
1291 {
1292  AVFormatContext *ic = d->f.ctx;
1293  AVCodecParameters *par = st->codecpar;
1294  DemuxStream *ds;
1295  InputStream *ist;
1296  const char *framerate = NULL, *hwaccel_device = NULL;
1297  const char *hwaccel = NULL;
1298  const char *apply_cropping = NULL;
1299  const char *hwaccel_output_format = NULL;
1300  const char *codec_tag = NULL;
1301  const char *bsfs = NULL;
1302  char *next;
1303  const char *discard_str = NULL;
1304  int ret;
1305 
1306  ds = demux_stream_alloc(d, st);
1307  if (!ds)
1308  return AVERROR(ENOMEM);
1309 
1310  ist = &ds->ist;
1311 
1312  ds->discard = 1;
1313  st->discard = AVDISCARD_ALL;
1314  ds->first_dts = AV_NOPTS_VALUE;
1315  ds->next_dts = AV_NOPTS_VALUE;
1316 
1317  ds->dec_opts.time_base = st->time_base;
1318 
1319  ds->ts_scale = 1.0;
1320  opt_match_per_stream_dbl(ist, &o->ts_scale, ic, st, &ds->ts_scale);
1321 
1322  ds->autorotate = 1;
1323  opt_match_per_stream_int(ist, &o->autorotate, ic, st, &ds->autorotate);
1324 
1325  ds->apply_cropping = CROP_ALL;
1327  if (apply_cropping) {
1328  const AVOption opts[] = {
1329  { "apply_cropping", NULL, 0, AV_OPT_TYPE_INT,
1330  { .i64 = CROP_ALL }, CROP_DISABLED, CROP_CONTAINER, AV_OPT_FLAG_DECODING_PARAM, .unit = "apply_cropping" },
1331  { "none", NULL, 0, AV_OPT_TYPE_CONST, { .i64 = CROP_DISABLED }, .unit = "apply_cropping" },
1332  { "all", NULL, 0, AV_OPT_TYPE_CONST, { .i64 = CROP_ALL }, .unit = "apply_cropping" },
1333  { "codec", NULL, 0, AV_OPT_TYPE_CONST, { .i64 = CROP_CODEC }, .unit = "apply_cropping" },
1334  { "container", NULL, 0, AV_OPT_TYPE_CONST, { .i64 = CROP_CONTAINER }, .unit = "apply_cropping" },
1335  { NULL },
1336  };
1337  const AVClass class = {
1338  .class_name = "apply_cropping",
1339  .item_name = av_default_item_name,
1340  .option = opts,
1341  .version = LIBAVUTIL_VERSION_INT,
1342  };
1343  const AVClass *pclass = &class;
1344 
1346  if (ret < 0) {
1347  av_log(ist, AV_LOG_ERROR, "Invalid apply_cropping value '%s'.\n", apply_cropping);
1348  return ret;
1349  }
1350  }
1351 
1352  opt_match_per_stream_str(ist, &o->codec_tags, ic, st, &codec_tag);
1353  if (codec_tag) {
1354  uint32_t tag = strtol(codec_tag, &next, 0);
1355  if (*next) {
1356  uint8_t buf[4] = { 0 };
1357  memcpy(buf, codec_tag, FFMIN(sizeof(buf), strlen(codec_tag)));
1358  tag = AV_RL32(buf);
1359  }
1360 
1361  st->codecpar->codec_tag = tag;
1362  }
1363 
1364  if (st->codecpar->codec_type == AVMEDIA_TYPE_VIDEO) {
1365  ret = add_display_matrix_to_stream(o, ic, ist);
1366  if (ret < 0)
1367  return ret;
1368 
1369  opt_match_per_stream_str(ist, &o->hwaccels, ic, st, &hwaccel);
1371  &hwaccel_output_format);
1372  if (!hwaccel_output_format && hwaccel && !strcmp(hwaccel, "cuvid")) {
1373  av_log(ist, AV_LOG_WARNING,
1374  "WARNING: defaulting hwaccel_output_format to cuda for compatibility "
1375  "with old commandlines. This behaviour is DEPRECATED and will be removed "
1376  "in the future. Please explicitly set \"-hwaccel_output_format cuda\".\n");
1378  } else if (!hwaccel_output_format && hwaccel && !strcmp(hwaccel, "qsv")) {
1379  av_log(ist, AV_LOG_WARNING,
1380  "WARNING: defaulting hwaccel_output_format to qsv for compatibility "
1381  "with old commandlines. This behaviour is DEPRECATED and will be removed "
1382  "in the future. Please explicitly set \"-hwaccel_output_format qsv\".\n");
1384  } else if (!hwaccel_output_format && hwaccel && !strcmp(hwaccel, "mediacodec")) {
1385  // There is no real AVHWFrameContext implementation. Set
1386  // hwaccel_output_format to avoid av_hwframe_transfer_data error.
1388  } else if (hwaccel_output_format) {
1389  ds->dec_opts.hwaccel_output_format = av_get_pix_fmt(hwaccel_output_format);
1391  av_log(ist, AV_LOG_FATAL, "Unrecognised hwaccel output "
1392  "format: %s", hwaccel_output_format);
1393  }
1394  } else {
1396  }
1397 
1398  if (hwaccel) {
1399  // The NVDEC hwaccels use a CUDA device, so remap the name here.
1400  if (!strcmp(hwaccel, "nvdec") || !strcmp(hwaccel, "cuvid"))
1401  hwaccel = "cuda";
1402 
1403  if (!strcmp(hwaccel, "none"))
1405  else if (!strcmp(hwaccel, "auto"))
1407  else {
1409  if (type != AV_HWDEVICE_TYPE_NONE) {
1412  }
1413 
1414  if (!ds->dec_opts.hwaccel_id) {
1415  av_log(ist, AV_LOG_FATAL, "Unrecognized hwaccel: %s.\n",
1416  hwaccel);
1417  av_log(ist, AV_LOG_FATAL, "Supported hwaccels: ");
1419  while ((type = av_hwdevice_iterate_types(type)) !=
1421  av_log(ist, AV_LOG_FATAL, "%s ",
1423  av_log(ist, AV_LOG_FATAL, "\n");
1424  return AVERROR(EINVAL);
1425  }
1426  }
1427  }
1428 
1429  opt_match_per_stream_str(ist, &o->hwaccel_devices, ic, st, &hwaccel_device);
1430  if (hwaccel_device) {
1431  ds->dec_opts.hwaccel_device = av_strdup(hwaccel_device);
1432  if (!ds->dec_opts.hwaccel_device)
1433  return AVERROR(ENOMEM);
1434  }
1435  }
1436 
1437  ret = choose_decoder(o, ist, ic, st, ds->dec_opts.hwaccel_id,
1438  ds->dec_opts.hwaccel_device_type, &ist->dec);
1439  if (ret < 0)
1440  return ret;
1441 
1442  if (ist->dec) {
1444  ic, st, ist->dec, &ds->decoder_opts, opts_used);
1445  if (ret < 0)
1446  return ret;
1447  }
1448 
1449  ds->reinit_filters = -1;
1450  opt_match_per_stream_int(ist, &o->reinit_filters, ic, st, &ds->reinit_filters);
1451 
1452  ds->drop_changed = 0;
1453  opt_match_per_stream_int(ist, &o->drop_changed, ic, st, &ds->drop_changed);
1454 
1455  if (ds->drop_changed && ds->reinit_filters) {
1456  if (ds->reinit_filters > 0) {
1457  av_log(ist, AV_LOG_ERROR, "drop_changed and reinit_filters both enabled. These are mutually exclusive.\n");
1458  return AVERROR(EINVAL);
1459  }
1460  ds->reinit_filters = 0;
1461  }
1462 
1464 
1465  if ((o->video_disable && ist->st->codecpar->codec_type == AVMEDIA_TYPE_VIDEO) ||
1470 
1471  opt_match_per_stream_str(ist, &o->discard, ic, st, &discard_str);
1472  if (discard_str) {
1473  ret = av_opt_set(ist->st, "discard", discard_str, 0);
1474  if (ret < 0) {
1475  av_log(ist, AV_LOG_ERROR, "Error parsing discard %s.\n", discard_str);
1476  return ret;
1477  }
1478  ist->user_set_discard = ist->st->discard;
1479  }
1480 
1482 
1483  av_dict_set_int(&ds->decoder_opts, "apply_cropping",
1484  ds->apply_cropping && ds->apply_cropping != CROP_CONTAINER, 0);
1485 
1486  if (ds->force_display_matrix) {
1487  char buf[32];
1488  if (av_dict_get(ds->decoder_opts, "side_data_prefer_packet", NULL, 0))
1489  buf[0] = ',';
1490  else
1491  buf[0] = '\0';
1492  av_strlcat(buf, "displaymatrix", sizeof(buf));
1493  av_dict_set(&ds->decoder_opts, "side_data_prefer_packet", buf, AV_DICT_APPEND);
1494  }
1495  /* Attached pics are sparse, therefore we would not want to delay their decoding
1496  * till EOF. */
1498  av_dict_set(&ds->decoder_opts, "thread_type", "-frame", 0);
1499 
1500  switch (par->codec_type) {
1501  case AVMEDIA_TYPE_VIDEO:
1502  opt_match_per_stream_str(ist, &o->frame_rates, ic, st, &framerate);
1503  if (framerate) {
1505  if (ret < 0) {
1506  av_log(ist, AV_LOG_ERROR, "Error parsing framerate %s.\n",
1507  framerate);
1508  return ret;
1509  }
1510  }
1511 
1512 #if FFMPEG_OPT_TOP
1513  ist->top_field_first = -1;
1514  opt_match_per_stream_int(ist, &o->top_field_first, ic, st, &ist->top_field_first);
1515 #endif
1516 
1517  break;
1518  case AVMEDIA_TYPE_AUDIO: {
1519  const char *ch_layout_str = NULL;
1520 
1521  opt_match_per_stream_str(ist, &o->audio_ch_layouts, ic, st, &ch_layout_str);
1522  if (ch_layout_str) {
1523  AVChannelLayout ch_layout;
1524  ret = av_channel_layout_from_string(&ch_layout, ch_layout_str);
1525  if (ret < 0) {
1526  av_log(ist, AV_LOG_ERROR, "Error parsing channel layout %s.\n", ch_layout_str);
1527  return ret;
1528  }
1529  if (par->ch_layout.nb_channels <= 0 || par->ch_layout.nb_channels == ch_layout.nb_channels) {
1531  par->ch_layout = ch_layout;
1532  } else {
1533  av_log(ist, AV_LOG_ERROR,
1534  "Specified channel layout '%s' has %d channels, but input has %d channels.\n",
1535  ch_layout_str, ch_layout.nb_channels, par->ch_layout.nb_channels);
1536  av_channel_layout_uninit(&ch_layout);
1537  return AVERROR(EINVAL);
1538  }
1539  } else {
1540  int guess_layout_max = INT_MAX;
1541  opt_match_per_stream_int(ist, &o->guess_layout_max, ic, st, &guess_layout_max);
1542  guess_input_channel_layout(ist, par, guess_layout_max);
1543  }
1544  break;
1545  }
1546  case AVMEDIA_TYPE_DATA:
1547  case AVMEDIA_TYPE_SUBTITLE: {
1548  const char *canvas_size = NULL;
1549 
1551  opt_match_per_stream_str(ist, &o->canvas_sizes, ic, st, &canvas_size);
1552  if (canvas_size) {
1553  ret = av_parse_video_size(&par->width, &par->height,
1554  canvas_size);
1555  if (ret < 0) {
1556  av_log(ist, AV_LOG_FATAL, "Invalid canvas size: %s.\n", canvas_size);
1557  return ret;
1558  }
1559  }
1560  break;
1561  }
1563  case AVMEDIA_TYPE_UNKNOWN:
1564  break;
1565  default: av_assert0(0);
1566  }
1567 
1568  ist->par = avcodec_parameters_alloc();
1569  if (!ist->par)
1570  return AVERROR(ENOMEM);
1571 
1572  ret = avcodec_parameters_copy(ist->par, par);
1573  if (ret < 0) {
1574  av_log(ist, AV_LOG_ERROR, "Error exporting stream parameters.\n");
1575  return ret;
1576  }
1577 
1578  if (ist->st->sample_aspect_ratio.num)
1580 
1581  opt_match_per_stream_str(ist, &o->bitstream_filters, ic, st, &bsfs);
1582  if (bsfs) {
1583  ret = av_bsf_list_parse_str(bsfs, &ds->bsf);
1584  if (ret < 0) {
1585  av_log(ist, AV_LOG_ERROR,
1586  "Error parsing bitstream filter sequence '%s': %s\n",
1587  bsfs, av_err2str(ret));
1588  return ret;
1589  }
1590 
1591  ret = avcodec_parameters_copy(ds->bsf->par_in, ist->par);
1592  if (ret < 0)
1593  return ret;
1594  ds->bsf->time_base_in = ist->st->time_base;
1595 
1596  ret = av_bsf_init(ds->bsf);
1597  if (ret < 0) {
1598  av_log(ist, AV_LOG_ERROR, "Error initializing bitstream filters: %s\n",
1599  av_err2str(ret));
1600  return ret;
1601  }
1602 
1603  ret = avcodec_parameters_copy(ist->par, ds->bsf->par_out);
1604  if (ret < 0)
1605  return ret;
1606  }
1607 
1609 
1610  return 0;
1611 }
1612 
1613 static const char *input_stream_group_item_name(void *obj)
1614 {
1615  const DemuxStreamGroup *dsg = obj;
1616 
1617  return dsg->log_name;
1618 }
1619 
1621  .class_name = "InputStreamGroup",
1622  .version = LIBAVUTIL_VERSION_INT,
1623  .item_name = input_stream_group_item_name,
1624  .category = AV_CLASS_CATEGORY_DEMUXER,
1625 };
1626 
1628 {
1629  InputFile *f = &d->f;
1630  DemuxStreamGroup *dsg;
1631 
1632  dsg = allocate_array_elem(&f->stream_groups, sizeof(*dsg), &f->nb_stream_groups);
1633  if (!dsg)
1634  return NULL;
1635 
1636  dsg->istg.stg = stg;
1637  dsg->istg.file = f;
1638  dsg->istg.index = stg->index;
1640 
1641  snprintf(dsg->log_name, sizeof(dsg->log_name), "istg#%d:%d/%s",
1642  d->f.index, stg->index, avformat_stream_group_name(stg->type));
1643 
1644  return dsg;
1645 }
1646 
1648 {
1649  InputFile *f = &d->f;
1650  AVFormatContext *ic = d->f.ctx;
1651  AVStreamGroup *stg = istg->stg;
1652  const AVStreamGroupTileGrid *tg = stg->params.tile_grid;
1654  AVBPrint bp;
1655  char *graph_str;
1656  int autorotate = 1;
1657  const char *apply_cropping = NULL;
1658  int ret;
1659 
1660  if (tg->nb_tiles == 1)
1661  return 0;
1662 
1663  memset(&opts, 0, sizeof(opts));
1664 
1666  if (autorotate)
1667  opts.flags |= OFILTER_FLAG_AUTOROTATE;
1668 
1669  opts.flags |= OFILTER_FLAG_CROP;
1671  if (apply_cropping) {
1672  char *p;
1673  int crop = strtol(apply_cropping, &p, 0);
1674  if (*p)
1675  return AVERROR(EINVAL);
1676  if (!crop)
1677  opts.flags &= ~OFILTER_FLAG_CROP;
1678  }
1679 
1681  for (int i = 0; i < tg->nb_tiles; i++)
1682  av_bprintf(&bp, "[%d:g:%d:%d]", f->index, stg->index, tg->offsets[i].idx);
1683  av_bprintf(&bp, "xstack=inputs=%d:layout=", tg->nb_tiles);
1684  for (int i = 0; i < tg->nb_tiles - 1; i++)
1685  av_bprintf(&bp, "%d_%d|", tg->offsets[i].horizontal,
1686  tg->offsets[i].vertical);
1687  av_bprintf(&bp, "%d_%d:fill=0x%02X%02X%02X@0x%02X", tg->offsets[tg->nb_tiles - 1].horizontal,
1688  tg->offsets[tg->nb_tiles - 1].vertical,
1689  tg->background[0], tg->background[1],
1690  tg->background[2], tg->background[3]);
1691  av_bprintf(&bp, "[%d:g:%d]", f->index, stg->index);
1692  ret = av_bprint_finalize(&bp, &graph_str);
1693  if (ret < 0)
1694  return ret;
1695 
1696  if (tg->coded_width != tg->width || tg->coded_height != tg->height) {
1697  opts.crop_top = tg->vertical_offset;
1698  opts.crop_bottom = tg->coded_height - tg->height - tg->vertical_offset;
1699  opts.crop_left = tg->horizontal_offset;
1700  opts.crop_right = tg->coded_width - tg->width - tg->horizontal_offset;
1701  }
1702 
1703  for (int i = 0; i < tg->nb_coded_side_data; i++) {
1704  const AVPacketSideData *sd = &tg->coded_side_data[i];
1705 
1706  ret = av_packet_side_data_to_frame(&opts.side_data, &opts.nb_side_data, sd, 0);
1707  if (ret < 0 && ret != AVERROR(EINVAL))
1708  goto fail;
1709  }
1710 
1711  ret = fg_create(NULL, &graph_str, d->sch, &opts);
1712  if (ret < 0)
1713  goto fail;
1714 
1715  istg->fg = filtergraphs[nb_filtergraphs-1];
1716  istg->fg->is_internal = 1;
1717 
1718  ret = 0;
1719 fail:
1720  if (ret < 0)
1721  av_freep(&graph_str);
1722 
1723  return ret;
1724 }
1725 
1726 static int istg_add(const OptionsContext *o, Demuxer *d, AVStreamGroup *stg)
1727 {
1728  DemuxStreamGroup *dsg;
1729  InputStreamGroup *istg;
1730  int ret;
1731 
1732  dsg = demux_stream_group_alloc(d, stg);
1733  if (!dsg)
1734  return AVERROR(ENOMEM);
1735 
1736  istg = &dsg->istg;
1737 
1738  switch (stg->type) {
1740  ret = istg_parse_tile_grid(o, d, istg);
1741  if (ret < 0)
1742  return ret;
1743  break;
1744  default:
1745  break;
1746  }
1747 
1748  return 0;
1749 }
1750 
1751 static int dump_attachment(InputStream *ist, const char *filename)
1752 {
1753  AVStream *st = ist->st;
1754  int ret;
1755  AVIOContext *out = NULL;
1756  const AVDictionaryEntry *e;
1757 
1758  if (!st->codecpar->extradata_size) {
1759  av_log(ist, AV_LOG_WARNING, "No extradata to dump.\n");
1760  return 0;
1761  }
1762  if (!*filename && (e = av_dict_get(st->metadata, "filename", NULL, 0)))
1763  filename = e->value;
1764  if (!*filename) {
1765  av_log(ist, AV_LOG_FATAL, "No filename specified and no 'filename' tag");
1766  return AVERROR(EINVAL);
1767  }
1768 
1769  ret = assert_file_overwrite(filename);
1770  if (ret < 0)
1771  return ret;
1772 
1773  if ((ret = avio_open2(&out, filename, AVIO_FLAG_WRITE, &int_cb, NULL)) < 0) {
1774  av_log(ist, AV_LOG_FATAL, "Could not open file %s for writing.\n",
1775  filename);
1776  return ret;
1777  }
1778 
1780  ret = avio_close(out);
1781 
1782  if (ret >= 0)
1783  av_log(ist, AV_LOG_INFO, "Wrote attachment (%d bytes) to '%s'\n",
1784  st->codecpar->extradata_size, filename);
1785 
1786  return ret;
1787 }
1788 
1789 static const char *input_file_item_name(void *obj)
1790 {
1791  const Demuxer *d = obj;
1792 
1793  return d->log_name;
1794 }
1795 
1796 static const AVClass input_file_class = {
1797  .class_name = "InputFile",
1798  .version = LIBAVUTIL_VERSION_INT,
1799  .item_name = input_file_item_name,
1800  .category = AV_CLASS_CATEGORY_DEMUXER,
1801 };
1802 
1803 static Demuxer *demux_alloc(void)
1804 {
1806 
1807  if (!d)
1808  return NULL;
1809 
1810  d->f.class = &input_file_class;
1811  d->f.index = nb_input_files - 1;
1812 
1813  snprintf(d->log_name, sizeof(d->log_name), "in#%d", d->f.index);
1814 
1815  return d;
1816 }
1817 
1818 int ifile_open(const OptionsContext *o, const char *filename, Scheduler *sch)
1819 {
1820  Demuxer *d;
1821  InputFile *f;
1822  AVFormatContext *ic;
1823  const AVInputFormat *file_iformat = NULL;
1824  int err, ret = 0;
1825  int64_t timestamp;
1826  AVDictionary *opts_used = NULL;
1827  const char* video_codec_name = NULL;
1828  const char* audio_codec_name = NULL;
1829  const char* subtitle_codec_name = NULL;
1830  const char* data_codec_name = NULL;
1831  int scan_all_pmts_set = 0;
1832 
1834  int64_t start_time_eof = o->start_time_eof;
1835  int64_t stop_time = o->stop_time;
1836  int64_t recording_time = o->recording_time;
1837 
1838  d = demux_alloc();
1839  if (!d)
1840  return AVERROR(ENOMEM);
1841 
1842  f = &d->f;
1843 
1844  ret = sch_add_demux(sch, input_thread, d);
1845  if (ret < 0)
1846  return ret;
1847  d->sch = sch;
1848 
1849  if (stop_time != INT64_MAX && recording_time != INT64_MAX) {
1850  stop_time = INT64_MAX;
1851  av_log(d, AV_LOG_WARNING, "-t and -to cannot be used together; using -t.\n");
1852  }
1853 
1854  if (stop_time != INT64_MAX && recording_time == INT64_MAX) {
1855  int64_t start = start_time == AV_NOPTS_VALUE ? 0 : start_time;
1856  if (stop_time <= start) {
1857  av_log(d, AV_LOG_ERROR, "-to value smaller than -ss; aborting.\n");
1858  return AVERROR(EINVAL);
1859  } else {
1860  recording_time = stop_time - start;
1861  }
1862  }
1863 
1864  if (o->format) {
1865  if (!(file_iformat = av_find_input_format(o->format))) {
1866  av_log(d, AV_LOG_FATAL, "Unknown input format: '%s'\n", o->format);
1867  return AVERROR(EINVAL);
1868  }
1869  }
1870 
1871  if (!strcmp(filename, "-"))
1872  filename = "fd:";
1873 
1874  stdin_interaction &= strncmp(filename, "pipe:", 5) &&
1875  strcmp(filename, "fd:") &&
1876  strcmp(filename, "/dev/stdin");
1877 
1878  /* get default parameters from command line */
1879  ic = avformat_alloc_context();
1880  if (!ic)
1881  return AVERROR(ENOMEM);
1882  if (o->audio_sample_rate.nb_opt) {
1883  av_dict_set_int(&o->g->format_opts, "sample_rate", o->audio_sample_rate.opt[o->audio_sample_rate.nb_opt - 1].u.i, 0);
1884  }
1885  if (o->audio_channels.nb_opt) {
1886  const AVClass *priv_class;
1887  if (file_iformat && (priv_class = file_iformat->priv_class) &&
1888  av_opt_find(&priv_class, "ch_layout", NULL, 0,
1890  char buf[32];
1891  snprintf(buf, sizeof(buf), "%dC", o->audio_channels.opt[o->audio_channels.nb_opt - 1].u.i);
1892  av_dict_set(&o->g->format_opts, "ch_layout", buf, 0);
1893  }
1894  }
1895  if (o->audio_ch_layouts.nb_opt) {
1896  const AVClass *priv_class;
1897  if (file_iformat && (priv_class = file_iformat->priv_class) &&
1898  av_opt_find(&priv_class, "ch_layout", NULL, 0,
1900  av_dict_set(&o->g->format_opts, "ch_layout", o->audio_ch_layouts.opt[o->audio_ch_layouts.nb_opt - 1].u.str, 0);
1901  }
1902  }
1903  if (o->frame_rates.nb_opt) {
1904  const AVClass *priv_class;
1905  /* set the format-level framerate option;
1906  * this is important for video grabbers, e.g. x11 */
1907  if (file_iformat && (priv_class = file_iformat->priv_class) &&
1908  av_opt_find(&priv_class, "framerate", NULL, 0,
1910  av_dict_set(&o->g->format_opts, "framerate",
1911  o->frame_rates.opt[o->frame_rates.nb_opt - 1].u.str, 0);
1912  }
1913  }
1914  if (o->frame_sizes.nb_opt) {
1915  av_dict_set(&o->g->format_opts, "video_size", o->frame_sizes.opt[o->frame_sizes.nb_opt - 1].u.str, 0);
1916  }
1917  if (o->frame_pix_fmts.nb_opt)
1918  av_dict_set(&o->g->format_opts, "pixel_format", o->frame_pix_fmts.opt[o->frame_pix_fmts.nb_opt - 1].u.str, 0);
1919 
1924 
1925  if (video_codec_name)
1927  &ic->video_codec));
1928  if (audio_codec_name)
1930  &ic->audio_codec));
1931  if (subtitle_codec_name)
1933  &ic->subtitle_codec));
1934  if (data_codec_name)
1936  &ic->data_codec));
1937  if (ret < 0) {
1939  return ret;
1940  }
1941 
1946 
1947  ic->flags |= AVFMT_FLAG_NONBLOCK;
1948  if (o->bitexact)
1949  ic->flags |= AVFMT_FLAG_BITEXACT;
1950  ic->interrupt_callback = int_cb;
1951 
1952  if (!av_dict_get(o->g->format_opts, "scan_all_pmts", NULL, AV_DICT_MATCH_CASE)) {
1953  av_dict_set(&o->g->format_opts, "scan_all_pmts", "1", AV_DICT_DONT_OVERWRITE);
1954  scan_all_pmts_set = 1;
1955  }
1956  /* open the input file with generic avformat function */
1957  err = avformat_open_input(&ic, filename, file_iformat, &o->g->format_opts);
1958  if (err < 0) {
1959  if (err != AVERROR_EXIT)
1960  av_log(d, AV_LOG_ERROR,
1961  "Error opening input: %s\n", av_err2str(err));
1962  if (err == AVERROR_PROTOCOL_NOT_FOUND)
1963  av_log(d, AV_LOG_ERROR, "Did you mean file:%s?\n", filename);
1964  return err;
1965  }
1966  f->ctx = ic;
1967 
1968  av_strlcat(d->log_name, "/", sizeof(d->log_name));
1969  av_strlcat(d->log_name, ic->iformat->name, sizeof(d->log_name));
1970 
1971  if (scan_all_pmts_set)
1972  av_dict_set(&o->g->format_opts, "scan_all_pmts", NULL, AV_DICT_MATCH_CASE);
1974 
1976  if (ret < 0)
1977  return ret;
1978 
1979  /* apply forced codec ids */
1980  for (int i = 0; i < ic->nb_streams; i++) {
1981  const AVCodec *dummy;
1983  &dummy);
1984  if (ret < 0)
1985  return ret;
1986  }
1987 
1988  if (o->find_stream_info) {
1989  AVDictionary **opts;
1990  int orig_nb_streams = ic->nb_streams;
1991 
1993  if (ret < 0)
1994  return ret;
1995 
1996  /* If not enough info to get the stream parameters, we decode the
1997  first frames to get it. (used in mpeg case for example) */
1999 
2000  for (int i = 0; i < orig_nb_streams; i++)
2001  av_dict_free(&opts[i]);
2002  av_freep(&opts);
2003 
2004  if (ret < 0) {
2005  av_log(d, AV_LOG_FATAL, "could not find codec parameters\n");
2006  if (ic->nb_streams == 0)
2007  return ret;
2008  }
2009  }
2010 
2011  if (start_time != AV_NOPTS_VALUE && start_time_eof != AV_NOPTS_VALUE) {
2012  av_log(d, AV_LOG_WARNING, "Cannot use -ss and -sseof both, using -ss\n");
2013  start_time_eof = AV_NOPTS_VALUE;
2014  }
2015 
2016  if (start_time_eof != AV_NOPTS_VALUE) {
2017  if (start_time_eof >= 0) {
2018  av_log(d, AV_LOG_ERROR, "-sseof value must be negative; aborting\n");
2019  return AVERROR(EINVAL);
2020  }
2021  if (ic->duration > 0) {
2022  start_time = start_time_eof + ic->duration;
2023  if (start_time < 0) {
2024  av_log(d, AV_LOG_WARNING, "-sseof value seeks to before start of file; ignored\n");
2026  }
2027  } else
2028  av_log(d, AV_LOG_WARNING, "Cannot use -sseof, file duration not known\n");
2029  }
2030  timestamp = (start_time == AV_NOPTS_VALUE) ? 0 : start_time;
2031  /* add the stream start time */
2032  if (!o->seek_timestamp && ic->start_time != AV_NOPTS_VALUE)
2033  timestamp += ic->start_time;
2034 
2035  /* if seeking requested, we execute it */
2036  if (start_time != AV_NOPTS_VALUE) {
2037  int64_t seek_timestamp = timestamp;
2038 
2039  if (!(ic->iformat->flags & AVFMT_SEEK_TO_PTS)) {
2040  int dts_heuristic = 0;
2041  for (int i = 0; i < ic->nb_streams; i++) {
2042  const AVCodecParameters *par = ic->streams[i]->codecpar;
2043  if (par->video_delay) {
2044  dts_heuristic = 1;
2045  break;
2046  }
2047  }
2048  if (dts_heuristic) {
2049  seek_timestamp -= 3*AV_TIME_BASE / 23;
2050  }
2051  }
2052  ret = avformat_seek_file(ic, -1, INT64_MIN, seek_timestamp, seek_timestamp, 0);
2053  if (ret < 0) {
2054  av_log(d, AV_LOG_WARNING, "could not seek to position %0.3f\n",
2055  (double)timestamp / AV_TIME_BASE);
2056  }
2057  }
2058 
2059  f->start_time = start_time;
2060  d->recording_time = recording_time;
2061  f->input_sync_ref = o->input_sync_ref;
2062  f->input_ts_offset = o->input_ts_offset;
2063  f->ts_offset = o->input_ts_offset - (copy_ts ? (start_at_zero && ic->start_time != AV_NOPTS_VALUE ? ic->start_time : 0) : timestamp);
2064  d->accurate_seek = o->accurate_seek;
2065  d->loop = o->loop;
2066  d->nb_streams_warn = ic->nb_streams;
2067 
2068  d->duration = (Timestamp){ .ts = 0, .tb = (AVRational){ 1, 1 } };
2069  d->min_pts = (Timestamp){ .ts = AV_NOPTS_VALUE, .tb = (AVRational){ 1, 1 } };
2070  d->max_pts = (Timestamp){ .ts = AV_NOPTS_VALUE, .tb = (AVRational){ 1, 1 } };
2071 
2072  d->readrate = o->readrate ? o->readrate : 0.0;
2073  if (d->readrate < 0.0f) {
2074  av_log(d, AV_LOG_ERROR, "Option -readrate is %0.3f; it must be non-negative.\n", d->readrate);
2075  return AVERROR(EINVAL);
2076  }
2077  if (o->rate_emu) {
2078  if (d->readrate) {
2079  av_log(d, AV_LOG_WARNING, "Both -readrate and -re set. Using -readrate %0.3f.\n", d->readrate);
2080  } else
2081  d->readrate = 1.0f;
2082  }
2083 
2084  if (d->readrate) {
2086  if (d->readrate_initial_burst < 0.0) {
2087  av_log(d, AV_LOG_ERROR,
2088  "Option -readrate_initial_burst is %0.3f; it must be non-negative.\n",
2090  return AVERROR(EINVAL);
2091  }
2093  if (d->readrate_catchup < d->readrate) {
2094  av_log(d, AV_LOG_ERROR,
2095  "Option -readrate_catchup is %0.3f; it must be at least equal to %0.3f.\n",
2096  d->readrate_catchup, d->readrate);
2097  return AVERROR(EINVAL);
2098  }
2099  } else {
2100  if (o->readrate_initial_burst) {
2101  av_log(d, AV_LOG_WARNING, "Option -readrate_initial_burst ignored "
2102  "since neither -readrate nor -re were given\n");
2103  }
2104  if (o->readrate_catchup) {
2105  av_log(d, AV_LOG_WARNING, "Option -readrate_catchup ignored "
2106  "since neither -readrate nor -re were given\n");
2107  }
2108  }
2109 
2110  /* Add all the streams from the given input file to the demuxer */
2111  for (int i = 0; i < ic->nb_streams; i++) {
2112  ret = ist_add(o, d, ic->streams[i], &opts_used);
2113  if (ret < 0) {
2114  av_dict_free(&opts_used);
2115  return ret;
2116  }
2117  }
2118 
2119  /* Add all the stream groups from the given input file to the demuxer */
2120  for (int i = 0; i < ic->nb_stream_groups; i++) {
2121  ret = istg_add(o, d, ic->stream_groups[i]);
2122  if (ret < 0)
2123  return ret;
2124  }
2125 
2126  /* dump the file content */
2127  av_dump_format(ic, f->index, filename, 0);
2128 
2129  /* check if all codec options have been used */
2130  ret = check_avoptions_used(o->g->codec_opts, opts_used, d, 1);
2131  av_dict_free(&opts_used);
2132  if (ret < 0)
2133  return ret;
2134 
2135  for (int i = 0; i < o->dump_attachment.nb_opt; i++) {
2136  for (int j = 0; j < f->nb_streams; j++) {
2137  InputStream *ist = f->streams[j];
2138 
2139  if (check_stream_specifier(ic, ist->st, o->dump_attachment.opt[i].specifier) == 1) {
2141  if (ret < 0)
2142  return ret;
2143  }
2144  }
2145  }
2146 
2147  return 0;
2148 }
OptionsContext::readrate
float readrate
Definition: ffmpeg.h:167
flags
const SwsFlags flags[]
Definition: swscale.c:61
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:105
av_packet_unref
void av_packet_unref(AVPacket *pkt)
Wipe the packet.
Definition: packet.c:432
AVCodec
AVCodec.
Definition: codec.h:172
OptionsContext::input_ts_offset
int64_t input_ts_offset
Definition: ffmpeg.h:164
AVMEDIA_TYPE_SUBTITLE
@ AVMEDIA_TYPE_SUBTITLE
Definition: avutil.h:203
DemuxStream::ist
InputStream ist
Definition: ffmpeg_demux.c:44
av_gettime_relative
int64_t av_gettime_relative(void)
Get the current time in microseconds since some unspecified starting point.
Definition: time.c:56
AVBSFContext::par_in
AVCodecParameters * par_in
Parameters of the input stream.
Definition: bsf.h:90
AV_LOG_WARNING
#define AV_LOG_WARNING
Something somehow does not look correct.
Definition: log.h:216
AV_BPRINT_SIZE_UNLIMITED
#define AV_BPRINT_SIZE_UNLIMITED
InputFile::start_time
int64_t start_time
Definition: ffmpeg.h:536
AV_PIX_FMT_CUDA
@ AV_PIX_FMT_CUDA
HW acceleration through CUDA.
Definition: pixfmt.h:260
AVCodecParameters::extradata
uint8_t * extradata
Extra binary data needed for initializing the decoder, codec-dependent.
Definition: codec_par.h:69
AVFormatContext::stream_groups
AVStreamGroup ** stream_groups
A list of all stream groups in the file.
Definition: avformat.h:1351
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:192
demux_final_stats
static void demux_final_stats(Demuxer *d)
Definition: ffmpeg_demux.c:835
err_merge
static int err_merge(int err0, int err1)
Merge two return codes - return one of the error codes if at least one of them was negative,...
Definition: ffmpeg_utils.h:39
AVERROR
Filter the word “frame” indicates either a video frame or a group of audio as stored in an AVFrame structure Format for each input and each output the list of supported formats For video that means pixel format For audio that means channel sample they are references to shared objects When the negotiation mechanism computes the intersection of the formats supported at each end of a all references to both lists are replaced with a reference to the intersection And when a single format is eventually chosen for a link amongst the remaining all references to the list are updated That means that if a filter requires that its input and output have the same format amongst a supported all it has to do is use a reference to the same list of formats query_formats can leave some formats unset and return AVERROR(EAGAIN) to cause the negotiation mechanism toagain later. That can be used by filters with complex requirements to use the format negotiated on one link to set the formats supported on another. Frame references ownership and permissions
nb_input_files
int nb_input_files
Definition: ffmpeg.c:109
opt.h
AVCodecParameters::codec_type
enum AVMediaType codec_type
General type of the encoded data.
Definition: codec_par.h:51
AVStreamGroup::tile_grid
struct AVStreamGroupTileGrid * tile_grid
Definition: avformat.h:1133
input_stream_class
static const AVClass input_stream_class
Definition: ffmpeg_demux.c:1258
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
FrameData
Definition: ffmpeg.h:715
DemuxStreamGroup
Definition: ffmpeg_demux.c:107
check_avoptions
int check_avoptions(AVDictionary *m)
Definition: cmdutils.c:1605
apply_cropping
static int apply_cropping(AVCodecContext *avctx, AVFrame *frame)
Definition: decode.c:742
out
FILE * out
Definition: movenc.c:55
DemuxStream::drop_changed
int drop_changed
Definition: ffmpeg_demux.c:71
av_bprint_init
void av_bprint_init(AVBPrint *buf, unsigned size_init, unsigned size_max)
Definition: bprint.c:69
DecoderOpts
Definition: ffmpeg.h:440
is
The official guide to swscale for confused that is
Definition: swscale.txt:28
AV_PKT_DATA_FRAME_CROPPING
@ AV_PKT_DATA_FRAME_CROPPING
The number of pixels to discard from the top/bottom/left/right border of the decoded frame to obtain ...
Definition: packet.h:340
AVCodecParameters
This struct describes the properties of an encoded stream.
Definition: codec_par.h:47
DECODER_FLAG_SEND_END_TS
@ DECODER_FLAG_SEND_END_TS
Definition: ffmpeg.h:435
AVERROR_EOF
#define AVERROR_EOF
End of file.
Definition: error.h:57
AVStreamGroupTileGrid::horizontal_offset
int horizontal_offset
Offset in pixels from the left edge of the canvas where the actual image meant for presentation start...
Definition: avformat.h:1018
AV_DISPOSITION_ATTACHED_PIC
#define AV_DISPOSITION_ATTACHED_PIC
The stream is stored in the file as an attached picture/"cover art" (e.g.
Definition: avformat.h:670
AVStream::discard
enum AVDiscard discard
Selects which packets can be discarded at will and do not need to be demuxed.
Definition: avformat.h:815
FrameData::dts_est
int64_t dts_est
Definition: ffmpeg.h:718
sch_add_demux
int sch_add_demux(Scheduler *sch, SchThreadFunc func, void *ctx)
Add a demuxer to the scheduler.
Definition: ffmpeg_sched.c:698
input_packet_process
static int input_packet_process(Demuxer *d, AVPacket *pkt, unsigned *send_flags)
Definition: ffmpeg_demux.c:463
demux_thread_init
static int demux_thread_init(DemuxThreadContext *dt)
Definition: ffmpeg_demux.c:712
SCH_DSTREAM
#define SCH_DSTREAM(file, stream)
Definition: ffmpeg_sched.h:111
AVFMT_NOTIMESTAMPS
#define AVFMT_NOTIMESTAMPS
Format does not need / have any timestamps.
Definition: avformat.h:478
AV_TIME_BASE_Q
#define AV_TIME_BASE_Q
Internal time base represented as fractional value.
Definition: avutil.h:263
int64_t
long long int64_t
Definition: coverity.c:34
InputStream::user_set_discard
int user_set_discard
Definition: ffmpeg.h:485
DemuxStream::sch_idx_stream
int sch_idx_stream
Definition: ffmpeg_demux.c:49
OptionsContext::audio_ch_layouts
SpecifierOptList audio_ch_layouts
Definition: ffmpeg.h:155
ist_add
static int ist_add(const OptionsContext *o, Demuxer *d, AVStream *st, AVDictionary **opts_used)
Definition: ffmpeg_demux.c:1290
ist_iter
InputStream * ist_iter(InputStream *prev)
Definition: ffmpeg.c:386
av_frame_free
void av_frame_free(AVFrame **frame)
Free the frame and any dynamically allocated objects in it, e.g.
Definition: frame.c:64
DemuxStream::finished
int finished
Definition: ffmpeg_demux.c:63
InputFile::index
int index
Definition: ffmpeg.h:525
AVFrame
This structure describes decoded (raw) audio or video data.
Definition: frame.h:427
pixdesc.h
AVFormatContext::streams
AVStream ** streams
A list of all streams in the file.
Definition: avformat.h:1332
AVFrame::width
int width
Definition: frame.h:499
DECODER_FLAG_FRAMERATE_FORCED
@ DECODER_FLAG_FRAMERATE_FORCED
Definition: ffmpeg.h:431
AVPacketSideData
This structure stores auxiliary information for decoding, presenting, or otherwise processing the cod...
Definition: packet.h:409
OptionsContext::display_hflips
SpecifierOptList display_hflips
Definition: ffmpeg.h:219
DecoderOpts::par
const AVCodecParameters * par
Definition: ffmpeg.h:447
demux_stream_group_alloc
static DemuxStreamGroup * demux_stream_group_alloc(Demuxer *d, AVStreamGroup *stg)
Definition: ffmpeg_demux.c:1627
ifile_close
void ifile_close(InputFile **pf)
Definition: ffmpeg_demux.c:909
DemuxStream::streamcopy_needed
int streamcopy_needed
Definition: ffmpeg_demux.c:65
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:342
AV_HWDEVICE_TYPE_NONE
@ AV_HWDEVICE_TYPE_NONE
Definition: hwcontext.h:28
OptionsContext::subtitle_disable
int subtitle_disable
Definition: ffmpeg.h:202
demux_stream_alloc
static DemuxStream * demux_stream_alloc(Demuxer *d, AVStream *st)
Definition: ffmpeg_demux.c:1265
OptionsContext::readrate_catchup
float readrate_catchup
Definition: ffmpeg.h:168
AVOption
AVOption.
Definition: opt.h:429
AVStream::avg_frame_rate
AVRational avg_frame_rate
Average framerate.
Definition: avformat.h:833
AVStreamGroupTileGrid::vertical_offset
int vertical_offset
Offset in pixels from the top edge of the canvas where the actual image meant for presentation starts...
Definition: avformat.h:1025
DecoderOpts::hwaccel_id
enum HWAccelID hwaccel_id
Definition: ffmpeg.h:450
InputStream::nb_filters
int nb_filters
Definition: ffmpeg.h:507
AV_DICT_APPEND
#define AV_DICT_APPEND
If the entry already exists, append to it.
Definition: dict.h:82
AVCodecParameters::framerate
AVRational framerate
Video only.
Definition: codec_par.h:156
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:110
ffmpeg.h
AV_LOG_VERBOSE
#define AV_LOG_VERBOSE
Detailed information.
Definition: log.h:226
float.h
DemuxStream::decoder_opts
AVDictionary * decoder_opts
Definition: ffmpeg_demux.c:87
AVFormatContext::programs
AVProgram ** programs
Definition: avformat.h:1462
av_hwdevice_iterate_types
enum AVHWDeviceType av_hwdevice_iterate_types(enum AVHWDeviceType prev)
Iterate over supported device types.
Definition: hwcontext.c:129
autorotate
static int autorotate
Definition: ffplay.c:350
OptionsContext::bitexact
int bitexact
Definition: ffmpeg.h:198
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
AVPacket::duration
int64_t duration
Duration of this packet in AVStream->time_base units, 0 if unknown.
Definition: packet.h:606
ViewSpecifier
Definition: ffmpeg.h:129
AVCodecParameters::codec_tag
uint32_t codec_tag
Additional information about the codec (corresponds to the AVI FOURCC).
Definition: codec_par.h:59
AVDictionary
Definition: dict.c:32
AVChannelLayout::order
enum AVChannelOrder order
Channel order used in this layout.
Definition: channel_layout.h:324
FFMAX
#define FFMAX(a, b)
Definition: macros.h:47
AVStreamGroupTileGrid::vertical
int vertical
Offset in pixels from the top edge of the canvas where the tile should be placed.
Definition: avformat.h:1000
av_read_frame
int av_read_frame(AVFormatContext *s, AVPacket *pkt)
Return the next frame of a stream.
Definition: demux.c:1583
AVFormatContext::video_codec_id
enum AVCodecID video_codec_id
Forced video codec_id.
Definition: avformat.h:1468
IFILTER_FLAG_AUTOROTATE
@ IFILTER_FLAG_AUTOROTATE
Definition: ffmpeg.h:264
OptionsContext::format
const char * format
Definition: ffmpeg.h:152
AVChannelLayout::nb_channels
int nb_channels
Number of channels in this layout.
Definition: channel_layout.h:329
DECODER_FLAG_BITEXACT
@ DECODER_FLAG_BITEXACT
Definition: ffmpeg.h:437
av_bsf_free
void av_bsf_free(AVBSFContext **pctx)
Free a bitstream filter context and everything associated with it; write NULL into the supplied point...
Definition: bsf.c:52
Timestamp::ts
int64_t ts
Definition: ffmpeg_utils.h:31
av_packet_side_data_to_frame
int av_packet_side_data_to_frame(AVFrameSideData ***psd, int *pnb_sd, const AVPacketSideData *src, unsigned int flags)
Add a new frame side data entry to an array based on existing packet side data, if a matching type ex...
Definition: avcodec.c:865
tf_sess_config.config
config
Definition: tf_sess_config.py:33
file_iformat
static const AVInputFormat * file_iformat
Definition: ffplay.c:307
DemuxStream::lag
int64_t lag
Definition: ffmpeg_demux.c:104
av_packet_free
void av_packet_free(AVPacket **pkt)
Free the packet, if the packet is reference counted, it will be unreferenced first.
Definition: packet.c:74
OptionsContext::frame_pix_fmts
SpecifierOptList frame_pix_fmts
Definition: ffmpeg.h:161
AVBSFContext
The bitstream filter state.
Definition: bsf.h:68
input_stream_group_item_name
static const char * input_stream_group_item_name(void *obj)
Definition: ffmpeg_demux.c:1613
OptionsContext::canvas_sizes
SpecifierOptList canvas_sizes
Definition: ffmpeg.h:240
Demuxer::wallclock_start
int64_t wallclock_start
Definition: ffmpeg_demux.c:120
SpecifierOpt::i
int i
Definition: cmdutils.h:175
InputStream
Definition: ffmpeg.h:476
DecoderOpts::hwaccel_output_format
enum AVPixelFormat hwaccel_output_format
Definition: ffmpeg.h:453
debug_ts
int debug_ts
Definition: ffmpeg_opt.c:70
avformat_close_input
void avformat_close_input(AVFormatContext **s)
Close an opened input AVFormatContext.
Definition: demux.c:377
AVPacketSideData::size
size_t size
Definition: packet.h:411
OutputFilterOptions
Definition: ffmpeg.h:307
AVFormatContext::interrupt_callback
AVIOInterruptCB interrupt_callback
Custom interrupt callbacks for the I/O layer.
Definition: avformat.h:1534
Demuxer
Definition: ffmpeg_demux.c:114
OptionsContext::rate_emu
int rate_emu
Definition: ffmpeg.h:166
CROP_CODEC
@ CROP_CODEC
Definition: ffmpeg.h:638
dts_delta_threshold
float dts_delta_threshold
Definition: ffmpeg_opt.c:56
DemuxStream::data_size
uint64_t data_size
Definition: ffmpeg_demux.c:98
finish
static void finish(void)
Definition: movenc.c:374
bsf.h
AVFMT_SEEK_TO_PTS
#define AVFMT_SEEK_TO_PTS
Seeking is based on PTS.
Definition: avformat.h:499
InputStreamGroup
Definition: ffmpeg.h:510
OptionsContext::g
OptionGroup * g
Definition: ffmpeg.h:146
Demuxer::log_name
char log_name[32]
Definition: ffmpeg_demux.c:118
Decoder::frames_decoded
uint64_t frames_decoded
Definition: ffmpeg.h:471
Demuxer::nb_streams_finished
int nb_streams_finished
Definition: ffmpeg_demux.c:153
opt_match_per_stream_int
void opt_match_per_stream_int(void *logctx, const SpecifierOptList *sol, AVFormatContext *fc, AVStream *st, int *out)
fail
#define fail()
Definition: checkasm.h:217
AVStreamGroupTileGrid
AVStreamGroupTileGrid holds information on how to combine several independent images on a single canv...
Definition: avformat.h:951
dummy
int dummy
Definition: motion.c:64
avformat_stream_group_name
const char * avformat_stream_group_name(enum AVStreamGroupParamsType type)
Definition: avformat.c:258
AVStreamGroupTileGrid::coded_width
int coded_width
Width of the canvas.
Definition: avformat.h:966
DecoderOpts::log_parent
void * log_parent
Definition: ffmpeg.h:444
InputStreamGroup::index
int index
Definition: ffmpeg.h:516
input_file_item_name
static const char * input_file_item_name(void *obj)
Definition: ffmpeg_demux.c:1789
AVDISCARD_NONE
@ AVDISCARD_NONE
discard nothing
Definition: defs.h:226
AVFrame::ch_layout
AVChannelLayout ch_layout
Channel layout of the audio data.
Definition: frame.h:770
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
AVStreamGroupTileGrid::coded_height
int coded_height
Width of the canvas.
Definition: avformat.h:972
pts
static int64_t pts
Definition: transcode_aac.c:644
OptionsContext
Definition: ffmpeg.h:145
AVBSFContext::par_out
AVCodecParameters * par_out
Parameters of the output stream.
Definition: bsf.h:96
av_opt_set
int av_opt_set(void *obj, const char *name, const char *val, int search_flags)
Definition: opt.c:835
DemuxStreamGroup::istg
InputStreamGroup istg
Definition: ffmpeg_demux.c:108
do_pkt_dump
int do_pkt_dump
Definition: ffmpeg_opt.c:66
Demuxer::ts_offset_discont
int64_t ts_offset_discont
Extra timestamp offset added by discontinuity handling.
Definition: ffmpeg_demux.c:125
AVRational::num
int num
Numerator.
Definition: rational.h:59
Demuxer::f
InputFile f
Definition: ffmpeg_demux.c:115
Decoder::samples_decoded
uint64_t samples_decoded
Definition: ffmpeg.h:472
InputFile
Definition: ffmpeg.h:522
DemuxStream::nb_packets
uint64_t nb_packets
Definition: ffmpeg_demux.c:96
Demuxer::nb_streams_used
int nb_streams_used
Definition: ffmpeg_demux.c:152
OptionsContext::recording_time
int64_t recording_time
Definition: ffmpeg.h:191
av_frame_alloc
AVFrame * av_frame_alloc(void)
Allocate an AVFrame and set its fields to default values.
Definition: frame.c:52
AV_CODEC_ID_DVB_SUBTITLE
@ AV_CODEC_ID_DVB_SUBTITLE
Definition: codec_id.h:573
LATENCY_PROBE_DEMUX
@ LATENCY_PROBE_DEMUX
Definition: ffmpeg.h:100
OptionsContext::audio_disable
int audio_disable
Definition: ffmpeg.h:201
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:1338
avassert.h
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:210
ifile_open
int ifile_open(const OptionsContext *o, const char *filename, Scheduler *sch)
Definition: ffmpeg_demux.c:1818
AVInputFormat
Definition: avformat.h:544
AV_PKT_FLAG_CORRUPT
#define AV_PKT_FLAG_CORRUPT
The packet content is corrupted.
Definition: packet.h:644
fg_create
int fg_create(FilterGraph **pfg, char **graph_desc, Scheduler *sch, const OutputFilterOptions *opts)
Create a new filtergraph in the global filtergraph list.
Definition: ffmpeg_filter.c:1085
OptionGroup::codec_opts
AVDictionary * codec_opts
Definition: cmdutils.h:347
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:845
OptionsContext::hwaccel_output_formats
SpecifierOptList hwaccel_output_formats
Definition: ffmpeg.h:179
SpecifierOptList::nb_opt
int nb_opt
Definition: cmdutils.h:185
CROP_DISABLED
@ CROP_DISABLED
Definition: ffmpeg.h:636
opt_match_per_stream_group_str
void opt_match_per_stream_group_str(void *logctx, const SpecifierOptList *sol, AVFormatContext *fc, AVStreamGroup *stg, const char **out)
duration
int64_t duration
Definition: movenc.c:65
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:231
AVCodecParameters::frame_size
int frame_size
Audio only.
Definition: codec_par.h:195
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:653
HWACCEL_GENERIC
@ HWACCEL_GENERIC
Definition: ffmpeg.h:85
assert_file_overwrite
int assert_file_overwrite(const char *filename)
Definition: ffmpeg_opt.c:837
SpecifierOpt::specifier
char * specifier
Definition: cmdutils.h:169
AVCodecDescriptor
This struct describes the properties of a single codec described by an AVCodecID.
Definition: codec_desc.h:38
intreadwrite.h
AVFormatContext::video_codec
const struct AVCodec * video_codec
Forced video codec.
Definition: avformat.h:1786
s
#define s(width, name)
Definition: cbs_vp9.c:198
DemuxStream::first_dts
int64_t first_dts
dts of the first packet read for this stream (in AV_TIME_BASE units)
Definition: ffmpeg_demux.c:77
Demuxer::readrate
float readrate
Definition: ffmpeg_demux.c:143
av_bsf_flush
void av_bsf_flush(AVBSFContext *ctx)
Reset the internal bitstream filter state.
Definition: bsf.c:190
InputStream::framerate
AVRational framerate
Definition: ffmpeg.h:497
AVFormatContext::flags
int flags
Flags modifying the (de)muxer behaviour.
Definition: avformat.h:1415
AVCodecParameters::sample_aspect_ratio
AVRational sample_aspect_ratio
Video only.
Definition: codec_par.h:144
AVFormatContext::nb_programs
unsigned int nb_programs
Definition: avformat.h:1461
AVInputFormat::name
const char * name
A comma separated list of short names for the format.
Definition: avformat.h:549
dec_init
int dec_init(Decoder **pdec, Scheduler *sch, AVDictionary **dec_opts, const DecoderOpts *o, AVFrame *param_out)
Definition: ffmpeg_dec.c:1656
AVFormatContext::iformat
const struct AVInputFormat * iformat
The input container format.
Definition: avformat.h:1276
AVMEDIA_TYPE_AUDIO
@ AVMEDIA_TYPE_AUDIO
Definition: avutil.h:201
AVCodecParameters::width
int width
Video only.
Definition: codec_par.h:134
OptionsContext::hwaccel_devices
SpecifierOptList hwaccel_devices
Definition: ffmpeg.h:178
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:119
sch_add_demux_stream
int sch_add_demux_stream(Scheduler *sch, unsigned demux_idx)
Add a demuxed stream for a previously added demuxer.
Definition: ffmpeg_sched.c:725
av_q2d
static double av_q2d(AVRational a)
Convert an AVRational to a double.
Definition: rational.h:104
Demuxer::readrate_initial_burst
double readrate_initial_burst
Definition: ffmpeg_demux.c:144
InputFilter
Definition: ffmpeg.h:366
DemuxStream::ts_scale
double ts_scale
Definition: ffmpeg_demux.c:52
av_assert0
#define av_assert0(cond)
assert() equivalent, that is always enabled.
Definition: avassert.h:41
AVHWDeviceType
AVHWDeviceType
Definition: hwcontext.h:27
AVIO_FLAG_WRITE
#define AVIO_FLAG_WRITE
write-only
Definition: avio.h:618
discard_unused_programs
static void discard_unused_programs(InputFile *ifile)
Definition: ffmpeg_demux.c:679
AVStreamGroup::index
unsigned int index
Group index in AVFormatContext.
Definition: avformat.h:1109
AV_LOG_DEBUG
#define AV_LOG_DEBUG
Stuff which is only useful for libav* developers.
Definition: log.h:231
AVPacketSideData::data
uint8_t * data
Definition: packet.h:410
DemuxThreadContext
Definition: ffmpeg_demux.c:156
ctx
AVFormatContext * ctx
Definition: movenc.c:49
AVBSFContext::time_base_in
AVRational time_base_in
The timebase used for the timestamps of the input packets.
Definition: bsf.h:102
InputStream::filters
InputFilter ** filters
Definition: ffmpeg.h:506
demux_send
static int demux_send(Demuxer *d, DemuxThreadContext *dt, DemuxStream *ds, AVPacket *pkt, unsigned flags)
Definition: ffmpeg_demux.c:585
Demuxer::nb_streams_warn
int nb_streams_warn
Definition: ffmpeg_demux.c:141
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
OptionsContext::fix_sub_duration
SpecifierOptList fix_sub_duration
Definition: ffmpeg.h:238
DecoderOpts::hwaccel_device
char * hwaccel_device
Definition: ffmpeg.h:452
input_stream_item_name
static const char * input_stream_item_name(void *obj)
Definition: ffmpeg_demux.c:1251
ffmpeg_utils.h
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:120
OptionsContext::accurate_seek
int accurate_seek
Definition: ffmpeg.h:170
av_usleep
int av_usleep(unsigned usec)
Sleep for a period of time.
Definition: time.c:84
AVCodecParameters::nb_coded_side_data
int nb_coded_side_data
Amount of entries in coded_side_data.
Definition: codec_par.h:86
AVMEDIA_TYPE_DATA
@ AVMEDIA_TYPE_DATA
Opaque data information usually continuous.
Definition: avutil.h:202
InputStreamGroup::stg
AVStreamGroup * stg
Definition: ffmpeg.h:519
AV_ROUND_NEAR_INF
@ AV_ROUND_NEAR_INF
Round to nearest and halfway cases away from zero.
Definition: mathematics.h:135
AVPacket::opaque
void * opaque
for some private data of the user
Definition: packet.h:613
InputStreamGroup::file
struct InputFile * file
Definition: ffmpeg.h:514
AVFormatContext::data_codec
const struct AVCodec * data_codec
Forced data codec.
Definition: avformat.h:1810
SCH_DEC_IN
#define SCH_DEC_IN(decoder)
Definition: ffmpeg_sched.h:117
AV_ROUND_PASS_MINMAX
@ AV_ROUND_PASS_MINMAX
Flag telling rescaling functions to pass INT64_MIN/MAX through unchanged, avoiding special cases for ...
Definition: mathematics.h:159
Demuxer::duration
Timestamp duration
Definition: ffmpeg_demux.c:135
DemuxThreadContext::pkt_demux
AVPacket * pkt_demux
Definition: ffmpeg_demux.c:158
AV_PIX_FMT_MEDIACODEC
@ AV_PIX_FMT_MEDIACODEC
hardware decoding through MediaCodec
Definition: pixfmt.h:316
arg
const char * arg
Definition: jacosubdec.c:65
AV_CLASS_CATEGORY_DEMUXER
@ AV_CLASS_CATEGORY_DEMUXER
Definition: log.h:33
AVCodecDescriptor::props
int props
Codec properties, a combination of AV_CODEC_PROP_* flags.
Definition: codec_desc.h:54
fields
the definition of that something depends on the semantic of the filter The callback must examine the status of the filter s links and proceed accordingly The status of output links is stored in the status_in and status_out fields and tested by the then the processing requires a frame on this link and the filter is expected to make efforts in that direction The status of input links is stored by the fifo and status_out fields
Definition: filter_design.txt:155
FFABS
#define FFABS(a)
Absolute value, Note, INT_MIN / INT64_MIN result in undefined behavior as they are not representable ...
Definition: common.h:74
AVCodecParserContext::repeat_pict
int repeat_pict
This field is used for proper frame duration computation in lavf.
Definition: avcodec.h:2607
OptionsContext::start_time
int64_t start_time
Definition: ffmpeg.h:149
AVDISCARD_ALL
@ AVDISCARD_ALL
discard all
Definition: defs.h:232
AVFormatContext
Format I/O context.
Definition: avformat.h:1264
DECODING_FOR_OST
#define DECODING_FOR_OST
Definition: ffmpeg_demux.c:56
AVFormatContext::audio_codec_id
enum AVCodecID audio_codec_id
Forced audio codec_id.
Definition: avformat.h:1474
OptionGroup::format_opts
AVDictionary * format_opts
Definition: cmdutils.h:348
opts
AVDictionary * opts
Definition: movenc.c:51
AVStream::codecpar
AVCodecParameters * codecpar
Codec parameters associated with this stream.
Definition: avformat.h:767
framerate
float framerate
Definition: av1_levels.c:29
LIBAVUTIL_VERSION_INT
#define LIBAVUTIL_VERSION_INT
Definition: version.h:85
av_bsf_init
int av_bsf_init(AVBSFContext *ctx)
Prepare the filter for use, after all the parameters and options have been set.
Definition: bsf.c:149
demuxer_from_ifile
static Demuxer * demuxer_from_ifile(InputFile *f)
Definition: ffmpeg_demux.c:168
AVClass
Describe the class of an AVClass context structure.
Definition: log.h:76
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:783
NULL
#define NULL
Definition: coverity.c:32
Demuxer::readrate_catchup
float readrate_catchup
Definition: ffmpeg_demux.c:145
dec_request_view
int dec_request_view(Decoder *dec, const ViewSpecifier *vs, SchedulerNode *src)
Definition: ffmpeg_dec.c:1029
Decoder::decode_errors
uint64_t decode_errors
Definition: ffmpeg.h:473
av_frame_copy_props
int av_frame_copy_props(AVFrame *dst, const AVFrame *src)
Copy only "metadata" fields from src to dst.
Definition: frame.c:599
InputStream::top_field_first
int top_field_first
Definition: ffmpeg.h:499
InputStream::st
AVStream * st
Definition: ffmpeg.h:484
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:67
av_bsf_receive_packet
int av_bsf_receive_packet(AVBSFContext *ctx, AVPacket *pkt)
Retrieve a filtered packet.
Definition: bsf.c:230
OptionsContext::audio_channels
SpecifierOptList audio_channels
Definition: ffmpeg.h:156
InputFile::start_time_effective
int64_t start_time_effective
Effective format start time based on enabled streams.
Definition: ffmpeg.h:533
AVStreamGroupTileGrid::coded_side_data
AVPacketSideData * coded_side_data
Additional data associated with the grid.
Definition: avformat.h:1054
AVRational
Rational number (pair of numerator and denominator).
Definition: rational.h:58
filter_codec_opts
int filter_codec_opts(const AVDictionary *opts, enum AVCodecID codec_id, AVFormatContext *s, AVStream *st, const AVCodec *codec, AVDictionary **dst, AVDictionary **opts_used)
Filter out options for given codec.
Definition: cmdutils.c:1423
av_default_item_name
const char * av_default_item_name(void *ptr)
Return the context name.
Definition: log.c:242
Demuxer::recording_time
int64_t recording_time
Definition: ffmpeg_demux.c:128
parseutils.h
AVStream::metadata
AVDictionary * metadata
Definition: avformat.h:824
OptionsContext::reinit_filters
SpecifierOptList reinit_filters
Definition: ffmpeg.h:236
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:613
OptionsContext::dump_attachment
SpecifierOptList dump_attachment
Definition: ffmpeg.h:176
InputStream::fix_sub_duration
int fix_sub_duration
Definition: ffmpeg.h:502
FrameData::wallclock
int64_t wallclock[LATENCY_PROBE_NB]
Definition: ffmpeg.h:732
InputStreamGroup::class
const AVClass * class
Definition: ffmpeg.h:511
AV_DICT_DONT_OVERWRITE
#define AV_DICT_DONT_OVERWRITE
Don't overwrite existing entries.
Definition: dict.h:81
time.h
DEMUX_SEND_STREAMCOPY_EOF
@ DEMUX_SEND_STREAMCOPY_EOF
Treat the packet as an EOF for SCH_NODE_TYPE_MUX destinations send normally to other types.
Definition: ffmpeg_sched.h:340
OptionsContext::display_vflips
SpecifierOptList display_vflips
Definition: ffmpeg.h:220
DemuxStreamGroup::log_name
char log_name[32]
Definition: ffmpeg_demux.c:111
DemuxThreadContext::pkt_bsf
AVPacket * pkt_bsf
Definition: ffmpeg_demux.c:160
InputFilterOptions
Definition: ffmpeg.h:271
av_opt_get_int
int av_opt_get_int(void *obj, const char *name, int search_flags, int64_t *out_val)
Definition: opt.c:1273
AV_PIX_FMT_QSV
@ AV_PIX_FMT_QSV
HW acceleration through QSV, data[3] contains a pointer to the mfxFrameSurface1 structure.
Definition: pixfmt.h:247
Demuxer::read_started
int read_started
Definition: ffmpeg_demux.c:151
AVCodecParameters::ch_layout
AVChannelLayout ch_layout
Audio only.
Definition: codec_par.h:180
OptionsContext::input_sync_ref
int input_sync_ref
Definition: ffmpeg.h:172
report_new_stream
static void report_new_stream(Demuxer *d, const AVPacket *pkt)
Definition: ffmpeg_demux.c:184
guess_input_channel_layout
static int guess_input_channel_layout(InputStream *ist, AVCodecParameters *par, int guess_layout_max)
Definition: ffmpeg_demux.c:1190
DECODER_FLAG_FIX_SUB_DURATION
@ DECODER_FLAG_FIX_SUB_DURATION
Definition: ffmpeg.h:426
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
AVCodecParameters::sample_rate
int sample_rate
Audio only.
Definition: codec_par.h:184
Demuxer::sch
Scheduler * sch
Definition: ffmpeg_demux.c:147
find_codec
int find_codec(void *logctx, const char *name, enum AVMediaType type, int encoder, const AVCodec **codec)
Definition: ffmpeg_opt.c:804
AVFormatContext::audio_codec
const struct AVCodec * audio_codec
Forced audio codec.
Definition: avformat.h:1794
InputStream::par
AVCodecParameters * par
Codec parameters - to be used by the decoding/streamcopy code.
Definition: ffmpeg.h:492
input_files
InputFile ** input_files
Definition: ffmpeg.c:108
error.h
Scheduler
Definition: ffmpeg_sched.c:273
av_packet_side_data_get
const AVPacketSideData * av_packet_side_data_get(const AVPacketSideData *sd, int nb_sd, enum AVPacketSideDataType type)
Get side information from a side data array.
Definition: packet.c:644
avcodec_find_decoder
const AVCodec * avcodec_find_decoder(enum AVCodecID id)
Find a registered decoder with a matching codec ID.
Definition: allcodecs.c:1043
recast_media
int recast_media
Definition: ffmpeg_opt.c:91
AVCodecParameters::extradata_size
int extradata_size
Size of the extradata content in bytes.
Definition: codec_par.h:73
AVFormatContext::nb_streams
unsigned int nb_streams
Number of elements in AVFormatContext.streams.
Definition: avformat.h:1320
istg_parse_tile_grid
static int istg_parse_tile_grid(const OptionsContext *o, Demuxer *d, InputStreamGroup *istg)
Definition: ffmpeg_demux.c:1647
AV_STREAM_GROUP_PARAMS_TILE_GRID
@ AV_STREAM_GROUP_PARAMS_TILE_GRID
Definition: avformat.h:1091
DemuxStream::dts
int64_t dts
dts of the last packet read for this stream (in AV_TIME_BASE units)
Definition: ffmpeg_demux.c:83
av_codec_is_decoder
int av_codec_is_decoder(const AVCodec *codec)
Definition: utils.c:85
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:2602
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:1991
OptionsContext::discard
SpecifierOptList discard
Definition: ffmpeg.h:247
IFILTER_FLAG_REINIT
@ IFILTER_FLAG_REINIT
Definition: ffmpeg.h:265
f
f
Definition: af_crystalizer.c:122
AVIOContext
Bytestream IO Context.
Definition: avio.h:160
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:83
seek_to_start
static int seek_to_start(Demuxer *d, Timestamp end_pts)
Definition: ffmpeg_demux.c:197
AVMediaType
AVMediaType
Definition: avutil.h:198
AVPacket::size
int size
Definition: packet.h:589
InputStreamGroup::fg
FilterGraph * fg
Definition: ffmpeg.h:518
avformat_alloc_context
AVFormatContext * avformat_alloc_context(void)
Allocate an AVFormatContext.
Definition: options.c:162
AVDISCARD_DEFAULT
@ AVDISCARD_DEFAULT
discard useless packets like 0 size packets in avi
Definition: defs.h:227
av_bprint_finalize
int av_bprint_finalize(AVBPrint *buf, char **ret_str)
Finalize a print buffer.
Definition: bprint.c:235
AVChannelLayout
An AVChannelLayout holds information about the channel layout of audio data.
Definition: channel_layout.h:319
DemuxStream::have_sub2video
int have_sub2video
Definition: ffmpeg_demux.c:66
av_bsf_send_packet
int av_bsf_send_packet(AVBSFContext *ctx, AVPacket *pkt)
Submit a packet for filtering.
Definition: bsf.c:202
DemuxStream::resume_pts
int64_t resume_pts
Definition: ffmpeg_demux.c:102
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
start_time
static int64_t start_time
Definition: ffplay.c:328
Demuxer::pkt_heartbeat
AVPacket * pkt_heartbeat
Definition: ffmpeg_demux.c:149
DemuxStream::decoding_needed
int decoding_needed
Definition: ffmpeg_demux.c:55
OptionsContext::apply_cropping
SpecifierOptList apply_cropping
Definition: ffmpeg.h:181
demux_thread_uninit
static void demux_thread_uninit(DemuxThreadContext *dt)
Definition: ffmpeg_demux.c:704
copy_ts
int copy_ts
Definition: ffmpeg_opt.c:67
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:664
AV_NOPTS_VALUE
#define AV_NOPTS_VALUE
Undefined timestamp value.
Definition: avutil.h:247
AV_CODEC_PROP_FIELDS
#define AV_CODEC_PROP_FIELDS
Video codec supports separate coding of fields in interlaced frames.
Definition: codec_desc.h:97
OptionsContext::seek_timestamp
int seek_timestamp
Definition: ffmpeg.h:151
input_file_class
static const AVClass input_file_class
Definition: ffmpeg_demux.c:1796
DECODING_FOR_FILTER
#define DECODING_FOR_FILTER
Definition: ffmpeg_demux.c:57
ist_use
int ist_use(InputStream *ist, int decoding_needed, const ViewSpecifier *vs, SchedulerNode *src)
Definition: ffmpeg_demux.c:935
AVFrame::format
int format
format of the frame, -1 if unknown or unset Values correspond to enum AVPixelFormat for video frames,...
Definition: frame.h:514
AVMEDIA_TYPE_UNKNOWN
@ AVMEDIA_TYPE_UNKNOWN
Usually treated as AVMEDIA_TYPE_DATA.
Definition: avutil.h:199
DemuxStream::bsf
AVBSFContext * bsf
Definition: ffmpeg_demux.c:93
AVStream::sample_aspect_ratio
AVRational sample_aspect_ratio
sample aspect ratio (0 if unknown)
Definition: avformat.h:822
AVStreamGroup::params
union AVStreamGroup::@426 params
Group type-specific parameters.
OptionsContext::readrate_initial_burst
double readrate_initial_burst
Definition: ffmpeg.h:169
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:1540
AVPacket::dts
int64_t dts
Decompression timestamp in AVStream->time_base units; the time at which the packet is decompressed.
Definition: packet.h:587
avio_write
void avio_write(AVIOContext *s, const unsigned char *buf, int size)
Definition: aviobuf.c:206
OptionsContext::find_stream_info
int find_stream_info
Definition: ffmpeg.h:173
OptionsContext::display_rotations
SpecifierOptList display_rotations
Definition: ffmpeg.h:218
DemuxStream::autorotate
int autorotate
Definition: ffmpeg_demux.c:68
DemuxStream::sch_idx_dec
int sch_idx_dec
Definition: ffmpeg_demux.c:50
AVStreamGroupTileGrid::nb_tiles
unsigned int nb_tiles
Amount of tiles in the grid.
Definition: avformat.h:959
SpecifierOptList::opt
SpecifierOpt * opt
Definition: cmdutils.h:184
offset
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 offset
Definition: writing_filters.txt:86
opt_match_per_stream_dbl
void opt_match_per_stream_dbl(void *logctx, const SpecifierOptList *sol, AVFormatContext *fc, AVStream *st, double *out)
AVPacket::flags
int flags
A combination of AV_PKT_FLAG values.
Definition: packet.h:594
av_packet_alloc
AVPacket * av_packet_alloc(void)
Allocate an AVPacket and set its fields to default values.
Definition: packet.c:63
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:233
OptionsContext::ts_scale
SpecifierOptList ts_scale
Definition: ffmpeg.h:175
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
av_packet_rescale_ts
void av_packet_rescale_ts(AVPacket *pkt, AVRational src_tb, AVRational dst_tb)
Convert valid timing fields (timestamps / durations) in a packet from one timebase to another.
Definition: packet.c:536
AV_LOG_INFO
#define AV_LOG_INFO
Standard information.
Definition: log.h:221
video_codec_name
static const char * video_codec_name
Definition: ffplay.c:343
DemuxStream::next_dts
int64_t next_dts
Definition: ffmpeg_demux.c:81
AVCodec::id
enum AVCodecID id
Definition: codec.h:186
CROP_CONTAINER
@ CROP_CONTAINER
Definition: ffmpeg.h:639
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:839
avcodec_parameters_alloc
AVCodecParameters * avcodec_parameters_alloc(void)
Allocate a new AVCodecParameters and set its fields to default values (unknown/invalid/0).
Definition: codec_par.c:57
avcodec_get_name
const char * avcodec_get_name(enum AVCodecID id)
Get the name of a codec.
Definition: utils.c:406
HWACCEL_AUTO
@ HWACCEL_AUTO
Definition: ffmpeg.h:84
AVStreamGroupTileGrid::nb_coded_side_data
int nb_coded_side_data
Amount of entries in coded_side_data.
Definition: avformat.h:1059
DemuxStream
Definition: ffmpeg_demux.c:43
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
CROP_ALL
@ CROP_ALL
Definition: ffmpeg.h:637
DemuxStream::dec_name
char dec_name[16]
Definition: ffmpeg_demux.c:89
av_channel_layout_from_string
int av_channel_layout_from_string(AVChannelLayout *channel_layout, const char *str)
Initialize a channel layout from a given string description.
Definition: channel_layout.c:312
DemuxStream::apply_cropping
int apply_cropping
Definition: ffmpeg_demux.c:69
AVStreamGroupTileGrid::width
int width
Width of the final image for presentation.
Definition: avformat.h:1036
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:256
AVPacket::pts
int64_t pts
Presentation timestamp in AVStream->time_base units; the time at which the decompressed packet will b...
Definition: packet.h:581
OptionsContext::frame_rates
SpecifierOptList frame_rates
Definition: ffmpeg.h:158
setup_find_stream_info_opts
int setup_find_stream_info_opts(AVFormatContext *s, AVDictionary *local_codec_opts, AVDictionary ***dst)
Setup AVCodecContext options for avformat_find_stream_info().
Definition: cmdutils.c:1491
OptionsContext::codec_names
SpecifierOptList codec_names
Definition: ffmpeg.h:154
packet.h
demux_bsf_flush
static int demux_bsf_flush(Demuxer *d, DemuxThreadContext *dt)
Definition: ffmpeg_demux.c:654
AVFormatContext::subtitle_codec
const struct AVCodec * subtitle_codec
Forced subtitle codec.
Definition: avformat.h:1802
AVCodecParameters::height
int height
Definition: codec_par.h:135
OptionsContext::autorotate
SpecifierOptList autorotate
Definition: ffmpeg.h:180
AV_TIME_BASE
#define AV_TIME_BASE
Internal time base represented as integer.
Definition: avutil.h:253
DecoderOpts::time_base
AVRational time_base
Definition: ffmpeg.h:455
SHOW_TS_DEBUG
#define SHOW_TS_DEBUG(tag_)
opt_match_per_stream_group_int
void opt_match_per_stream_group_int(void *logctx, const SpecifierOptList *sol, AVFormatContext *fc, AVStreamGroup *stg, int *out)
OptionsContext::start_time_eof
int64_t start_time_eof
Definition: ffmpeg.h:150
display.h
SCH_DEC_OUT
#define SCH_DEC_OUT(decoder, out_idx)
Definition: ffmpeg_sched.h:120
exit_on_error
int exit_on_error
Definition: ffmpeg_opt.c:71
Demuxer::have_audio_dec
int have_audio_dec
Definition: ffmpeg_demux.c:133
av_assert1
#define av_assert1(cond)
assert() equivalent, that does not lie in speed critical code.
Definition: avassert.h:57
DemuxStream::force_display_matrix
int force_display_matrix
Definition: ffmpeg_demux.c:70
delta
float delta
Definition: vorbis_enc_data.h:430
AVMEDIA_TYPE_ATTACHMENT
@ AVMEDIA_TYPE_ATTACHMENT
Opaque data information usually sparse.
Definition: avutil.h:204
DemuxStream::resume_wc
int64_t resume_wc
Definition: ffmpeg_demux.c:100
InputFile::ctx
AVFormatContext * ctx
Definition: ffmpeg.h:527
FFMIN
#define FFMIN(a, b)
Definition: macros.h:49
OptionsContext::hwaccels
SpecifierOptList hwaccels
Definition: ffmpeg.h:177
AVProgram
New fields can be added to the end with minor version bumps.
Definition: avformat.h:1188
av_inv_q
static av_always_inline AVRational av_inv_q(AVRational q)
Invert a rational.
Definition: rational.h:159
IFILTER_FLAG_DROPCHANGED
@ IFILTER_FLAG_DROPCHANGED
Definition: ffmpeg.h:268
SchedulerNode
Definition: ffmpeg_sched.h:103
filtergraphs
FilterGraph ** filtergraphs
Definition: ffmpeg.c:114
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:311
AVBSFContext::time_base_out
AVRational time_base_out
The timebase used for the timestamps of the output packets.
Definition: bsf.h:108
AVCodecParameters::coded_side_data
AVPacketSideData * coded_side_data
Additional data associated with the entire stream.
Definition: codec_par.h:81
DemuxStream::discard
int discard
Definition: ffmpeg_demux.c:60
OFILTER_FLAG_CROP
@ OFILTER_FLAG_CROP
Definition: ffmpeg.h:304
AVFMT_FLAG_NONBLOCK
#define AVFMT_FLAG_NONBLOCK
Do not block when reading packets from input.
Definition: avformat.h:1418
av_codec_iterate
const AVCodec * av_codec_iterate(void **opaque)
Iterate over all registered codecs.
Definition: allcodecs.c:994
sch_connect
int sch_connect(Scheduler *sch, SchedulerNode src, SchedulerNode dst)
Definition: ffmpeg_sched.c:937
AVStreamGroupTileGrid::horizontal
int horizontal
Offset in pixels from the left edge of the canvas where the tile should be placed.
Definition: avformat.h:995
ist_find_unused
InputStream * ist_find_unused(enum AVMediaType type)
Find an unused input stream of given type.
Definition: ffmpeg_demux.c:173
istg_add
static int istg_add(const OptionsContext *o, Demuxer *d, AVStreamGroup *stg)
Definition: ffmpeg_demux.c:1726
Timestamp::tb
AVRational tb
Definition: ffmpeg_utils.h:32
InputStream::decoder
Decoder * decoder
Definition: ffmpeg.h:493
OFILTER_FLAG_AUTOROTATE
@ OFILTER_FLAG_AUTOROTATE
Definition: ffmpeg.h:303
AVStream::disposition
int disposition
Stream disposition - a combination of AV_DISPOSITION_* flags.
Definition: avformat.h:813
DemuxStream::codec_desc
const AVCodecDescriptor * codec_desc
Definition: ffmpeg_demux.c:85
ts_discontinuity_process
static void ts_discontinuity_process(Demuxer *d, InputStream *ist, AVPacket *pkt)
Definition: ffmpeg_demux.c:292
tag
uint32_t tag
Definition: movenc.c:2032
AVStream::id
int id
Format-specific stream ID.
Definition: avformat.h:756
AVFMT_FLAG_BITEXACT
#define AVFMT_FLAG_BITEXACT
When muxing, try to avoid writing any random/volatile data to the output.
Definition: avformat.h:1432
ret
ret
Definition: filter_design.txt:187
AVStream
Stream structure.
Definition: avformat.h:744
AV_LOG_FATAL
#define AV_LOG_FATAL
Something went wrong and recovery is not possible.
Definition: log.h:204
dec_free
void dec_free(Decoder **pdec)
Definition: ffmpeg_dec.c:118
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:685
DemuxStream::wrap_correction_done
int wrap_correction_done
Definition: ffmpeg_demux.c:74
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:81
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:95
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:132
InputFile::streams
InputStream ** streams
Definition: ffmpeg.h:541
add_display_matrix_to_stream
static int add_display_matrix_to_stream(const OptionsContext *o, AVFormatContext *ctx, InputStream *ist)
Definition: ffmpeg_demux.c:1207
hwaccel
static const char * hwaccel
Definition: ffplay.c:356
DECODER_FLAG_TOP_FIELD_FIRST
@ DECODER_FLAG_TOP_FIELD_FIRST
Definition: ffmpeg.h:433
Demuxer::accurate_seek
int accurate_seek
Definition: ffmpeg_demux.c:129
avformat.h
HWAccelID
HWAccelID
Definition: ffmpeg.h:82
av_bprintf
void av_bprintf(AVBPrint *buf, const char *fmt,...)
Definition: bprint.c:122
av_packet_side_data_new
AVPacketSideData * av_packet_side_data_new(AVPacketSideData **psd, int *pnb_sd, enum AVPacketSideDataType type, size_t size, int flags)
Allocate a new packet side data.
Definition: packet.c:694
choose_decoder
static int choose_decoder(const OptionsContext *o, void *logctx, AVFormatContext *s, AVStream *st, enum HWAccelID hwaccel_id, enum AVHWDeviceType hwaccel_device_type, const AVCodec **pcodec)
Definition: ffmpeg_demux.c:1143
OptionsContext::drop_changed
SpecifierOptList drop_changed
Definition: ffmpeg.h:237
check_avoptions_used
int check_avoptions_used(const AVDictionary *opts, const AVDictionary *opts_used, void *logctx, int decode)
Definition: ffmpeg.c:500
remove_avoptions
void remove_avoptions(AVDictionary **a, AVDictionary *b)
Definition: cmdutils.c:1596
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
istg_free
static void istg_free(InputStreamGroup **pistg)
Definition: ffmpeg_demux.c:899
av_get_pix_fmt
enum AVPixelFormat av_get_pix_fmt(const char *name)
Return the pixel format corresponding to name.
Definition: pixdesc.c:3388
AVStreamGroup
Definition: avformat.h:1098
AVFormatContext::data_codec_id
enum AVCodecID data_codec_id
Forced Data codec_id.
Definition: avformat.h:1486
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
AVFrame::height
int height
Definition: frame.h:499
AVStream::index
int index
stream index in AVFormatContext
Definition: avformat.h:750
IFILTER_FLAG_CROP
@ IFILTER_FLAG_CROP
Definition: ffmpeg.h:267
InputFile::class
const AVClass * class
Definition: ffmpeg.h:523
OptionsContext::audio_sample_rate
SpecifierOptList audio_sample_rate
Definition: ffmpeg.h:157
audio_codec_name
static const char * audio_codec_name
Definition: ffplay.c:341
sch_demux_send
int sch_demux_send(Scheduler *sch, unsigned demux_idx, AVPacket *pkt, unsigned flags)
Called by demuxer tasks to communicate with their downstreams.
Definition: ffmpeg_sched.c:2137
ts_discontinuity_detect
static void ts_discontinuity_detect(Demuxer *d, InputStream *ist, AVPacket *pkt)
Definition: ffmpeg_demux.c:224
PKT_OPAQUE_SUB_HEARTBEAT
@ PKT_OPAQUE_SUB_HEARTBEAT
Definition: ffmpeg.h:95
AVInputFormat::flags
int flags
Can use flags: AVFMT_NOFILE, AVFMT_NEEDNUMBER, AVFMT_SHOW_IDS, AVFMT_NOTIMESTAMPS,...
Definition: avformat.h:563
AVRational::den
int den
Denominator.
Definition: rational.h:60
InputStream::file
struct InputFile * file
Definition: ffmpeg.h:480
SpecifierOpt::str
uint8_t * str
Definition: cmdutils.h:174
AV_PIX_FMT_NONE
@ AV_PIX_FMT_NONE
Definition: pixfmt.h:72
AV_OPT_TYPE_INT
@ AV_OPT_TYPE_INT
Underlying C type is int.
Definition: opt.h:259
av_channel_layout_uninit
void av_channel_layout_uninit(AVChannelLayout *channel_layout)
Free any allocated data in the channel layout and reset the channel count to 0.
Definition: channel_layout.c:442
avformat_free_context
void avformat_free_context(AVFormatContext *s)
Free an AVFormatContext and all its streams.
Definition: avformat.c:143
IFILTER_FLAG_CFR
@ IFILTER_FLAG_CFR
Definition: ffmpeg.h:266
OptionsContext::frame_sizes
SpecifierOptList frame_sizes
Definition: ffmpeg.h:160
OptionsContext::video_disable
int video_disable
Definition: ffmpeg.h:200
ds_from_ist
static DemuxStream * ds_from_ist(InputStream *ist)
Definition: ffmpeg_demux.c:163
input_stream_group_class
static const AVClass input_stream_group_class
Definition: ffmpeg_demux.c:1620
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:146
Windows::Graphics::DirectX::Direct3D11::p
IDirect3DDxgiInterfaceAccess _COM_Outptr_ void ** p
Definition: vsrc_gfxcapture_winrt.hpp:53
demux_alloc
static Demuxer * demux_alloc(void)
Definition: ffmpeg_demux.c:1803
AVFormatContext::duration
int64_t duration
Duration of the stream, in AV_TIME_BASE fractional seconds.
Definition: avformat.h:1399
av_mul_q
AVRational av_mul_q(AVRational b, AVRational c)
Multiply two rationals.
Definition: rational.c:80
AVPacket::stream_index
int stream_index
Definition: packet.h:590
GROW_ARRAY
#define GROW_ARRAY(array, nb_elems)
Definition: cmdutils.h:536
HWACCEL_NONE
@ HWACCEL_NONE
Definition: ffmpeg.h:83
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:850
ist_dts_update
static int ist_dts_update(DemuxStream *ds, AVPacket *pkt, FrameData *fd)
Definition: ffmpeg_demux.c:312
data_codec_name
static const char * data_codec_name
Definition: ffprobe.c:135
InputFile::ts_offset
int64_t ts_offset
Definition: ffmpeg.h:534
av_channel_layout_copy
int av_channel_layout_copy(AVChannelLayout *dst, const AVChannelLayout *src)
Make a copy of a channel layout.
Definition: channel_layout.c:449
av_log_once
void av_log_once(void *avcl, int initial_level, int subsequent_level, int *state, const char *fmt,...)
Definition: log.c:451
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:177
OptionsContext::codec_tags
SpecifierOptList codec_tags
Definition: ffmpeg.h:211
DecoderOpts::flags
int flags
Definition: ffmpeg.h:441
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:356
AVMEDIA_TYPE_VIDEO
@ AVMEDIA_TYPE_VIDEO
Definition: avutil.h:200
av_bsf_list_parse_str
int av_bsf_list_parse_str(const char *str, AVBSFContext **bsf_lst)
Parse string describing list of bitstream filters and create single AVBSFContext describing the whole...
Definition: bsf.c:526
start_at_zero
int start_at_zero
Definition: ffmpeg_opt.c:68
AVFMT_TS_DISCONT
#define AVFMT_TS_DISCONT
Format allows timestamp discontinuities.
Definition: avformat.h:480
mem.h
AVStreamGroup::type
enum AVStreamGroupParamsType type
Group type.
Definition: avformat.h:1125
SpecifierOpt::u
union SpecifierOpt::@0 u
avio_open2
int avio_open2(AVIOContext **s, const char *filename, int flags, const AVIOInterruptCB *int_cb, AVDictionary **options)
Create and initialize a AVIOContext for accessing the resource indicated by url.
Definition: avio.c:492
DECODER_FLAG_TS_UNRELIABLE
@ DECODER_FLAG_TS_UNRELIABLE
Definition: ffmpeg.h:428
AVCodecParameters::video_delay
int video_delay
Video only.
Definition: codec_par.h:175
DemuxStream::log_name
char log_name[32]
Definition: ffmpeg_demux.c:47
DecoderOpts::codec
const AVCodec * codec
Definition: ffmpeg.h:446
InputStream::class
const AVClass * class
Definition: ffmpeg.h:477
InputStream::index
int index
Definition: ffmpeg.h:482
readrate_sleep
static void readrate_sleep(Demuxer *d)
Definition: ffmpeg_demux.c:507
AVFormatContext::nb_stream_groups
unsigned int nb_stream_groups
Number of elements in AVFormatContext.stream_groups.
Definition: avformat.h:1339
AVStreamGroupTileGrid::height
int height
Height of the final image for presentation.
Definition: avformat.h:1046
ffmpeg_sched.h
AVDictionaryEntry
Definition: dict.h:90
Demuxer::max_pts
Timestamp max_pts
Definition: ffmpeg_demux.c:138
DemuxStream::dec_opts
DecoderOpts dec_opts
Definition: ffmpeg_demux.c:88
stdin_interaction
int stdin_interaction
Definition: ffmpeg_opt.c:74
do_hex_dump
int do_hex_dump
Definition: ffmpeg_opt.c:65
AVCodecParameters::codec_id
enum AVCodecID codec_id
Specific type of the encoded data (the codec used).
Definition: codec_par.h:55
AVPacket
This structure stores compressed data.
Definition: packet.h:565
ist_filter_add
int ist_filter_add(InputStream *ist, InputFilter *ifilter, int is_simple, const ViewSpecifier *vs, InputFilterOptions *opts, SchedulerNode *src)
Definition: ffmpeg_demux.c:1045
av_freep
#define av_freep(p)
Definition: tableprint_vlc.h:35
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:608
packet_data
FrameData * packet_data(AVPacket *pkt)
Definition: ffmpeg.c:488
OptionsContext::data_disable
int data_disable
Definition: ffmpeg.h:203
nb_filtergraphs
int nb_filtergraphs
Definition: ffmpeg.c:115
int32_t
int32_t
Definition: audioconvert.c:56
ist_free
static void ist_free(InputStream **pist)
Definition: ffmpeg_demux.c:875
DemuxStream::reinit_filters
int reinit_filters
Definition: ffmpeg_demux.c:67
timestamp.h
Demuxer::min_pts
Timestamp min_pts
Definition: ffmpeg_demux.c:137
AVERROR_BUG
#define AVERROR_BUG
Internal bug, also see AVERROR_BUG2.
Definition: error.h:52
ts_fixup
static int ts_fixup(Demuxer *d, AVPacket *pkt, FrameData *fd)
Definition: ffmpeg_demux.c:372
avio_close
int avio_close(AVIOContext *s)
Close the resource accessed by the AVIOContext s and free it.
Definition: avio.c:617
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:1389
DecoderOpts::framerate
AVRational framerate
Definition: ffmpeg.h:459
dts_error_threshold
float dts_error_threshold
Definition: ffmpeg_opt.c:57
AVERROR_INVALIDDATA
#define AVERROR_INVALIDDATA
Invalid data found when processing input.
Definition: error.h:61
av_ts2str
#define av_ts2str(ts)
Convenience macro, the return value should be used only directly in function arguments but never stan...
Definition: timestamp.h:54
av_stream_get_parser
struct AVCodecParserContext * av_stream_get_parser(const AVStream *s)
Definition: demux_utils.c:33
AVCodecHWConfig
Definition: codec.h:330
AVERROR_EXIT
#define AVERROR_EXIT
Immediate exit was requested; the called function should not be restarted.
Definition: error.h:58
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:122
avcodec_descriptor_get
const AVCodecDescriptor * avcodec_descriptor_get(enum AVCodecID id)
Definition: codec_desc.c:3887
do_send
static int do_send(Demuxer *d, DemuxStream *ds, AVPacket *pkt, unsigned flags, const char *pkt_desc)
Definition: ffmpeg_demux.c:556
Demuxer::last_ts
int64_t last_ts
Definition: ffmpeg_demux.c:126
DemuxStream::decoded_params
AVFrame * decoded_params
Definition: ffmpeg_demux.c:91
AVDictionaryEntry::value
char * value
Definition: dict.h:92
avstring.h
Timestamp
Definition: ffmpeg_utils.h:30
opt_match_per_type_str
const char * opt_match_per_type_str(const SpecifierOptList *sol, char mediatype)
Definition: ffmpeg_opt.c:168
AVStreamGroupTileGrid::idx
unsigned int idx
Index of the stream in the group this tile references.
Definition: avformat.h:990
opt_match_per_stream_str
void opt_match_per_stream_str(void *logctx, const SpecifierOptList *sol, AVFormatContext *fc, AVStream *st, const char **out)
DemuxStream::saw_first_ts
int saw_first_ts
Definition: ffmpeg_demux.c:75
InputFile::nb_streams
int nb_streams
Definition: ffmpeg.h:542
OptionsContext::guess_layout_max
SpecifierOptList guess_layout_max
Definition: ffmpeg.h:245
AVStream::pts_wrap_bits
int pts_wrap_bits
Number of bits in timestamps.
Definition: avformat.h:887
dump_attachment
static int dump_attachment(InputStream *ist, const char *filename)
Definition: ffmpeg_demux.c:1751
AVERROR_PROTOCOL_NOT_FOUND
#define AVERROR_PROTOCOL_NOT_FOUND
Protocol not found.
Definition: error.h:65
AV_OPT_TYPE_CONST
@ AV_OPT_TYPE_CONST
Special option type for declaring named constants.
Definition: opt.h:299
InputStream::dec
const AVCodec * dec
Definition: ffmpeg.h:494
snprintf
#define snprintf
Definition: snprintf.h:34
DecoderOpts::hwaccel_device_type
enum AVHWDeviceType hwaccel_device_type
Definition: ffmpeg.h:451
FilterGraph::is_internal
int is_internal
Definition: ffmpeg.h:419
av_rescale_q_rnd
int64_t av_rescale_q_rnd(int64_t a, AVRational bq, AVRational cq, enum AVRounding rnd)
Rescale a 64-bit integer by 2 rational numbers with specified rounding.
Definition: mathematics.c:134
OptionsContext::bitstream_filters
SpecifierOptList bitstream_filters
Definition: ffmpeg.h:210
input_thread
static int input_thread(void *arg)
Definition: ffmpeg_demux.c:727
src
#define src
Definition: vp8dsp.c:248
AVInputFormat::priv_class
const AVClass * priv_class
AVClass for the private context.
Definition: avformat.h:574
avcodec_parameters_copy
int avcodec_parameters_copy(AVCodecParameters *dst, const AVCodecParameters *src)
Copy the contents of src to dst.
Definition: codec_par.c:107
AVStreamGroupTileGrid::background
uint8_t background[4]
The pixel value per channel in RGBA format used if no pixel of any tile is located at a particular pi...
Definition: avformat.h:1010
AVPacket::time_base
AVRational time_base
Time base of the packet's timestamps.
Definition: packet.h:632
AVStreamGroupTileGrid::offsets
struct AVStreamGroupTileGrid::@425 * offsets
An nb_tiles sized array of offsets in pixels from the topleft edge of the canvas, indicating where ea...
OptionsContext::top_field_first
SpecifierOptList top_field_first
Definition: ffmpeg.h:226
OptionsContext::loop
int loop
Definition: ffmpeg.h:165
thread_set_name
static void thread_set_name(InputFile *f)
Definition: ffmpeg_demux.c:697
ff_thread_setname
static int ff_thread_setname(const char *name)
Definition: thread.h:216
AVFormatContext::subtitle_codec_id
enum AVCodecID subtitle_codec_id
Forced subtitle codec_id.
Definition: avformat.h:1480
DecoderOpts::name
char * name
Definition: ffmpeg.h:443