FFmpeg
All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Modules Pages
ffmpeg_demux.c
Go to the documentation of this file.
1 /*
2  * This file is part of FFmpeg.
3  *
4  * FFmpeg is free software; you can redistribute it and/or
5  * modify it under the terms of the GNU Lesser General Public
6  * License as published by the Free Software Foundation; either
7  * version 2.1 of the License, or (at your option) any later version.
8  *
9  * FFmpeg is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12  * Lesser General Public License for more details.
13  *
14  * You should have received a copy of the GNU Lesser General Public
15  * License along with FFmpeg; if not, write to the Free Software
16  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
17  */
18 
19 #include <float.h>
20 #include <stdint.h>
21 
22 #include "ffmpeg.h"
23 #include "ffmpeg_sched.h"
24 #include "ffmpeg_utils.h"
25 
26 #include "libavutil/avassert.h"
27 #include "libavutil/avstring.h"
28 #include "libavutil/display.h"
29 #include "libavutil/error.h"
30 #include "libavutil/intreadwrite.h"
31 #include "libavutil/mem.h"
32 #include "libavutil/opt.h"
33 #include "libavutil/parseutils.h"
34 #include "libavutil/pixdesc.h"
35 #include "libavutil/time.h"
36 #include "libavutil/timestamp.h"
37 
38 #include "libavcodec/bsf.h"
39 #include "libavcodec/packet.h"
40 
41 #include "libavformat/avformat.h"
42 
43 typedef struct DemuxStream {
45 
46  // name used for logging
47  char log_name[32];
48 
51 
52  double ts_scale;
53 
54  /* non zero if the packets must be decoded in 'raw_fifo', see DECODING_FOR_* */
56 #define DECODING_FOR_OST 1
57 #define DECODING_FOR_FILTER 2
58 
59  /* true if stream data should be discarded */
60  int discard;
61 
62  // scheduler returned EOF for this stream
63  int finished;
64 
71 
72 
75  /// dts of the first packet read for this stream (in AV_TIME_BASE units)
77 
78  /* predicted dts of the next packet read for this stream or (when there are
79  * several frames in a packet) of the next frame in current packet (in AV_TIME_BASE units) */
81  /// dts of the last packet read for this stream (in AV_TIME_BASE units)
83 
85 
88  char dec_name[16];
89  // decoded media properties, as estimated by opening the decoder
91 
93 
94  /* number of packets successfully read for this stream */
95  uint64_t nb_packets;
96  // combined size of all the packets read
97  uint64_t data_size;
98  // latest wallclock time at which packet reading resumed after a stall - used for readrate
100  // timestamp of first packet sent after the latest stall - used for readrate
102  // measure of how far behind packet reading is against spceified readrate
104 } DemuxStream;
105 
106 typedef struct Demuxer {
108 
109  // name used for logging
110  char log_name[32];
111 
113 
114  /**
115  * Extra timestamp offset added by discontinuity handling.
116  */
119 
122 
123  /* number of times input stream should be looped */
124  int loop;
126  /* duration of the looped segment of the input file */
128  /* pts with the smallest/largest values ever seen */
131 
132  /* number of streams that the user was warned of */
134 
135  float readrate;
138 
140 
142 
146 } Demuxer;
147 
148 typedef struct DemuxThreadContext {
149  // packet used for reading from the demuxer
151  // packet for reading from BSFs
154 
156 {
157  return (DemuxStream*)ist;
158 }
159 
161 {
162  return (Demuxer*)f;
163 }
164 
166 {
167  for (InputStream *ist = ist_iter(NULL); ist; ist = ist_iter(ist)) {
168  DemuxStream *ds = ds_from_ist(ist);
169  if (ist->par->codec_type == type && ds->discard &&
170  ist->user_set_discard != AVDISCARD_ALL)
171  return ist;
172  }
173  return NULL;
174 }
175 
176 static void report_new_stream(Demuxer *d, const AVPacket *pkt)
177 {
178  const AVStream *st = d->f.ctx->streams[pkt->stream_index];
179 
180  if (pkt->stream_index < d->nb_streams_warn)
181  return;
183  "New %s stream with index %d at pos:%"PRId64" and DTS:%ss\n",
186  d->nb_streams_warn = pkt->stream_index + 1;
187 }
188 
189 static int seek_to_start(Demuxer *d, Timestamp end_pts)
190 {
191  InputFile *ifile = &d->f;
192  AVFormatContext *is = ifile->ctx;
193  int ret;
194 
195  ret = avformat_seek_file(is, -1, INT64_MIN, is->start_time, is->start_time, 0);
196  if (ret < 0)
197  return ret;
198 
199  if (end_pts.ts != AV_NOPTS_VALUE &&
200  (d->max_pts.ts == AV_NOPTS_VALUE ||
201  av_compare_ts(d->max_pts.ts, d->max_pts.tb, end_pts.ts, end_pts.tb) < 0))
202  d->max_pts = end_pts;
203 
204  if (d->max_pts.ts != AV_NOPTS_VALUE) {
205  int64_t min_pts = d->min_pts.ts == AV_NOPTS_VALUE ? 0 : d->min_pts.ts;
206  d->duration.ts = d->max_pts.ts - av_rescale_q(min_pts, d->min_pts.tb, d->max_pts.tb);
207  }
208  d->duration.tb = d->max_pts.tb;
209 
210  if (d->loop > 0)
211  d->loop--;
212 
213  return ret;
214 }
215 
217  AVPacket *pkt)
218 {
219  InputFile *ifile = &d->f;
220  DemuxStream *ds = ds_from_ist(ist);
221  const int fmt_is_discont = ifile->ctx->iformat->flags & AVFMT_TS_DISCONT;
222  int disable_discontinuity_correction = copy_ts;
225 
226  if (copy_ts && ds->next_dts != AV_NOPTS_VALUE &&
227  fmt_is_discont && ist->st->pts_wrap_bits < 60) {
228  int64_t wrap_dts = av_rescale_q_rnd(pkt->dts + (1LL<<ist->st->pts_wrap_bits),
231  if (FFABS(wrap_dts - ds->next_dts) < FFABS(pkt_dts - ds->next_dts)/10)
232  disable_discontinuity_correction = 0;
233  }
234 
235  if (ds->next_dts != AV_NOPTS_VALUE && !disable_discontinuity_correction) {
236  int64_t delta = pkt_dts - ds->next_dts;
237  if (fmt_is_discont) {
238  if (FFABS(delta) > 1LL * dts_delta_threshold * AV_TIME_BASE ||
239  pkt_dts + AV_TIME_BASE/10 < ds->dts) {
240  d->ts_offset_discont -= delta;
241  av_log(ist, AV_LOG_WARNING,
242  "timestamp discontinuity "
243  "(stream id=%d): %"PRId64", new offset= %"PRId64"\n",
244  ist->st->id, delta, d->ts_offset_discont);
246  if (pkt->pts != AV_NOPTS_VALUE)
248  }
249  } else {
250  if (FFABS(delta) > 1LL * dts_error_threshold * AV_TIME_BASE) {
251  av_log(ist, AV_LOG_WARNING,
252  "DTS %"PRId64", next:%"PRId64" st:%d invalid dropping\n",
253  pkt->dts, ds->next_dts, pkt->stream_index);
255  }
256  if (pkt->pts != AV_NOPTS_VALUE){
258  delta = pkt_pts - ds->next_dts;
259  if (FFABS(delta) > 1LL * dts_error_threshold * AV_TIME_BASE) {
260  av_log(ist, AV_LOG_WARNING,
261  "PTS %"PRId64", next:%"PRId64" invalid dropping st:%d\n",
262  pkt->pts, ds->next_dts, pkt->stream_index);
264  }
265  }
266  }
267  } else if (ds->next_dts == AV_NOPTS_VALUE && !copy_ts &&
268  fmt_is_discont && d->last_ts != AV_NOPTS_VALUE) {
269  int64_t delta = pkt_dts - d->last_ts;
270  if (FFABS(delta) > 1LL * dts_delta_threshold * AV_TIME_BASE) {
271  d->ts_offset_discont -= delta;
272  av_log(ist, AV_LOG_DEBUG,
273  "Inter stream timestamp discontinuity %"PRId64", new offset= %"PRId64"\n",
276  if (pkt->pts != AV_NOPTS_VALUE)
278  }
279  }
280 
282 }
283 
285  AVPacket *pkt)
286 {
288  pkt->time_base);
289 
290  // apply previously-detected timestamp-discontinuity offset
291  // (to all streams, not just audio/video)
292  if (pkt->dts != AV_NOPTS_VALUE)
293  pkt->dts += offset;
294  if (pkt->pts != AV_NOPTS_VALUE)
295  pkt->pts += offset;
296 
297  // detect timestamp discontinuities for audio/video
298  if ((ist->par->codec_type == AVMEDIA_TYPE_VIDEO ||
299  ist->par->codec_type == AVMEDIA_TYPE_AUDIO) &&
300  pkt->dts != AV_NOPTS_VALUE)
301  ts_discontinuity_detect(d, ist, pkt);
302 }
303 
305 {
306  InputStream *ist = &ds->ist;
307  const AVCodecParameters *par = ist->par;
308 
309  if (!ds->saw_first_ts) {
310  ds->first_dts =
311  ds->dts = ist->st->avg_frame_rate.num ? - ist->par->video_delay * AV_TIME_BASE / av_q2d(ist->st->avg_frame_rate) : 0;
312  if (pkt->pts != AV_NOPTS_VALUE) {
313  ds->first_dts =
315  }
316  ds->saw_first_ts = 1;
317  }
318 
319  if (ds->next_dts == AV_NOPTS_VALUE)
320  ds->next_dts = ds->dts;
321 
322  if (pkt->dts != AV_NOPTS_VALUE)
324 
325  ds->dts = ds->next_dts;
326  switch (par->codec_type) {
327  case AVMEDIA_TYPE_AUDIO:
328  av_assert1(pkt->duration >= 0);
329  if (par->sample_rate) {
330  ds->next_dts += ((int64_t)AV_TIME_BASE * par->frame_size) /
331  par->sample_rate;
332  } else {
334  }
335  break;
336  case AVMEDIA_TYPE_VIDEO:
337  if (ist->framerate.num) {
338  // TODO: Remove work-around for c99-to-c89 issue 7
339  AVRational time_base_q = AV_TIME_BASE_Q;
340  int64_t next_dts = av_rescale_q(ds->next_dts, time_base_q, av_inv_q(ist->framerate));
341  ds->next_dts = av_rescale_q(next_dts + 1, av_inv_q(ist->framerate), time_base_q);
342  } else if (pkt->duration) {
344  } else if (ist->par->framerate.num != 0) {
345  AVRational field_rate = av_mul_q(ist->par->framerate,
346  (AVRational){ 2, 1 });
347  int fields = 2;
348 
349  if (ds->codec_desc &&
351  av_stream_get_parser(ist->st))
353 
354  ds->next_dts += av_rescale_q(fields, av_inv_q(field_rate), AV_TIME_BASE_Q);
355  }
356  break;
357  }
358 
359  fd->dts_est = ds->dts;
360 
361  return 0;
362 }
363 
364 static int ts_fixup(Demuxer *d, AVPacket *pkt, FrameData *fd)
365 {
366  InputFile *ifile = &d->f;
367  InputStream *ist = ifile->streams[pkt->stream_index];
368  DemuxStream *ds = ds_from_ist(ist);
369  const int64_t start_time = ifile->start_time_effective;
371  int ret;
372 
373  pkt->time_base = ist->st->time_base;
374 
375 #define SHOW_TS_DEBUG(tag_) \
376  if (debug_ts) { \
377  av_log(ist, AV_LOG_INFO, "%s -> ist_index:%d:%d type:%s " \
378  "pkt_pts:%s pkt_pts_time:%s pkt_dts:%s pkt_dts_time:%s duration:%s duration_time:%s\n", \
379  tag_, ifile->index, pkt->stream_index, \
380  av_get_media_type_string(ist->st->codecpar->codec_type), \
381  av_ts2str(pkt->pts), av_ts2timestr(pkt->pts, &pkt->time_base), \
382  av_ts2str(pkt->dts), av_ts2timestr(pkt->dts, &pkt->time_base), \
383  av_ts2str(pkt->duration), av_ts2timestr(pkt->duration, &pkt->time_base)); \
384  }
385 
386  SHOW_TS_DEBUG("demuxer");
387 
389  ist->st->pts_wrap_bits < 64) {
390  int64_t stime, stime2;
391 
393  stime2= stime + (1ULL<<ist->st->pts_wrap_bits);
394  ds->wrap_correction_done = 1;
395 
396  if(stime2 > stime && pkt->dts != AV_NOPTS_VALUE && pkt->dts > stime + (1LL<<(ist->st->pts_wrap_bits-1))) {
397  pkt->dts -= 1ULL<<ist->st->pts_wrap_bits;
398  ds->wrap_correction_done = 0;
399  }
400  if(stime2 > stime && pkt->pts != AV_NOPTS_VALUE && pkt->pts > stime + (1LL<<(ist->st->pts_wrap_bits-1))) {
401  pkt->pts -= 1ULL<<ist->st->pts_wrap_bits;
402  ds->wrap_correction_done = 0;
403  }
404  }
405 
406  if (pkt->dts != AV_NOPTS_VALUE)
408  if (pkt->pts != AV_NOPTS_VALUE)
410 
411  if (pkt->pts != AV_NOPTS_VALUE)
412  pkt->pts *= ds->ts_scale;
413  if (pkt->dts != AV_NOPTS_VALUE)
414  pkt->dts *= ds->ts_scale;
415 
417  if (pkt->pts != AV_NOPTS_VALUE) {
418  // audio decoders take precedence for estimating total file duration
419  int64_t pkt_duration = d->have_audio_dec ? 0 : pkt->duration;
420 
421  pkt->pts += duration;
422 
423  // update max/min pts that will be used to compute total file duration
424  // when using -stream_loop
425  if (d->max_pts.ts == AV_NOPTS_VALUE ||
427  pkt->pts + pkt_duration, pkt->time_base) < 0) {
428  d->max_pts = (Timestamp){ .ts = pkt->pts + pkt_duration,
429  .tb = pkt->time_base };
430  }
431  if (d->min_pts.ts == AV_NOPTS_VALUE ||
433  pkt->pts, pkt->time_base) > 0) {
434  d->min_pts = (Timestamp){ .ts = pkt->pts,
435  .tb = pkt->time_base };
436  }
437  }
438 
439  if (pkt->dts != AV_NOPTS_VALUE)
440  pkt->dts += duration;
441 
442  SHOW_TS_DEBUG("demuxer+tsfixup");
443 
444  // detect and try to correct for timestamp discontinuities
445  ts_discontinuity_process(d, ist, pkt);
446 
447  // update estimated/predicted dts
448  ret = ist_dts_update(ds, pkt, fd);
449  if (ret < 0)
450  return ret;
451 
452  return 0;
453 }
454 
455 static int input_packet_process(Demuxer *d, AVPacket *pkt, unsigned *send_flags)
456 {
457  InputFile *f = &d->f;
458  InputStream *ist = f->streams[pkt->stream_index];
459  DemuxStream *ds = ds_from_ist(ist);
460  FrameData *fd;
461  int ret = 0;
462 
463  fd = packet_data(pkt);
464  if (!fd)
465  return AVERROR(ENOMEM);
466 
467  ret = ts_fixup(d, pkt, fd);
468  if (ret < 0)
469  return ret;
470 
471  if (d->recording_time != INT64_MAX) {
472  int64_t start_time = 0;
473  if (copy_ts) {
474  start_time += f->start_time != AV_NOPTS_VALUE ? f->start_time : 0;
475  start_time += start_at_zero ? 0 : f->start_time_effective;
476  }
477  if (ds->dts >= d->recording_time + start_time)
478  *send_flags |= DEMUX_SEND_STREAMCOPY_EOF;
479  }
480 
481  ds->data_size += pkt->size;
482  ds->nb_packets++;
483 
485 
486  if (debug_ts) {
487  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",
488  f->index, pkt->stream_index,
493  av_ts2str(f->ts_offset), av_ts2timestr(f->ts_offset, &AV_TIME_BASE_Q));
494  }
495 
496  return 0;
497 }
498 
499 static void readrate_sleep(Demuxer *d)
500 {
501  InputFile *f = &d->f;
502  int64_t file_start = copy_ts * (
503  (f->start_time_effective != AV_NOPTS_VALUE ? f->start_time_effective * !start_at_zero : 0) +
504  (f->start_time != AV_NOPTS_VALUE ? f->start_time : 0)
505  );
506  int64_t initial_burst = AV_TIME_BASE * d->readrate_initial_burst;
507  int resume_warn;
508 
509  for (int i = 0; i < f->nb_streams; i++) {
510  InputStream *ist = f->streams[i];
511  DemuxStream *ds = ds_from_ist(ist);
512  int64_t stream_ts_offset, pts, now, wc_elapsed, elapsed, lag, max_pts, limit_pts;
513 
514  if (ds->discard) continue;
515 
516  stream_ts_offset = FFMAX(ds->first_dts != AV_NOPTS_VALUE ? ds->first_dts : 0, file_start);
517  pts = av_rescale(ds->dts, 1000000, AV_TIME_BASE);
518  now = av_gettime_relative();
519  wc_elapsed = now - d->wallclock_start;
520  max_pts = stream_ts_offset + initial_burst + wc_elapsed * d->readrate;
521  lag = FFMAX(max_pts - pts, 0);
522  if ( (!ds->lag && lag > 0.3 * AV_TIME_BASE) || ( lag > ds->lag + 0.3 * AV_TIME_BASE) ) {
523  ds->lag = lag;
524  ds->resume_wc = now;
525  ds->resume_pts = pts;
526  av_log_once(ds, AV_LOG_WARNING, AV_LOG_DEBUG, &resume_warn,
527  "Resumed reading at pts %0.3f with rate %0.3f after a lag of %0.3fs\n",
528  (float)pts/AV_TIME_BASE, d->readrate_catchup, (float)lag/AV_TIME_BASE);
529  }
530  if (ds->lag && !lag)
531  ds->lag = ds->resume_wc = ds->resume_pts = 0;
532  if (ds->resume_wc) {
533  elapsed = now - ds->resume_wc;
534  limit_pts = ds->resume_pts + elapsed * d->readrate_catchup;
535  } else {
536  elapsed = wc_elapsed;
537  limit_pts = max_pts;
538  }
539 
540  if (pts > limit_pts)
541  av_usleep(pts - limit_pts);
542  }
543 }
544 
545 static int do_send(Demuxer *d, DemuxStream *ds, AVPacket *pkt, unsigned flags,
546  const char *pkt_desc)
547 {
548  int ret;
549 
551 
552  ret = sch_demux_send(d->sch, d->f.index, pkt, flags);
553  if (ret == AVERROR_EOF) {
555 
556  av_log(ds, AV_LOG_VERBOSE, "All consumers of this stream are done\n");
557  ds->finished = 1;
558 
559  if (++d->nb_streams_finished == d->nb_streams_used) {
560  av_log(d, AV_LOG_VERBOSE, "All consumers are done\n");
561  return AVERROR_EOF;
562  }
563  } else if (ret < 0) {
564  if (ret != AVERROR_EXIT)
565  av_log(d, AV_LOG_ERROR,
566  "Unable to send %s packet to consumers: %s\n",
567  pkt_desc, av_err2str(ret));
568  return ret;
569  }
570 
571  return 0;
572 }
573 
575  AVPacket *pkt, unsigned flags)
576 {
577  InputFile *f = &d->f;
578  int ret;
579 
580  // pkt can be NULL only when flushing BSFs
581  av_assert0(ds->bsf || pkt);
582 
583  // send heartbeat for sub2video streams
584  if (d->pkt_heartbeat && pkt && pkt->pts != AV_NOPTS_VALUE) {
585  for (int i = 0; i < f->nb_streams; i++) {
586  DemuxStream *ds1 = ds_from_ist(f->streams[i]);
587 
588  if (ds1->finished || !ds1->have_sub2video)
589  continue;
590 
591  d->pkt_heartbeat->pts = pkt->pts;
593  d->pkt_heartbeat->opaque = (void*)(intptr_t)PKT_OPAQUE_SUB_HEARTBEAT;
594 
595  ret = do_send(d, ds1, d->pkt_heartbeat, 0, "heartbeat");
596  if (ret < 0)
597  return ret;
598  }
599  }
600 
601  if (ds->bsf) {
602  if (pkt)
604 
605  ret = av_bsf_send_packet(ds->bsf, pkt);
606  if (ret < 0) {
607  if (pkt)
609  av_log(ds, AV_LOG_ERROR, "Error submitting a packet for filtering: %s\n",
610  av_err2str(ret));
611  return ret;
612  }
613 
614  while (1) {
615  ret = av_bsf_receive_packet(ds->bsf, dt->pkt_bsf);
616  if (ret == AVERROR(EAGAIN))
617  return 0;
618  else if (ret < 0) {
619  if (ret != AVERROR_EOF)
620  av_log(ds, AV_LOG_ERROR,
621  "Error applying bitstream filters to a packet: %s\n",
622  av_err2str(ret));
623  return ret;
624  }
625 
626  dt->pkt_bsf->time_base = ds->bsf->time_base_out;
627 
628  ret = do_send(d, ds, dt->pkt_bsf, 0, "filtered");
629  if (ret < 0) {
631  return ret;
632  }
633  }
634  } else {
635  ret = do_send(d, ds, pkt, flags, "demuxed");
636  if (ret < 0)
637  return ret;
638  }
639 
640  return 0;
641 }
642 
644 {
645  InputFile *f = &d->f;
646  int ret;
647 
648  for (unsigned i = 0; i < f->nb_streams; i++) {
649  DemuxStream *ds = ds_from_ist(f->streams[i]);
650 
651  if (!ds->bsf)
652  continue;
653 
654  ret = demux_send(d, dt, ds, NULL, 0);
655  ret = (ret == AVERROR_EOF) ? 0 : (ret < 0) ? ret : AVERROR_BUG;
656  if (ret < 0) {
657  av_log(ds, AV_LOG_ERROR, "Error flushing BSFs: %s\n",
658  av_err2str(ret));
659  return ret;
660  }
661 
662  av_bsf_flush(ds->bsf);
663  }
664 
665  return 0;
666 }
667 
669 {
670  for (int j = 0; j < ifile->ctx->nb_programs; j++) {
671  AVProgram *p = ifile->ctx->programs[j];
672  int discard = AVDISCARD_ALL;
673 
674  for (int k = 0; k < p->nb_stream_indexes; k++) {
675  DemuxStream *ds = ds_from_ist(ifile->streams[p->stream_index[k]]);
676 
677  if (!ds->discard) {
678  discard = AVDISCARD_DEFAULT;
679  break;
680  }
681  }
682  p->discard = discard;
683  }
684 }
685 
687 {
688  char name[16];
689  snprintf(name, sizeof(name), "dmx%d:%s", f->index, f->ctx->iformat->name);
691 }
692 
694 {
696  av_packet_free(&dt->pkt_bsf);
697 
698  memset(dt, 0, sizeof(*dt));
699 }
700 
702 {
703  memset(dt, 0, sizeof(*dt));
704 
705  dt->pkt_demux = av_packet_alloc();
706  if (!dt->pkt_demux)
707  return AVERROR(ENOMEM);
708 
709  dt->pkt_bsf = av_packet_alloc();
710  if (!dt->pkt_bsf)
711  return AVERROR(ENOMEM);
712 
713  return 0;
714 }
715 
716 static int input_thread(void *arg)
717 {
718  Demuxer *d = arg;
719  InputFile *f = &d->f;
720 
722 
723  int ret = 0;
724 
725  ret = demux_thread_init(&dt);
726  if (ret < 0)
727  goto finish;
728 
730 
732 
733  d->read_started = 1;
735 
736  while (1) {
737  DemuxStream *ds;
738  unsigned send_flags = 0;
739 
740  ret = av_read_frame(f->ctx, dt.pkt_demux);
741 
742  if (ret == AVERROR(EAGAIN)) {
743  av_usleep(10000);
744  continue;
745  }
746  if (ret < 0) {
747  int ret_bsf;
748 
749  if (ret == AVERROR_EOF)
750  av_log(d, AV_LOG_VERBOSE, "EOF while reading input\n");
751  else {
752  av_log(d, AV_LOG_ERROR, "Error during demuxing: %s\n",
753  av_err2str(ret));
754  ret = exit_on_error ? ret : 0;
755  }
756 
757  ret_bsf = demux_bsf_flush(d, &dt);
758  ret = err_merge(ret == AVERROR_EOF ? 0 : ret, ret_bsf);
759 
760  if (d->loop) {
761  /* signal looping to our consumers */
762  dt.pkt_demux->stream_index = -1;
763  ret = sch_demux_send(d->sch, f->index, dt.pkt_demux, 0);
764  if (ret >= 0)
765  ret = seek_to_start(d, (Timestamp){ .ts = dt.pkt_demux->pts,
766  .tb = dt.pkt_demux->time_base });
767  if (ret >= 0)
768  continue;
769 
770  /* fallthrough to the error path */
771  }
772 
773  break;
774  }
775 
776  if (do_pkt_dump) {
778  f->ctx->streams[dt.pkt_demux->stream_index]);
779  }
780 
781  /* the following test is needed in case new streams appear
782  dynamically in stream : we ignore them */
783  ds = dt.pkt_demux->stream_index < f->nb_streams ?
784  ds_from_ist(f->streams[dt.pkt_demux->stream_index]) : NULL;
785  if (!ds || ds->discard || ds->finished) {
788  continue;
789  }
790 
791  if (dt.pkt_demux->flags & AV_PKT_FLAG_CORRUPT) {
793  "corrupt input packet in stream %d\n",
794  dt.pkt_demux->stream_index);
795  if (exit_on_error) {
798  break;
799  }
800  }
801 
802  ret = input_packet_process(d, dt.pkt_demux, &send_flags);
803  if (ret < 0)
804  break;
805 
806  if (d->readrate)
807  readrate_sleep(d);
808 
809  ret = demux_send(d, &dt, ds, dt.pkt_demux, send_flags);
810  if (ret < 0)
811  break;
812  }
813 
814  // EOF/EXIT is normal termination
815  if (ret == AVERROR_EOF || ret == AVERROR_EXIT)
816  ret = 0;
817 
818 finish:
819  demux_thread_uninit(&dt);
820 
821  return ret;
822 }
823 
824 static void demux_final_stats(Demuxer *d)
825 {
826  InputFile *f = &d->f;
827  uint64_t total_packets = 0, total_size = 0;
828 
829  av_log(f, AV_LOG_VERBOSE, "Input file #%d (%s):\n",
830  f->index, f->ctx->url);
831 
832  for (int j = 0; j < f->nb_streams; j++) {
833  InputStream *ist = f->streams[j];
834  DemuxStream *ds = ds_from_ist(ist);
835  enum AVMediaType type = ist->par->codec_type;
836 
837  if (ds->discard || type == AVMEDIA_TYPE_ATTACHMENT)
838  continue;
839 
840  total_size += ds->data_size;
841  total_packets += ds->nb_packets;
842 
843  av_log(f, AV_LOG_VERBOSE, " Input stream #%d:%d (%s): ",
844  f->index, j, av_get_media_type_string(type));
845  av_log(f, AV_LOG_VERBOSE, "%"PRIu64" packets read (%"PRIu64" bytes); ",
846  ds->nb_packets, ds->data_size);
847 
848  if (ds->decoding_needed) {
850  "%"PRIu64" frames decoded; %"PRIu64" decode errors",
852  if (type == AVMEDIA_TYPE_AUDIO)
853  av_log(f, AV_LOG_VERBOSE, " (%"PRIu64" samples)", ist->decoder->samples_decoded);
854  av_log(f, AV_LOG_VERBOSE, "; ");
855  }
856 
857  av_log(f, AV_LOG_VERBOSE, "\n");
858  }
859 
860  av_log(f, AV_LOG_VERBOSE, " Total: %"PRIu64" packets (%"PRIu64" bytes) demuxed\n",
861  total_packets, total_size);
862 }
863 
864 static void ist_free(InputStream **pist)
865 {
866  InputStream *ist = *pist;
867  DemuxStream *ds;
868 
869  if (!ist)
870  return;
871  ds = ds_from_ist(ist);
872 
873  dec_free(&ist->decoder);
874 
876  av_freep(&ist->filters);
878 
880 
882 
883  av_bsf_free(&ds->bsf);
884 
885  av_freep(pist);
886 }
887 
889 {
890  InputFile *f = *pf;
892 
893  if (!f)
894  return;
895 
896  if (d->read_started)
898 
899  for (int i = 0; i < f->nb_streams; i++)
900  ist_free(&f->streams[i]);
901  av_freep(&f->streams);
902 
903  avformat_close_input(&f->ctx);
904 
906 
907  av_freep(pf);
908 }
909 
910 int ist_use(InputStream *ist, int decoding_needed,
911  const ViewSpecifier *vs, SchedulerNode *src)
912 {
913  Demuxer *d = demuxer_from_ifile(ist->file);
914  DemuxStream *ds = ds_from_ist(ist);
915  int ret;
916 
917  if (ist->user_set_discard == AVDISCARD_ALL) {
918  av_log(ist, AV_LOG_ERROR, "Cannot %s a disabled input stream\n",
919  decoding_needed ? "decode" : "streamcopy");
920  return AVERROR(EINVAL);
921  }
922 
923  if (decoding_needed && !ist->dec) {
924  av_log(ist, AV_LOG_ERROR,
925  "Decoding requested, but no decoder found for: %s\n",
926  avcodec_get_name(ist->par->codec_id));
927  return AVERROR(EINVAL);
928  }
929 
930  if (ds->sch_idx_stream < 0) {
931  ret = sch_add_demux_stream(d->sch, d->f.index);
932  if (ret < 0)
933  return ret;
934  ds->sch_idx_stream = ret;
935  }
936 
937  if (ds->discard) {
938  ds->discard = 0;
939  d->nb_streams_used++;
940  }
941 
942  ist->st->discard = ist->user_set_discard;
943  ds->decoding_needed |= decoding_needed;
944  ds->streamcopy_needed |= !decoding_needed;
945 
946  if (decoding_needed && ds->sch_idx_dec < 0) {
947  int is_audio = ist->st->codecpar->codec_type == AVMEDIA_TYPE_AUDIO;
948 
951  (!!(d->loop && is_audio) * DECODER_FLAG_SEND_END_TS)
952 #if FFMPEG_OPT_TOP
954 #endif
955  ;
956 
957  if (ist->framerate.num) {
959  ds->dec_opts.framerate = ist->framerate;
960  } else
961  ds->dec_opts.framerate = ist->st->avg_frame_rate;
962 
963  if (ist->dec->id == AV_CODEC_ID_DVB_SUBTITLE &&
965  av_dict_set(&ds->decoder_opts, "compute_edt", "1", AV_DICT_DONT_OVERWRITE);
967  av_log(ist, AV_LOG_WARNING,
968  "Warning using DVB subtitles for filtering and output at the "
969  "same time is not fully supported, also see -compute_edt [0|1]\n");
970  }
971 
972  snprintf(ds->dec_name, sizeof(ds->dec_name), "%d:%d", ist->file->index, ist->index);
973  ds->dec_opts.name = ds->dec_name;
974 
975  ds->dec_opts.codec = ist->dec;
976  ds->dec_opts.par = ist->par;
977 
978  ds->dec_opts.log_parent = ist;
979 
981  if (!ds->decoded_params)
982  return AVERROR(ENOMEM);
983 
984  ret = dec_init(&ist->decoder, d->sch,
985  &ds->decoder_opts, &ds->dec_opts, ds->decoded_params);
986  if (ret < 0)
987  return ret;
988  ds->sch_idx_dec = ret;
989 
991  SCH_DEC_IN(ds->sch_idx_dec));
992  if (ret < 0)
993  return ret;
994 
995  d->have_audio_dec |= is_audio;
996  }
997 
998  if (decoding_needed && ist->par->codec_type == AVMEDIA_TYPE_VIDEO) {
999  ret = dec_request_view(ist->decoder, vs, src);
1000  if (ret < 0)
1001  return ret;
1002  } else {
1003  *src = decoding_needed ?
1004  SCH_DEC_OUT(ds->sch_idx_dec, 0) :
1005  SCH_DSTREAM(d->f.index, ds->sch_idx_stream);
1006  }
1007 
1008  return 0;
1009 }
1010 
1011 int ist_filter_add(InputStream *ist, InputFilter *ifilter, int is_simple,
1013  SchedulerNode *src)
1014 {
1015  Demuxer *d = demuxer_from_ifile(ist->file);
1016  DemuxStream *ds = ds_from_ist(ist);
1017  int64_t tsoffset = 0;
1018  int ret;
1019 
1020  ret = ist_use(ist, is_simple ? DECODING_FOR_OST : DECODING_FOR_FILTER,
1021  vs, src);
1022  if (ret < 0)
1023  return ret;
1024 
1025  ret = GROW_ARRAY(ist->filters, ist->nb_filters);
1026  if (ret < 0)
1027  return ret;
1028 
1029  ist->filters[ist->nb_filters - 1] = ifilter;
1030 
1031  if (ist->par->codec_type == AVMEDIA_TYPE_VIDEO) {
1033  ist->par->nb_coded_side_data,
1035  if (ist->framerate.num > 0 && ist->framerate.den > 0) {
1036  opts->framerate = ist->framerate;
1037  opts->flags |= IFILTER_FLAG_CFR;
1038  } else
1039  opts->framerate = av_guess_frame_rate(d->f.ctx, ist->st, NULL);
1040  if (sd && sd->size >= sizeof(uint32_t) * 4) {
1041  opts->crop_top = AV_RL32(sd->data + 0);
1042  opts->crop_bottom = AV_RL32(sd->data + 4);
1043  opts->crop_left = AV_RL32(sd->data + 8);
1044  opts->crop_right = AV_RL32(sd->data + 12);
1045  if (ds->apply_cropping && ds->apply_cropping != CROP_CODEC &&
1046  (opts->crop_top | opts->crop_bottom | opts->crop_left | opts->crop_right))
1047  opts->flags |= IFILTER_FLAG_CROP;
1048  }
1049  } else if (ist->par->codec_type == AVMEDIA_TYPE_SUBTITLE) {
1050  /* Compute the size of the canvas for the subtitles stream.
1051  If the subtitles codecpar has set a size, use it. Otherwise use the
1052  maximum dimensions of the video streams in the same file. */
1053  opts->sub2video_width = ist->par->width;
1054  opts->sub2video_height = ist->par->height;
1055  if (!(opts->sub2video_width && opts->sub2video_height)) {
1056  for (int j = 0; j < d->f.nb_streams; j++) {
1057  AVCodecParameters *par1 = d->f.streams[j]->par;
1058  if (par1->codec_type == AVMEDIA_TYPE_VIDEO) {
1059  opts->sub2video_width = FFMAX(opts->sub2video_width, par1->width);
1060  opts->sub2video_height = FFMAX(opts->sub2video_height, par1->height);
1061  }
1062  }
1063  }
1064 
1065  if (!(opts->sub2video_width && opts->sub2video_height)) {
1066  opts->sub2video_width = FFMAX(opts->sub2video_width, 720);
1067  opts->sub2video_height = FFMAX(opts->sub2video_height, 576);
1068  }
1069 
1070  if (!d->pkt_heartbeat) {
1072  if (!d->pkt_heartbeat)
1073  return AVERROR(ENOMEM);
1074  }
1075  ds->have_sub2video = 1;
1076  }
1077 
1078  ret = av_frame_copy_props(opts->fallback, ds->decoded_params);
1079  if (ret < 0)
1080  return ret;
1081  opts->fallback->format = ds->decoded_params->format;
1082  opts->fallback->width = ds->decoded_params->width;
1083  opts->fallback->height = ds->decoded_params->height;
1084 
1085  ret = av_channel_layout_copy(&opts->fallback->ch_layout, &ds->decoded_params->ch_layout);
1086  if (ret < 0)
1087  return ret;
1088 
1089  if (copy_ts) {
1090  tsoffset = d->f.start_time == AV_NOPTS_VALUE ? 0 : d->f.start_time;
1091  if (!start_at_zero && d->f.ctx->start_time != AV_NOPTS_VALUE)
1092  tsoffset += d->f.ctx->start_time;
1093  }
1094  opts->trim_start_us = ((d->f.start_time == AV_NOPTS_VALUE) || !d->accurate_seek) ?
1095  AV_NOPTS_VALUE : tsoffset;
1096  opts->trim_end_us = d->recording_time;
1097 
1098  opts->name = av_strdup(ds->dec_name);
1099  if (!opts->name)
1100  return AVERROR(ENOMEM);
1101 
1102  opts->flags |= IFILTER_FLAG_AUTOROTATE * !!(ds->autorotate) |
1105 
1106  return 0;
1107 }
1108 
1109 static int choose_decoder(const OptionsContext *o, void *logctx,
1110  AVFormatContext *s, AVStream *st,
1111  enum HWAccelID hwaccel_id, enum AVHWDeviceType hwaccel_device_type,
1112  const AVCodec **pcodec)
1113 
1114 {
1115  const char *codec_name = NULL;
1116 
1117  opt_match_per_stream_str(logctx, &o->codec_names, s, st, &codec_name);
1118  if (codec_name) {
1119  int ret = find_codec(NULL, codec_name, st->codecpar->codec_type, 0, pcodec);
1120  if (ret < 0)
1121  return ret;
1122  st->codecpar->codec_id = (*pcodec)->id;
1123  if (recast_media && st->codecpar->codec_type != (*pcodec)->type)
1124  st->codecpar->codec_type = (*pcodec)->type;
1125  return 0;
1126  } else {
1127  if (st->codecpar->codec_type == AVMEDIA_TYPE_VIDEO &&
1128  hwaccel_id == HWACCEL_GENERIC &&
1129  hwaccel_device_type != AV_HWDEVICE_TYPE_NONE) {
1130  const AVCodec *c;
1131  void *i = NULL;
1132 
1133  while ((c = av_codec_iterate(&i))) {
1134  const AVCodecHWConfig *config;
1135 
1136  if (c->id != st->codecpar->codec_id ||
1138  continue;
1139 
1140  for (int j = 0; config = avcodec_get_hw_config(c, j); j++) {
1141  if (config->device_type == hwaccel_device_type) {
1142  av_log(logctx, AV_LOG_VERBOSE, "Selecting decoder '%s' because of requested hwaccel method %s\n",
1143  c->name, av_hwdevice_get_type_name(hwaccel_device_type));
1144  *pcodec = c;
1145  return 0;
1146  }
1147  }
1148  }
1149  }
1150 
1151  *pcodec = avcodec_find_decoder(st->codecpar->codec_id);
1152  return 0;
1153  }
1154 }
1155 
1157  int guess_layout_max)
1158 {
1159  if (par->ch_layout.order == AV_CHANNEL_ORDER_UNSPEC) {
1160  char layout_name[256];
1161 
1162  if (par->ch_layout.nb_channels > guess_layout_max)
1163  return 0;
1166  return 0;
1167  av_channel_layout_describe(&par->ch_layout, layout_name, sizeof(layout_name));
1168  av_log(ist, AV_LOG_WARNING, "Guessed Channel Layout: %s\n", layout_name);
1169  }
1170  return 1;
1171 }
1172 
1175 {
1176  AVStream *st = ist->st;
1177  AVPacketSideData *sd;
1178  double rotation = DBL_MAX;
1179  int hflip = -1, vflip = -1;
1180  int hflip_set = 0, vflip_set = 0, rotation_set = 0;
1181  int32_t *buf;
1182 
1183  opt_match_per_stream_dbl(ist, &o->display_rotations, ctx, st, &rotation);
1184  opt_match_per_stream_int(ist, &o->display_hflips, ctx, st, &hflip);
1185  opt_match_per_stream_int(ist, &o->display_vflips, ctx, st, &vflip);
1186 
1187  rotation_set = rotation != DBL_MAX;
1188  hflip_set = hflip != -1;
1189  vflip_set = vflip != -1;
1190 
1191  if (!rotation_set && !hflip_set && !vflip_set)
1192  return 0;
1193 
1197  sizeof(int32_t) * 9, 0);
1198  if (!sd) {
1199  av_log(ist, AV_LOG_FATAL, "Failed to generate a display matrix!\n");
1200  return AVERROR(ENOMEM);
1201  }
1202 
1203  buf = (int32_t *)sd->data;
1205  rotation_set ? -(rotation) : -0.0f);
1206 
1208  hflip_set ? hflip : 0,
1209  vflip_set ? vflip : 0);
1210 
1211  return 0;
1212 }
1213 
1214 static const char *input_stream_item_name(void *obj)
1215 {
1216  const DemuxStream *ds = obj;
1217 
1218  return ds->log_name;
1219 }
1220 
1221 static const AVClass input_stream_class = {
1222  .class_name = "InputStream",
1223  .version = LIBAVUTIL_VERSION_INT,
1224  .item_name = input_stream_item_name,
1225  .category = AV_CLASS_CATEGORY_DEMUXER,
1226 };
1227 
1229 {
1230  const char *type_str = av_get_media_type_string(st->codecpar->codec_type);
1231  InputFile *f = &d->f;
1232  DemuxStream *ds;
1233 
1234  ds = allocate_array_elem(&f->streams, sizeof(*ds), &f->nb_streams);
1235  if (!ds)
1236  return NULL;
1237 
1238  ds->sch_idx_stream = -1;
1239  ds->sch_idx_dec = -1;
1240 
1241  ds->ist.st = st;
1242  ds->ist.file = f;
1243  ds->ist.index = st->index;
1244  ds->ist.class = &input_stream_class;
1245 
1246  snprintf(ds->log_name, sizeof(ds->log_name), "%cist#%d:%d/%s",
1247  type_str ? *type_str : '?', d->f.index, st->index,
1249 
1250  return ds;
1251 }
1252 
1253 static int ist_add(const OptionsContext *o, Demuxer *d, AVStream *st, AVDictionary **opts_used)
1254 {
1255  AVFormatContext *ic = d->f.ctx;
1256  AVCodecParameters *par = st->codecpar;
1257  DemuxStream *ds;
1258  InputStream *ist;
1259  const char *framerate = NULL, *hwaccel_device = NULL;
1260  const char *hwaccel = NULL;
1261  const char *apply_cropping = NULL;
1262  const char *hwaccel_output_format = NULL;
1263  const char *codec_tag = NULL;
1264  const char *bsfs = NULL;
1265  char *next;
1266  const char *discard_str = NULL;
1267  int ret;
1268 
1269  ds = demux_stream_alloc(d, st);
1270  if (!ds)
1271  return AVERROR(ENOMEM);
1272 
1273  ist = &ds->ist;
1274 
1275  ds->discard = 1;
1276  st->discard = AVDISCARD_ALL;
1277  ds->first_dts = AV_NOPTS_VALUE;
1278  ds->next_dts = AV_NOPTS_VALUE;
1279 
1280  ds->dec_opts.time_base = st->time_base;
1281 
1282  ds->ts_scale = 1.0;
1283  opt_match_per_stream_dbl(ist, &o->ts_scale, ic, st, &ds->ts_scale);
1284 
1285  ds->autorotate = 1;
1286  opt_match_per_stream_int(ist, &o->autorotate, ic, st, &ds->autorotate);
1287 
1288  ds->apply_cropping = CROP_ALL;
1290  if (apply_cropping) {
1291  const AVOption opts[] = {
1292  { "apply_cropping", NULL, 0, AV_OPT_TYPE_INT,
1293  { .i64 = CROP_ALL }, CROP_DISABLED, CROP_CONTAINER, AV_OPT_FLAG_DECODING_PARAM, .unit = "apply_cropping" },
1294  { "none", NULL, 0, AV_OPT_TYPE_CONST, { .i64 = CROP_DISABLED }, .unit = "apply_cropping" },
1295  { "all", NULL, 0, AV_OPT_TYPE_CONST, { .i64 = CROP_ALL }, .unit = "apply_cropping" },
1296  { "codec", NULL, 0, AV_OPT_TYPE_CONST, { .i64 = CROP_CODEC }, .unit = "apply_cropping" },
1297  { "container", NULL, 0, AV_OPT_TYPE_CONST, { .i64 = CROP_CONTAINER }, .unit = "apply_cropping" },
1298  { NULL },
1299  };
1300  const AVClass class = {
1301  .class_name = "apply_cropping",
1302  .item_name = av_default_item_name,
1303  .option = opts,
1304  .version = LIBAVUTIL_VERSION_INT,
1305  };
1306  const AVClass *pclass = &class;
1307 
1309  if (ret < 0) {
1310  av_log(ist, AV_LOG_ERROR, "Invalid apply_cropping value '%s'.\n", apply_cropping);
1311  return ret;
1312  }
1313  }
1314 
1315  opt_match_per_stream_str(ist, &o->codec_tags, ic, st, &codec_tag);
1316  if (codec_tag) {
1317  uint32_t tag = strtol(codec_tag, &next, 0);
1318  if (*next) {
1319  uint8_t buf[4] = { 0 };
1320  memcpy(buf, codec_tag, FFMIN(sizeof(buf), strlen(codec_tag)));
1321  tag = AV_RL32(buf);
1322  }
1323 
1324  st->codecpar->codec_tag = tag;
1325  }
1326 
1327  if (st->codecpar->codec_type == AVMEDIA_TYPE_VIDEO) {
1328  ret = add_display_matrix_to_stream(o, ic, ist);
1329  if (ret < 0)
1330  return ret;
1331 
1332  opt_match_per_stream_str(ist, &o->hwaccels, ic, st, &hwaccel);
1334  &hwaccel_output_format);
1335  if (!hwaccel_output_format && hwaccel && !strcmp(hwaccel, "cuvid")) {
1336  av_log(ist, AV_LOG_WARNING,
1337  "WARNING: defaulting hwaccel_output_format to cuda for compatibility "
1338  "with old commandlines. This behaviour is DEPRECATED and will be removed "
1339  "in the future. Please explicitly set \"-hwaccel_output_format cuda\".\n");
1341  } else if (!hwaccel_output_format && hwaccel && !strcmp(hwaccel, "qsv")) {
1342  av_log(ist, AV_LOG_WARNING,
1343  "WARNING: defaulting hwaccel_output_format to qsv for compatibility "
1344  "with old commandlines. This behaviour is DEPRECATED and will be removed "
1345  "in the future. Please explicitly set \"-hwaccel_output_format qsv\".\n");
1347  } else if (!hwaccel_output_format && hwaccel && !strcmp(hwaccel, "mediacodec")) {
1348  // There is no real AVHWFrameContext implementation. Set
1349  // hwaccel_output_format to avoid av_hwframe_transfer_data error.
1351  } else if (hwaccel_output_format) {
1352  ds->dec_opts.hwaccel_output_format = av_get_pix_fmt(hwaccel_output_format);
1354  av_log(ist, AV_LOG_FATAL, "Unrecognised hwaccel output "
1355  "format: %s", hwaccel_output_format);
1356  }
1357  } else {
1359  }
1360 
1361  if (hwaccel) {
1362  // The NVDEC hwaccels use a CUDA device, so remap the name here.
1363  if (!strcmp(hwaccel, "nvdec") || !strcmp(hwaccel, "cuvid"))
1364  hwaccel = "cuda";
1365 
1366  if (!strcmp(hwaccel, "none"))
1368  else if (!strcmp(hwaccel, "auto"))
1370  else {
1372  if (type != AV_HWDEVICE_TYPE_NONE) {
1375  }
1376 
1377  if (!ds->dec_opts.hwaccel_id) {
1378  av_log(ist, AV_LOG_FATAL, "Unrecognized hwaccel: %s.\n",
1379  hwaccel);
1380  av_log(ist, AV_LOG_FATAL, "Supported hwaccels: ");
1382  while ((type = av_hwdevice_iterate_types(type)) !=
1384  av_log(ist, AV_LOG_FATAL, "%s ",
1386  av_log(ist, AV_LOG_FATAL, "\n");
1387  return AVERROR(EINVAL);
1388  }
1389  }
1390  }
1391 
1392  opt_match_per_stream_str(ist, &o->hwaccel_devices, ic, st, &hwaccel_device);
1393  if (hwaccel_device) {
1394  ds->dec_opts.hwaccel_device = av_strdup(hwaccel_device);
1395  if (!ds->dec_opts.hwaccel_device)
1396  return AVERROR(ENOMEM);
1397  }
1398  }
1399 
1400  ret = choose_decoder(o, ist, ic, st, ds->dec_opts.hwaccel_id,
1401  ds->dec_opts.hwaccel_device_type, &ist->dec);
1402  if (ret < 0)
1403  return ret;
1404 
1405  if (ist->dec) {
1407  ic, st, ist->dec, &ds->decoder_opts, opts_used);
1408  if (ret < 0)
1409  return ret;
1410  }
1411 
1412  ds->reinit_filters = -1;
1413  opt_match_per_stream_int(ist, &o->reinit_filters, ic, st, &ds->reinit_filters);
1414 
1415  ds->drop_changed = 0;
1416  opt_match_per_stream_int(ist, &o->drop_changed, ic, st, &ds->drop_changed);
1417 
1418  if (ds->drop_changed && ds->reinit_filters) {
1419  if (ds->reinit_filters > 0) {
1420  av_log(ist, AV_LOG_ERROR, "drop_changed and reinit_filters both enabled. These are mutually exclusive.\n");
1421  return AVERROR(EINVAL);
1422  }
1423  ds->reinit_filters = 0;
1424  }
1425 
1427 
1428  if ((o->video_disable && ist->st->codecpar->codec_type == AVMEDIA_TYPE_VIDEO) ||
1433 
1434  opt_match_per_stream_str(ist, &o->discard, ic, st, &discard_str);
1435  if (discard_str) {
1436  ret = av_opt_set(ist->st, "discard", discard_str, 0);
1437  if (ret < 0) {
1438  av_log(ist, AV_LOG_ERROR, "Error parsing discard %s.\n", discard_str);
1439  return ret;
1440  }
1441  ist->user_set_discard = ist->st->discard;
1442  }
1443 
1445 
1446  av_dict_set_int(&ds->decoder_opts, "apply_cropping",
1447  ds->apply_cropping && ds->apply_cropping != CROP_CONTAINER, 0);
1448 
1449  /* Attached pics are sparse, therefore we would not want to delay their decoding
1450  * till EOF. */
1452  av_dict_set(&ds->decoder_opts, "thread_type", "-frame", 0);
1453 
1454  switch (par->codec_type) {
1455  case AVMEDIA_TYPE_VIDEO:
1456  opt_match_per_stream_str(ist, &o->frame_rates, ic, st, &framerate);
1457  if (framerate) {
1459  if (ret < 0) {
1460  av_log(ist, AV_LOG_ERROR, "Error parsing framerate %s.\n",
1461  framerate);
1462  return ret;
1463  }
1464  }
1465 
1466 #if FFMPEG_OPT_TOP
1467  ist->top_field_first = -1;
1468  opt_match_per_stream_int(ist, &o->top_field_first, ic, st, &ist->top_field_first);
1469 #endif
1470 
1471  break;
1472  case AVMEDIA_TYPE_AUDIO: {
1473  const char *ch_layout_str = NULL;
1474 
1475  opt_match_per_stream_str(ist, &o->audio_ch_layouts, ic, st, &ch_layout_str);
1476  if (ch_layout_str) {
1477  AVChannelLayout ch_layout;
1478  ret = av_channel_layout_from_string(&ch_layout, ch_layout_str);
1479  if (ret < 0) {
1480  av_log(ist, AV_LOG_ERROR, "Error parsing channel layout %s.\n", ch_layout_str);
1481  return ret;
1482  }
1483  if (par->ch_layout.nb_channels <= 0 || par->ch_layout.nb_channels == ch_layout.nb_channels) {
1485  par->ch_layout = ch_layout;
1486  } else {
1487  av_log(ist, AV_LOG_ERROR,
1488  "Specified channel layout '%s' has %d channels, but input has %d channels.\n",
1489  ch_layout_str, ch_layout.nb_channels, par->ch_layout.nb_channels);
1490  av_channel_layout_uninit(&ch_layout);
1491  return AVERROR(EINVAL);
1492  }
1493  } else {
1494  int guess_layout_max = INT_MAX;
1495  opt_match_per_stream_int(ist, &o->guess_layout_max, ic, st, &guess_layout_max);
1496  guess_input_channel_layout(ist, par, guess_layout_max);
1497  }
1498  break;
1499  }
1500  case AVMEDIA_TYPE_DATA:
1501  case AVMEDIA_TYPE_SUBTITLE: {
1502  const char *canvas_size = NULL;
1503 
1505  opt_match_per_stream_str(ist, &o->canvas_sizes, ic, st, &canvas_size);
1506  if (canvas_size) {
1507  ret = av_parse_video_size(&par->width, &par->height,
1508  canvas_size);
1509  if (ret < 0) {
1510  av_log(ist, AV_LOG_FATAL, "Invalid canvas size: %s.\n", canvas_size);
1511  return ret;
1512  }
1513  }
1514  break;
1515  }
1517  case AVMEDIA_TYPE_UNKNOWN:
1518  break;
1519  default: av_assert0(0);
1520  }
1521 
1522  ist->par = avcodec_parameters_alloc();
1523  if (!ist->par)
1524  return AVERROR(ENOMEM);
1525 
1526  ret = avcodec_parameters_copy(ist->par, par);
1527  if (ret < 0) {
1528  av_log(ist, AV_LOG_ERROR, "Error exporting stream parameters.\n");
1529  return ret;
1530  }
1531 
1532  if (ist->st->sample_aspect_ratio.num)
1534 
1535  opt_match_per_stream_str(ist, &o->bitstream_filters, ic, st, &bsfs);
1536  if (bsfs) {
1537  ret = av_bsf_list_parse_str(bsfs, &ds->bsf);
1538  if (ret < 0) {
1539  av_log(ist, AV_LOG_ERROR,
1540  "Error parsing bitstream filter sequence '%s': %s\n",
1541  bsfs, av_err2str(ret));
1542  return ret;
1543  }
1544 
1545  ret = avcodec_parameters_copy(ds->bsf->par_in, ist->par);
1546  if (ret < 0)
1547  return ret;
1548  ds->bsf->time_base_in = ist->st->time_base;
1549 
1550  ret = av_bsf_init(ds->bsf);
1551  if (ret < 0) {
1552  av_log(ist, AV_LOG_ERROR, "Error initializing bitstream filters: %s\n",
1553  av_err2str(ret));
1554  return ret;
1555  }
1556 
1557  ret = avcodec_parameters_copy(ist->par, ds->bsf->par_out);
1558  if (ret < 0)
1559  return ret;
1560  }
1561 
1563 
1564  return 0;
1565 }
1566 
1567 static int dump_attachment(InputStream *ist, const char *filename)
1568 {
1569  AVStream *st = ist->st;
1570  int ret;
1571  AVIOContext *out = NULL;
1572  const AVDictionaryEntry *e;
1573 
1574  if (!st->codecpar->extradata_size) {
1575  av_log(ist, AV_LOG_WARNING, "No extradata to dump.\n");
1576  return 0;
1577  }
1578  if (!*filename && (e = av_dict_get(st->metadata, "filename", NULL, 0)))
1579  filename = e->value;
1580  if (!*filename) {
1581  av_log(ist, AV_LOG_FATAL, "No filename specified and no 'filename' tag");
1582  return AVERROR(EINVAL);
1583  }
1584 
1585  ret = assert_file_overwrite(filename);
1586  if (ret < 0)
1587  return ret;
1588 
1589  if ((ret = avio_open2(&out, filename, AVIO_FLAG_WRITE, &int_cb, NULL)) < 0) {
1590  av_log(ist, AV_LOG_FATAL, "Could not open file %s for writing.\n",
1591  filename);
1592  return ret;
1593  }
1594 
1596  ret = avio_close(out);
1597 
1598  if (ret >= 0)
1599  av_log(ist, AV_LOG_INFO, "Wrote attachment (%d bytes) to '%s'\n",
1600  st->codecpar->extradata_size, filename);
1601 
1602  return ret;
1603 }
1604 
1605 static const char *input_file_item_name(void *obj)
1606 {
1607  const Demuxer *d = obj;
1608 
1609  return d->log_name;
1610 }
1611 
1612 static const AVClass input_file_class = {
1613  .class_name = "InputFile",
1614  .version = LIBAVUTIL_VERSION_INT,
1615  .item_name = input_file_item_name,
1616  .category = AV_CLASS_CATEGORY_DEMUXER,
1617 };
1618 
1619 static Demuxer *demux_alloc(void)
1620 {
1622 
1623  if (!d)
1624  return NULL;
1625 
1626  d->f.class = &input_file_class;
1627  d->f.index = nb_input_files - 1;
1628 
1629  snprintf(d->log_name, sizeof(d->log_name), "in#%d", d->f.index);
1630 
1631  return d;
1632 }
1633 
1634 int ifile_open(const OptionsContext *o, const char *filename, Scheduler *sch)
1635 {
1636  Demuxer *d;
1637  InputFile *f;
1638  AVFormatContext *ic;
1639  const AVInputFormat *file_iformat = NULL;
1640  int err, ret = 0;
1641  int64_t timestamp;
1642  AVDictionary *opts_used = NULL;
1643  const char* video_codec_name = NULL;
1644  const char* audio_codec_name = NULL;
1645  const char* subtitle_codec_name = NULL;
1646  const char* data_codec_name = NULL;
1647  int scan_all_pmts_set = 0;
1648 
1650  int64_t start_time_eof = o->start_time_eof;
1651  int64_t stop_time = o->stop_time;
1652  int64_t recording_time = o->recording_time;
1653 
1654  d = demux_alloc();
1655  if (!d)
1656  return AVERROR(ENOMEM);
1657 
1658  f = &d->f;
1659 
1660  ret = sch_add_demux(sch, input_thread, d);
1661  if (ret < 0)
1662  return ret;
1663  d->sch = sch;
1664 
1665  if (stop_time != INT64_MAX && recording_time != INT64_MAX) {
1666  stop_time = INT64_MAX;
1667  av_log(d, AV_LOG_WARNING, "-t and -to cannot be used together; using -t.\n");
1668  }
1669 
1670  if (stop_time != INT64_MAX && recording_time == INT64_MAX) {
1671  int64_t start = start_time == AV_NOPTS_VALUE ? 0 : start_time;
1672  if (stop_time <= start) {
1673  av_log(d, AV_LOG_ERROR, "-to value smaller than -ss; aborting.\n");
1674  return AVERROR(EINVAL);
1675  } else {
1676  recording_time = stop_time - start;
1677  }
1678  }
1679 
1680  if (o->format) {
1681  if (!(file_iformat = av_find_input_format(o->format))) {
1682  av_log(d, AV_LOG_FATAL, "Unknown input format: '%s'\n", o->format);
1683  return AVERROR(EINVAL);
1684  }
1685  }
1686 
1687  if (!strcmp(filename, "-"))
1688  filename = "fd:";
1689 
1690  stdin_interaction &= strncmp(filename, "pipe:", 5) &&
1691  strcmp(filename, "fd:") &&
1692  strcmp(filename, "/dev/stdin");
1693 
1694  /* get default parameters from command line */
1695  ic = avformat_alloc_context();
1696  if (!ic)
1697  return AVERROR(ENOMEM);
1698  if (o->audio_sample_rate.nb_opt) {
1699  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);
1700  }
1701  if (o->audio_channels.nb_opt) {
1702  const AVClass *priv_class;
1703  if (file_iformat && (priv_class = file_iformat->priv_class) &&
1704  av_opt_find(&priv_class, "ch_layout", NULL, 0,
1706  char buf[32];
1707  snprintf(buf, sizeof(buf), "%dC", o->audio_channels.opt[o->audio_channels.nb_opt - 1].u.i);
1708  av_dict_set(&o->g->format_opts, "ch_layout", buf, 0);
1709  }
1710  }
1711  if (o->audio_ch_layouts.nb_opt) {
1712  const AVClass *priv_class;
1713  if (file_iformat && (priv_class = file_iformat->priv_class) &&
1714  av_opt_find(&priv_class, "ch_layout", NULL, 0,
1716  av_dict_set(&o->g->format_opts, "ch_layout", o->audio_ch_layouts.opt[o->audio_ch_layouts.nb_opt - 1].u.str, 0);
1717  }
1718  }
1719  if (o->frame_rates.nb_opt) {
1720  const AVClass *priv_class;
1721  /* set the format-level framerate option;
1722  * this is important for video grabbers, e.g. x11 */
1723  if (file_iformat && (priv_class = file_iformat->priv_class) &&
1724  av_opt_find(&priv_class, "framerate", NULL, 0,
1726  av_dict_set(&o->g->format_opts, "framerate",
1727  o->frame_rates.opt[o->frame_rates.nb_opt - 1].u.str, 0);
1728  }
1729  }
1730  if (o->frame_sizes.nb_opt) {
1731  av_dict_set(&o->g->format_opts, "video_size", o->frame_sizes.opt[o->frame_sizes.nb_opt - 1].u.str, 0);
1732  }
1733  if (o->frame_pix_fmts.nb_opt)
1734  av_dict_set(&o->g->format_opts, "pixel_format", o->frame_pix_fmts.opt[o->frame_pix_fmts.nb_opt - 1].u.str, 0);
1735 
1739  data_codec_name = opt_match_per_type_str(&o->codec_names, 'd');
1740 
1741  if (video_codec_name)
1743  &ic->video_codec));
1744  if (audio_codec_name)
1746  &ic->audio_codec));
1747  if (subtitle_codec_name)
1749  &ic->subtitle_codec));
1750  if (data_codec_name)
1751  ret = err_merge(ret, find_codec(NULL, data_codec_name , AVMEDIA_TYPE_DATA, 0,
1752  &ic->data_codec));
1753  if (ret < 0) {
1755  return ret;
1756  }
1757 
1761  ic->data_codec_id = data_codec_name ? ic->data_codec->id : AV_CODEC_ID_NONE;
1762 
1763  ic->flags |= AVFMT_FLAG_NONBLOCK;
1764  if (o->bitexact)
1765  ic->flags |= AVFMT_FLAG_BITEXACT;
1766  ic->interrupt_callback = int_cb;
1767 
1768  if (!av_dict_get(o->g->format_opts, "scan_all_pmts", NULL, AV_DICT_MATCH_CASE)) {
1769  av_dict_set(&o->g->format_opts, "scan_all_pmts", "1", AV_DICT_DONT_OVERWRITE);
1770  scan_all_pmts_set = 1;
1771  }
1772  /* open the input file with generic avformat function */
1773  err = avformat_open_input(&ic, filename, file_iformat, &o->g->format_opts);
1774  if (err < 0) {
1775  if (err != AVERROR_EXIT)
1776  av_log(d, AV_LOG_ERROR,
1777  "Error opening input: %s\n", av_err2str(err));
1778  if (err == AVERROR_PROTOCOL_NOT_FOUND)
1779  av_log(d, AV_LOG_ERROR, "Did you mean file:%s?\n", filename);
1780  return err;
1781  }
1782  f->ctx = ic;
1783 
1784  av_strlcat(d->log_name, "/", sizeof(d->log_name));
1785  av_strlcat(d->log_name, ic->iformat->name, sizeof(d->log_name));
1786 
1787  if (scan_all_pmts_set)
1788  av_dict_set(&o->g->format_opts, "scan_all_pmts", NULL, AV_DICT_MATCH_CASE);
1790 
1792  if (ret < 0)
1793  return ret;
1794 
1795  /* apply forced codec ids */
1796  for (int i = 0; i < ic->nb_streams; i++) {
1797  const AVCodec *dummy;
1799  &dummy);
1800  if (ret < 0)
1801  return ret;
1802  }
1803 
1804  if (o->find_stream_info) {
1805  AVDictionary **opts;
1806  int orig_nb_streams = ic->nb_streams;
1807 
1809  if (ret < 0)
1810  return ret;
1811 
1812  /* If not enough info to get the stream parameters, we decode the
1813  first frames to get it. (used in mpeg case for example) */
1815 
1816  for (int i = 0; i < orig_nb_streams; i++)
1817  av_dict_free(&opts[i]);
1818  av_freep(&opts);
1819 
1820  if (ret < 0) {
1821  av_log(d, AV_LOG_FATAL, "could not find codec parameters\n");
1822  if (ic->nb_streams == 0)
1823  return ret;
1824  }
1825  }
1826 
1827  if (start_time != AV_NOPTS_VALUE && start_time_eof != AV_NOPTS_VALUE) {
1828  av_log(d, AV_LOG_WARNING, "Cannot use -ss and -sseof both, using -ss\n");
1829  start_time_eof = AV_NOPTS_VALUE;
1830  }
1831 
1832  if (start_time_eof != AV_NOPTS_VALUE) {
1833  if (start_time_eof >= 0) {
1834  av_log(d, AV_LOG_ERROR, "-sseof value must be negative; aborting\n");
1835  return AVERROR(EINVAL);
1836  }
1837  if (ic->duration > 0) {
1838  start_time = start_time_eof + ic->duration;
1839  if (start_time < 0) {
1840  av_log(d, AV_LOG_WARNING, "-sseof value seeks to before start of file; ignored\n");
1842  }
1843  } else
1844  av_log(d, AV_LOG_WARNING, "Cannot use -sseof, file duration not known\n");
1845  }
1846  timestamp = (start_time == AV_NOPTS_VALUE) ? 0 : start_time;
1847  /* add the stream start time */
1848  if (!o->seek_timestamp && ic->start_time != AV_NOPTS_VALUE)
1849  timestamp += ic->start_time;
1850 
1851  /* if seeking requested, we execute it */
1852  if (start_time != AV_NOPTS_VALUE) {
1853  int64_t seek_timestamp = timestamp;
1854 
1855  if (!(ic->iformat->flags & AVFMT_SEEK_TO_PTS)) {
1856  int dts_heuristic = 0;
1857  for (int i = 0; i < ic->nb_streams; i++) {
1858  const AVCodecParameters *par = ic->streams[i]->codecpar;
1859  if (par->video_delay) {
1860  dts_heuristic = 1;
1861  break;
1862  }
1863  }
1864  if (dts_heuristic) {
1865  seek_timestamp -= 3*AV_TIME_BASE / 23;
1866  }
1867  }
1868  ret = avformat_seek_file(ic, -1, INT64_MIN, seek_timestamp, seek_timestamp, 0);
1869  if (ret < 0) {
1870  av_log(d, AV_LOG_WARNING, "could not seek to position %0.3f\n",
1871  (double)timestamp / AV_TIME_BASE);
1872  }
1873  }
1874 
1875  f->start_time = start_time;
1876  d->recording_time = recording_time;
1877  f->input_sync_ref = o->input_sync_ref;
1878  f->input_ts_offset = o->input_ts_offset;
1879  f->ts_offset = o->input_ts_offset - (copy_ts ? (start_at_zero && ic->start_time != AV_NOPTS_VALUE ? ic->start_time : 0) : timestamp);
1880  d->accurate_seek = o->accurate_seek;
1881  d->loop = o->loop;
1882  d->nb_streams_warn = ic->nb_streams;
1883 
1884  d->duration = (Timestamp){ .ts = 0, .tb = (AVRational){ 1, 1 } };
1885  d->min_pts = (Timestamp){ .ts = AV_NOPTS_VALUE, .tb = (AVRational){ 1, 1 } };
1886  d->max_pts = (Timestamp){ .ts = AV_NOPTS_VALUE, .tb = (AVRational){ 1, 1 } };
1887 
1888  d->readrate = o->readrate ? o->readrate : 0.0;
1889  if (d->readrate < 0.0f) {
1890  av_log(d, AV_LOG_ERROR, "Option -readrate is %0.3f; it must be non-negative.\n", d->readrate);
1891  return AVERROR(EINVAL);
1892  }
1893  if (o->rate_emu) {
1894  if (d->readrate) {
1895  av_log(d, AV_LOG_WARNING, "Both -readrate and -re set. Using -readrate %0.3f.\n", d->readrate);
1896  } else
1897  d->readrate = 1.0f;
1898  }
1899 
1900  if (d->readrate) {
1902  if (d->readrate_initial_burst < 0.0) {
1903  av_log(d, AV_LOG_ERROR,
1904  "Option -readrate_initial_burst is %0.3f; it must be non-negative.\n",
1906  return AVERROR(EINVAL);
1907  }
1909  if (d->readrate_catchup < d->readrate) {
1910  av_log(d, AV_LOG_ERROR,
1911  "Option -readrate_catchup is %0.3f; it must be at least equal to %0.3f.\n",
1912  d->readrate_catchup, d->readrate);
1913  return AVERROR(EINVAL);
1914  }
1915  } else {
1916  if (o->readrate_initial_burst) {
1917  av_log(d, AV_LOG_WARNING, "Option -readrate_initial_burst ignored "
1918  "since neither -readrate nor -re were given\n");
1919  }
1920  if (o->readrate_catchup) {
1921  av_log(d, AV_LOG_WARNING, "Option -readrate_catchup ignored "
1922  "since neither -readrate nor -re were given\n");
1923  }
1924  }
1925 
1926  /* Add all the streams from the given input file to the demuxer */
1927  for (int i = 0; i < ic->nb_streams; i++) {
1928  ret = ist_add(o, d, ic->streams[i], &opts_used);
1929  if (ret < 0) {
1930  av_dict_free(&opts_used);
1931  return ret;
1932  }
1933  }
1934 
1935  /* dump the file content */
1936  av_dump_format(ic, f->index, filename, 0);
1937 
1938  /* check if all codec options have been used */
1939  ret = check_avoptions_used(o->g->codec_opts, opts_used, d, 1);
1940  av_dict_free(&opts_used);
1941  if (ret < 0)
1942  return ret;
1943 
1944  for (int i = 0; i < o->dump_attachment.nb_opt; i++) {
1945  for (int j = 0; j < f->nb_streams; j++) {
1946  InputStream *ist = f->streams[j];
1947 
1948  if (check_stream_specifier(ic, ist->st, o->dump_attachment.opt[i].specifier) == 1) {
1950  if (ret < 0)
1951  return ret;
1952  }
1953  }
1954  }
1955 
1956  return 0;
1957 }
OptionsContext::readrate
float readrate
Definition: ffmpeg.h:165
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:430
AVCodec
AVCodec.
Definition: codec.h:187
OptionsContext::input_ts_offset
int64_t input_ts_offset
Definition: ffmpeg.h:162
AVMEDIA_TYPE_SUBTITLE
@ AVMEDIA_TYPE_SUBTITLE
Definition: avutil.h:204
DemuxStream::ist
InputStream ist
Definition: ffmpeg_demux.c:44
av_gettime_relative
int64_t av_gettime_relative(void)
Get the current time in microseconds since some unspecified starting point.
Definition: time.c:56
AVBSFContext::par_in
AVCodecParameters * par_in
Parameters of the input stream.
Definition: bsf.h:90
AV_LOG_WARNING
#define AV_LOG_WARNING
Something somehow does not look correct.
Definition: log.h:215
InputFile::start_time
int64_t start_time
Definition: ffmpeg.h:485
AV_PIX_FMT_CUDA
@ AV_PIX_FMT_CUDA
HW acceleration through CUDA.
Definition: pixfmt.h:260
AVCodecParameters::extradata
uint8_t * extradata
Extra binary data needed for initializing the decoder, codec-dependent.
Definition: codec_par.h:69
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:190
demux_final_stats
static void demux_final_stats(Demuxer *d)
Definition: ffmpeg_demux.c:824
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:105
opt.h
AVCodecParameters::codec_type
enum AVMediaType codec_type
General type of the encoded data.
Definition: codec_par.h:51
input_stream_class
static const AVClass input_stream_class
Definition: ffmpeg_demux.c:1221
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:658
AVProgram::nb_stream_indexes
unsigned int nb_stream_indexes
Definition: avformat.h:1229
check_avoptions
int check_avoptions(AVDictionary *m)
Definition: cmdutils.c:1529
apply_cropping
static int apply_cropping(AVCodecContext *avctx, AVFrame *frame)
Definition: decode.c:761
out
FILE * out
Definition: movenc.c:55
DemuxStream::drop_changed
int drop_changed
Definition: ffmpeg_demux.c:70
DecoderOpts
Definition: ffmpeg.h:401
is
The official guide to swscale for confused that is
Definition: swscale.txt:28
AV_PKT_DATA_FRAME_CROPPING
@ AV_PKT_DATA_FRAME_CROPPING
The number of pixels to discard from the top/bottom/left/right border of the decoded frame to obtain ...
Definition: packet.h:340
AVCodecParameters
This struct describes the properties of an encoded stream.
Definition: codec_par.h:47
DECODER_FLAG_SEND_END_TS
@ DECODER_FLAG_SEND_END_TS
Definition: ffmpeg.h:396
AVERROR_EOF
#define AVERROR_EOF
End of file.
Definition: error.h:57
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:674
AVStream::discard
enum AVDiscard discard
Selects which packets can be discarded at will and do not need to be demuxed.
Definition: avformat.h:819
FrameData::dts_est
int64_t dts_est
Definition: ffmpeg.h:661
sch_add_demux
int sch_add_demux(Scheduler *sch, SchThreadFunc func, void *ctx)
Add a demuxer to the scheduler.
Definition: ffmpeg_sched.c:680
input_packet_process
static int input_packet_process(Demuxer *d, AVPacket *pkt, unsigned *send_flags)
Definition: ffmpeg_demux.c:455
demux_thread_init
static int demux_thread_init(DemuxThreadContext *dt)
Definition: ffmpeg_demux.c:701
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:264
int64_t
long long int64_t
Definition: coverity.c:34
InputStream::user_set_discard
int user_set_discard
Definition: ffmpeg.h:446
DemuxStream::sch_idx_stream
int sch_idx_stream
Definition: ffmpeg_demux.c:49
OptionsContext::audio_ch_layouts
SpecifierOptList audio_ch_layouts
Definition: ffmpeg.h:153
ist_add
static int ist_add(const OptionsContext *o, Demuxer *d, AVStream *st, AVDictionary **opts_used)
Definition: ffmpeg_demux.c:1253
ist_iter
InputStream * ist_iter(InputStream *prev)
Definition: ffmpeg.c:376
av_frame_free
void av_frame_free(AVFrame **frame)
Free the frame and any dynamically allocated objects in it, e.g.
Definition: frame.c:70
DemuxStream::finished
int finished
Definition: ffmpeg_demux.c:63
InputFile::index
int index
Definition: ffmpeg.h:474
AVFrame
This structure describes decoded (raw) audio or video data.
Definition: frame.h:410
pixdesc.h
AVFormatContext::streams
AVStream ** streams
A list of all streams in the file.
Definition: avformat.h:1368
AVFrame::width
int width
Definition: frame.h:482
DECODER_FLAG_FRAMERATE_FORCED
@ DECODER_FLAG_FRAMERATE_FORCED
Definition: ffmpeg.h:392
AVPacketSideData
This structure stores auxiliary information for decoding, presenting, or otherwise processing the cod...
Definition: packet.h:390
OptionsContext::display_hflips
SpecifierOptList display_hflips
Definition: ffmpeg.h:217
DecoderOpts::par
const AVCodecParameters * par
Definition: ffmpeg.h:408
ifile_close
void ifile_close(InputFile **pf)
Definition: ffmpeg_demux.c:888
DemuxStream::streamcopy_needed
int streamcopy_needed
Definition: ffmpeg_demux.c:65
av_display_matrix_flip
void av_display_matrix_flip(int32_t matrix[9], int hflip, int vflip)
Flip the input matrix horizontally and/or vertically.
Definition: display.c:66
subtitle_codec_name
static const char * subtitle_codec_name
Definition: ffplay.c:340
AV_HWDEVICE_TYPE_NONE
@ AV_HWDEVICE_TYPE_NONE
Definition: hwcontext.h:28
OptionsContext::subtitle_disable
int subtitle_disable
Definition: ffmpeg.h:200
demux_stream_alloc
static DemuxStream * demux_stream_alloc(Demuxer *d, AVStream *st)
Definition: ffmpeg_demux.c:1228
OptionsContext::readrate_catchup
float readrate_catchup
Definition: ffmpeg.h:166
AVOption
AVOption.
Definition: opt.h:429
AVStream::avg_frame_rate
AVRational avg_frame_rate
Average framerate.
Definition: avformat.h:837
DecoderOpts::hwaccel_id
enum HWAccelID hwaccel_id
Definition: ffmpeg.h:411
InputStream::nb_filters
int nb_filters
Definition: ffmpeg.h:468
AVCodecParameters::framerate
AVRational framerate
Video only.
Definition: codec_par.h:156
av_hwdevice_find_type_by_name
enum AVHWDeviceType av_hwdevice_find_type_by_name(const char *name)
Look up an AVHWDeviceType by name.
Definition: hwcontext.c:106
ffmpeg.h
AV_LOG_VERBOSE
#define AV_LOG_VERBOSE
Detailed information.
Definition: log.h:225
float.h
DemuxStream::decoder_opts
AVDictionary * decoder_opts
Definition: ffmpeg_demux.c:86
AVFormatContext::programs
AVProgram ** programs
Definition: avformat.h:1501
av_hwdevice_iterate_types
enum AVHWDeviceType av_hwdevice_iterate_types(enum AVHWDeviceType prev)
Iterate over supported device types.
Definition: hwcontext.c:125
OptionsContext::bitexact
int bitexact
Definition: ffmpeg.h:196
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:557
ViewSpecifier
Definition: ffmpeg.h:128
AVCodecParameters::codec_tag
uint32_t codec_tag
Additional information about the codec (corresponds to the AVI FOURCC).
Definition: codec_par.h:59
AVDictionary
Definition: dict.c:34
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
av_read_frame
int av_read_frame(AVFormatContext *s, AVPacket *pkt)
Return the next frame of a stream.
Definition: demux.c:1556
AVFormatContext::video_codec_id
enum AVCodecID video_codec_id
Forced video codec_id.
Definition: avformat.h:1507
IFILTER_FLAG_AUTOROTATE
@ IFILTER_FLAG_AUTOROTATE
Definition: ffmpeg.h:262
OptionsContext::format
const char * format
Definition: ffmpeg.h:150
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:398
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
tf_sess_config.config
config
Definition: tf_sess_config.py:33
file_iformat
static const AVInputFormat * file_iformat
Definition: ffplay.c:305
DemuxStream::lag
int64_t lag
Definition: ffmpeg_demux.c:103
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:75
OptionsContext::frame_pix_fmts
SpecifierOptList frame_pix_fmts
Definition: ffmpeg.h:159
AVBSFContext
The bitstream filter state.
Definition: bsf.h:68
OptionsContext::canvas_sizes
SpecifierOptList canvas_sizes
Definition: ffmpeg.h:238
Demuxer::wallclock_start
int64_t wallclock_start
Definition: ffmpeg_demux.c:112
SpecifierOpt::i
int i
Definition: cmdutils.h:171
InputStream
Definition: ffmpeg.h:437
DecoderOpts::hwaccel_output_format
enum AVPixelFormat hwaccel_output_format
Definition: ffmpeg.h:414
debug_ts
int debug_ts
Definition: ffmpeg_opt.c:69
avformat_close_input
void avformat_close_input(AVFormatContext **s)
Close an opened input AVFormatContext.
Definition: demux.c:367
AVPacketSideData::size
size_t size
Definition: packet.h:392
AVFormatContext::interrupt_callback
AVIOInterruptCB interrupt_callback
Custom interrupt callbacks for the I/O layer.
Definition: avformat.h:1573
Demuxer
Definition: ffmpeg_demux.c:106
OptionsContext::rate_emu
int rate_emu
Definition: ffmpeg.h:164
CROP_CODEC
@ CROP_CODEC
Definition: ffmpeg.h:581
dts_delta_threshold
float dts_delta_threshold
Definition: ffmpeg_opt.c:55
DemuxStream::data_size
uint64_t data_size
Definition: ffmpeg_demux.c:97
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:503
OptionsContext::g
OptionGroup * g
Definition: ffmpeg.h:144
Demuxer::log_name
char log_name[32]
Definition: ffmpeg_demux.c:110
Decoder::frames_decoded
uint64_t frames_decoded
Definition: ffmpeg.h:432
Demuxer::nb_streams_finished
int nb_streams_finished
Definition: ffmpeg_demux.c:145
opt_match_per_stream_int
void opt_match_per_stream_int(void *logctx, const SpecifierOptList *sol, AVFormatContext *fc, AVStream *st, int *out)
dummy
int dummy
Definition: motion.c:66
AVProgram::discard
enum AVDiscard discard
selects which program to discard and which to feed to the caller
Definition: avformat.h:1227
DecoderOpts::log_parent
void * log_parent
Definition: ffmpeg.h:405
input_file_item_name
static const char * input_file_item_name(void *obj)
Definition: ffmpeg_demux.c:1605
AVDISCARD_NONE
@ AVDISCARD_NONE
discard nothing
Definition: defs.h:215
AVFrame::ch_layout
AVChannelLayout ch_layout
Channel layout of the audio data.
Definition: frame.h:819
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
pts
static int64_t pts
Definition: transcode_aac.c:644
OptionsContext
Definition: ffmpeg.h:143
AVBSFContext::par_out
AVCodecParameters * par_out
Parameters of the output stream.
Definition: bsf.h:96
av_opt_set
int av_opt_set(void *obj, const char *name, const char *val, int search_flags)
Definition: opt.c:835
do_pkt_dump
int do_pkt_dump
Definition: ffmpeg_opt.c:65
Demuxer::ts_offset_discont
int64_t ts_offset_discont
Extra timestamp offset added by discontinuity handling.
Definition: ffmpeg_demux.c:117
AVRational::num
int num
Numerator.
Definition: rational.h:59
Demuxer::f
InputFile f
Definition: ffmpeg_demux.c:107
Decoder::samples_decoded
uint64_t samples_decoded
Definition: ffmpeg.h:433
InputFile
Definition: ffmpeg.h:471
DemuxStream::nb_packets
uint64_t nb_packets
Definition: ffmpeg_demux.c:95
Demuxer::nb_streams_used
int nb_streams_used
Definition: ffmpeg_demux.c:144
OptionsContext::recording_time
int64_t recording_time
Definition: ffmpeg.h:189
av_frame_alloc
AVFrame * av_frame_alloc(void)
Allocate an AVFrame and set its fields to default values.
Definition: frame.c:58
AV_CODEC_ID_DVB_SUBTITLE
@ AV_CODEC_ID_DVB_SUBTITLE
Definition: codec_id.h:559
LATENCY_PROBE_DEMUX
@ LATENCY_PROBE_DEMUX
Definition: ffmpeg.h:99
OptionsContext::audio_disable
int audio_disable
Definition: ffmpeg.h:199
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:1336
avassert.h
pkt
AVPacket * pkt
Definition: movenc.c:60
AV_LOG_ERROR
#define AV_LOG_ERROR
Something went wrong and cannot losslessly be recovered.
Definition: log.h:209
ifile_open
int ifile_open(const OptionsContext *o, const char *filename, Scheduler *sch)
Definition: ffmpeg_demux.c:1634
AVInputFormat
Definition: avformat.h:548
AV_PKT_FLAG_CORRUPT
#define AV_PKT_FLAG_CORRUPT
The packet content is corrupted.
Definition: packet.h:595
OptionGroup::codec_opts
AVDictionary * codec_opts
Definition: cmdutils.h:343
av_dump_format
void av_dump_format(AVFormatContext *ic, int index, const char *url, int is_output)
Print detailed information about the input or output format, such as duration, bitrate,...
Definition: dump.c:845
OptionsContext::hwaccel_output_formats
SpecifierOptList hwaccel_output_formats
Definition: ffmpeg.h:177
SpecifierOptList::nb_opt
int nb_opt
Definition: cmdutils.h:181
CROP_DISABLED
@ CROP_DISABLED
Definition: ffmpeg.h:579
duration
int64_t duration
Definition: movenc.c:65
avformat_open_input
int avformat_open_input(AVFormatContext **ps, const char *url, const AVInputFormat *fmt, AVDictionary **options)
Open an input stream and read the header.
Definition: demux.c:217
AVCodecParameters::frame_size
int frame_size
Audio only.
Definition: codec_par.h:195
av_dict_get
AVDictionaryEntry * av_dict_get(const AVDictionary *m, const char *key, const AVDictionaryEntry *prev, int flags)
Get a dictionary entry with matching key.
Definition: dict.c:62
av_channel_layout_describe
int av_channel_layout_describe(const AVChannelLayout *channel_layout, char *buf, size_t buf_size)
Get a human-readable string describing the channel layout properties.
Definition: channel_layout.c:653
flags
#define flags(name, subs,...)
Definition: cbs_av1.c:503
HWACCEL_GENERIC
@ HWACCEL_GENERIC
Definition: ffmpeg.h:84
assert_file_overwrite
int assert_file_overwrite(const char *filename)
Definition: ffmpeg_opt.c:743
SpecifierOpt::specifier
char * specifier
Definition: cmdutils.h:165
AVCodecDescriptor
This struct describes the properties of a single codec described by an AVCodecID.
Definition: codec_desc.h:38
intreadwrite.h
AVFormatContext::video_codec
const struct AVCodec * video_codec
Forced video codec.
Definition: avformat.h:1825
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:76
Demuxer::readrate
float readrate
Definition: ffmpeg_demux.c:135
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:458
AVFormatContext::flags
int flags
Flags modifying the (de)muxer behaviour.
Definition: avformat.h:1451
AVCodecParameters::sample_aspect_ratio
AVRational sample_aspect_ratio
Video only.
Definition: codec_par.h:144
AVFormatContext::nb_programs
unsigned int nb_programs
Definition: avformat.h:1500
AVInputFormat::name
const char * name
A comma separated list of short names for the format.
Definition: avformat.h:553
dec_init
int dec_init(Decoder **pdec, Scheduler *sch, AVDictionary **dec_opts, const DecoderOpts *o, AVFrame *param_out)
Definition: ffmpeg_dec.c:1652
AVFormatContext::iformat
const struct AVInputFormat * iformat
The input container format.
Definition: avformat.h:1312
AVMEDIA_TYPE_AUDIO
@ AVMEDIA_TYPE_AUDIO
Definition: avutil.h:202
AVCodecParameters::width
int width
Video only.
Definition: codec_par.h:134
OptionsContext::hwaccel_devices
SpecifierOptList hwaccel_devices
Definition: ffmpeg.h:176
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:707
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:136
InputFilter
Definition: ffmpeg.h:352
DemuxStream::ts_scale
double ts_scale
Definition: ffmpeg_demux.c:52
av_assert0
#define av_assert0(cond)
assert() equivalent, that is always enabled.
Definition: avassert.h:40
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:668
AV_LOG_DEBUG
#define AV_LOG_DEBUG
Stuff which is only useful for libav* developers.
Definition: log.h:230
AVPacketSideData::data
uint8_t * data
Definition: packet.h:391
DemuxThreadContext
Definition: ffmpeg_demux.c:148
ctx
AVFormatContext * ctx
Definition: movenc.c:49
AVBSFContext::time_base_in
AVRational time_base_in
The timebase used for the timestamps of the input packets.
Definition: bsf.h:102
InputStream::filters
InputFilter ** filters
Definition: ffmpeg.h:467
demux_send
static int demux_send(Demuxer *d, DemuxThreadContext *dt, DemuxStream *ds, AVPacket *pkt, unsigned flags)
Definition: ffmpeg_demux.c:574
Demuxer::nb_streams_warn
int nb_streams_warn
Definition: ffmpeg_demux.c:133
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:236
DecoderOpts::hwaccel_device
char * hwaccel_device
Definition: ffmpeg.h:413
input_stream_item_name
static const char * input_stream_item_name(void *obj)
Definition: ffmpeg_demux.c:1214
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:116
OptionsContext::accurate_seek
int accurate_seek
Definition: ffmpeg.h:168
av_usleep
int av_usleep(unsigned usec)
Sleep for a period of time.
Definition: time.c:84
AVCodecParameters::nb_coded_side_data
int nb_coded_side_data
Amount of entries in coded_side_data.
Definition: codec_par.h:86
AVMEDIA_TYPE_DATA
@ AVMEDIA_TYPE_DATA
Opaque data information usually continuous.
Definition: avutil.h:203
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:564
AVFormatContext::data_codec
const struct AVCodec * data_codec
Forced data codec.
Definition: avformat.h:1849
SCH_DEC_IN
#define SCH_DEC_IN(decoder)
Definition: ffmpeg_sched.h:117
AV_ROUND_PASS_MINMAX
@ AV_ROUND_PASS_MINMAX
Flag telling rescaling functions to pass INT64_MIN/MAX through unchanged, avoiding special cases for ...
Definition: mathematics.h:159
Demuxer::duration
Timestamp duration
Definition: ffmpeg_demux.c:127
DemuxThreadContext::pkt_demux
AVPacket * pkt_demux
Definition: ffmpeg_demux.c:150
AV_PIX_FMT_MEDIACODEC
@ AV_PIX_FMT_MEDIACODEC
hardware decoding through MediaCodec
Definition: pixfmt.h:316
arg
const char * arg
Definition: jacosubdec.c:67
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:2785
OptionsContext::start_time
int64_t start_time
Definition: ffmpeg.h:147
AVDISCARD_ALL
@ AVDISCARD_ALL
discard all
Definition: defs.h:221
AVFormatContext
Format I/O context.
Definition: avformat.h:1300
DECODING_FOR_OST
#define DECODING_FOR_OST
Definition: ffmpeg_demux.c:56
AVFormatContext::audio_codec_id
enum AVCodecID audio_codec_id
Forced audio codec_id.
Definition: avformat.h:1513
OptionGroup::format_opts
AVDictionary * format_opts
Definition: cmdutils.h:344
opts
AVDictionary * opts
Definition: movenc.c:51
AVStream::codecpar
AVCodecParameters * codecpar
Codec parameters associated with this stream.
Definition: avformat.h:771
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:160
AVClass
Describe the class of an AVClass context structure.
Definition: log.h:75
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:787
NULL
#define NULL
Definition: coverity.c:32
Demuxer::readrate_catchup
float readrate_catchup
Definition: ffmpeg_demux.c:137
dec_request_view
int dec_request_view(Decoder *dec, const ViewSpecifier *vs, SchedulerNode *src)
Definition: ffmpeg_dec.c:1026
Decoder::decode_errors
uint64_t decode_errors
Definition: ffmpeg.h:434
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:633
InputStream::top_field_first
int top_field_first
Definition: ffmpeg.h:460
InputStream::st
AVStream * st
Definition: ffmpeg.h:445
avcodec_parameters_free
void avcodec_parameters_free(AVCodecParameters **ppar)
Free an AVCodecParameters instance and everything associated with it and write NULL to the supplied p...
Definition: codec_par.c:66
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:154
InputFile::start_time_effective
int64_t start_time_effective
Effective format start time based on enabled streams.
Definition: ffmpeg.h:482
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:1350
av_default_item_name
const char * av_default_item_name(void *ptr)
Return the context name.
Definition: log.c:239
Demuxer::recording_time
int64_t recording_time
Definition: ffmpeg_demux.c:120
parseutils.h
AVProgram::stream_index
unsigned int * stream_index
Definition: avformat.h:1228
AVStream::metadata
AVDictionary * metadata
Definition: avformat.h:828
OptionsContext::reinit_filters
SpecifierOptList reinit_filters
Definition: ffmpeg.h:234
AV_OPT_SEARCH_FAKE_OBJ
#define AV_OPT_SEARCH_FAKE_OBJ
The obj passed to av_opt_find() is fake – only a double pointer to AVClass instead of a required poin...
Definition: opt.h:613
OptionsContext::dump_attachment
SpecifierOptList dump_attachment
Definition: ffmpeg.h:174
InputStream::fix_sub_duration
int fix_sub_duration
Definition: ffmpeg.h:463
FrameData::wallclock
int64_t wallclock[LATENCY_PROBE_NB]
Definition: ffmpeg.h:675
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:338
OptionsContext::display_vflips
SpecifierOptList display_vflips
Definition: ffmpeg.h:218
DemuxThreadContext::pkt_bsf
AVPacket * pkt_bsf
Definition: ffmpeg_demux.c:152
InputFilterOptions
Definition: ffmpeg.h:269
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:143
AVCodecParameters::ch_layout
AVChannelLayout ch_layout
Audio only.
Definition: codec_par.h:180
OptionsContext::input_sync_ref
int input_sync_ref
Definition: ffmpeg.h:170
report_new_stream
static void report_new_stream(Demuxer *d, const AVPacket *pkt)
Definition: ffmpeg_demux.c:176
guess_input_channel_layout
static int guess_input_channel_layout(InputStream *ist, AVCodecParameters *par, int guess_layout_max)
Definition: ffmpeg_demux.c:1156
DECODER_FLAG_FIX_SUB_DURATION
@ DECODER_FLAG_FIX_SUB_DURATION
Definition: ffmpeg.h:387
c
Undefined Behavior In the C some operations are like signed integer dereferencing freed accessing outside allocated Undefined Behavior must not occur in a C it is not safe even if the output of undefined operations is unused The unsafety may seem nit picking but Optimizing compilers have in fact optimized code on the assumption that no undefined Behavior occurs Optimizing code based on wrong assumptions can and has in some cases lead to effects beyond the output of computations The signed integer overflow problem in speed critical code Code which is highly optimized and works with signed integers sometimes has the problem that often the output of the computation does not c
Definition: undefined.txt:32
AVCodecParameters::sample_rate
int sample_rate
Audio only.
Definition: codec_par.h:184
Demuxer::sch
Scheduler * sch
Definition: ffmpeg_demux.c:139
find_codec
int find_codec(void *logctx, const char *name, enum AVMediaType type, int encoder, const AVCodec **codec)
Definition: ffmpeg_opt.c:710
AVFormatContext::audio_codec
const struct AVCodec * audio_codec
Forced audio codec.
Definition: avformat.h:1833
InputStream::par
AVCodecParameters * par
Codec parameters - to be used by the decoding/streamcopy code.
Definition: ffmpeg.h:453
input_files
InputFile ** input_files
Definition: ffmpeg.c:104
error.h
Scheduler
Definition: ffmpeg_sched.c:275
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:657
avcodec_find_decoder
const AVCodec * avcodec_find_decoder(enum AVCodecID id)
Find a registered decoder with a matching codec ID.
Definition: allcodecs.c:1016
recast_media
int recast_media
Definition: ffmpeg_opt.c:86
AVCodecParameters::extradata_size
int extradata_size
Size of the extradata content in bytes.
Definition: codec_par.h:73
AVFormatContext::nb_streams
unsigned int nb_streams
Number of elements in AVFormatContext.streams.
Definition: avformat.h:1356
DemuxStream::dts
int64_t dts
dts of the last packet read for this stream (in AV_TIME_BASE units)
Definition: ffmpeg_demux.c:82
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:2534
av_opt_find
const AVOption * av_opt_find(void *obj, const char *name, const char *unit, int opt_flags, int search_flags)
Look for an option in an object.
Definition: opt.c:1991
OptionsContext::discard
SpecifierOptList discard
Definition: ffmpeg.h:245
IFILTER_FLAG_REINIT
@ IFILTER_FLAG_REINIT
Definition: ffmpeg.h:263
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:189
AVMediaType
AVMediaType
Definition: avutil.h:199
AVPacket::size
int size
Definition: packet.h:540
avformat_alloc_context
AVFormatContext * avformat_alloc_context(void)
Allocate an AVFormatContext.
Definition: options.c:162
AVDISCARD_DEFAULT
@ AVDISCARD_DEFAULT
discard useless packets like 0 size packets in avi
Definition: defs.h:216
AVChannelLayout
An AVChannelLayout holds information about the channel layout of audio data.
Definition: channel_layout.h:319
FFMPEG_OPT_TOP
#define FFMPEG_OPT_TOP
Definition: ffmpeg.h:57
DemuxStream::have_sub2video
int have_sub2video
Definition: ffmpeg_demux.c:66
av_bsf_send_packet
int av_bsf_send_packet(AVBSFContext *ctx, AVPacket *pkt)
Submit a packet for filtering.
Definition: bsf.c:202
DemuxStream::resume_pts
int64_t resume_pts
Definition: ffmpeg_demux.c:101
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:326
Demuxer::pkt_heartbeat
AVPacket * pkt_heartbeat
Definition: ffmpeg_demux.c:141
DemuxStream::decoding_needed
int decoding_needed
Definition: ffmpeg_demux.c:55
OptionsContext::apply_cropping
SpecifierOptList apply_cropping
Definition: ffmpeg.h:179
demux_thread_uninit
static void demux_thread_uninit(DemuxThreadContext *dt)
Definition: ffmpeg_demux.c:693
copy_ts
int copy_ts
Definition: ffmpeg_opt.c:66
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:248
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:149
input_file_class
static const AVClass input_file_class
Definition: ffmpeg_demux.c:1612
DECODING_FOR_FILTER
#define DECODING_FOR_FILTER
Definition: ffmpeg_demux.c:57
ist_use
int ist_use(InputStream *ist, int decoding_needed, const ViewSpecifier *vs, SchedulerNode *src)
Definition: ffmpeg_demux.c:910
AVFrame::format
int format
format of the frame, -1 if unknown or unset Values correspond to enum AVPixelFormat for video frames,...
Definition: frame.h:497
AVMEDIA_TYPE_UNKNOWN
@ AVMEDIA_TYPE_UNKNOWN
Usually treated as AVMEDIA_TYPE_DATA.
Definition: avutil.h:200
DemuxStream::bsf
AVBSFContext * bsf
Definition: ffmpeg_demux.c:92
AVStream::sample_aspect_ratio
AVRational sample_aspect_ratio
sample aspect ratio (0 if unknown)
Definition: avformat.h:826
OptionsContext::readrate_initial_burst
double readrate_initial_burst
Definition: ffmpeg.h:167
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:1467
AVPacket::dts
int64_t dts
Decompression timestamp in AVStream->time_base units; the time at which the packet is decompressed.
Definition: packet.h:538
avio_write
void avio_write(AVIOContext *s, const unsigned char *buf, int size)
Definition: aviobuf.c:201
OptionsContext::find_stream_info
int find_stream_info
Definition: ffmpeg.h:171
OptionsContext::display_rotations
SpecifierOptList display_rotations
Definition: ffmpeg.h:216
DemuxStream::autorotate
int autorotate
Definition: ffmpeg_demux.c:68
DemuxStream::sch_idx_dec
int sch_idx_dec
Definition: ffmpeg_demux.c:50
SpecifierOptList::opt
SpecifierOpt * opt
Definition: cmdutils.h:180
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:545
av_packet_alloc
AVPacket * av_packet_alloc(void)
Allocate an AVPacket and set its fields to default values.
Definition: packet.c:64
av_dict_free
void av_dict_free(AVDictionary **pm)
Free all the memory allocated for an AVDictionary struct and all keys and values.
Definition: dict.c:223
OptionsContext::ts_scale
SpecifierOptList ts_scale
Definition: ffmpeg.h:173
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:534
AV_LOG_INFO
#define AV_LOG_INFO
Standard information.
Definition: log.h:220
video_codec_name
static const char * video_codec_name
Definition: ffplay.c:341
DemuxStream::next_dts
int64_t next_dts
Definition: ffmpeg_demux.c:80
AVCodec::id
enum AVCodecID id
Definition: codec.h:201
CROP_CONTAINER
@ CROP_CONTAINER
Definition: ffmpeg.h:582
av_channel_layout_default
void av_channel_layout_default(AVChannelLayout *ch_layout, int nb_channels)
Get the default channel layout for a given number of channels.
Definition: channel_layout.c:839
avcodec_parameters_alloc
AVCodecParameters * avcodec_parameters_alloc(void)
Allocate a new AVCodecParameters and set its fields to default values (unknown/invalid/0).
Definition: codec_par.c:56
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:83
DemuxStream
Definition: ffmpeg_demux.c:43
av_parse_video_rate
int av_parse_video_rate(AVRational *rate, const char *arg)
Parse str and store the detected values in *rate.
Definition: parseutils.c:181
CROP_ALL
@ CROP_ALL
Definition: ffmpeg.h:580
DemuxStream::dec_name
char dec_name[16]
Definition: ffmpeg_demux.c:88
av_channel_layout_from_string
int av_channel_layout_from_string(AVChannelLayout *channel_layout, const char *str)
Initialize a channel layout from a given string description.
Definition: channel_layout.c:312
DemuxStream::apply_cropping
int apply_cropping
Definition: ffmpeg_demux.c:69
AV_CODEC_ID_NONE
@ AV_CODEC_ID_NONE
Definition: codec_id.h:50
i
#define i(width, name, range_min, range_max)
Definition: cbs_h2645.c:256
AVPacket::pts
int64_t pts
Presentation timestamp in AVStream->time_base units; the time at which the decompressed packet will b...
Definition: packet.h:532
OptionsContext::frame_rates
SpecifierOptList frame_rates
Definition: ffmpeg.h:156
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:1418
OptionsContext::codec_names
SpecifierOptList codec_names
Definition: ffmpeg.h:152
packet.h
demux_bsf_flush
static int demux_bsf_flush(Demuxer *d, DemuxThreadContext *dt)
Definition: ffmpeg_demux.c:643
AVFormatContext::subtitle_codec
const struct AVCodec * subtitle_codec
Forced subtitle codec.
Definition: avformat.h:1841
AVCodecParameters::height
int height
Definition: codec_par.h:135
OptionsContext::autorotate
SpecifierOptList autorotate
Definition: ffmpeg.h:178
AV_TIME_BASE
#define AV_TIME_BASE
Internal time base represented as integer.
Definition: avutil.h:254
DecoderOpts::time_base
AVRational time_base
Definition: ffmpeg.h:416
SHOW_TS_DEBUG
#define SHOW_TS_DEBUG(tag_)
OptionsContext::start_time_eof
int64_t start_time_eof
Definition: ffmpeg.h:148
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:70
Demuxer::have_audio_dec
int have_audio_dec
Definition: ffmpeg_demux.c:125
av_assert1
#define av_assert1(cond)
assert() equivalent, that does not lie in speed critical code.
Definition: avassert.h:56
delta
float delta
Definition: vorbis_enc_data.h:430
AVMEDIA_TYPE_ATTACHMENT
@ AVMEDIA_TYPE_ATTACHMENT
Opaque data information usually sparse.
Definition: avutil.h:205
DemuxStream::resume_wc
int64_t resume_wc
Definition: ffmpeg_demux.c:99
InputFile::ctx
AVFormatContext * ctx
Definition: ffmpeg.h:476
FFMIN
#define FFMIN(a, b)
Definition: macros.h:49
OptionsContext::hwaccels
SpecifierOptList hwaccels
Definition: ffmpeg.h:175
AVProgram
New fields can be added to the end with minor version bumps.
Definition: avformat.h:1224
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:266
SchedulerNode
Definition: ffmpeg_sched.h:103
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:307
AVBSFContext::time_base_out
AVRational time_base_out
The timebase used for the timestamps of the output packets.
Definition: bsf.h:108
AVCodecParameters::coded_side_data
AVPacketSideData * coded_side_data
Additional data associated with the entire stream.
Definition: codec_par.h:81
DemuxStream::discard
int discard
Definition: ffmpeg_demux.c:60
AVFMT_FLAG_NONBLOCK
#define AVFMT_FLAG_NONBLOCK
Do not block when reading packets from input.
Definition: avformat.h:1454
av_codec_iterate
const AVCodec * av_codec_iterate(void **opaque)
Iterate over all registered codecs.
Definition: allcodecs.c:967
sch_connect
int sch_connect(Scheduler *sch, SchedulerNode src, SchedulerNode dst)
Definition: ffmpeg_sched.c:919
ist_find_unused
InputStream * ist_find_unused(enum AVMediaType type)
Find an unused input stream of given type.
Definition: ffmpeg_demux.c:165
Timestamp::tb
AVRational tb
Definition: ffmpeg_utils.h:32
InputStream::decoder
Decoder * decoder
Definition: ffmpeg.h:454
AVStream::disposition
int disposition
Stream disposition - a combination of AV_DISPOSITION_* flags.
Definition: avformat.h:817
DemuxStream::codec_desc
const AVCodecDescriptor * codec_desc
Definition: ffmpeg_demux.c:84
ts_discontinuity_process
static void ts_discontinuity_process(Demuxer *d, InputStream *ist, AVPacket *pkt)
Definition: ffmpeg_demux.c:284
tag
uint32_t tag
Definition: movenc.c:1911
AVStream::id
int id
Format-specific stream ID.
Definition: avformat.h:760
AVFMT_FLAG_BITEXACT
#define AVFMT_FLAG_BITEXACT
When muxing, try to avoid writing any random/volatile data to the output.
Definition: avformat.h:1468
ret
ret
Definition: filter_design.txt:187
AVStream
Stream structure.
Definition: avformat.h:748
AV_LOG_FATAL
#define AV_LOG_FATAL
Something went wrong and recovery is not possible.
Definition: log.h:203
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:763
DemuxStream::wrap_correction_done
int wrap_correction_done
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:80
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:124
InputFile::streams
InputStream ** streams
Definition: ffmpeg.h:490
add_display_matrix_to_stream
static int add_display_matrix_to_stream(const OptionsContext *o, AVFormatContext *ctx, InputStream *ist)
Definition: ffmpeg_demux.c:1173
hwaccel
static const char * hwaccel
Definition: ffplay.c:353
DECODER_FLAG_TOP_FIELD_FIRST
@ DECODER_FLAG_TOP_FIELD_FIRST
Definition: ffmpeg.h:394
Demuxer::accurate_seek
int accurate_seek
Definition: ffmpeg_demux.c:121
avformat.h
HWAccelID
HWAccelID
Definition: ffmpeg.h:81
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:707
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:1109
OptionsContext::drop_changed
SpecifierOptList drop_changed
Definition: ffmpeg.h:235
check_avoptions_used
int check_avoptions_used(const AVDictionary *opts, const AVDictionary *opts_used, void *logctx, int decode)
Definition: ffmpeg.c:477
remove_avoptions
void remove_avoptions(AVDictionary **a, AVDictionary *b)
Definition: cmdutils.c:1520
AV_DICT_MATCH_CASE
#define AV_DICT_MATCH_CASE
Only get an entry with exact-case key match.
Definition: dict.h:74
AV_RL32
uint64_t_TMPL AV_WL64 unsigned int_TMPL AV_RL32
Definition: bytestream.h:92
av_get_pix_fmt
enum AVPixelFormat av_get_pix_fmt(const char *name)
Return the pixel format corresponding to name.
Definition: pixdesc.c:3273
AVFormatContext::data_codec_id
enum AVCodecID data_codec_id
Forced Data codec_id.
Definition: avformat.h:1525
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:482
AVStream::index
int index
stream index in AVFormatContext
Definition: avformat.h:754
IFILTER_FLAG_CROP
@ IFILTER_FLAG_CROP
Definition: ffmpeg.h:265
InputFile::class
const AVClass * class
Definition: ffmpeg.h:472
OptionsContext::audio_sample_rate
SpecifierOptList audio_sample_rate
Definition: ffmpeg.h:155
audio_codec_name
static const char * audio_codec_name
Definition: ffplay.c:339
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:2029
ts_discontinuity_detect
static void ts_discontinuity_detect(Demuxer *d, InputStream *ist, AVPacket *pkt)
Definition: ffmpeg_demux.c:216
PKT_OPAQUE_SUB_HEARTBEAT
@ PKT_OPAQUE_SUB_HEARTBEAT
Definition: ffmpeg.h:94
AVInputFormat::flags
int flags
Can use flags: AVFMT_NOFILE, AVFMT_NEEDNUMBER, AVFMT_SHOW_IDS, AVFMT_NOTIMESTAMPS,...
Definition: avformat.h:567
AVRational::den
int den
Denominator.
Definition: rational.h:60
InputStream::file
struct InputFile * file
Definition: ffmpeg.h:441
SpecifierOpt::str
uint8_t * str
Definition: cmdutils.h:170
AV_PIX_FMT_NONE
@ AV_PIX_FMT_NONE
Definition: pixfmt.h:72
AV_OPT_TYPE_INT
@ AV_OPT_TYPE_INT
Underlying C type is int.
Definition: opt.h:259
av_channel_layout_uninit
void av_channel_layout_uninit(AVChannelLayout *channel_layout)
Free any allocated data in the channel layout and reset the channel count to 0.
Definition: channel_layout.c:442
avformat_free_context
void avformat_free_context(AVFormatContext *s)
Free an AVFormatContext and all its streams.
Definition: avformat.c:149
IFILTER_FLAG_CFR
@ IFILTER_FLAG_CFR
Definition: ffmpeg.h:264
OptionsContext::frame_sizes
SpecifierOptList frame_sizes
Definition: ffmpeg.h:158
OptionsContext::video_disable
int video_disable
Definition: ffmpeg.h:198
ds_from_ist
static DemuxStream * ds_from_ist(InputStream *ist)
Definition: ffmpeg_demux.c:155
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:144
demux_alloc
static Demuxer * demux_alloc(void)
Definition: ffmpeg_demux.c:1619
AVFormatContext::duration
int64_t duration
Duration of the stream, in AV_TIME_BASE fractional seconds.
Definition: avformat.h:1435
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:541
GROW_ARRAY
#define GROW_ARRAY(array, nb_elems)
Definition: cmdutils.h:532
HWACCEL_NONE
@ HWACCEL_NONE
Definition: ffmpeg.h:82
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:836
ist_dts_update
static int ist_dts_update(DemuxStream *ds, AVPacket *pkt, FrameData *fd)
Definition: ffmpeg_demux.c:304
InputFile::ts_offset
int64_t ts_offset
Definition: ffmpeg.h:483
av_channel_layout_copy
int av_channel_layout_copy(AVChannelLayout *dst, const AVChannelLayout *src)
Make a copy of a channel layout.
Definition: channel_layout.c:449
av_log_once
void av_log_once(void *avcl, int initial_level, int subsequent_level, int *state, const char *fmt,...)
Definition: log.c:448
av_dict_set_int
int av_dict_set_int(AVDictionary **pm, const char *key, int64_t value, int flags)
Convenience wrapper for av_dict_set() that converts the value to a string and stores it.
Definition: dict.c:167
OptionsContext::codec_tags
SpecifierOptList codec_tags
Definition: ffmpeg.h:209
DecoderOpts::flags
int flags
Definition: ffmpeg.h:402
av_strdup
char * av_strdup(const char *s)
Duplicate a string.
Definition: mem.c:272
AV_OPT_FLAG_DECODING_PARAM
#define AV_OPT_FLAG_DECODING_PARAM
A generic parameter which can be set by the user for demuxing or decoding.
Definition: opt.h:356
AVMEDIA_TYPE_VIDEO
@ AVMEDIA_TYPE_VIDEO
Definition: avutil.h:201
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:67
AVFMT_TS_DISCONT
#define AVFMT_TS_DISCONT
Format allows timestamp discontinuities.
Definition: avformat.h:481
mem.h
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:491
DECODER_FLAG_TS_UNRELIABLE
@ DECODER_FLAG_TS_UNRELIABLE
Definition: ffmpeg.h:389
AVCodecParameters::video_delay
int video_delay
Video only.
Definition: codec_par.h:175
DemuxStream::log_name
char log_name[32]
Definition: ffmpeg_demux.c:47
DecoderOpts::codec
const AVCodec * codec
Definition: ffmpeg.h:407
InputStream::class
const AVClass * class
Definition: ffmpeg.h:438
InputStream::index
int index
Definition: ffmpeg.h:443
readrate_sleep
static void readrate_sleep(Demuxer *d)
Definition: ffmpeg_demux.c:499
ffmpeg_sched.h
AVDictionaryEntry
Definition: dict.h:89
Demuxer::max_pts
Timestamp max_pts
Definition: ffmpeg_demux.c:130
DemuxStream::dec_opts
DecoderOpts dec_opts
Definition: ffmpeg_demux.c:87
stdin_interaction
int stdin_interaction
Definition: ffmpeg_opt.c:73
do_hex_dump
int do_hex_dump
Definition: ffmpeg_opt.c:64
AVCodecParameters::codec_id
enum AVCodecID codec_id
Specific type of the encoded data (the codec used).
Definition: codec_par.h:55
AVPacket
This structure stores compressed data.
Definition: packet.h:516
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:1011
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:88
AVPacket::pos
int64_t pos
byte position in stream, -1 if unknown
Definition: packet.h:559
packet_data
FrameData * packet_data(AVPacket *pkt)
Definition: ffmpeg.c:465
OptionsContext::data_disable
int data_disable
Definition: ffmpeg.h:201
int32_t
int32_t
Definition: audioconvert.c:56
ist_free
static void ist_free(InputStream **pist)
Definition: ffmpeg_demux.c:864
DemuxStream::reinit_filters
int reinit_filters
Definition: ffmpeg_demux.c:67
timestamp.h
Demuxer::min_pts
Timestamp min_pts
Definition: ffmpeg_demux.c:129
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:364
avio_close
int avio_close(AVIOContext *s)
Close the resource accessed by the AVIOContext s and free it.
Definition: avio.c:616
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:1425
DecoderOpts::framerate
AVRational framerate
Definition: ffmpeg.h:420
dts_error_threshold
float dts_error_threshold
Definition: ffmpeg_opt.c:56
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:345
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:121
avcodec_descriptor_get
const AVCodecDescriptor * avcodec_descriptor_get(enum AVCodecID id)
Definition: codec_desc.c:3780
do_send
static int do_send(Demuxer *d, DemuxStream *ds, AVPacket *pkt, unsigned flags, const char *pkt_desc)
Definition: ffmpeg_demux.c:545
Demuxer::last_ts
int64_t last_ts
Definition: ffmpeg_demux.c:118
DemuxStream::decoded_params
AVFrame * decoded_params
Definition: ffmpeg_demux.c:90
AVDictionaryEntry::value
char * value
Definition: dict.h:91
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:163
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:74
InputFile::nb_streams
int nb_streams
Definition: ffmpeg.h:491
OptionsContext::guess_layout_max
SpecifierOptList guess_layout_max
Definition: ffmpeg.h:243
AVStream::pts_wrap_bits
int pts_wrap_bits
Number of bits in timestamps.
Definition: avformat.h:923
dump_attachment
static int dump_attachment(InputStream *ist, const char *filename)
Definition: ffmpeg_demux.c:1567
AVERROR_PROTOCOL_NOT_FOUND
#define AVERROR_PROTOCOL_NOT_FOUND
Protocol not found.
Definition: error.h:65
AV_OPT_TYPE_CONST
@ AV_OPT_TYPE_CONST
Special option type for declaring named constants.
Definition: opt.h:299
InputStream::dec
const AVCodec * dec
Definition: ffmpeg.h:455
snprintf
#define snprintf
Definition: snprintf.h:34
DecoderOpts::hwaccel_device_type
enum AVHWDeviceType hwaccel_device_type
Definition: ffmpeg.h:412
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:208
input_thread
static int input_thread(void *arg)
Definition: ffmpeg_demux.c:716
src
#define src
Definition: vp8dsp.c:248
AVInputFormat::priv_class
const AVClass * priv_class
AVClass for the private context.
Definition: avformat.h:578
avcodec_parameters_copy
int avcodec_parameters_copy(AVCodecParameters *dst, const AVCodecParameters *src)
Copy the contents of src to dst.
Definition: codec_par.c:106
AVPacket::time_base
AVRational time_base
Time base of the packet's timestamps.
Definition: packet.h:583
OptionsContext::top_field_first
SpecifierOptList top_field_first
Definition: ffmpeg.h:224
OptionsContext::loop
int loop
Definition: ffmpeg.h:163
thread_set_name
static void thread_set_name(InputFile *f)
Definition: ffmpeg_demux.c:686
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:1519
DecoderOpts::name
char * name
Definition: ffmpeg.h:404