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"
32 #include "libavutil/mem.h"
33 #include "libavutil/opt.h"
34 #include "libavutil/parseutils.h"
35 #include "libavutil/pixdesc.h"
36 #include "libavutil/time.h"
37 #include "libavutil/timestamp.h"
38 
39 #include "libavcodec/bsf.h"
40 #include "libavcodec/packet.h"
41 
42 #include "libavformat/avformat.h"
43 
44 typedef struct DemuxStream {
46 
47  // name used for logging
48  char log_name[32];
49 
52 
53  double ts_scale;
54 
55  /* non zero if the packets must be decoded in 'raw_fifo', see DECODING_FOR_* */
57 #define DECODING_FOR_OST 1
58 #define DECODING_FOR_FILTER 2
59 
60  /* true if stream data should be discarded */
61  int discard;
62 
63  // scheduler returned EOF for this stream
64  int finished;
65 
75 
76 
79  /// dts of the first packet read for this stream (in AV_TIME_BASE units)
81 
82  /* predicted dts of the next packet read for this stream or (when there are
83  * several frames in a packet) of the next frame in current packet (in AV_TIME_BASE units) */
85  /// dts of the last packet read for this stream (in AV_TIME_BASE units)
87 
89 
92  char dec_name[16];
93  // decoded media properties, as estimated by opening the decoder
95 
97 
98  /* number of packets successfully read for this stream */
99  uint64_t nb_packets;
100  // combined size of all the packets read
101  uint64_t data_size;
102  // latest wallclock time at which packet reading resumed after a stall - used for readrate
104  // timestamp of first packet sent after the latest stall - used for readrate
106  // measure of how far behind packet reading is against spceified readrate
108 } DemuxStream;
109 
110 typedef struct DemuxStreamGroup {
112 
113  // name used for logging
114  char log_name[32];
116 
117 typedef struct Demuxer {
119 
120  // name used for logging
121  char log_name[32];
122 
124 
125  /**
126  * Extra timestamp offset added by discontinuity handling.
127  */
130 
133 
134  /* number of times input stream should be looped */
135  int loop;
137  /* duration of the looped segment of the input file */
139  /* pts with the smallest/largest values ever seen */
142 
143  /* number of streams that the user was warned of */
145 
146  float readrate;
149 
151 
153 
157 } Demuxer;
158 
159 typedef struct DemuxThreadContext {
160  // packet used for reading from the demuxer
162  // packet for reading from BSFs
165 
167 {
168  return (DemuxStream*)ist;
169 }
170 
172 {
173  return (Demuxer*)f;
174 }
175 
177 {
178  for (InputStream *ist = ist_iter(NULL); ist; ist = ist_iter(ist)) {
179  DemuxStream *ds = ds_from_ist(ist);
180  if (ist->par->codec_type == type && ds->discard &&
181  ist->user_set_discard != AVDISCARD_ALL)
182  return ist;
183  }
184  return NULL;
185 }
186 
187 static void report_new_stream(Demuxer *d, const AVPacket *pkt)
188 {
189  const AVStream *st = d->f.ctx->streams[pkt->stream_index];
190 
191  if (pkt->stream_index < d->nb_streams_warn)
192  return;
194  "New %s stream with index %d at pos:%"PRId64" and DTS:%ss\n",
197  d->nb_streams_warn = pkt->stream_index + 1;
198 }
199 
200 static int seek_to_start(Demuxer *d, Timestamp end_pts)
201 {
202  InputFile *ifile = &d->f;
203  AVFormatContext *is = ifile->ctx;
204  int ret;
205 
206  ret = avformat_seek_file(is, -1, INT64_MIN, is->start_time, is->start_time, 0);
207  if (ret < 0)
208  return ret;
209 
210  if (end_pts.ts != AV_NOPTS_VALUE &&
211  (d->max_pts.ts == AV_NOPTS_VALUE ||
212  av_compare_ts(d->max_pts.ts, d->max_pts.tb, end_pts.ts, end_pts.tb) < 0))
213  d->max_pts = end_pts;
214 
215  if (d->max_pts.ts != AV_NOPTS_VALUE) {
216  int64_t min_pts = d->min_pts.ts == AV_NOPTS_VALUE ? 0 : d->min_pts.ts;
217  d->duration.ts = d->max_pts.ts - av_rescale_q(min_pts, d->min_pts.tb, d->max_pts.tb);
218  }
219  d->duration.tb = d->max_pts.tb;
220 
221  if (d->loop > 0)
222  d->loop--;
223 
224  return ret;
225 }
226 
228  AVPacket *pkt)
229 {
230  InputFile *ifile = &d->f;
231  DemuxStream *ds = ds_from_ist(ist);
232  const int fmt_is_discont = ifile->ctx->iformat->flags & AVFMT_TS_DISCONT;
233  int disable_discontinuity_correction = copy_ts;
236 
237  if (copy_ts && ds->next_dts != AV_NOPTS_VALUE &&
238  fmt_is_discont && ist->st->pts_wrap_bits < 60) {
239  int64_t wrap_dts = av_rescale_q_rnd(pkt->dts + (1LL<<ist->st->pts_wrap_bits),
242  if (FFABS(wrap_dts - ds->next_dts) < FFABS(pkt_dts - ds->next_dts)/10)
243  disable_discontinuity_correction = 0;
244  }
245 
246  if (ds->next_dts != AV_NOPTS_VALUE && !disable_discontinuity_correction) {
247  int64_t delta = pkt_dts - ds->next_dts;
248  if (fmt_is_discont) {
249  if (FFABS(delta) > 1LL * dts_delta_threshold * AV_TIME_BASE ||
250  pkt_dts + AV_TIME_BASE/10 < ds->dts) {
251  d->ts_offset_discont -= delta;
252  av_log(ist, AV_LOG_WARNING,
253  "timestamp discontinuity "
254  "(stream id=%d): %"PRId64", new offset= %"PRId64"\n",
255  ist->st->id, delta, d->ts_offset_discont);
257  if (pkt->pts != AV_NOPTS_VALUE)
259  }
260  } else {
261  if (FFABS(delta) > 1LL * dts_error_threshold * AV_TIME_BASE) {
262  av_log(ist, AV_LOG_WARNING,
263  "DTS %"PRId64", next:%"PRId64" st:%d invalid dropping\n",
264  pkt->dts, ds->next_dts, pkt->stream_index);
266  }
267  if (pkt->pts != AV_NOPTS_VALUE){
269  delta = pkt_pts - ds->next_dts;
270  if (FFABS(delta) > 1LL * dts_error_threshold * AV_TIME_BASE) {
271  av_log(ist, AV_LOG_WARNING,
272  "PTS %"PRId64", next:%"PRId64" invalid dropping st:%d\n",
273  pkt->pts, ds->next_dts, pkt->stream_index);
275  }
276  }
277  }
278  } else if (ds->next_dts == AV_NOPTS_VALUE && !copy_ts &&
279  fmt_is_discont && d->last_ts != AV_NOPTS_VALUE) {
280  int64_t delta = pkt_dts - d->last_ts;
281  if (FFABS(delta) > 1LL * dts_delta_threshold * AV_TIME_BASE) {
282  d->ts_offset_discont -= delta;
283  av_log(ist, AV_LOG_DEBUG,
284  "Inter stream timestamp discontinuity %"PRId64", new offset= %"PRId64"\n",
287  if (pkt->pts != AV_NOPTS_VALUE)
289  }
290  }
291 
293 }
294 
296  AVPacket *pkt)
297 {
299  pkt->time_base);
300 
301  // apply previously-detected timestamp-discontinuity offset
302  // (to all streams, not just audio/video)
303  if (pkt->dts != AV_NOPTS_VALUE)
304  pkt->dts += offset;
305  if (pkt->pts != AV_NOPTS_VALUE)
306  pkt->pts += offset;
307 
308  // detect timestamp discontinuities for audio/video
309  if ((ist->par->codec_type == AVMEDIA_TYPE_VIDEO ||
310  ist->par->codec_type == AVMEDIA_TYPE_AUDIO) &&
311  pkt->dts != AV_NOPTS_VALUE)
312  ts_discontinuity_detect(d, ist, pkt);
313 }
314 
316 {
317  InputStream *ist = &ds->ist;
318  const AVCodecParameters *par = ist->par;
319 
320  if (!ds->saw_first_ts) {
321  ds->first_dts =
322  ds->dts = ist->st->avg_frame_rate.num ? - ist->par->video_delay * AV_TIME_BASE / av_q2d(ist->st->avg_frame_rate) : 0;
323  if (pkt->pts != AV_NOPTS_VALUE) {
324  ds->first_dts =
326  }
327  ds->saw_first_ts = 1;
328  }
329 
330  if (ds->next_dts == AV_NOPTS_VALUE)
331  ds->next_dts = ds->dts;
332 
333  if (pkt->dts != AV_NOPTS_VALUE)
335 
336  ds->dts = ds->next_dts;
337  switch (par->codec_type) {
338  case AVMEDIA_TYPE_AUDIO:
339  av_assert1(pkt->duration >= 0);
340  if (par->sample_rate) {
341  ds->next_dts += ((int64_t)AV_TIME_BASE * par->frame_size) /
342  par->sample_rate;
343  } else {
345  }
346  break;
347  case AVMEDIA_TYPE_VIDEO:
348  if (ist->framerate.num) {
349  // TODO: Remove work-around for c99-to-c89 issue 7
350  AVRational time_base_q = AV_TIME_BASE_Q;
351  int64_t next_dts = av_rescale_q(ds->next_dts, time_base_q, av_inv_q(ist->framerate));
352  ds->next_dts = av_rescale_q(next_dts + 1, av_inv_q(ist->framerate), time_base_q);
353  } else if (pkt->duration) {
355  } else if (ist->par->framerate.num != 0) {
356  AVRational field_rate = av_mul_q(ist->par->framerate,
357  (AVRational){ 2, 1 });
358  int fields = 2;
359 
360  if (ds->codec_desc &&
362  av_stream_get_parser(ist->st))
364 
365  ds->next_dts += av_rescale_q(fields, av_inv_q(field_rate), AV_TIME_BASE_Q);
366  }
367  break;
368  }
369 
370  fd->dts_est = ds->dts;
371 
372  return 0;
373 }
374 
375 static int ts_fixup(Demuxer *d, AVPacket *pkt, FrameData *fd)
376 {
377  InputFile *ifile = &d->f;
378  InputStream *ist = ifile->streams[pkt->stream_index];
379  DemuxStream *ds = ds_from_ist(ist);
380  const int64_t start_time = ifile->start_time_effective;
382  int ret;
383 
384  pkt->time_base = ist->st->time_base;
385 
386 #define SHOW_TS_DEBUG(tag_) \
387  if (debug_ts) { \
388  av_log(ist, AV_LOG_INFO, "%s -> ist_index:%d:%d type:%s " \
389  "pkt_pts:%s pkt_pts_time:%s pkt_dts:%s pkt_dts_time:%s duration:%s duration_time:%s\n", \
390  tag_, ifile->index, pkt->stream_index, \
391  av_get_media_type_string(ist->st->codecpar->codec_type), \
392  av_ts2str(pkt->pts), av_ts2timestr(pkt->pts, &pkt->time_base), \
393  av_ts2str(pkt->dts), av_ts2timestr(pkt->dts, &pkt->time_base), \
394  av_ts2str(pkt->duration), av_ts2timestr(pkt->duration, &pkt->time_base)); \
395  }
396 
397  SHOW_TS_DEBUG("demuxer");
398 
400  ist->st->pts_wrap_bits < 64) {
401  int64_t stime, stime2;
402 
404  stime2= stime + (1ULL<<ist->st->pts_wrap_bits);
405  ds->wrap_correction_done = 1;
406 
407  if(stime2 > stime && pkt->dts != AV_NOPTS_VALUE && pkt->dts > stime + (1LL<<(ist->st->pts_wrap_bits-1))) {
408  pkt->dts -= 1ULL<<ist->st->pts_wrap_bits;
409  ds->wrap_correction_done = 0;
410  }
411  if(stime2 > stime && pkt->pts != AV_NOPTS_VALUE && pkt->pts > stime + (1LL<<(ist->st->pts_wrap_bits-1))) {
412  pkt->pts -= 1ULL<<ist->st->pts_wrap_bits;
413  ds->wrap_correction_done = 0;
414  }
415  }
416 
417  if (pkt->dts != AV_NOPTS_VALUE)
419  if (pkt->pts != AV_NOPTS_VALUE)
421 
422  if (pkt->pts != AV_NOPTS_VALUE)
423  pkt->pts *= ds->ts_scale;
424  if (pkt->dts != AV_NOPTS_VALUE)
425  pkt->dts *= ds->ts_scale;
426 
428  if (pkt->pts != AV_NOPTS_VALUE) {
429  // audio decoders take precedence for estimating total file duration
430  int64_t pkt_duration = d->have_audio_dec ? 0 : pkt->duration;
431 
432  pkt->pts += duration;
433 
434  // update max/min pts that will be used to compute total file duration
435  // when using -stream_loop
436  if (d->max_pts.ts == AV_NOPTS_VALUE ||
438  pkt->pts + pkt_duration, pkt->time_base) < 0) {
439  d->max_pts = (Timestamp){ .ts = pkt->pts + pkt_duration,
440  .tb = pkt->time_base };
441  }
442  if (d->min_pts.ts == AV_NOPTS_VALUE ||
444  pkt->pts, pkt->time_base) > 0) {
445  d->min_pts = (Timestamp){ .ts = pkt->pts,
446  .tb = pkt->time_base };
447  }
448  }
449 
450  if (pkt->dts != AV_NOPTS_VALUE)
451  pkt->dts += duration;
452 
453  SHOW_TS_DEBUG("demuxer+tsfixup");
454 
455  // detect and try to correct for timestamp discontinuities
456  ts_discontinuity_process(d, ist, pkt);
457 
458  // update estimated/predicted dts
459  ret = ist_dts_update(ds, pkt, fd);
460  if (ret < 0)
461  return ret;
462 
463  return 0;
464 }
465 
466 static int input_packet_process(Demuxer *d, AVPacket *pkt, unsigned *send_flags)
467 {
468  InputFile *f = &d->f;
469  InputStream *ist = f->streams[pkt->stream_index];
470  DemuxStream *ds = ds_from_ist(ist);
471  FrameData *fd;
472  int ret = 0;
473 
474  fd = packet_data(pkt);
475  if (!fd)
476  return AVERROR(ENOMEM);
477 
478  ret = ts_fixup(d, pkt, fd);
479  if (ret < 0)
480  return ret;
481 
482  if (d->recording_time != INT64_MAX) {
483  int64_t start_time = 0;
484  if (copy_ts) {
485  start_time += f->start_time != AV_NOPTS_VALUE ? f->start_time : 0;
486  start_time += start_at_zero ? 0 : f->start_time_effective;
487  }
488  if (ds->dts >= d->recording_time + start_time)
489  *send_flags |= DEMUX_SEND_STREAMCOPY_EOF;
490  }
491 
492  ds->data_size += pkt->size;
493  ds->nb_packets++;
494 
496 
497  if (debug_ts) {
498  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",
499  f->index, pkt->stream_index,
504  av_ts2str(f->ts_offset), av_ts2timestr(f->ts_offset, &AV_TIME_BASE_Q));
505  }
506 
507  return 0;
508 }
509 
510 static void readrate_sleep(Demuxer *d)
511 {
512  InputFile *f = &d->f;
513  int64_t file_start = copy_ts * (
514  (f->start_time_effective != AV_NOPTS_VALUE ? f->start_time_effective * !start_at_zero : 0) +
515  (f->start_time != AV_NOPTS_VALUE ? f->start_time : 0)
516  );
517  int64_t initial_burst = AV_TIME_BASE * d->readrate_initial_burst;
518  int resume_warn = 0;
519 
520  for (int i = 0; i < f->nb_streams; i++) {
521  InputStream *ist = f->streams[i];
522  DemuxStream *ds = ds_from_ist(ist);
523  int64_t stream_ts_offset, pts, now, wc_elapsed, elapsed, lag, max_pts, limit_pts;
524 
525  if (ds->discard) continue;
526 
527  stream_ts_offset = FFMAX(ds->first_dts != AV_NOPTS_VALUE ? ds->first_dts : 0, file_start);
528  pts = av_rescale(ds->dts, 1000000, AV_TIME_BASE);
529  now = av_gettime_relative();
530  wc_elapsed = now - d->wallclock_start;
531 
532  if (pts <= stream_ts_offset + initial_burst) continue;
533 
534  max_pts = stream_ts_offset + initial_burst + (int64_t)(wc_elapsed * d->readrate);
535  lag = FFMAX(max_pts - pts, 0);
536  if ( (!ds->lag && lag > 0.3 * AV_TIME_BASE) || ( lag > ds->lag + 0.3 * AV_TIME_BASE) ) {
537  ds->lag = lag;
538  ds->resume_wc = now;
539  ds->resume_pts = pts;
540  av_log_once(ds, AV_LOG_WARNING, AV_LOG_DEBUG, &resume_warn,
541  "Resumed reading at pts %0.3f with rate %0.3f after a lag of %0.3fs\n",
542  (float)pts/AV_TIME_BASE, d->readrate_catchup, (float)lag/AV_TIME_BASE);
543  }
544  if (ds->lag && !lag)
545  ds->lag = ds->resume_wc = ds->resume_pts = 0;
546  if (ds->resume_wc) {
547  elapsed = now - ds->resume_wc;
548  limit_pts = ds->resume_pts + (int64_t)(elapsed * d->readrate_catchup);
549  } else {
550  elapsed = wc_elapsed;
551  limit_pts = max_pts;
552  }
553 
554  if (pts > limit_pts)
555  av_usleep(pts - limit_pts);
556  }
557 }
558 
559 static int do_send(Demuxer *d, DemuxStream *ds, AVPacket *pkt, unsigned flags,
560  const char *pkt_desc)
561 {
562  int ret;
563 
565 
566  ret = sch_demux_send(d->sch, d->f.index, pkt, flags);
567  if (ret == AVERROR_EOF) {
569 
570  av_log(ds, AV_LOG_VERBOSE, "All consumers of this stream are done\n");
571  ds->finished = 1;
572 
573  if (++d->nb_streams_finished == d->nb_streams_used) {
574  av_log(d, AV_LOG_VERBOSE, "All consumers are done\n");
575  return AVERROR_EOF;
576  }
577  } else if (ret < 0) {
578  if (ret != AVERROR_EXIT)
579  av_log(d, AV_LOG_ERROR,
580  "Unable to send %s packet to consumers: %s\n",
581  pkt_desc, av_err2str(ret));
582  return ret;
583  }
584 
585  return 0;
586 }
587 
589  AVPacket *pkt, unsigned flags)
590 {
591  InputFile *f = &d->f;
592  int ret;
593 
594  // pkt can be NULL only when flushing BSFs
595  av_assert0(ds->bsf || pkt);
596 
597  // send heartbeat for sub2video streams
598  if (d->pkt_heartbeat && pkt && pkt->pts != AV_NOPTS_VALUE) {
599  for (int i = 0; i < f->nb_streams; i++) {
600  DemuxStream *ds1 = ds_from_ist(f->streams[i]);
601 
602  if (ds1->finished || !ds1->have_sub2video)
603  continue;
604 
605  d->pkt_heartbeat->pts = pkt->pts;
607  d->pkt_heartbeat->opaque = (void*)(intptr_t)PKT_OPAQUE_SUB_HEARTBEAT;
608 
609  ret = do_send(d, ds1, d->pkt_heartbeat, 0, "heartbeat");
610  if (ret < 0)
611  return ret;
612  }
613  }
614 
615  if (ds->bsf) {
616  if (pkt)
618 
619  ret = av_bsf_send_packet(ds->bsf, pkt);
620  if (ret < 0) {
621  if (pkt)
623  av_log(ds, AV_LOG_ERROR, "Error submitting a packet for filtering: %s\n",
624  av_err2str(ret));
625  return ret;
626  }
627 
628  while (1) {
629  ret = av_bsf_receive_packet(ds->bsf, dt->pkt_bsf);
630  if (ret == AVERROR(EAGAIN))
631  return 0;
632  else if (ret < 0) {
633  if (ret != AVERROR_EOF)
634  av_log(ds, AV_LOG_ERROR,
635  "Error applying bitstream filters to a packet: %s\n",
636  av_err2str(ret));
637  return ret;
638  }
639 
640  dt->pkt_bsf->time_base = ds->bsf->time_base_out;
641 
642  ret = do_send(d, ds, dt->pkt_bsf, 0, "filtered");
643  if (ret < 0) {
645  return ret;
646  }
647  }
648  } else {
649  ret = do_send(d, ds, pkt, flags, "demuxed");
650  if (ret < 0)
651  return ret;
652  }
653 
654  return 0;
655 }
656 
658 {
659  InputFile *f = &d->f;
660  int ret;
661 
662  for (unsigned i = 0; i < f->nb_streams; i++) {
663  DemuxStream *ds = ds_from_ist(f->streams[i]);
664 
665  if (!ds->bsf)
666  continue;
667 
668  ret = demux_send(d, dt, ds, NULL, 0);
669  ret = (ret == AVERROR_EOF) ? 0 : (ret < 0) ? ret : AVERROR_BUG;
670  if (ret < 0) {
671  av_log(ds, AV_LOG_ERROR, "Error flushing BSFs: %s\n",
672  av_err2str(ret));
673  return ret;
674  }
675 
676  av_bsf_flush(ds->bsf);
677  }
678 
679  return 0;
680 }
681 
683 {
684  for (int j = 0; j < ifile->ctx->nb_programs; j++) {
685  AVProgram *p = ifile->ctx->programs[j];
686  int discard = AVDISCARD_ALL;
687 
688  for (int k = 0; k < p->nb_stream_indexes; k++) {
689  DemuxStream *ds = ds_from_ist(ifile->streams[p->stream_index[k]]);
690 
691  if (!ds->discard) {
692  discard = AVDISCARD_DEFAULT;
693  break;
694  }
695  }
696  p->discard = discard;
697  }
698 }
699 
701 {
702  char name[16];
703  snprintf(name, sizeof(name), "dmx%d:%s", f->index, f->ctx->iformat->name);
705 }
706 
708 {
710  av_packet_free(&dt->pkt_bsf);
711 
712  memset(dt, 0, sizeof(*dt));
713 }
714 
716 {
717  memset(dt, 0, sizeof(*dt));
718 
719  dt->pkt_demux = av_packet_alloc();
720  if (!dt->pkt_demux)
721  return AVERROR(ENOMEM);
722 
723  dt->pkt_bsf = av_packet_alloc();
724  if (!dt->pkt_bsf)
725  return AVERROR(ENOMEM);
726 
727  return 0;
728 }
729 
730 static int input_thread(void *arg)
731 {
732  Demuxer *d = arg;
733  InputFile *f = &d->f;
734 
736 
737  int ret = 0;
738 
739  ret = demux_thread_init(&dt);
740  if (ret < 0)
741  goto finish;
742 
744 
746 
747  d->read_started = 1;
749 
750  while (1) {
751  DemuxStream *ds;
752  unsigned send_flags = 0;
753 
754  ret = av_read_frame(f->ctx, dt.pkt_demux);
755 
756  if (ret == AVERROR(EAGAIN)) {
757  av_usleep(10000);
758  continue;
759  }
760  if (ret < 0) {
761  int ret_bsf;
762 
763  if (ret == AVERROR_EOF)
764  av_log(d, AV_LOG_VERBOSE, "EOF while reading input\n");
765  else {
766  av_log(d, AV_LOG_ERROR, "Error during demuxing: %s\n",
767  av_err2str(ret));
768  ret = exit_on_error ? ret : 0;
769  }
770 
771  ret_bsf = demux_bsf_flush(d, &dt);
772  ret = err_merge(ret == AVERROR_EOF ? 0 : ret, ret_bsf);
773 
774  if (d->loop) {
775  /* signal looping to our consumers */
776  dt.pkt_demux->stream_index = -1;
777  ret = sch_demux_send(d->sch, f->index, dt.pkt_demux, 0);
778  if (ret >= 0)
779  ret = seek_to_start(d, (Timestamp){ .ts = dt.pkt_demux->pts,
780  .tb = dt.pkt_demux->time_base });
781  if (ret >= 0)
782  continue;
783 
784  /* fallthrough to the error path */
785  }
786 
787  break;
788  }
789 
790  if (do_pkt_dump) {
792  f->ctx->streams[dt.pkt_demux->stream_index]);
793  }
794 
795  /* the following test is needed in case new streams appear
796  dynamically in stream : we ignore them */
797  ds = dt.pkt_demux->stream_index < f->nb_streams ?
798  ds_from_ist(f->streams[dt.pkt_demux->stream_index]) : NULL;
799  if (!ds || ds->discard || ds->finished) {
802  continue;
803  }
804 
805  if (dt.pkt_demux->flags & AV_PKT_FLAG_CORRUPT) {
807  "corrupt input packet in stream %d\n",
808  dt.pkt_demux->stream_index);
809  if (exit_on_error) {
812  break;
813  }
814  }
815 
816  ret = input_packet_process(d, dt.pkt_demux, &send_flags);
817  if (ret < 0)
818  break;
819 
820  if (d->readrate)
821  readrate_sleep(d);
822 
823  ret = demux_send(d, &dt, ds, dt.pkt_demux, send_flags);
824  if (ret < 0)
825  break;
826  }
827 
828  // EOF/EXIT is normal termination
829  if (ret == AVERROR_EOF || ret == AVERROR_EXIT)
830  ret = 0;
831 
832 finish:
833  demux_thread_uninit(&dt);
834 
835  return ret;
836 }
837 
838 static void demux_final_stats(Demuxer *d)
839 {
840  InputFile *f = &d->f;
841  uint64_t total_packets = 0, total_size = 0;
842 
843  av_log(f, AV_LOG_VERBOSE, "Input file #%d (%s):\n",
844  f->index, f->ctx->url);
845 
846  for (int j = 0; j < f->nb_streams; j++) {
847  InputStream *ist = f->streams[j];
848  DemuxStream *ds = ds_from_ist(ist);
849  enum AVMediaType type = ist->par->codec_type;
850 
851  if (ds->discard || type == AVMEDIA_TYPE_ATTACHMENT)
852  continue;
853 
854  total_size += ds->data_size;
855  total_packets += ds->nb_packets;
856 
857  av_log(f, AV_LOG_VERBOSE, " Input stream #%d:%d (%s): ",
858  f->index, j, av_get_media_type_string(type));
859  av_log(f, AV_LOG_VERBOSE, "%"PRIu64" packets read (%"PRIu64" bytes); ",
860  ds->nb_packets, ds->data_size);
861 
862  if (ds->decoding_needed) {
864  "%"PRIu64" frames decoded; %"PRIu64" decode errors",
866  if (type == AVMEDIA_TYPE_AUDIO)
867  av_log(f, AV_LOG_VERBOSE, " (%"PRIu64" samples)", ist->decoder->samples_decoded);
868  av_log(f, AV_LOG_VERBOSE, "; ");
869  }
870 
871  av_log(f, AV_LOG_VERBOSE, "\n");
872  }
873 
874  av_log(f, AV_LOG_VERBOSE, " Total: %"PRIu64" packets (%"PRIu64" bytes) demuxed\n",
875  total_packets, total_size);
876 }
877 
878 static void ist_free(InputStream **pist)
879 {
880  InputStream *ist = *pist;
881  DemuxStream *ds;
882 
883  if (!ist)
884  return;
885  ds = ds_from_ist(ist);
886 
887  dec_free(&ist->decoder);
888 
890  av_freep(&ist->filters);
892 
894 
896 
897  av_bsf_free(&ds->bsf);
898 
899  av_freep(pist);
900 }
901 
902 static void istg_free(InputStreamGroup **pistg)
903 {
904  InputStreamGroup *istg = *pistg;
905 
906  if (!istg)
907  return;
908 
909  av_freep(pistg);
910 }
911 
913 {
914  InputFile *f = *pf;
916 
917  if (!f)
918  return;
919 
920  if (d->read_started)
922 
923  for (int i = 0; i < f->nb_streams; i++)
924  ist_free(&f->streams[i]);
925  av_freep(&f->streams);
926 
927  for (int i = 0; i < f->nb_stream_groups; i++)
928  istg_free(&f->stream_groups[i]);
929  av_freep(&f->stream_groups);
930 
931  avformat_close_input(&f->ctx);
932 
934 
935  av_freep(pf);
936 }
937 
938 int ist_use(InputStream *ist, int decoding_needed,
939  const ViewSpecifier *vs, SchedulerNode *src)
940 {
941  Demuxer *d = demuxer_from_ifile(ist->file);
942  DemuxStream *ds = ds_from_ist(ist);
943  int ret;
944 
945  if (ist->user_set_discard == AVDISCARD_ALL) {
946  av_log(ist, AV_LOG_ERROR, "Cannot %s a disabled input stream\n",
947  decoding_needed ? "decode" : "streamcopy");
948  return AVERROR(EINVAL);
949  }
950 
951  if (decoding_needed && !ist->dec) {
952  av_log(ist, AV_LOG_ERROR,
953  "Decoding requested, but no decoder found for: %s\n",
954  avcodec_get_name(ist->par->codec_id));
955  return AVERROR(EINVAL);
956  }
957 
958  if (ds->sch_idx_stream < 0) {
959  ret = sch_add_demux_stream(d->sch, d->f.index);
960  if (ret < 0)
961  return ret;
962  ds->sch_idx_stream = ret;
963  }
964 
965  if (ds->discard) {
966  ds->discard = 0;
967  d->nb_streams_used++;
968  }
969 
970  ist->st->discard = ist->user_set_discard;
971  ds->decoding_needed |= decoding_needed;
972  ds->streamcopy_needed |= !decoding_needed;
973 
974  if (decoding_needed && ds->sch_idx_dec < 0) {
975  int is_audio = ist->st->codecpar->codec_type == AVMEDIA_TYPE_AUDIO;
976  int is_unreliable = !!(d->f.ctx->iformat->flags & AVFMT_NOTIMESTAMPS);
977  int64_t use_wallclock_as_timestamps;
978 
979  ret = av_opt_get_int(d->f.ctx, "use_wallclock_as_timestamps", 0, &use_wallclock_as_timestamps);
980  if (ret < 0)
981  return ret;
982 
983  if (use_wallclock_as_timestamps)
984  is_unreliable = 0;
985 
987  (!!is_unreliable * DECODER_FLAG_TS_UNRELIABLE) |
988  (!!(d->loop && is_audio) * DECODER_FLAG_SEND_END_TS);
989 
990  if (ist->framerate.num) {
992  ds->dec_opts.framerate = ist->framerate;
993  } else
994  ds->dec_opts.framerate = ist->st->avg_frame_rate;
995 
996  if (ist->dec->id == AV_CODEC_ID_DVB_SUBTITLE &&
998  av_dict_set(&ds->decoder_opts, "compute_edt", "1", AV_DICT_DONT_OVERWRITE);
1000  av_log(ist, AV_LOG_WARNING,
1001  "Warning using DVB subtitles for filtering and output at the "
1002  "same time is not fully supported, also see -compute_edt [0|1]\n");
1003  }
1004 
1005  snprintf(ds->dec_name, sizeof(ds->dec_name), "%d:%d", ist->file->index, ist->index);
1006  ds->dec_opts.name = ds->dec_name;
1007 
1008  ds->dec_opts.codec = ist->dec;
1009  ds->dec_opts.par = ist->par;
1010 
1011  ds->dec_opts.log_parent = ist;
1012 
1014  if (!ds->decoded_params)
1015  return AVERROR(ENOMEM);
1016 
1017  ret = dec_init(&ist->decoder, d->sch,
1018  &ds->decoder_opts, &ds->dec_opts, ds->decoded_params);
1019  if (ret < 0)
1020  return ret;
1021  ds->sch_idx_dec = ret;
1022 
1024  SCH_DEC_IN(ds->sch_idx_dec));
1025  if (ret < 0)
1026  return ret;
1027 
1028  d->have_audio_dec |= is_audio;
1029  }
1030 
1031  if (decoding_needed && ist->par->codec_type == AVMEDIA_TYPE_VIDEO) {
1032  ret = dec_request_view(ist->decoder, vs, src);
1033  if (ret < 0)
1034  return ret;
1035  } else {
1036  *src = decoding_needed ?
1037  SCH_DEC_OUT(ds->sch_idx_dec, 0) :
1038  SCH_DSTREAM(d->f.index, ds->sch_idx_stream);
1039  }
1040 
1041  return 0;
1042 }
1043 
1044 int ist_filter_add(InputStream *ist, InputFilter *ifilter, int is_simple,
1046  SchedulerNode *src)
1047 {
1048  Demuxer *d = demuxer_from_ifile(ist->file);
1049  DemuxStream *ds = ds_from_ist(ist);
1050  int64_t tsoffset = 0;
1051  int ret;
1052 
1053  ret = ist_use(ist, is_simple ? DECODING_FOR_OST : DECODING_FOR_FILTER,
1054  vs, src);
1055  if (ret < 0)
1056  return ret;
1057 
1058  ret = GROW_ARRAY(ist->filters, ist->nb_filters);
1059  if (ret < 0)
1060  return ret;
1061 
1062  ist->filters[ist->nb_filters - 1] = ifilter;
1063 
1064  if (ist->par->codec_type == AVMEDIA_TYPE_VIDEO) {
1066  ist->par->nb_coded_side_data,
1068  if (ist->framerate.num > 0 && ist->framerate.den > 0) {
1069  opts->framerate = ist->framerate;
1070  opts->flags |= IFILTER_FLAG_CFR;
1071  } else
1072  opts->framerate = av_guess_frame_rate(d->f.ctx, ist->st, NULL);
1073  if (sd && sd->size >= sizeof(uint32_t) * 4) {
1074  opts->crop_top = AV_RL32(sd->data + 0);
1075  opts->crop_bottom = AV_RL32(sd->data + 4);
1076  opts->crop_left = AV_RL32(sd->data + 8);
1077  opts->crop_right = AV_RL32(sd->data + 12);
1078  if (ds->apply_cropping && ds->apply_cropping != CROP_CODEC &&
1079  (opts->crop_top | opts->crop_bottom | opts->crop_left | opts->crop_right))
1080  opts->flags |= IFILTER_FLAG_CROP;
1081  }
1082  } else if (ist->par->codec_type == AVMEDIA_TYPE_SUBTITLE) {
1083  /* Compute the size of the canvas for the subtitles stream.
1084  If the subtitles codecpar has set a size, use it. Otherwise use the
1085  maximum dimensions of the video streams in the same file. */
1086  opts->sub2video_width = ist->par->width;
1087  opts->sub2video_height = ist->par->height;
1088  if (!(opts->sub2video_width && opts->sub2video_height)) {
1089  for (int j = 0; j < d->f.nb_streams; j++) {
1090  AVCodecParameters *par1 = d->f.streams[j]->par;
1091  if (par1->codec_type == AVMEDIA_TYPE_VIDEO) {
1092  opts->sub2video_width = FFMAX(opts->sub2video_width, par1->width);
1093  opts->sub2video_height = FFMAX(opts->sub2video_height, par1->height);
1094  }
1095  }
1096  }
1097 
1098  if (!(opts->sub2video_width && opts->sub2video_height)) {
1099  opts->sub2video_width = FFMAX(opts->sub2video_width, 720);
1100  opts->sub2video_height = FFMAX(opts->sub2video_height, 576);
1101  }
1102 
1103  if (!d->pkt_heartbeat) {
1105  if (!d->pkt_heartbeat)
1106  return AVERROR(ENOMEM);
1107  }
1108  ds->have_sub2video = 1;
1109  }
1110 
1111  ret = av_frame_copy_props(opts->fallback, ds->decoded_params);
1112  if (ret < 0)
1113  return ret;
1114  opts->fallback->format = ds->decoded_params->format;
1115  opts->fallback->width = ds->decoded_params->width;
1116  opts->fallback->height = ds->decoded_params->height;
1117 
1118  ret = av_channel_layout_copy(&opts->fallback->ch_layout, &ds->decoded_params->ch_layout);
1119  if (ret < 0)
1120  return ret;
1121 
1122  if (copy_ts) {
1123  tsoffset = d->f.start_time == AV_NOPTS_VALUE ? 0 : d->f.start_time;
1124  if (!start_at_zero && d->f.ctx->start_time != AV_NOPTS_VALUE)
1125  tsoffset += d->f.ctx->start_time;
1126  }
1127  opts->trim_start_us = ((d->f.start_time == AV_NOPTS_VALUE) || !d->accurate_seek) ?
1128  AV_NOPTS_VALUE : tsoffset;
1129  opts->trim_end_us = d->recording_time;
1130 
1131  opts->name = av_strdup(ds->dec_name);
1132  if (!opts->name)
1133  return AVERROR(ENOMEM);
1134 
1135  opts->flags |= IFILTER_FLAG_AUTOROTATE * !!(ds->autorotate) |
1138 
1139  return 0;
1140 }
1141 
1142 static int choose_decoder(const OptionsContext *o, void *logctx,
1143  AVFormatContext *s, AVStream *st,
1144  enum HWAccelID hwaccel_id, enum AVHWDeviceType hwaccel_device_type,
1145  const AVCodec **pcodec)
1146 
1147 {
1148  const char *codec_name = NULL;
1149 
1150  opt_match_per_stream_str(logctx, &o->codec_names, s, st, &codec_name);
1151  if (codec_name) {
1152  int ret = find_codec(NULL, codec_name, st->codecpar->codec_type, 0, pcodec);
1153  if (ret < 0)
1154  return ret;
1155  st->codecpar->codec_id = (*pcodec)->id;
1156  if (recast_media && st->codecpar->codec_type != (*pcodec)->type)
1157  st->codecpar->codec_type = (*pcodec)->type;
1158  return 0;
1159  } else {
1160  if (st->codecpar->codec_type == AVMEDIA_TYPE_VIDEO &&
1161  hwaccel_id == HWACCEL_GENERIC &&
1162  hwaccel_device_type != AV_HWDEVICE_TYPE_NONE) {
1163  const AVCodec *c;
1164  void *i = NULL;
1165 
1166  while ((c = av_codec_iterate(&i))) {
1167  const AVCodecHWConfig *config;
1168 
1169  if (c->id != st->codecpar->codec_id ||
1171  continue;
1172 
1173  for (int j = 0; config = avcodec_get_hw_config(c, j); j++) {
1174  if (config->device_type == hwaccel_device_type) {
1175  av_log(logctx, AV_LOG_VERBOSE, "Selecting decoder '%s' because of requested hwaccel method %s\n",
1176  c->name, av_hwdevice_get_type_name(hwaccel_device_type));
1177  *pcodec = c;
1178  return 0;
1179  }
1180  }
1181  }
1182  }
1183 
1184  *pcodec = avcodec_find_decoder(st->codecpar->codec_id);
1185  return 0;
1186  }
1187 }
1188 
1190  int guess_layout_max)
1191 {
1192  if (par->ch_layout.order == AV_CHANNEL_ORDER_UNSPEC) {
1193  char layout_name[256];
1194 
1195  if (par->ch_layout.nb_channels > guess_layout_max)
1196  return 0;
1199  return 0;
1200  av_channel_layout_describe(&par->ch_layout, layout_name, sizeof(layout_name));
1201  av_log(ist, AV_LOG_WARNING, "Guessed Channel Layout: %s\n", layout_name);
1202  }
1203  return 1;
1204 }
1205 
1208 {
1209  AVStream *st = ist->st;
1210  DemuxStream *ds = ds_from_ist(ist);
1211  AVPacketSideData *sd;
1212  double rotation = DBL_MAX;
1213  int hflip = -1, vflip = -1;
1214  int hflip_set = 0, vflip_set = 0, rotation_set = 0;
1215  int32_t *buf;
1216 
1217  opt_match_per_stream_dbl(ist, &o->display_rotations, ctx, st, &rotation);
1218  opt_match_per_stream_int(ist, &o->display_hflips, ctx, st, &hflip);
1219  opt_match_per_stream_int(ist, &o->display_vflips, ctx, st, &vflip);
1220 
1221  rotation_set = rotation != DBL_MAX;
1222  hflip_set = hflip != -1;
1223  vflip_set = vflip != -1;
1224 
1225  if (!rotation_set && !hflip_set && !vflip_set)
1226  return 0;
1227 
1231  sizeof(int32_t) * 9, 0);
1232  if (!sd) {
1233  av_log(ist, AV_LOG_FATAL, "Failed to generate a display matrix!\n");
1234  return AVERROR(ENOMEM);
1235  }
1236 
1237  buf = (int32_t *)sd->data;
1239  rotation_set ? -(rotation) : -0.0f);
1240 
1242  hflip_set ? hflip : 0,
1243  vflip_set ? vflip : 0);
1244 
1245  ds->force_display_matrix = 1;
1246 
1247  return 0;
1248 }
1249 
1252 {
1253  AVStream *st = ist->st;
1254  DemuxStream *ds = ds_from_ist(ist);
1255  AVMasteringDisplayMetadata *master_display;
1256  AVPacketSideData *sd;
1257  const char *p = NULL;
1258  const int chroma_den = 50000;
1259  const int luma_den = 10000;
1260  size_t size;
1261  int ret;
1262 
1264 
1265  if (!p)
1266  return 0;
1267 
1269  if (!master_display)
1270  return AVERROR(ENOMEM);
1271 
1272  ret = sscanf(p,
1273  "G(%u,%u)B(%u,%u)R(%u,%u)WP(%u,%u)L(%u,%u)",
1274  (unsigned*)&master_display->display_primaries[1][0].num,
1275  (unsigned*)&master_display->display_primaries[1][1].num,
1276  (unsigned*)&master_display->display_primaries[2][0].num,
1277  (unsigned*)&master_display->display_primaries[2][1].num,
1278  (unsigned*)&master_display->display_primaries[0][0].num,
1279  (unsigned*)&master_display->display_primaries[0][1].num,
1280  (unsigned*)&master_display->white_point[0].num,
1281  (unsigned*)&master_display->white_point[1].num,
1282  (unsigned*)&master_display->max_luminance.num,
1283  (unsigned*)&master_display->min_luminance.num);
1284 
1285  if (ret != 10 ||
1286  (unsigned)(master_display->display_primaries[1][0].num | master_display->display_primaries[1][1].num |
1287  master_display->display_primaries[2][0].num | master_display->display_primaries[2][1].num |
1288  master_display->display_primaries[0][0].num | master_display->display_primaries[0][1].num |
1289  master_display->white_point[0].num | master_display->white_point[1].num) > UINT16_MAX ||
1290  (unsigned)(master_display->max_luminance.num | master_display->min_luminance.num) > INT_MAX ||
1291  master_display->min_luminance.num > master_display->max_luminance.num) {
1292  av_freep(&master_display);
1293  av_log(ist, AV_LOG_ERROR, "Failed to parse mastering display option\n");
1294  return AVERROR(EINVAL);
1295  }
1296 
1297  master_display->display_primaries[1][0].den = chroma_den;
1298  master_display->display_primaries[1][1].den = chroma_den;
1299  master_display->display_primaries[2][0].den = chroma_den;
1300  master_display->display_primaries[2][1].den = chroma_den;
1301  master_display->display_primaries[0][0].den = chroma_den;
1302  master_display->display_primaries[0][1].den = chroma_den;
1303  master_display->white_point[0].den = chroma_den;
1304  master_display->white_point[1].den = chroma_den;
1305  master_display->max_luminance.den = luma_den;
1306  master_display->min_luminance.den = luma_den;
1307 
1308  master_display->has_primaries = 1;
1309  master_display->has_luminance = 1;
1310 
1314  (uint8_t *)master_display, size, 0);
1315  if (!sd) {
1316  av_freep(&master_display);
1317  return AVERROR(ENOMEM);
1318  }
1319 
1320  ds->force_mastering_display = 1;
1321 
1322  return 0;
1323 }
1324 
1327 {
1328  AVStream *st = ist->st;
1329  DemuxStream *ds = ds_from_ist(ist);
1331  AVPacketSideData *sd;
1332  const char *p = NULL;
1333  size_t size;
1334  int ret;
1335 
1336  opt_match_per_stream_str(ist, &o->content_lights, ctx, st, &p);
1337 
1338  if (!p)
1339  return 0;
1340 
1342  if (!cll)
1343  return AVERROR(ENOMEM);
1344 
1345  ret = sscanf(p, "%u,%u",
1346  (unsigned*)&cll->MaxCLL,
1347  (unsigned*)&cll->MaxFALL);
1348 
1349  if (ret != 2 || (unsigned)(cll->MaxCLL | cll->MaxFALL) > UINT16_MAX) {
1350  av_freep(&cll);
1351  av_log(ist, AV_LOG_ERROR, "Failed to parse content light option\n");
1352  return AVERROR(EINVAL);
1353  }
1354 
1358  (uint8_t *)cll, size, 0);
1359  if (!sd) {
1360  av_freep(&cll);
1361  return AVERROR(ENOMEM);
1362  }
1363 
1364  ds->force_content_light = 1;
1365 
1366  return 0;
1367 }
1368 
1369 static const char *input_stream_item_name(void *obj)
1370 {
1371  const DemuxStream *ds = obj;
1372 
1373  return ds->log_name;
1374 }
1375 
1376 static const AVClass input_stream_class = {
1377  .class_name = "InputStream",
1378  .version = LIBAVUTIL_VERSION_INT,
1379  .item_name = input_stream_item_name,
1380  .category = AV_CLASS_CATEGORY_DEMUXER,
1381 };
1382 
1384 {
1385  const char *type_str = av_get_media_type_string(st->codecpar->codec_type);
1386  InputFile *f = &d->f;
1387  DemuxStream *ds;
1388 
1389  ds = allocate_array_elem(&f->streams, sizeof(*ds), &f->nb_streams);
1390  if (!ds)
1391  return NULL;
1392 
1393  ds->sch_idx_stream = -1;
1394  ds->sch_idx_dec = -1;
1395 
1396  ds->ist.st = st;
1397  ds->ist.file = f;
1398  ds->ist.index = st->index;
1399  ds->ist.class = &input_stream_class;
1400 
1401  snprintf(ds->log_name, sizeof(ds->log_name), "%cist#%d:%d/%s",
1402  type_str ? *type_str : '?', d->f.index, st->index,
1404 
1405  return ds;
1406 }
1407 
1408 static int ist_add(const OptionsContext *o, Demuxer *d, AVStream *st, AVDictionary **opts_used)
1409 {
1410  AVFormatContext *ic = d->f.ctx;
1411  AVCodecParameters *par = st->codecpar;
1412  DemuxStream *ds;
1413  InputStream *ist;
1414  const char *framerate = NULL, *hwaccel_device = NULL;
1415  const char *hwaccel = NULL;
1416  const char *apply_cropping = NULL;
1417  const char *hwaccel_output_format = NULL;
1418  const char *codec_tag = NULL;
1419  const char *bsfs = NULL;
1420  char *next;
1421  const char *discard_str = NULL;
1422  AVBPrint bp;
1423  int ret;
1424 
1425  ds = demux_stream_alloc(d, st);
1426  if (!ds)
1427  return AVERROR(ENOMEM);
1428 
1429  ist = &ds->ist;
1430 
1431  ds->discard = 1;
1432  st->discard = AVDISCARD_ALL;
1433  ds->first_dts = AV_NOPTS_VALUE;
1434  ds->next_dts = AV_NOPTS_VALUE;
1435 
1436  ds->dec_opts.time_base = st->time_base;
1437 
1438  ds->ts_scale = 1.0;
1439  opt_match_per_stream_dbl(ist, &o->ts_scale, ic, st, &ds->ts_scale);
1440 
1441  ds->autorotate = 1;
1442  opt_match_per_stream_int(ist, &o->autorotate, ic, st, &ds->autorotate);
1443 
1444  ds->apply_cropping = CROP_ALL;
1446  if (apply_cropping) {
1447  const AVOption opts[] = {
1448  { "apply_cropping", NULL, 0, AV_OPT_TYPE_INT,
1449  { .i64 = CROP_ALL }, CROP_DISABLED, CROP_CONTAINER, AV_OPT_FLAG_DECODING_PARAM, .unit = "apply_cropping" },
1450  { "none", NULL, 0, AV_OPT_TYPE_CONST, { .i64 = CROP_DISABLED }, .unit = "apply_cropping" },
1451  { "all", NULL, 0, AV_OPT_TYPE_CONST, { .i64 = CROP_ALL }, .unit = "apply_cropping" },
1452  { "codec", NULL, 0, AV_OPT_TYPE_CONST, { .i64 = CROP_CODEC }, .unit = "apply_cropping" },
1453  { "container", NULL, 0, AV_OPT_TYPE_CONST, { .i64 = CROP_CONTAINER }, .unit = "apply_cropping" },
1454  { NULL },
1455  };
1456  const AVClass class = {
1457  .class_name = "apply_cropping",
1458  .item_name = av_default_item_name,
1459  .option = opts,
1460  .version = LIBAVUTIL_VERSION_INT,
1461  };
1462  const AVClass *pclass = &class;
1463 
1465  if (ret < 0) {
1466  av_log(ist, AV_LOG_ERROR, "Invalid apply_cropping value '%s'.\n", apply_cropping);
1467  return ret;
1468  }
1469  }
1470 
1471  opt_match_per_stream_str(ist, &o->codec_tags, ic, st, &codec_tag);
1472  if (codec_tag) {
1473  uint32_t tag = strtol(codec_tag, &next, 0);
1474  if (*next) {
1475  uint8_t buf[4] = { 0 };
1476  memcpy(buf, codec_tag, FFMIN(sizeof(buf), strlen(codec_tag)));
1477  tag = AV_RL32(buf);
1478  }
1479 
1480  st->codecpar->codec_tag = tag;
1481  }
1482 
1483  if (st->codecpar->codec_type == AVMEDIA_TYPE_VIDEO) {
1484  ret = add_display_matrix_to_stream(o, ic, ist);
1485  if (ret < 0)
1486  return ret;
1487 
1488  ret = add_mastering_display_to_stream(o, ic, ist);
1489  if (ret < 0)
1490  return ret;
1491 
1492  ret = add_content_light_to_stream(o, ic, ist);
1493  if (ret < 0)
1494  return ret;
1495 
1496  opt_match_per_stream_str(ist, &o->hwaccels, ic, st, &hwaccel);
1498  &hwaccel_output_format);
1499  if (!hwaccel_output_format && hwaccel && !strcmp(hwaccel, "cuvid")) {
1500  av_log(ist, AV_LOG_WARNING,
1501  "WARNING: defaulting hwaccel_output_format to cuda for compatibility "
1502  "with old commandlines. This behaviour is DEPRECATED and will be removed "
1503  "in the future. Please explicitly set \"-hwaccel_output_format cuda\".\n");
1505  } else if (!hwaccel_output_format && hwaccel && !strcmp(hwaccel, "qsv")) {
1506  av_log(ist, AV_LOG_WARNING,
1507  "WARNING: defaulting hwaccel_output_format to qsv for compatibility "
1508  "with old commandlines. This behaviour is DEPRECATED and will be removed "
1509  "in the future. Please explicitly set \"-hwaccel_output_format qsv\".\n");
1511  } else if (!hwaccel_output_format && hwaccel && !strcmp(hwaccel, "mediacodec")) {
1512  // There is no real AVHWFrameContext implementation. Set
1513  // hwaccel_output_format to avoid av_hwframe_transfer_data error.
1515  } else if (hwaccel_output_format) {
1516  ds->dec_opts.hwaccel_output_format = av_get_pix_fmt(hwaccel_output_format);
1518  av_log(ist, AV_LOG_FATAL, "Unrecognised hwaccel output "
1519  "format: %s", hwaccel_output_format);
1520  }
1521  } else {
1523  }
1524 
1525  if (hwaccel) {
1526  // The NVDEC hwaccels use a CUDA device, so remap the name here.
1527  if (!strcmp(hwaccel, "nvdec") || !strcmp(hwaccel, "cuvid"))
1528  hwaccel = "cuda";
1529 
1530  if (!strcmp(hwaccel, "none"))
1532  else if (!strcmp(hwaccel, "auto"))
1534  else {
1536  if (type != AV_HWDEVICE_TYPE_NONE) {
1539  }
1540 
1541  if (!ds->dec_opts.hwaccel_id) {
1542  av_log(ist, AV_LOG_FATAL, "Unrecognized hwaccel: %s.\n",
1543  hwaccel);
1544  av_log(ist, AV_LOG_FATAL, "Supported hwaccels: ");
1546  while ((type = av_hwdevice_iterate_types(type)) !=
1548  av_log(ist, AV_LOG_FATAL, "%s ",
1550  av_log(ist, AV_LOG_FATAL, "\n");
1551  return AVERROR(EINVAL);
1552  }
1553  }
1554  }
1555 
1556  opt_match_per_stream_str(ist, &o->hwaccel_devices, ic, st, &hwaccel_device);
1557  if (hwaccel_device) {
1558  ds->dec_opts.hwaccel_device = av_strdup(hwaccel_device);
1559  if (!ds->dec_opts.hwaccel_device)
1560  return AVERROR(ENOMEM);
1561  }
1562  }
1563 
1564  ret = choose_decoder(o, ist, ic, st, ds->dec_opts.hwaccel_id,
1565  ds->dec_opts.hwaccel_device_type, &ist->dec);
1566  if (ret < 0)
1567  return ret;
1568 
1569  if (ist->dec) {
1571  ic, st, ist->dec, &ds->decoder_opts, opts_used);
1572  if (ret < 0)
1573  return ret;
1574  }
1575 
1576  ds->reinit_filters = -1;
1577  opt_match_per_stream_int(ist, &o->reinit_filters, ic, st, &ds->reinit_filters);
1578 
1579  ds->drop_changed = 0;
1580  opt_match_per_stream_int(ist, &o->drop_changed, ic, st, &ds->drop_changed);
1581 
1582  if (ds->drop_changed && ds->reinit_filters) {
1583  if (ds->reinit_filters > 0) {
1584  av_log(ist, AV_LOG_ERROR, "drop_changed and reinit_filters both enabled. These are mutually exclusive.\n");
1585  return AVERROR(EINVAL);
1586  }
1587  ds->reinit_filters = 0;
1588  }
1589 
1591 
1592  if ((o->video_disable && ist->st->codecpar->codec_type == AVMEDIA_TYPE_VIDEO) ||
1597 
1598  opt_match_per_stream_str(ist, &o->discard, ic, st, &discard_str);
1599  if (discard_str) {
1600  ret = av_opt_set(ist->st, "discard", discard_str, 0);
1601  if (ret < 0) {
1602  av_log(ist, AV_LOG_ERROR, "Error parsing discard %s.\n", discard_str);
1603  return ret;
1604  }
1605  ist->user_set_discard = ist->st->discard;
1606  }
1607 
1609 
1610  av_dict_set_int(&ds->decoder_opts, "apply_cropping",
1611  ds->apply_cropping && ds->apply_cropping != CROP_CONTAINER, 0);
1612 
1614  if (ds->force_display_matrix) {
1615  if (av_dict_get(ds->decoder_opts, "side_data_prefer_packet", NULL, 0))
1616  av_bprintf(&bp, ",");
1617  av_bprintf(&bp, "displaymatrix");
1618  }
1619  if (ds->force_mastering_display) {
1620  if (bp.len || av_dict_get(ds->decoder_opts, "side_data_prefer_packet", NULL, 0))
1621  av_bprintf(&bp, ",");
1622  av_bprintf(&bp, "mastering_display_metadata");
1623  }
1624  if (ds->force_content_light) {
1625  if (bp.len || av_dict_get(ds->decoder_opts, "side_data_prefer_packet", NULL, 0))
1626  av_bprintf(&bp, ",");
1627  av_bprintf(&bp, "content_light_level");
1628  }
1629  if (bp.len)
1630  av_dict_set(&ds->decoder_opts, "side_data_prefer_packet", bp.str, AV_DICT_APPEND);
1631  av_bprint_finalize(&bp, NULL);
1632 
1633  /* Attached pics are sparse, therefore we would not want to delay their decoding
1634  * till EOF. */
1636  av_dict_set(&ds->decoder_opts, "thread_type", "-frame", 0);
1637 
1638  switch (par->codec_type) {
1639  case AVMEDIA_TYPE_VIDEO:
1640  opt_match_per_stream_str(ist, &o->frame_rates, ic, st, &framerate);
1641  if (framerate) {
1643  if (ret < 0) {
1644  av_log(ist, AV_LOG_ERROR, "Error parsing framerate %s.\n",
1645  framerate);
1646  return ret;
1647  }
1648  }
1649  break;
1650  case AVMEDIA_TYPE_AUDIO: {
1651  const char *ch_layout_str = NULL;
1652 
1653  opt_match_per_stream_str(ist, &o->audio_ch_layouts, ic, st, &ch_layout_str);
1654  if (ch_layout_str) {
1655  AVChannelLayout ch_layout;
1656  ret = av_channel_layout_from_string(&ch_layout, ch_layout_str);
1657  if (ret < 0) {
1658  av_log(ist, AV_LOG_ERROR, "Error parsing channel layout %s.\n", ch_layout_str);
1659  return ret;
1660  }
1661  if (par->ch_layout.nb_channels <= 0 || par->ch_layout.nb_channels == ch_layout.nb_channels) {
1663  par->ch_layout = ch_layout;
1664  } else {
1665  av_log(ist, AV_LOG_ERROR,
1666  "Specified channel layout '%s' has %d channels, but input has %d channels.\n",
1667  ch_layout_str, ch_layout.nb_channels, par->ch_layout.nb_channels);
1668  av_channel_layout_uninit(&ch_layout);
1669  return AVERROR(EINVAL);
1670  }
1671  } else {
1672  int guess_layout_max = INT_MAX;
1673  opt_match_per_stream_int(ist, &o->guess_layout_max, ic, st, &guess_layout_max);
1674  guess_input_channel_layout(ist, par, guess_layout_max);
1675  }
1676  break;
1677  }
1678  case AVMEDIA_TYPE_DATA:
1679  case AVMEDIA_TYPE_SUBTITLE: {
1680  const char *canvas_size = NULL;
1681 
1683  opt_match_per_stream_str(ist, &o->canvas_sizes, ic, st, &canvas_size);
1684  if (canvas_size) {
1685  ret = av_parse_video_size(&par->width, &par->height,
1686  canvas_size);
1687  if (ret < 0) {
1688  av_log(ist, AV_LOG_FATAL, "Invalid canvas size: %s.\n", canvas_size);
1689  return ret;
1690  }
1691  }
1692  break;
1693  }
1695  case AVMEDIA_TYPE_UNKNOWN:
1696  break;
1697  default: av_assert0(0);
1698  }
1699 
1700  ist->par = avcodec_parameters_alloc();
1701  if (!ist->par)
1702  return AVERROR(ENOMEM);
1703 
1704  ret = avcodec_parameters_copy(ist->par, par);
1705  if (ret < 0) {
1706  av_log(ist, AV_LOG_ERROR, "Error exporting stream parameters.\n");
1707  return ret;
1708  }
1709 
1710  if (ist->st->sample_aspect_ratio.num)
1712 
1713  opt_match_per_stream_str(ist, &o->bitstream_filters, ic, st, &bsfs);
1714  if (bsfs) {
1715  ret = av_bsf_list_parse_str(bsfs, &ds->bsf);
1716  if (ret < 0) {
1717  av_log(ist, AV_LOG_ERROR,
1718  "Error parsing bitstream filter sequence '%s': %s\n",
1719  bsfs, av_err2str(ret));
1720  return ret;
1721  }
1722 
1723  ret = avcodec_parameters_copy(ds->bsf->par_in, ist->par);
1724  if (ret < 0)
1725  return ret;
1726  ds->bsf->time_base_in = ist->st->time_base;
1727 
1728  ret = av_bsf_init(ds->bsf);
1729  if (ret < 0) {
1730  av_log(ist, AV_LOG_ERROR, "Error initializing bitstream filters: %s\n",
1731  av_err2str(ret));
1732  return ret;
1733  }
1734 
1735  ret = avcodec_parameters_copy(ist->par, ds->bsf->par_out);
1736  if (ret < 0)
1737  return ret;
1738  }
1739 
1741 
1742  return 0;
1743 }
1744 
1745 static const char *input_stream_group_item_name(void *obj)
1746 {
1747  const DemuxStreamGroup *dsg = obj;
1748 
1749  return dsg->log_name;
1750 }
1751 
1753  .class_name = "InputStreamGroup",
1754  .version = LIBAVUTIL_VERSION_INT,
1755  .item_name = input_stream_group_item_name,
1756  .category = AV_CLASS_CATEGORY_DEMUXER,
1757 };
1758 
1760 {
1761  InputFile *f = &d->f;
1762  DemuxStreamGroup *dsg;
1763 
1764  dsg = allocate_array_elem(&f->stream_groups, sizeof(*dsg), &f->nb_stream_groups);
1765  if (!dsg)
1766  return NULL;
1767 
1768  dsg->istg.stg = stg;
1769  dsg->istg.file = f;
1770  dsg->istg.index = stg->index;
1772 
1773  snprintf(dsg->log_name, sizeof(dsg->log_name), "istg#%d:%d/%s",
1774  d->f.index, stg->index, avformat_stream_group_name(stg->type));
1775 
1776  return dsg;
1777 }
1778 
1780 {
1781  InputFile *f = &d->f;
1782  AVFormatContext *ic = d->f.ctx;
1783  AVStreamGroup *stg = istg->stg;
1784  const AVStreamGroupTileGrid *tg = stg->params.tile_grid;
1786  AVBPrint bp;
1787  char *graph_str;
1788  int autorotate = 1;
1789  const char *apply_cropping = NULL;
1790  int ret;
1791 
1792  if (tg->nb_tiles == 1)
1793  return 0;
1794  if (!tg->nb_tiles) {
1795  av_log(istg, AV_LOG_FATAL, "A demuxer exported an invalid tile group stream group. "
1796  "This is a bug, please report it.\n");
1797  return AVERROR_BUG;
1798  }
1799 
1800  memset(&opts, 0, sizeof(opts));
1801 
1803  if (autorotate)
1804  opts.flags |= OFILTER_FLAG_AUTOROTATE;
1805 
1806  opts.flags |= OFILTER_FLAG_CROP;
1808  if (apply_cropping) {
1809  char *p;
1810  int crop = strtol(apply_cropping, &p, 0);
1811  if (*p)
1812  return AVERROR(EINVAL);
1813  if (!crop)
1814  opts.flags &= ~OFILTER_FLAG_CROP;
1815  }
1816 
1818  for (int i = 0; i < tg->nb_tiles; i++)
1819  av_bprintf(&bp, "[%d:g:%d:%d]", f->index, stg->index, tg->offsets[i].idx);
1820  av_bprintf(&bp, "xstack=inputs=%d:layout=", tg->nb_tiles);
1821  for (int i = 0; i < tg->nb_tiles - 1; i++)
1822  av_bprintf(&bp, "%d_%d|", tg->offsets[i].horizontal,
1823  tg->offsets[i].vertical);
1824  av_bprintf(&bp, "%d_%d:fill=0x%02X%02X%02X@0x%02X", tg->offsets[tg->nb_tiles - 1].horizontal,
1825  tg->offsets[tg->nb_tiles - 1].vertical,
1826  tg->background[0], tg->background[1],
1827  tg->background[2], tg->background[3]);
1828  av_bprintf(&bp, "[%d:g:%d]", f->index, stg->index);
1829  ret = av_bprint_finalize(&bp, &graph_str);
1830  if (ret < 0)
1831  return ret;
1832 
1833  if (tg->coded_width != tg->width || tg->coded_height != tg->height) {
1834  opts.crop_top = tg->vertical_offset;
1835  opts.crop_bottom = tg->coded_height - tg->height - tg->vertical_offset;
1836  opts.crop_left = tg->horizontal_offset;
1837  opts.crop_right = tg->coded_width - tg->width - tg->horizontal_offset;
1838  }
1839 
1840  for (int i = 0; i < tg->nb_coded_side_data; i++) {
1841  const AVPacketSideData *sd = &tg->coded_side_data[i];
1842 
1843  ret = av_packet_side_data_to_frame(&opts.side_data, &opts.nb_side_data, sd, 0);
1844  if (ret < 0 && ret != AVERROR(EINVAL))
1845  goto fail;
1846  }
1847 
1848  ret = fg_create(NULL, &graph_str, d->sch, &opts);
1849  if (ret < 0)
1850  goto fail;
1851 
1852  istg->fg = filtergraphs[nb_filtergraphs-1];
1853  istg->fg->is_internal = 1;
1854 
1855  ret = 0;
1856 fail:
1857  if (ret < 0)
1858  av_freep(&graph_str);
1859 
1860  return ret;
1861 }
1862 
1863 static int istg_add(const OptionsContext *o, Demuxer *d, AVStreamGroup *stg)
1864 {
1865  DemuxStreamGroup *dsg;
1866  InputStreamGroup *istg;
1867  int ret;
1868 
1869  dsg = demux_stream_group_alloc(d, stg);
1870  if (!dsg)
1871  return AVERROR(ENOMEM);
1872 
1873  istg = &dsg->istg;
1874 
1875  switch (stg->type) {
1877  ret = istg_parse_tile_grid(o, d, istg);
1878  if (ret < 0)
1879  return ret;
1880  break;
1881  default:
1882  break;
1883  }
1884 
1885  return 0;
1886 }
1887 
1888 static int is_windows_reserved_device_name(const char *f)
1889 {
1890 #if HAVE_DOS_PATHS
1891  for (const char *p = f; p && *p; ) {
1892  char stem[6], *s;
1893  av_strlcpy(stem, p, sizeof(stem));
1894  if ((s = strchr(stem, '.')))
1895  *s = 0;
1896  if ((s = strpbrk(stem, "123456789")))
1897  *s = '1';
1898 
1899  if( !av_strcasecmp(stem, "AUX") ||
1900  !av_strcasecmp(stem, "CON") ||
1901  !av_strcasecmp(stem, "NUL") ||
1902  !av_strcasecmp(stem, "PRN") ||
1903  !av_strcasecmp(stem, "COM1") ||
1904  !av_strcasecmp(stem, "LPT1")
1905  )
1906  return 1;
1907 
1908  p = strchr(p, '/');
1909  if (p)
1910  p++;
1911  }
1912 #endif
1913  return 0;
1914 }
1915 
1916 static int safe_filename(const char *f, int allow_subdir)
1917 {
1918  const char *start = f;
1919 
1921  return 0;
1922 
1923  for (; *f; f++) {
1924  /* A-Za-z0-9_- */
1925  if (!((unsigned)((*f | 32) - 'a') < 26 ||
1926  (unsigned)(*f - '0') < 10 || *f == '_' || *f == '-')) {
1927  if (f == start)
1928  return 0;
1929  else if (allow_subdir && *f == '/')
1930  start = f + 1;
1931  else if (*f != '.')
1932  return 0;
1933  }
1934  }
1935  return 1;
1936 }
1937 
1938 static int dump_attachment(InputStream *ist, const char *filename)
1939 {
1940  AVStream *st = ist->st;
1941  int ret;
1942  AVIOContext *out = NULL;
1943  const AVDictionaryEntry *e;
1944 
1945  if (!st->codecpar->extradata_size) {
1946  av_log(ist, AV_LOG_WARNING, "No extradata to dump.\n");
1947  return 0;
1948  }
1949  if (!*filename && (e = av_dict_get(st->metadata, "filename", NULL, 0))) {
1950  filename = e->value;
1951  if (!safe_filename(filename, 0)) {
1952  av_log(ist, AV_LOG_ERROR, "Filename %s is unsafe\n", filename);
1953  return AVERROR(EINVAL);
1954  }
1955  }
1956  if (!*filename) {
1957  av_log(ist, AV_LOG_FATAL, "No filename specified and no 'filename' tag");
1958  return AVERROR(EINVAL);
1959  }
1960 
1961  ret = assert_file_overwrite(filename);
1962  if (ret < 0)
1963  return ret;
1964 
1965  if ((ret = avio_open2(&out, filename, AVIO_FLAG_WRITE, &int_cb, NULL)) < 0) {
1966  av_log(ist, AV_LOG_FATAL, "Could not open file %s for writing.\n",
1967  filename);
1968  return ret;
1969  }
1970 
1972  ret = avio_close(out);
1973 
1974  if (ret >= 0)
1975  av_log(ist, AV_LOG_INFO, "Wrote attachment (%d bytes) to '%s'\n",
1976  st->codecpar->extradata_size, filename);
1977 
1978  return ret;
1979 }
1980 
1981 static const char *input_file_item_name(void *obj)
1982 {
1983  const Demuxer *d = obj;
1984 
1985  return d->log_name;
1986 }
1987 
1988 static const AVClass input_file_class = {
1989  .class_name = "InputFile",
1990  .version = LIBAVUTIL_VERSION_INT,
1991  .item_name = input_file_item_name,
1992  .category = AV_CLASS_CATEGORY_DEMUXER,
1993 };
1994 
1995 static Demuxer *demux_alloc(void)
1996 {
1998 
1999  if (!d)
2000  return NULL;
2001 
2002  d->f.class = &input_file_class;
2003  d->f.index = nb_input_files - 1;
2004 
2005  snprintf(d->log_name, sizeof(d->log_name), "in#%d", d->f.index);
2006 
2007  return d;
2008 }
2009 
2010 int ifile_open(const OptionsContext *o, const char *filename, Scheduler *sch)
2011 {
2012  Demuxer *d;
2013  InputFile *f;
2014  AVFormatContext *ic;
2015  const AVInputFormat *file_iformat = NULL;
2016  int err, ret = 0;
2017  int64_t timestamp;
2018  AVDictionary *opts_used = NULL;
2019  const char* video_codec_name = NULL;
2020  const char* audio_codec_name = NULL;
2021  const char* subtitle_codec_name = NULL;
2022  const char* data_codec_name = NULL;
2023  int scan_all_pmts_set = 0;
2024 
2026  int64_t start_time_eof = o->start_time_eof;
2027  int64_t stop_time = o->stop_time;
2028  int64_t recording_time = o->recording_time;
2029 
2030  d = demux_alloc();
2031  if (!d)
2032  return AVERROR(ENOMEM);
2033 
2034  f = &d->f;
2035 
2036  ret = sch_add_demux(sch, input_thread, d);
2037  if (ret < 0)
2038  return ret;
2039  d->sch = sch;
2040 
2041  if (stop_time != INT64_MAX && recording_time != INT64_MAX) {
2042  stop_time = INT64_MAX;
2043  av_log(d, AV_LOG_WARNING, "-t and -to cannot be used together; using -t.\n");
2044  }
2045 
2046  if (stop_time != INT64_MAX && recording_time == INT64_MAX) {
2047  int64_t start = start_time == AV_NOPTS_VALUE ? 0 : start_time;
2048  if (stop_time <= start) {
2049  av_log(d, AV_LOG_ERROR, "-to value smaller than -ss; aborting.\n");
2050  return AVERROR(EINVAL);
2051  } else {
2052  recording_time = stop_time - start;
2053  }
2054  }
2055 
2056  if (o->format) {
2057  if (!(file_iformat = av_find_input_format(o->format))) {
2058  av_log(d, AV_LOG_FATAL, "Unknown input format: '%s'\n", o->format);
2059  return AVERROR(EINVAL);
2060  }
2061  }
2062 
2063  if (!strcmp(filename, "-"))
2064  filename = "fd:";
2065 
2066  stdin_interaction &= strncmp(filename, "pipe:", 5) &&
2067  strcmp(filename, "fd:") &&
2068  strcmp(filename, "/dev/stdin");
2069 
2070  /* get default parameters from command line */
2071  ic = avformat_alloc_context();
2072  if (!ic)
2073  return AVERROR(ENOMEM);
2074  ic->name = av_strdup(d->log_name);
2075  if (o->audio_sample_rate.nb_opt) {
2076  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);
2077  }
2078  if (o->audio_channels.nb_opt) {
2079  const AVClass *priv_class;
2080  if (file_iformat && (priv_class = file_iformat->priv_class) &&
2081  av_opt_find(&priv_class, "ch_layout", NULL, 0,
2083  char buf[32];
2084  snprintf(buf, sizeof(buf), "%dC", o->audio_channels.opt[o->audio_channels.nb_opt - 1].u.i);
2085  av_dict_set(&o->g->format_opts, "ch_layout", buf, 0);
2086  }
2087  }
2088  if (o->audio_ch_layouts.nb_opt) {
2089  const AVClass *priv_class;
2090  if (file_iformat && (priv_class = file_iformat->priv_class) &&
2091  av_opt_find(&priv_class, "ch_layout", NULL, 0,
2093  av_dict_set(&o->g->format_opts, "ch_layout", o->audio_ch_layouts.opt[o->audio_ch_layouts.nb_opt - 1].u.str, 0);
2094  }
2095  }
2096  if (o->frame_rates.nb_opt) {
2097  const AVClass *priv_class;
2098  /* set the format-level framerate option;
2099  * this is important for video grabbers, e.g. x11 */
2100  if (file_iformat && (priv_class = file_iformat->priv_class) &&
2101  av_opt_find(&priv_class, "framerate", NULL, 0,
2103  av_dict_set(&o->g->format_opts, "framerate",
2104  o->frame_rates.opt[o->frame_rates.nb_opt - 1].u.str, 0);
2105  }
2106  }
2107  if (o->frame_sizes.nb_opt) {
2108  av_dict_set(&o->g->format_opts, "video_size", o->frame_sizes.opt[o->frame_sizes.nb_opt - 1].u.str, 0);
2109  }
2110  if (o->frame_pix_fmts.nb_opt)
2111  av_dict_set(&o->g->format_opts, "pixel_format", o->frame_pix_fmts.opt[o->frame_pix_fmts.nb_opt - 1].u.str, 0);
2112 
2117 
2118  if (video_codec_name)
2120  &ic->video_codec));
2121  if (audio_codec_name)
2123  &ic->audio_codec));
2124  if (subtitle_codec_name)
2126  &ic->subtitle_codec));
2127  if (data_codec_name)
2129  &ic->data_codec));
2130  if (ret < 0) {
2132  return ret;
2133  }
2134 
2139 
2140  ic->flags |= AVFMT_FLAG_NONBLOCK;
2141  if (o->bitexact)
2142  ic->flags |= AVFMT_FLAG_BITEXACT;
2143  ic->interrupt_callback = int_cb;
2144 
2145  if (!av_dict_get(o->g->format_opts, "scan_all_pmts", NULL, AV_DICT_MATCH_CASE)) {
2146  av_dict_set(&o->g->format_opts, "scan_all_pmts", "1", AV_DICT_DONT_OVERWRITE);
2147  scan_all_pmts_set = 1;
2148  }
2149  /* open the input file with generic avformat function */
2150  err = avformat_open_input(&ic, filename, file_iformat, &o->g->format_opts);
2151  if (err < 0) {
2152  if (err != AVERROR_EXIT)
2153  av_log(d, AV_LOG_ERROR,
2154  "Error opening input: %s\n", av_err2str(err));
2155  if (err == AVERROR_PROTOCOL_NOT_FOUND)
2156  av_log(d, AV_LOG_ERROR, "Did you mean file:%s?\n", filename);
2157  return err;
2158  }
2159  f->ctx = ic;
2160 
2161  av_strlcat(d->log_name, "/", sizeof(d->log_name));
2162  av_strlcat(d->log_name, ic->iformat->name, sizeof(d->log_name));
2163  av_freep(&ic->name);
2164  ic->name = av_strdup(d->log_name);
2165 
2166  if (scan_all_pmts_set)
2167  av_dict_set(&o->g->format_opts, "scan_all_pmts", NULL, AV_DICT_MATCH_CASE);
2169 
2171  if (ret < 0)
2172  return ret;
2173 
2174  /* apply forced codec ids */
2175  for (int i = 0; i < ic->nb_streams; i++) {
2176  const AVCodec *dummy;
2178  &dummy);
2179  if (ret < 0)
2180  return ret;
2181  }
2182 
2183  if (o->find_stream_info) {
2184  AVDictionary **opts;
2185  int orig_nb_streams = ic->nb_streams;
2186 
2188  if (ret < 0)
2189  return ret;
2190 
2191  /* If not enough info to get the stream parameters, we decode the
2192  first frames to get it. (used in mpeg case for example) */
2194 
2195  for (int i = 0; i < orig_nb_streams; i++)
2196  av_dict_free(&opts[i]);
2197  av_freep(&opts);
2198 
2199  if (ret < 0) {
2200  av_log(d, AV_LOG_FATAL, "could not find codec parameters\n");
2201  if (ic->nb_streams == 0)
2202  return ret;
2203  }
2204  }
2205 
2206  if (start_time != AV_NOPTS_VALUE && start_time_eof != AV_NOPTS_VALUE) {
2207  av_log(d, AV_LOG_WARNING, "Cannot use -ss and -sseof both, using -ss\n");
2208  start_time_eof = AV_NOPTS_VALUE;
2209  }
2210 
2211  if (start_time_eof != AV_NOPTS_VALUE) {
2212  if (start_time_eof >= 0) {
2213  av_log(d, AV_LOG_ERROR, "-sseof value must be negative; aborting\n");
2214  return AVERROR(EINVAL);
2215  }
2216  if (ic->duration > 0) {
2217  start_time = start_time_eof + ic->duration;
2218  if (start_time < 0) {
2219  av_log(d, AV_LOG_WARNING, "-sseof value seeks to before start of file; ignored\n");
2221  }
2222  } else
2223  av_log(d, AV_LOG_WARNING, "Cannot use -sseof, file duration not known\n");
2224  }
2225  timestamp = (start_time == AV_NOPTS_VALUE) ? 0 : start_time;
2226  /* add the stream start time */
2227  if (!o->seek_timestamp && ic->start_time != AV_NOPTS_VALUE)
2228  timestamp += ic->start_time;
2229 
2230  /* if seeking requested, we execute it */
2231  if (start_time != AV_NOPTS_VALUE) {
2232  int64_t seek_timestamp = timestamp;
2233 
2234  if (!(ic->iformat->flags & AVFMT_SEEK_TO_PTS)) {
2235  int dts_heuristic = 0;
2236  for (int i = 0; i < ic->nb_streams; i++) {
2237  const AVCodecParameters *par = ic->streams[i]->codecpar;
2238  if (par->video_delay) {
2239  dts_heuristic = 1;
2240  break;
2241  }
2242  }
2243  if (dts_heuristic) {
2244  seek_timestamp -= 3*AV_TIME_BASE / 23;
2245  }
2246  }
2247  ret = avformat_seek_file(ic, -1, INT64_MIN, seek_timestamp, seek_timestamp, 0);
2248  if (ret < 0) {
2249  av_log(d, AV_LOG_WARNING, "could not seek to position %0.3f\n",
2250  (double)timestamp / AV_TIME_BASE);
2251  }
2252  }
2253 
2254  f->start_time = start_time;
2255  d->recording_time = recording_time;
2256  f->input_sync_ref = o->input_sync_ref;
2257  f->input_ts_offset = o->input_ts_offset;
2258  f->ts_offset = o->input_ts_offset - (copy_ts ? (start_at_zero && ic->start_time != AV_NOPTS_VALUE ? ic->start_time : 0) : timestamp);
2259  d->accurate_seek = o->accurate_seek;
2260  d->loop = o->loop;
2261  d->nb_streams_warn = ic->nb_streams;
2262 
2263  d->duration = (Timestamp){ .ts = 0, .tb = (AVRational){ 1, 1 } };
2264  d->min_pts = (Timestamp){ .ts = AV_NOPTS_VALUE, .tb = (AVRational){ 1, 1 } };
2265  d->max_pts = (Timestamp){ .ts = AV_NOPTS_VALUE, .tb = (AVRational){ 1, 1 } };
2266 
2267  d->readrate = o->readrate ? o->readrate : 0.0;
2268  if (d->readrate < 0.0f) {
2269  av_log(d, AV_LOG_ERROR, "Option -readrate is %0.3f; it must be non-negative.\n", d->readrate);
2270  return AVERROR(EINVAL);
2271  }
2272  if (o->rate_emu) {
2273  if (d->readrate) {
2274  av_log(d, AV_LOG_WARNING, "Both -readrate and -re set. Using -readrate %0.3f.\n", d->readrate);
2275  } else
2276  d->readrate = 1.0f;
2277  }
2278 
2279  if (d->readrate) {
2281  if (d->readrate_initial_burst < 0.0) {
2282  av_log(d, AV_LOG_ERROR,
2283  "Option -readrate_initial_burst is %0.3f; it must be non-negative.\n",
2285  return AVERROR(EINVAL);
2286  }
2288  if (d->readrate_catchup < d->readrate) {
2289  av_log(d, AV_LOG_ERROR,
2290  "Option -readrate_catchup is %0.3f; it must be at least equal to %0.3f.\n",
2291  d->readrate_catchup, d->readrate);
2292  return AVERROR(EINVAL);
2293  }
2294  } else {
2295  if (o->readrate_initial_burst) {
2296  av_log(d, AV_LOG_WARNING, "Option -readrate_initial_burst ignored "
2297  "since neither -readrate nor -re were given\n");
2298  }
2299  if (o->readrate_catchup) {
2300  av_log(d, AV_LOG_WARNING, "Option -readrate_catchup ignored "
2301  "since neither -readrate nor -re were given\n");
2302  }
2303  }
2304 
2305  /* Add all the streams from the given input file to the demuxer */
2306  for (int i = 0; i < ic->nb_streams; i++) {
2307  ret = ist_add(o, d, ic->streams[i], &opts_used);
2308  if (ret < 0) {
2309  av_dict_free(&opts_used);
2310  return ret;
2311  }
2312  }
2313 
2314  /* Add all the stream groups from the given input file to the demuxer */
2315  for (int i = 0; i < ic->nb_stream_groups; i++) {
2316  ret = istg_add(o, d, ic->stream_groups[i]);
2317  if (ret < 0)
2318  return ret;
2319  }
2320 
2321  /* dump the file content */
2322  av_dump_format(ic, f->index, filename, 0);
2323 
2324  /* check if all codec options have been used */
2325  ret = check_avoptions_used(o->g->codec_opts, opts_used, d, 1);
2326  av_dict_free(&opts_used);
2327  if (ret < 0)
2328  return ret;
2329 
2330  for (int i = 0; i < o->dump_attachment.nb_opt; i++) {
2331  for (int j = 0; j < f->nb_streams; j++) {
2332  InputStream *ist = f->streams[j];
2333 
2334  if (check_stream_specifier(ic, ist->st, o->dump_attachment.opt[i].specifier) == 1) {
2336  if (ret < 0)
2337  return ret;
2338  }
2339  }
2340  }
2341 
2342  return 0;
2343 }
OptionsContext::readrate
float readrate
Definition: ffmpeg.h:154
flags
const SwsFlags flags[]
Definition: swscale.c:85
AVMasteringDisplayMetadata::has_primaries
int has_primaries
Flag indicating whether the display primaries (and white point) are set.
Definition: mastering_display_metadata.h:62
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:434
AVCodec
AVCodec.
Definition: codec.h:169
OptionsContext::input_ts_offset
int64_t input_ts_offset
Definition: ffmpeg.h:151
AVMEDIA_TYPE_SUBTITLE
@ AVMEDIA_TYPE_SUBTITLE
Definition: avutil.h:203
DemuxStream::ist
InputStream ist
Definition: ffmpeg_demux.c:45
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:518
AV_PIX_FMT_CUDA
@ AV_PIX_FMT_CUDA
HW acceleration through CUDA.
Definition: pixfmt.h:260
AVMasteringDisplayMetadata::max_luminance
AVRational max_luminance
Max luminance of mastering display (cd/m^2).
Definition: mastering_display_metadata.h:57
AVCodecParameters::extradata
uint8_t * extradata
Extra binary data needed for initializing the decoder, codec-dependent.
Definition: codec_par.h:71
AVFormatContext::stream_groups
AVStreamGroup ** stream_groups
A list of all stream groups in the file.
Definition: avformat.h:1401
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:179
demux_final_stats
static void demux_final_stats(Demuxer *d)
Definition: ffmpeg_demux.c:838
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
safe_filename
static int safe_filename(const char *f, int allow_subdir)
Definition: ffmpeg_demux.c:1916
AVCodecParameters::codec_type
enum AVMediaType codec_type
General type of the encoded data.
Definition: codec_par.h:53
AVStreamGroup::tile_grid
struct AVStreamGroupTileGrid * tile_grid
Definition: avformat.h:1175
input_stream_class
static const AVClass input_stream_class
Definition: ffmpeg_demux.c:1376
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:690
DemuxStreamGroup
Definition: ffmpeg_demux.c:110
check_avoptions
int check_avoptions(AVDictionary *m)
Definition: cmdutils.c:1605
apply_cropping
static int apply_cropping(AVCodecContext *avctx, AVFrame *frame)
Definition: decode.c:757
out
static FILE * out
Definition: movenc.c:55
DemuxStream::drop_changed
int drop_changed
Definition: ffmpeg_demux.c:74
av_bprint_init
void av_bprint_init(AVBPrint *buf, unsigned size_init, unsigned size_max)
Definition: bprint.c:69
DecoderOpts
Definition: ffmpeg.h:425
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:49
DECODER_FLAG_SEND_END_TS
@ DECODER_FLAG_SEND_END_TS
Definition: ffmpeg.h:420
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:1021
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:673
AVStream::discard
enum AVDiscard discard
Selects which packets can be discarded at will and do not need to be demuxed.
Definition: avformat.h:818
AV_PKT_DATA_MASTERING_DISPLAY_METADATA
@ AV_PKT_DATA_MASTERING_DISPLAY_METADATA
Mastering display metadata (based on SMPTE-2086:2014).
Definition: packet.h:219
FrameData::dts_est
int64_t dts_est
Definition: ffmpeg.h:693
sch_add_demux
int sch_add_demux(Scheduler *sch, SchThreadFunc func, void *ctx)
Add a demuxer to the scheduler.
Definition: ffmpeg_sched.c:726
AVMasteringDisplayMetadata::display_primaries
AVRational display_primaries[3][2]
CIE 1931 xy chromaticity coords of color primaries (r, g, b order).
Definition: mastering_display_metadata.h:42
input_packet_process
static int input_packet_process(Demuxer *d, AVPacket *pkt, unsigned *send_flags)
Definition: ffmpeg_demux.c:466
demux_thread_init
static int demux_thread_init(DemuxThreadContext *dt)
Definition: ffmpeg_demux.c:715
AVMasteringDisplayMetadata::has_luminance
int has_luminance
Flag indicating whether the luminance (min_ and max_) have been set.
Definition: mastering_display_metadata.h:67
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:479
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:470
av_strcasecmp
int av_strcasecmp(const char *a, const char *b)
Locale-independent case-insensitive compare.
Definition: avstring.c:208
DemuxStream::sch_idx_stream
int sch_idx_stream
Definition: ffmpeg_demux.c:50
OptionsContext::audio_ch_layouts
SpecifierOptList audio_ch_layouts
Definition: ffmpeg.h:142
ist_add
static int ist_add(const OptionsContext *o, Demuxer *d, AVStream *st, AVDictionary **opts_used)
Definition: ffmpeg_demux.c:1408
ist_iter
InputStream * ist_iter(InputStream *prev)
Definition: ffmpeg.c:387
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
AVContentLightMetadata::MaxCLL
unsigned MaxCLL
Max content light level (cd/m^2).
Definition: mastering_display_metadata.h:111
DemuxStream::finished
int finished
Definition: ffmpeg_demux.c:64
InputFile::index
int index
Definition: ffmpeg.h:507
AVFrame
This structure describes decoded (raw) audio or video data.
Definition: frame.h:466
pixdesc.h
AVFormatContext::streams
AVStream ** streams
A list of all streams in the file.
Definition: avformat.h:1382
AVFrame::width
int width
Definition: frame.h:538
DECODER_FLAG_FRAMERATE_FORCED
@ DECODER_FLAG_FRAMERATE_FORCED
Definition: ffmpeg.h:419
AVPacketSideData
This structure stores auxiliary information for decoding, presenting, or otherwise processing the cod...
Definition: packet.h:424
OptionsContext::display_hflips
SpecifierOptList display_hflips
Definition: ffmpeg.h:206
DecoderOpts::par
const AVCodecParameters * par
Definition: ffmpeg.h:432
demux_stream_group_alloc
static DemuxStreamGroup * demux_stream_group_alloc(Demuxer *d, AVStreamGroup *stg)
Definition: ffmpeg_demux.c:1759
ifile_close
void ifile_close(InputFile **pf)
Definition: ffmpeg_demux.c:912
DemuxStream::streamcopy_needed
int streamcopy_needed
Definition: ffmpeg_demux.c:66
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:189
demux_stream_alloc
static DemuxStream * demux_stream_alloc(Demuxer *d, AVStream *st)
Definition: ffmpeg_demux.c:1383
OptionsContext::readrate_catchup
float readrate_catchup
Definition: ffmpeg.h:155
AVOption
AVOption.
Definition: opt.h:428
AVStream::avg_frame_rate
AVRational avg_frame_rate
Average framerate.
Definition: avformat.h:836
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:1028
DecoderOpts::hwaccel_id
enum HWAccelID hwaccel_id
Definition: ffmpeg.h:435
InputStream::nb_filters
int nb_filters
Definition: ffmpeg.h:489
AV_DICT_APPEND
#define AV_DICT_APPEND
If the entry already exists, append to it.
Definition: dict.h:82
AVCodecParameters::framerate
AVRational framerate
Number of frames per second, for streams with constant frame durations.
Definition: codec_par.h:175
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:90
AVFormatContext::programs
AVProgram ** programs
Definition: avformat.h:1512
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:185
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:621
ViewSpecifier
Definition: ffmpeg.h:116
AVCodecParameters::codec_tag
uint32_t codec_tag
Additional information about the codec (corresponds to the AVI FOURCC).
Definition: codec_par.h:61
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:1003
av_read_frame
int av_read_frame(AVFormatContext *s, AVPacket *pkt)
Return the next frame of a stream.
Definition: demux.c:1588
AVFormatContext::video_codec_id
enum AVCodecID video_codec_id
Forced video codec_id.
Definition: avformat.h:1518
IFILTER_FLAG_AUTOROTATE
@ IFILTER_FLAG_AUTOROTATE
Definition: ffmpeg.h:249
OptionsContext::format
const char * format
Definition: ffmpeg.h:139
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:422
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:862
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:107
dummy
static int dummy
Definition: ffplay.c:3751
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:148
AVBSFContext
The bitstream filter state.
Definition: bsf.h:68
AVStreamGroupTileGrid::offsets
struct AVStreamGroupTileGrid::@453 * offsets
An nb_tiles sized array of offsets in pixels from the topleft edge of the canvas, indicating where ea...
input_stream_group_item_name
static const char * input_stream_group_item_name(void *obj)
Definition: ffmpeg_demux.c:1745
OptionsContext::canvas_sizes
SpecifierOptList canvas_sizes
Definition: ffmpeg.h:223
Demuxer::wallclock_start
int64_t wallclock_start
Definition: ffmpeg_demux.c:123
AVContentLightMetadata
Content light level needed by to transmit HDR over HDMI (CTA-861.3).
Definition: mastering_display_metadata.h:107
add_mastering_display_to_stream
static int add_mastering_display_to_stream(const OptionsContext *o, AVFormatContext *ctx, InputStream *ist)
Definition: ffmpeg_demux.c:1250
SpecifierOpt::i
int i
Definition: cmdutils.h:175
InputStream
Definition: ffmpeg.h:461
DecoderOpts::hwaccel_output_format
enum AVPixelFormat hwaccel_output_format
Definition: ffmpeg.h:438
debug_ts
int debug_ts
Definition: ffmpeg_opt.c:67
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:426
OutputFilterOptions
Definition: ffmpeg.h:292
AVFormatContext::interrupt_callback
AVIOInterruptCB interrupt_callback
Custom interrupt callbacks for the I/O layer.
Definition: avformat.h:1584
Demuxer
Definition: ffmpeg_demux.c:117
OptionsContext::rate_emu
int rate_emu
Definition: ffmpeg.h:153
CROP_CODEC
@ CROP_CODEC
Definition: ffmpeg.h:617
dts_delta_threshold
float dts_delta_threshold
Definition: ffmpeg_opt.c:56
DemuxStream::data_size
uint64_t data_size
Definition: ffmpeg_demux.c:101
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:501
InputStreamGroup
Definition: ffmpeg.h:492
OptionsContext::g
OptionGroup * g
Definition: ffmpeg.h:133
Demuxer::log_name
char log_name[32]
Definition: ffmpeg_demux.c:121
Decoder::frames_decoded
uint64_t frames_decoded
Definition: ffmpeg.h:456
Demuxer::nb_streams_finished
int nb_streams_finished
Definition: ffmpeg_demux.c:156
opt_match_per_stream_int
void opt_match_per_stream_int(void *logctx, const SpecifierOptList *sol, AVFormatContext *fc, AVStream *st, int *out)
AVStreamGroupTileGrid
AVStreamGroupTileGrid holds information on how to combine several independent images on a single canv...
Definition: avformat.h:954
avformat_stream_group_name
const char * avformat_stream_group_name(enum AVStreamGroupParamsType type)
Definition: avformat.c:264
AVStreamGroupTileGrid::coded_width
int coded_width
Width of the canvas.
Definition: avformat.h:969
DecoderOpts::log_parent
void * log_parent
Definition: ffmpeg.h:429
InputStreamGroup::index
int index
Definition: ffmpeg.h:498
input_file_item_name
static const char * input_file_item_name(void *obj)
Definition: ffmpeg_demux.c:1981
AVDISCARD_NONE
@ AVDISCARD_NONE
discard nothing
Definition: defs.h:226
AV_BPRINT_SIZE_AUTOMATIC
#define AV_BPRINT_SIZE_AUTOMATIC
AVFrame::ch_layout
AVChannelLayout ch_layout
Channel layout of the audio data.
Definition: frame.h:809
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:975
pts
static int64_t pts
Definition: transcode_aac.c:649
OptionsContext
Definition: ffmpeg.h:132
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:824
DemuxStreamGroup::istg
InputStreamGroup istg
Definition: ffmpeg_demux.c:111
do_pkt_dump
int do_pkt_dump
Definition: ffmpeg_opt.c:63
Demuxer::ts_offset_discont
int64_t ts_offset_discont
Extra timestamp offset added by discontinuity handling.
Definition: ffmpeg_demux.c:128
AVRational::num
int num
Numerator.
Definition: rational.h:59
Demuxer::f
InputFile f
Definition: ffmpeg_demux.c:118
Decoder::samples_decoded
uint64_t samples_decoded
Definition: ffmpeg.h:457
InputFile
Definition: ffmpeg.h:504
DemuxStream::nb_packets
uint64_t nb_packets
Definition: ffmpeg_demux.c:99
Demuxer::nb_streams_used
int nb_streams_used
Definition: ffmpeg_demux.c:155
OptionsContext::recording_time
int64_t recording_time
Definition: ffmpeg.h:178
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:566
LATENCY_PROBE_DEMUX
@ LATENCY_PROBE_DEMUX
Definition: ffmpeg.h:87
OptionsContext::mastering_displays
SpecifierOptList mastering_displays
Definition: ffmpeg.h:208
OptionsContext::audio_disable
int audio_disable
Definition: ffmpeg.h:188
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
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:2010
AVInputFormat
Definition: avformat.h:546
AV_PKT_FLAG_CORRUPT
#define AV_PKT_FLAG_CORRUPT
The packet content is corrupted.
Definition: packet.h:651
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:1088
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:852
OptionsContext::hwaccel_output_formats
SpecifierOptList hwaccel_output_formats
Definition: ffmpeg.h:166
SpecifierOptList::nb_opt
int nb_opt
Definition: cmdutils.h:185
CROP_DISABLED
@ CROP_DISABLED
Definition: ffmpeg.h:615
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)
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 frame size, if known.
Definition: codec_par.h:227
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:654
HWACCEL_GENERIC
@ HWACCEL_GENERIC
Definition: ffmpeg.h:72
assert_file_overwrite
int assert_file_overwrite(const char *filename)
Definition: ffmpeg_opt.c:816
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
AVMasteringDisplayMetadata::white_point
AVRational white_point[2]
CIE 1931 xy chromaticity coords of white point.
Definition: mastering_display_metadata.h:47
intreadwrite.h
AVFormatContext::video_codec
const struct AVCodec * video_codec
Forced video codec.
Definition: avformat.h:1841
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:80
Demuxer::readrate
float readrate
Definition: ffmpeg_demux.c:146
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:482
AVFormatContext::flags
int flags
Flags modifying the (de)muxer behaviour.
Definition: avformat.h:1465
AVCodecParameters::sample_aspect_ratio
AVRational sample_aspect_ratio
The aspect ratio (width/height) which a single pixel should have when displayed.
Definition: codec_par.h:161
AVFormatContext::nb_programs
unsigned int nb_programs
Definition: avformat.h:1511
AVInputFormat::name
const char * name
A comma separated list of short names for the format.
Definition: avformat.h:551
dec_init
int dec_init(Decoder **pdec, Scheduler *sch, AVDictionary **dec_opts, const DecoderOpts *o, AVFrame *param_out)
Definition: ffmpeg_dec.c:1658
AVFormatContext::iformat
const struct AVInputFormat * iformat
The input container format.
Definition: avformat.h:1326
AVMEDIA_TYPE_AUDIO
@ AVMEDIA_TYPE_AUDIO
Definition: avutil.h:201
AVCodecParameters::width
int width
The width of the video frame in pixels.
Definition: codec_par.h:143
OptionsContext::hwaccel_devices
SpecifierOptList hwaccel_devices
Definition: ffmpeg.h:165
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:753
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:147
InputFilter
Definition: ffmpeg.h:354
DemuxStream::ts_scale
double ts_scale
Definition: ffmpeg_demux.c:53
av_assert0
#define av_assert0(cond)
assert() equivalent, that is always enabled.
Definition: avassert.h:42
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:682
AVStreamGroup::index
unsigned int index
Group index in AVFormatContext.
Definition: avformat.h:1151
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:425
DemuxThreadContext
Definition: ffmpeg_demux.c:159
ctx
static 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:488
demux_send
static int demux_send(Demuxer *d, DemuxThreadContext *dt, DemuxStream *ds, AVPacket *pkt, unsigned flags)
Definition: ffmpeg_demux.c:588
Demuxer::nb_streams_warn
int nb_streams_warn
Definition: ffmpeg_demux.c:144
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:221
DecoderOpts::hwaccel_device
char * hwaccel_device
Definition: ffmpeg.h:437
input_stream_item_name
static const char * input_stream_item_name(void *obj)
Definition: ffmpeg_demux.c:1369
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:157
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:88
AVMEDIA_TYPE_DATA
@ AVMEDIA_TYPE_DATA
Opaque data information usually continuous.
Definition: avutil.h:202
InputStreamGroup::stg
AVStreamGroup * stg
Definition: ffmpeg.h:501
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:628
InputStreamGroup::file
struct InputFile * file
Definition: ffmpeg.h:496
AVFormatContext::data_codec
const struct AVCodec * data_codec
Forced data codec.
Definition: avformat.h:1865
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
av_content_light_metadata_alloc
AVContentLightMetadata * av_content_light_metadata_alloc(size_t *size)
Allocate an AVContentLightMetadata structure and set its fields to default values.
Definition: mastering_display_metadata.c:73
Demuxer::duration
Timestamp duration
Definition: ffmpeg_demux.c:138
DemuxThreadContext::pkt_demux
AVPacket * pkt_demux
Definition: ffmpeg_demux.c:161
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:2609
OptionsContext::start_time
int64_t start_time
Definition: ffmpeg.h:136
AVDISCARD_ALL
@ AVDISCARD_ALL
discard all
Definition: defs.h:232
AVFormatContext
Format I/O context.
Definition: avformat.h:1314
fail
#define fail
Definition: test.h:478
DECODING_FOR_OST
#define DECODING_FOR_OST
Definition: ffmpeg_demux.c:57
AVFormatContext::audio_codec_id
enum AVCodecID audio_codec_id
Forced audio codec_id.
Definition: avformat.h:1524
OptionGroup::format_opts
AVDictionary * format_opts
Definition: cmdutils.h:348
opts
static AVDictionary * opts
Definition: movenc.c:51
AVStream::codecpar
AVCodecParameters * codecpar
Codec parameters associated with this stream.
Definition: avformat.h:770
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:171
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:786
NULL
#define NULL
Definition: coverity.c:32
Demuxer::readrate_catchup
float readrate_catchup
Definition: ffmpeg_demux.c:148
dec_request_view
int dec_request_view(Decoder *dec, const ViewSpecifier *vs, SchedulerNode *src)
Definition: ffmpeg_dec.c:1024
Decoder::decode_errors
uint64_t decode_errors
Definition: ffmpeg.h:458
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::st
AVStream * st
Definition: ffmpeg.h:469
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:143
InputFile::start_time_effective
int64_t start_time_effective
Effective format start time based on enabled streams.
Definition: ffmpeg.h:515
AVStreamGroupTileGrid::coded_side_data
AVPacketSideData * coded_side_data
Additional data associated with the grid.
Definition: avformat.h:1057
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:131
parseutils.h
AVStream::metadata
AVDictionary * metadata
Definition: avformat.h:827
OptionsContext::reinit_filters
SpecifierOptList reinit_filters
Definition: ffmpeg.h:219
AV_OPT_SEARCH_FAKE_OBJ
#define AV_OPT_SEARCH_FAKE_OBJ
The obj passed to av_opt_find() is fake – only a double pointer to AVClass instead of a required poin...
Definition: opt.h:612
OptionsContext::dump_attachment
SpecifierOptList dump_attachment
Definition: ffmpeg.h:163
InputStream::fix_sub_duration
int fix_sub_duration
Definition: ffmpeg.h:484
FrameData::wallclock
int64_t wallclock[LATENCY_PROBE_NB]
Definition: ffmpeg.h:707
InputStreamGroup::class
const AVClass * class
Definition: ffmpeg.h:493
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:207
DemuxStreamGroup::log_name
char log_name[32]
Definition: ffmpeg_demux.c:114
DemuxThreadContext::pkt_bsf
AVPacket * pkt_bsf
Definition: ffmpeg_demux.c:163
InputFilterOptions
Definition: ffmpeg.h:256
av_opt_get_int
int av_opt_get_int(void *obj, const char *name, int search_flags, int64_t *out_val)
Definition: opt.c:1262
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:154
AVCodecParameters::ch_layout
AVChannelLayout ch_layout
The channel layout and number of channels.
Definition: codec_par.h:207
OptionsContext::input_sync_ref
int input_sync_ref
Definition: ffmpeg.h:159
report_new_stream
static void report_new_stream(Demuxer *d, const AVPacket *pkt)
Definition: ffmpeg_demux.c:187
AV_PKT_DATA_CONTENT_LIGHT_LEVEL
@ AV_PKT_DATA_CONTENT_LIGHT_LEVEL
Content light level (based on CTA-861.3).
Definition: packet.h:232
guess_input_channel_layout
static int guess_input_channel_layout(InputStream *ist, AVCodecParameters *par, int guess_layout_max)
Definition: ffmpeg_demux.c:1189
DECODER_FLAG_FIX_SUB_DURATION
@ DECODER_FLAG_FIX_SUB_DURATION
Definition: ffmpeg.h:414
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
The number of audio samples per second.
Definition: codec_par.h:213
Demuxer::sch
Scheduler * sch
Definition: ffmpeg_demux.c:150
find_codec
int find_codec(void *logctx, const char *name, enum AVMediaType type, int encoder, const AVCodec **codec)
Definition: ffmpeg_opt.c:783
AVFormatContext::audio_codec
const struct AVCodec * audio_codec
Forced audio codec.
Definition: avformat.h:1849
InputStream::par
AVCodecParameters * par
Codec parameters - to be used by the decoding/streamcopy code.
Definition: ffmpeg.h:477
input_files
InputFile ** input_files
Definition: ffmpeg.c:108
error.h
Scheduler
Definition: ffmpeg_sched.c:278
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:570
avcodec_find_decoder
const AVCodec * avcodec_find_decoder(enum AVCodecID id)
Find a registered decoder with a matching codec ID.
Definition: allcodecs.c:988
recast_media
int recast_media
Definition: ffmpeg_opt.c:88
AVCodecParameters::extradata_size
int extradata_size
Size of the extradata content in bytes.
Definition: codec_par.h:75
AVFormatContext::nb_streams
unsigned int nb_streams
Number of elements in AVFormatContext.streams.
Definition: avformat.h:1370
istg_parse_tile_grid
static int istg_parse_tile_grid(const OptionsContext *o, Demuxer *d, InputStreamGroup *istg)
Definition: ffmpeg_demux.c:1779
AV_STREAM_GROUP_PARAMS_TILE_GRID
@ AV_STREAM_GROUP_PARAMS_TILE_GRID
Definition: avformat.h:1131
DemuxStream::dts
int64_t dts
dts of the last packet read for this stream (in AV_TIME_BASE units)
Definition: ffmpeg_demux.c:86
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:2607
av_opt_find
const AVOption * av_opt_find(void *obj, const char *name, const char *unit, int opt_flags, int search_flags)
Look for an option in an object.
Definition: opt.c:1984
add_content_light_to_stream
static int add_content_light_to_stream(const OptionsContext *o, AVFormatContext *ctx, InputStream *ist)
Definition: ffmpeg_demux.c:1325
OptionsContext::discard
SpecifierOptList discard
Definition: ffmpeg.h:230
IFILTER_FLAG_REINIT
@ IFILTER_FLAG_REINIT
Definition: ffmpeg.h:250
is_windows_reserved_device_name
static int is_windows_reserved_device_name(const char *f)
Definition: ffmpeg_demux.c:1888
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:200
AVMediaType
AVMediaType
Definition: avutil.h:198
AVPacket::size
int size
Definition: packet.h:604
InputStreamGroup::fg
FilterGraph * fg
Definition: ffmpeg.h:500
avformat_alloc_context
AVFormatContext * avformat_alloc_context(void)
Allocate an AVFormatContext.
Definition: options.c:164
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:67
av_bsf_send_packet
int av_bsf_send_packet(AVBSFContext *ctx, AVPacket *pkt)
Submit a packet for filtering.
Definition: bsf.c:202
i
#define i(width, name, range_min, range_max)
Definition: cbs_h264.c:63
DemuxStream::resume_pts
int64_t resume_pts
Definition: ffmpeg_demux.c:105
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:152
DemuxStream::decoding_needed
int decoding_needed
Definition: ffmpeg_demux.c:56
OptionsContext::apply_cropping
SpecifierOptList apply_cropping
Definition: ffmpeg.h:168
demux_thread_uninit
static void demux_thread_uninit(DemuxThreadContext *dt)
Definition: ffmpeg_demux.c:707
size
int size
Definition: twinvq_data.h:10344
copy_ts
int copy_ts
Definition: ffmpeg_opt.c:64
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:138
input_file_class
static const AVClass input_file_class
Definition: ffmpeg_demux.c:1988
DECODING_FOR_FILTER
#define DECODING_FOR_FILTER
Definition: ffmpeg_demux.c:58
ist_use
int ist_use(InputStream *ist, int decoding_needed, const ViewSpecifier *vs, SchedulerNode *src)
Definition: ffmpeg_demux.c:938
AVFrame::format
int format
format of the frame, -1 if unknown or unset Values correspond to enum AVPixelFormat for video frames,...
Definition: frame.h:553
AVMEDIA_TYPE_UNKNOWN
@ AVMEDIA_TYPE_UNKNOWN
Usually treated as AVMEDIA_TYPE_DATA.
Definition: avutil.h:199
DemuxStream::bsf
AVBSFContext * bsf
Definition: ffmpeg_demux.c:96
AVStream::sample_aspect_ratio
AVRational sample_aspect_ratio
sample aspect ratio (0 if unknown)
Definition: avformat.h:825
OptionsContext::readrate_initial_burst
double readrate_initial_burst
Definition: ffmpeg.h:156
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:602
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:160
OptionsContext::display_rotations
SpecifierOptList display_rotations
Definition: ffmpeg.h:205
DemuxStream::autorotate
int autorotate
Definition: ffmpeg_demux.c:69
DemuxStream::sch_idx_dec
int sch_idx_dec
Definition: ffmpeg_demux.c:51
AVStreamGroupTileGrid::nb_tiles
unsigned int nb_tiles
Amount of tiles in the grid.
Definition: avformat.h:962
SpecifierOptList::opt
SpecifierOpt * opt
Definition: cmdutils.h:184
av_packet_side_data_add
AVPacketSideData * av_packet_side_data_add(AVPacketSideData **psd, int *pnb_sd, enum AVPacketSideDataType type, void *data, size_t size, int flags)
Wrap existing data as packet side data.
Definition: packet.c:613
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:609
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
AVStreamGroup::params
union AVStreamGroup::@454 params
Group type-specific parameters.
OptionsContext::ts_scale
SpecifierOptList ts_scale
Definition: ffmpeg.h:162
AVCodecParameters::avcodec_parameters_alloc
AVCodecParameters * avcodec_parameters_alloc(void)
Allocate a new AVCodecParameters and set its fields to default values (unknown/invalid/0).
Definition: codec_par.c:57
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:538
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:84
AVCodec::id
enum AVCodecID id
Definition: codec.h:183
av_mastering_display_metadata_alloc_size
AVMasteringDisplayMetadata * av_mastering_display_metadata_alloc_size(size_t *size)
Allocate an AVMasteringDisplayMetadata structure and set its fields to default values.
Definition: mastering_display_metadata.c:44
CROP_CONTAINER
@ CROP_CONTAINER
Definition: ffmpeg.h:618
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:841
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:71
AVStreamGroupTileGrid::nb_coded_side_data
int nb_coded_side_data
Amount of entries in coded_side_data.
Definition: avformat.h:1062
DemuxStream
Definition: ffmpeg_demux.c:44
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:616
DemuxStream::dec_name
char dec_name[16]
Definition: ffmpeg_demux.c:92
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:313
DemuxStream::apply_cropping
int apply_cropping
Definition: ffmpeg_demux.c:70
AVStreamGroupTileGrid::width
int width
Width of the final image for presentation.
Definition: avformat.h:1039
AV_CODEC_ID_NONE
@ AV_CODEC_ID_NONE
Definition: codec_id.h:48
AVPacket::pts
int64_t pts
Presentation timestamp in AVStream->time_base units; the time at which the decompressed packet will b...
Definition: packet.h:596
OptionsContext::frame_rates
SpecifierOptList frame_rates
Definition: ffmpeg.h:145
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:141
packet.h
demux_bsf_flush
static int demux_bsf_flush(Demuxer *d, DemuxThreadContext *dt)
Definition: ffmpeg_demux.c:657
AVFormatContext::subtitle_codec
const struct AVCodec * subtitle_codec
Forced subtitle codec.
Definition: avformat.h:1857
AVCodecParameters::height
int height
The height of the video frame in pixels.
Definition: codec_par.h:150
OptionsContext::autorotate
SpecifierOptList autorotate
Definition: ffmpeg.h:167
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:440
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:137
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:68
Demuxer::have_audio_dec
int have_audio_dec
Definition: ffmpeg_demux.c:136
av_assert1
#define av_assert1(cond)
assert() equivalent, that does not lie in speed critical code.
Definition: avassert.h:58
DemuxStream::force_display_matrix
int force_display_matrix
Definition: ffmpeg_demux.c:71
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:103
InputFile::ctx
AVFormatContext * ctx
Definition: ffmpeg.h:509
FFMIN
#define FFMIN(a, b)
Definition: macros.h:49
OptionsContext::hwaccels
SpecifierOptList hwaccels
Definition: ffmpeg.h:164
AVProgram
New fields can be added to the end with minor version bumps.
Definition: avformat.h:1238
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:253
AVMasteringDisplayMetadata
Mastering display metadata capable of representing the color volume of the display used to master the...
Definition: mastering_display_metadata.h:38
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:312
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:83
DemuxStream::discard
int discard
Definition: ffmpeg_demux.c:61
OFILTER_FLAG_CROP
@ OFILTER_FLAG_CROP
Definition: ffmpeg.h:289
AVFMT_FLAG_NONBLOCK
#define AVFMT_FLAG_NONBLOCK
Do not block when reading packets from input.
Definition: avformat.h:1468
av_codec_iterate
const AVCodec * av_codec_iterate(void **opaque)
Iterate over all registered codecs.
Definition: allcodecs.c:941
sch_connect
int sch_connect(Scheduler *sch, SchedulerNode src, SchedulerNode dst)
Definition: ffmpeg_sched.c:973
AVStreamGroupTileGrid::horizontal
int horizontal
Offset in pixels from the left edge of the canvas where the tile should be placed.
Definition: avformat.h:998
ist_find_unused
InputStream * ist_find_unused(enum AVMediaType type)
Find an unused input stream of given type.
Definition: ffmpeg_demux.c:176
istg_add
static int istg_add(const OptionsContext *o, Demuxer *d, AVStreamGroup *stg)
Definition: ffmpeg_demux.c:1863
Timestamp::tb
AVRational tb
Definition: ffmpeg_utils.h:32
InputStream::decoder
Decoder * decoder
Definition: ffmpeg.h:478
AVCodecParameters::avcodec_parameters_copy
int avcodec_parameters_copy(AVCodecParameters *dst, const AVCodecParameters *src)
Copy the contents of src to dst.
Definition: codec_par.c:107
OFILTER_FLAG_AUTOROTATE
@ OFILTER_FLAG_AUTOROTATE
Definition: ffmpeg.h:288
AVStream::disposition
int disposition
Stream disposition - a combination of AV_DISPOSITION_* flags.
Definition: avformat.h:816
DemuxStream::codec_desc
const AVCodecDescriptor * codec_desc
Definition: ffmpeg_demux.c:88
ts_discontinuity_process
static void ts_discontinuity_process(Demuxer *d, InputStream *ist, AVPacket *pkt)
Definition: ffmpeg_demux.c:295
tag
uint32_t tag
Definition: movenc.c:2054
AVStream::id
int id
Format-specific stream ID.
Definition: avformat.h:759
AVFMT_FLAG_BITEXACT
#define AVFMT_FLAG_BITEXACT
When muxing, try to avoid writing any random/volatile data to the output.
Definition: avformat.h:1482
ret
ret
Definition: filter_design.txt:187
AVStream
Stream structure.
Definition: avformat.h:747
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:807
DemuxStream::wrap_correction_done
int wrap_correction_done
Definition: ffmpeg_demux.c:77
DemuxStream::force_content_light
int force_content_light
Definition: ffmpeg_demux.c:73
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:135
InputFile::streams
InputStream ** streams
Definition: ffmpeg.h:523
add_display_matrix_to_stream
static int add_display_matrix_to_stream(const OptionsContext *o, AVFormatContext *ctx, InputStream *ist)
Definition: ffmpeg_demux.c:1206
hwaccel
static const char * hwaccel
Definition: ffplay.c:356
Demuxer::accurate_seek
int accurate_seek
Definition: ffmpeg_demux.c:132
avformat.h
HWAccelID
HWAccelID
Definition: ffmpeg.h:69
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:620
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:1142
OptionsContext::drop_changed
SpecifierOptList drop_changed
Definition: ffmpeg.h:220
check_avoptions_used
int check_avoptions_used(const AVDictionary *opts, const AVDictionary *opts_used, void *logctx, int decode)
Definition: ffmpeg.c:501
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:902
av_get_pix_fmt
enum AVPixelFormat av_get_pix_fmt(const char *name)
Return the pixel format corresponding to name.
Definition: pixdesc.c:3388
AVCodecParameters::avcodec_parameters_free
void avcodec_parameters_free(AVCodecParameters **par)
Free an AVCodecParameters instance and everything associated with it and write NULL to the supplied p...
Definition: codec_par.c:67
AVStreamGroup
Definition: avformat.h:1140
AVFormatContext::data_codec_id
enum AVCodecID data_codec_id
Forced Data codec_id.
Definition: avformat.h:1536
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:538
AVStream::index
int index
stream index in AVFormatContext
Definition: avformat.h:753
IFILTER_FLAG_CROP
@ IFILTER_FLAG_CROP
Definition: ffmpeg.h:252
InputFile::class
const AVClass * class
Definition: ffmpeg.h:505
OptionsContext::audio_sample_rate
SpecifierOptList audio_sample_rate
Definition: ffmpeg.h:144
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:2208
ts_discontinuity_detect
static void ts_discontinuity_detect(Demuxer *d, InputStream *ist, AVPacket *pkt)
Definition: ffmpeg_demux.c:227
PKT_OPAQUE_SUB_HEARTBEAT
@ PKT_OPAQUE_SUB_HEARTBEAT
Definition: ffmpeg.h:82
AVInputFormat::flags
int flags
Can use flags: AVFMT_NOFILE, AVFMT_NEEDNUMBER, AVFMT_EXPERIMENTAL, AVFMT_SHOW_IDS,...
Definition: avformat.h:566
AVRational::den
int den
Denominator.
Definition: rational.h:60
InputStream::file
struct InputFile * file
Definition: ffmpeg.h:465
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:258
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:443
avformat_free_context
void avformat_free_context(AVFormatContext *s)
Free an AVFormatContext and all its streams.
Definition: avformat.c:148
IFILTER_FLAG_CFR
@ IFILTER_FLAG_CFR
Definition: ffmpeg.h:251
OptionsContext::frame_sizes
SpecifierOptList frame_sizes
Definition: ffmpeg.h:147
OptionsContext::video_disable
int video_disable
Definition: ffmpeg.h:187
ds_from_ist
static DemuxStream * ds_from_ist(InputStream *ist)
Definition: ffmpeg_demux.c:166
input_stream_group_class
static const AVClass input_stream_group_class
Definition: ffmpeg_demux.c:1752
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
AVMasteringDisplayMetadata::min_luminance
AVRational min_luminance
Min luminance of mastering display (cd/m^2).
Definition: mastering_display_metadata.h:52
demux_alloc
static Demuxer * demux_alloc(void)
Definition: ffmpeg_demux.c:1995
AVFormatContext::duration
int64_t duration
Duration of the stream, in AV_TIME_BASE fractional seconds.
Definition: avformat.h:1449
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:605
GROW_ARRAY
#define GROW_ARRAY(array, nb_elems)
Definition: cmdutils.h:536
HWACCEL_NONE
@ HWACCEL_NONE
Definition: ffmpeg.h:70
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:842
ist_dts_update
static int ist_dts_update(DemuxStream *ds, AVPacket *pkt, FrameData *fd)
Definition: ffmpeg_demux.c:315
data_codec_name
static const char * data_codec_name
Definition: ffprobe.c:136
InputFile::ts_offset
int64_t ts_offset
Definition: ffmpeg.h:516
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:450
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:198
DecoderOpts::flags
int flags
Definition: ffmpeg.h:426
AV_OPT_FLAG_DECODING_PARAM
#define AV_OPT_FLAG_DECODING_PARAM
A generic parameter which can be set by the user for demuxing or decoding.
Definition: opt.h:355
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:65
AVFMT_TS_DISCONT
#define AVFMT_TS_DISCONT
Format allows timestamp discontinuities.
Definition: avformat.h:481
mem.h
AVStreamGroup::type
enum AVStreamGroupParamsType type
Group type.
Definition: avformat.h:1167
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:497
av_strdup
#define av_strdup(s)
Definition: ops_asmgen.c:47
mastering_display_metadata.h
DECODER_FLAG_TS_UNRELIABLE
@ DECODER_FLAG_TS_UNRELIABLE
Definition: ffmpeg.h:416
AVCodecParameters::video_delay
int video_delay
Number of delayed frames.
Definition: codec_par.h:200
DemuxStream::log_name
char log_name[32]
Definition: ffmpeg_demux.c:48
DecoderOpts::codec
const AVCodec * codec
Definition: ffmpeg.h:431
InputStream::class
const AVClass * class
Definition: ffmpeg.h:462
InputStream::index
int index
Definition: ffmpeg.h:467
readrate_sleep
static void readrate_sleep(Demuxer *d)
Definition: ffmpeg_demux.c:510
AVFormatContext::nb_stream_groups
unsigned int nb_stream_groups
Number of elements in AVFormatContext.stream_groups.
Definition: avformat.h:1389
AVStreamGroupTileGrid::height
int height
Height of the final image for presentation.
Definition: avformat.h:1049
ffmpeg_sched.h
AVDictionaryEntry
Definition: dict.h:90
Demuxer::max_pts
Timestamp max_pts
Definition: ffmpeg_demux.c:141
DemuxStream::dec_opts
DecoderOpts dec_opts
Definition: ffmpeg_demux.c:91
stdin_interaction
int stdin_interaction
Definition: ffmpeg_opt.c:71
do_hex_dump
int do_hex_dump
Definition: ffmpeg_opt.c:62
AVCodecParameters::codec_id
enum AVCodecID codec_id
Specific type of the encoded data (the codec used).
Definition: codec_par.h:57
AVContentLightMetadata::MaxFALL
unsigned MaxFALL
Max average light level per frame (cd/m^2).
Definition: mastering_display_metadata.h:116
AVPacket
This structure stores compressed data.
Definition: packet.h:580
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:1044
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:623
AVFormatContext::name
char * name
Name of this format context, only used for logging purposes.
Definition: avformat.h:1944
packet_data
FrameData * packet_data(AVPacket *pkt)
Definition: ffmpeg.c:489
OptionsContext::data_disable
int data_disable
Definition: ffmpeg.h:190
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:878
DemuxStream::reinit_filters
int reinit_filters
Definition: ffmpeg_demux.c:68
timestamp.h
Demuxer::min_pts
Timestamp min_pts
Definition: ffmpeg_demux.c:140
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:375
avio_close
int avio_close(AVIOContext *s)
Close the resource accessed by the AVIOContext s and free it.
Definition: avio.c:622
av_strlcpy
size_t av_strlcpy(char *dst, const char *src, size_t size)
Copy the string src to dst, but no more than size - 1 bytes, and null-terminate dst.
Definition: avstring.c:85
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:1439
DecoderOpts::framerate
AVRational framerate
Definition: ffmpeg.h:444
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:308
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:3878
do_send
static int do_send(Demuxer *d, DemuxStream *ds, AVPacket *pkt, unsigned flags, const char *pkt_desc)
Definition: ffmpeg_demux.c:559
Demuxer::last_ts
int64_t last_ts
Definition: ffmpeg_demux.c:129
DemuxStream::decoded_params
AVFrame * decoded_params
Definition: ffmpeg_demux.c:94
AVDictionaryEntry::value
char * value
Definition: dict.h:92
pkt
static AVPacket * pkt
Definition: demux_decode.c:55
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:165
AVStreamGroupTileGrid::idx
unsigned int idx
Index of the stream in the group this tile references.
Definition: avformat.h:993
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:78
InputFile::nb_streams
int nb_streams
Definition: ffmpeg.h:524
OptionsContext::guess_layout_max
SpecifierOptList guess_layout_max
Definition: ffmpeg.h:228
AVStream::pts_wrap_bits
int pts_wrap_bits
Number of bits in timestamps.
Definition: avformat.h:890
dump_attachment
static int dump_attachment(InputStream *ist, const char *filename)
Definition: ffmpeg_demux.c:1938
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:298
InputStream::dec
const AVCodec * dec
Definition: ffmpeg.h:479
snprintf
#define snprintf
Definition: snprintf.h:34
DemuxStream::force_mastering_display
int force_mastering_display
Definition: ffmpeg_demux.c:72
DecoderOpts::hwaccel_device_type
enum AVHWDeviceType hwaccel_device_type
Definition: ffmpeg.h:436
FilterGraph::is_internal
int is_internal
Definition: ffmpeg.h:407
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:197
input_thread
static int input_thread(void *arg)
Definition: ffmpeg_demux.c:730
src
#define src
Definition: vp8dsp.c:248
duration
static int64_t duration
Definition: ffplay.c:329
AVInputFormat::priv_class
const AVClass * priv_class
AVClass for the private context.
Definition: avformat.h:577
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:1013
AVPacket::time_base
AVRational time_base
Time base of the packet's timestamps.
Definition: packet.h:647
OptionsContext::content_lights
SpecifierOptList content_lights
Definition: ffmpeg.h:209
OptionsContext::loop
int loop
Definition: ffmpeg.h:152
thread_set_name
static void thread_set_name(InputFile *f)
Definition: ffmpeg_demux.c:700
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:1530
DecoderOpts::name
char * name
Definition: ffmpeg.h:428