FFmpeg
ffmpeg_demux.c
Go to the documentation of this file.
1 /*
2  * This file is part of FFmpeg.
3  *
4  * FFmpeg is free software; you can redistribute it and/or
5  * modify it under the terms of the GNU Lesser General Public
6  * License as published by the Free Software Foundation; either
7  * version 2.1 of the License, or (at your option) any later version.
8  *
9  * FFmpeg is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12  * Lesser General Public License for more details.
13  *
14  * You should have received a copy of the GNU Lesser General Public
15  * License along with FFmpeg; if not, write to the Free Software
16  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
17  */
18 
19 #include <float.h>
20 #include <stdint.h>
21 
22 #include "ffmpeg.h"
23 #include "ffmpeg_utils.h"
24 
25 #include "libavutil/avassert.h"
26 #include "libavutil/avstring.h"
27 #include "libavutil/display.h"
28 #include "libavutil/error.h"
29 #include "libavutil/intreadwrite.h"
30 #include "libavutil/opt.h"
31 #include "libavutil/parseutils.h"
32 #include "libavutil/pixdesc.h"
33 #include "libavutil/time.h"
34 #include "libavutil/timestamp.h"
35 #include "libavutil/thread.h"
37 
38 #include "libavcodec/packet.h"
39 
40 #include "libavformat/avformat.h"
41 
42 static const char *const opt_name_discard[] = {"discard", NULL};
43 static const char *const opt_name_reinit_filters[] = {"reinit_filter", NULL};
44 static const char *const opt_name_fix_sub_duration[] = {"fix_sub_duration", NULL};
45 static const char *const opt_name_canvas_sizes[] = {"canvas_size", NULL};
46 static const char *const opt_name_guess_layout_max[] = {"guess_layout_max", NULL};
47 static const char *const opt_name_ts_scale[] = {"itsscale", NULL};
48 static const char *const opt_name_hwaccels[] = {"hwaccel", NULL};
49 static const char *const opt_name_hwaccel_devices[] = {"hwaccel_device", NULL};
50 static const char *const opt_name_hwaccel_output_formats[] = {"hwaccel_output_format", NULL};
51 static const char *const opt_name_autorotate[] = {"autorotate", NULL};
52 static const char *const opt_name_display_rotations[] = {"display_rotation", NULL};
53 static const char *const opt_name_display_hflips[] = {"display_hflip", NULL};
54 static const char *const opt_name_display_vflips[] = {"display_vflip", NULL};
55 
56 typedef struct DemuxStream {
58 
59  // name used for logging
60  char log_name[32];
61 
62  double ts_scale;
63 
65 
68  ///< dts of the first packet read for this stream (in AV_TIME_BASE units)
69  int64_t first_dts;
70 
71  /* predicted dts of the next packet read for this stream or (when there are
72  * several frames in a packet) of the next frame in current packet (in AV_TIME_BASE units) */
73  int64_t next_dts;
74  ///< dts of the last packet read for this stream (in AV_TIME_BASE units)
75  int64_t dts;
76 
77  /* number of packets successfully read for this stream */
78  uint64_t nb_packets;
79  // combined size of all the packets read
80  uint64_t data_size;
81 } DemuxStream;
82 
83 typedef struct Demuxer {
85 
86  // name used for logging
87  char log_name[32];
88 
89  int64_t wallclock_start;
90 
91  /**
92  * Extra timestamp offset added by discontinuity handling.
93  */
95  int64_t last_ts;
96 
97  /* number of times input stream should be looped */
98  int loop;
99  /* duration of the looped segment of the input file */
101  /* pts with the smallest/largest values ever seen */
104 
105  /* number of streams that the user was warned of */
107 
109 
114 
116 } Demuxer;
117 
118 typedef struct DemuxMsg {
120  int looping;
121 } DemuxMsg;
122 
124 {
125  return (DemuxStream*)ist;
126 }
127 
129 {
130  return (Demuxer*)f;
131 }
132 
134 {
135  for (InputStream *ist = ist_iter(NULL); ist; ist = ist_iter(ist)) {
136  if (ist->par->codec_type == type && ist->discard &&
137  ist->user_set_discard != AVDISCARD_ALL)
138  return ist;
139  }
140  return NULL;
141 }
142 
143 static void report_new_stream(Demuxer *d, const AVPacket *pkt)
144 {
145  AVStream *st = d->f.ctx->streams[pkt->stream_index];
146 
147  if (pkt->stream_index < d->nb_streams_warn)
148  return;
150  "New %s stream with index %d at pos:%"PRId64" and DTS:%ss\n",
153  d->nb_streams_warn = pkt->stream_index + 1;
154 }
155 
156 static int seek_to_start(Demuxer *d)
157 {
158  InputFile *ifile = &d->f;
159  AVFormatContext *is = ifile->ctx;
160  int ret;
161 
162  ret = avformat_seek_file(is, -1, INT64_MIN, is->start_time, is->start_time, 0);
163  if (ret < 0)
164  return ret;
165 
166  if (ifile->audio_ts_queue_size) {
167  int got_ts = 0;
168 
169  while (got_ts < ifile->audio_ts_queue_size) {
170  Timestamp ts;
172  if (ret < 0)
173  return ret;
174  got_ts++;
175 
176  if (d->max_pts.ts == AV_NOPTS_VALUE ||
177  av_compare_ts(d->max_pts.ts, d->max_pts.tb, ts.ts, ts.tb) < 0)
178  d->max_pts = ts;
179  }
180  }
181 
182  if (d->max_pts.ts != AV_NOPTS_VALUE) {
183  int64_t min_pts = d->min_pts.ts == AV_NOPTS_VALUE ? 0 : d->min_pts.ts;
184  d->duration.ts = d->max_pts.ts - av_rescale_q(min_pts, d->min_pts.tb, d->max_pts.tb);
185  }
186  d->duration.tb = d->max_pts.tb;
187 
188  if (d->loop > 0)
189  d->loop--;
190 
191  return ret;
192 }
193 
195  AVPacket *pkt)
196 {
197  InputFile *ifile = &d->f;
198  DemuxStream *ds = ds_from_ist(ist);
199  const int fmt_is_discont = ifile->ctx->iformat->flags & AVFMT_TS_DISCONT;
200  int disable_discontinuity_correction = copy_ts;
201  int64_t pkt_dts = av_rescale_q_rnd(pkt->dts, pkt->time_base, AV_TIME_BASE_Q,
203 
204  if (copy_ts && ds->next_dts != AV_NOPTS_VALUE &&
205  fmt_is_discont && ist->st->pts_wrap_bits < 60) {
206  int64_t wrap_dts = av_rescale_q_rnd(pkt->dts + (1LL<<ist->st->pts_wrap_bits),
209  if (FFABS(wrap_dts - ds->next_dts) < FFABS(pkt_dts - ds->next_dts)/10)
210  disable_discontinuity_correction = 0;
211  }
212 
213  if (ds->next_dts != AV_NOPTS_VALUE && !disable_discontinuity_correction) {
214  int64_t delta = pkt_dts - ds->next_dts;
215  if (fmt_is_discont) {
216  if (FFABS(delta) > 1LL * dts_delta_threshold * AV_TIME_BASE ||
217  pkt_dts + AV_TIME_BASE/10 < ds->dts) {
218  d->ts_offset_discont -= delta;
219  av_log(ist, AV_LOG_WARNING,
220  "timestamp discontinuity "
221  "(stream id=%d): %"PRId64", new offset= %"PRId64"\n",
222  ist->st->id, delta, d->ts_offset_discont);
224  if (pkt->pts != AV_NOPTS_VALUE)
226  }
227  } else {
228  if (FFABS(delta) > 1LL * dts_error_threshold * AV_TIME_BASE) {
230  "DTS %"PRId64", next:%"PRId64" st:%d invalid dropping\n",
231  pkt->dts, ds->next_dts, pkt->stream_index);
233  }
234  if (pkt->pts != AV_NOPTS_VALUE){
235  int64_t pkt_pts = av_rescale_q(pkt->pts, pkt->time_base, AV_TIME_BASE_Q);
236  delta = pkt_pts - ds->next_dts;
237  if (FFABS(delta) > 1LL * dts_error_threshold * AV_TIME_BASE) {
239  "PTS %"PRId64", next:%"PRId64" invalid dropping st:%d\n",
240  pkt->pts, ds->next_dts, pkt->stream_index);
242  }
243  }
244  }
245  } else if (ds->next_dts == AV_NOPTS_VALUE && !copy_ts &&
246  fmt_is_discont && d->last_ts != AV_NOPTS_VALUE) {
247  int64_t delta = pkt_dts - d->last_ts;
248  if (FFABS(delta) > 1LL * dts_delta_threshold * AV_TIME_BASE) {
249  d->ts_offset_discont -= delta;
251  "Inter stream timestamp discontinuity %"PRId64", new offset= %"PRId64"\n",
252  delta, d->ts_offset_discont);
254  if (pkt->pts != AV_NOPTS_VALUE)
256  }
257  }
258 
259  d->last_ts = av_rescale_q(pkt->dts, pkt->time_base, AV_TIME_BASE_Q);
260 }
261 
263  AVPacket *pkt)
264 {
265  int64_t offset = av_rescale_q(d->ts_offset_discont, AV_TIME_BASE_Q,
266  pkt->time_base);
267 
268  // apply previously-detected timestamp-discontinuity offset
269  // (to all streams, not just audio/video)
270  if (pkt->dts != AV_NOPTS_VALUE)
271  pkt->dts += offset;
272  if (pkt->pts != AV_NOPTS_VALUE)
273  pkt->pts += offset;
274 
275  // detect timestamp discontinuities for audio/video
276  if ((ist->par->codec_type == AVMEDIA_TYPE_VIDEO ||
277  ist->par->codec_type == AVMEDIA_TYPE_AUDIO) &&
278  pkt->dts != AV_NOPTS_VALUE)
280 }
281 
283 {
284  InputStream *ist = &ds->ist;
285  const AVCodecParameters *par = ist->par;
286 
287  if (!ds->saw_first_ts) {
288  ds->first_dts =
289  ds->dts = ist->st->avg_frame_rate.num ? - ist->par->video_delay * AV_TIME_BASE / av_q2d(ist->st->avg_frame_rate) : 0;
290  if (pkt->pts != AV_NOPTS_VALUE) {
291  ds->first_dts =
293  }
294  ds->saw_first_ts = 1;
295  }
296 
297  if (ds->next_dts == AV_NOPTS_VALUE)
298  ds->next_dts = ds->dts;
299 
300  if (pkt->dts != AV_NOPTS_VALUE)
302 
303  ds->dts = ds->next_dts;
304  switch (par->codec_type) {
305  case AVMEDIA_TYPE_AUDIO:
306  av_assert1(pkt->duration >= 0);
307  if (par->sample_rate) {
308  ds->next_dts += ((int64_t)AV_TIME_BASE * par->frame_size) /
309  par->sample_rate;
310  } else {
312  }
313  break;
314  case AVMEDIA_TYPE_VIDEO:
315  if (ist->framerate.num) {
316  // TODO: Remove work-around for c99-to-c89 issue 7
317  AVRational time_base_q = AV_TIME_BASE_Q;
318  int64_t next_dts = av_rescale_q(ds->next_dts, time_base_q, av_inv_q(ist->framerate));
319  ds->next_dts = av_rescale_q(next_dts + 1, av_inv_q(ist->framerate), time_base_q);
320  } else if (pkt->duration) {
322  } else if (ist->par->framerate.num != 0) {
323  AVRational field_rate = av_mul_q(ist->par->framerate,
324  (AVRational){ 2, 1 });
325  int fields = 2;
326 
327  if (ist->codec_desc &&
329  av_stream_get_parser(ist->st))
331 
332  ds->next_dts += av_rescale_q(fields, av_inv_q(field_rate), AV_TIME_BASE_Q);
333  }
334  break;
335  }
336 
338  if (ds->streamcopy_needed) {
339  DemuxPktData *pd;
340 
341  pkt->opaque_ref = av_buffer_allocz(sizeof(*pd));
342  if (!pkt->opaque_ref)
343  return AVERROR(ENOMEM);
344  pd = (DemuxPktData*)pkt->opaque_ref->data;
345 
346  pd->dts_est = ds->dts;
347  }
348 
349  return 0;
350 }
351 
352 static int ts_fixup(Demuxer *d, AVPacket *pkt)
353 {
354  InputFile *ifile = &d->f;
355  InputStream *ist = ifile->streams[pkt->stream_index];
356  DemuxStream *ds = ds_from_ist(ist);
357  const int64_t start_time = ifile->start_time_effective;
358  int64_t duration;
359  int ret;
360 
361  pkt->time_base = ist->st->time_base;
362 
363 #define SHOW_TS_DEBUG(tag_) \
364  if (debug_ts) { \
365  av_log(ist, AV_LOG_INFO, "%s -> ist_index:%d:%d type:%s " \
366  "pkt_pts:%s pkt_pts_time:%s pkt_dts:%s pkt_dts_time:%s duration:%s duration_time:%s\n", \
367  tag_, ifile->index, pkt->stream_index, \
368  av_get_media_type_string(ist->st->codecpar->codec_type), \
369  av_ts2str(pkt->pts), av_ts2timestr(pkt->pts, &pkt->time_base), \
370  av_ts2str(pkt->dts), av_ts2timestr(pkt->dts, &pkt->time_base), \
371  av_ts2str(pkt->duration), av_ts2timestr(pkt->duration, &pkt->time_base)); \
372  }
373 
374  SHOW_TS_DEBUG("demuxer");
375 
377  ist->st->pts_wrap_bits < 64) {
378  int64_t stime, stime2;
379 
381  stime2= stime + (1ULL<<ist->st->pts_wrap_bits);
382  ds->wrap_correction_done = 1;
383 
384  if(stime2 > stime && pkt->dts != AV_NOPTS_VALUE && pkt->dts > stime + (1LL<<(ist->st->pts_wrap_bits-1))) {
385  pkt->dts -= 1ULL<<ist->st->pts_wrap_bits;
386  ds->wrap_correction_done = 0;
387  }
388  if(stime2 > stime && pkt->pts != AV_NOPTS_VALUE && pkt->pts > stime + (1LL<<(ist->st->pts_wrap_bits-1))) {
389  pkt->pts -= 1ULL<<ist->st->pts_wrap_bits;
390  ds->wrap_correction_done = 0;
391  }
392  }
393 
394  if (pkt->dts != AV_NOPTS_VALUE)
396  if (pkt->pts != AV_NOPTS_VALUE)
398 
399  if (pkt->pts != AV_NOPTS_VALUE)
400  pkt->pts *= ds->ts_scale;
401  if (pkt->dts != AV_NOPTS_VALUE)
402  pkt->dts *= ds->ts_scale;
403 
404  duration = av_rescale_q(d->duration.ts, d->duration.tb, pkt->time_base);
405  if (pkt->pts != AV_NOPTS_VALUE) {
406  // audio decoders take precedence for estimating total file duration
407  int64_t pkt_duration = ifile->audio_ts_queue_size ? 0 : pkt->duration;
408 
409  pkt->pts += duration;
410 
411  // update max/min pts that will be used to compute total file duration
412  // when using -stream_loop
413  if (d->max_pts.ts == AV_NOPTS_VALUE ||
414  av_compare_ts(d->max_pts.ts, d->max_pts.tb,
415  pkt->pts + pkt_duration, pkt->time_base) < 0) {
416  d->max_pts = (Timestamp){ .ts = pkt->pts + pkt_duration,
417  .tb = pkt->time_base };
418  }
419  if (d->min_pts.ts == AV_NOPTS_VALUE ||
420  av_compare_ts(d->min_pts.ts, d->min_pts.tb,
421  pkt->pts, pkt->time_base) > 0) {
422  d->min_pts = (Timestamp){ .ts = pkt->pts,
423  .tb = pkt->time_base };
424  }
425  }
426 
427  if (pkt->dts != AV_NOPTS_VALUE)
428  pkt->dts += duration;
429 
430  SHOW_TS_DEBUG("demuxer+tsfixup");
431 
432  // detect and try to correct for timestamp discontinuities
434 
435  // update estimated/predicted dts
436  ret = ist_dts_update(ds, pkt);
437  if (ret < 0)
438  return ret;
439 
440  return 0;
441 }
442 
443 // process an input packet into a message to send to the consumer thread
444 // src is always cleared by this function
446 {
447  InputFile *f = &d->f;
448  InputStream *ist = f->streams[src->stream_index];
449  DemuxStream *ds = ds_from_ist(ist);
450  AVPacket *pkt;
451  int ret = 0;
452 
453  pkt = av_packet_alloc();
454  if (!pkt) {
456  return AVERROR(ENOMEM);
457  }
459 
460  ret = ts_fixup(d, pkt);
461  if (ret < 0)
462  goto fail;
463 
464  ds->data_size += pkt->size;
465  ds->nb_packets++;
466 
467  if (debug_ts) {
468  av_log(NULL, 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",
469  f->index, pkt->stream_index,
476  }
477 
478  msg->pkt = pkt;
479  pkt = NULL;
480 
481 fail:
483 
484  return ret;
485 }
486 
487 static void readrate_sleep(Demuxer *d)
488 {
489  InputFile *f = &d->f;
490  int64_t file_start = copy_ts * (
491  (f->start_time_effective != AV_NOPTS_VALUE ? f->start_time_effective * !start_at_zero : 0) +
492  (f->start_time != AV_NOPTS_VALUE ? f->start_time : 0)
493  );
494  int64_t burst_until = AV_TIME_BASE * d->readrate_initial_burst;
495  for (int i = 0; i < f->nb_streams; i++) {
496  InputStream *ist = f->streams[i];
497  DemuxStream *ds = ds_from_ist(ist);
498  int64_t stream_ts_offset, pts, now;
499  stream_ts_offset = FFMAX(ds->first_dts != AV_NOPTS_VALUE ? ds->first_dts : 0, file_start);
500  pts = av_rescale(ds->dts, 1000000, AV_TIME_BASE);
501  now = (av_gettime_relative() - d->wallclock_start) * f->readrate + stream_ts_offset;
502  if (pts - burst_until > now)
503  av_usleep(pts - burst_until - now);
504  }
505 }
506 
508 {
509  for (int j = 0; j < ifile->ctx->nb_programs; j++) {
510  AVProgram *p = ifile->ctx->programs[j];
511  int discard = AVDISCARD_ALL;
512 
513  for (int k = 0; k < p->nb_stream_indexes; k++)
514  if (!ifile->streams[p->stream_index[k]]->discard) {
515  discard = AVDISCARD_DEFAULT;
516  break;
517  }
518  p->discard = discard;
519  }
520 }
521 
523 {
524  char name[16];
525  snprintf(name, sizeof(name), "dmx%d:%s", f->index, f->ctx->iformat->name);
527 }
528 
529 static void *input_thread(void *arg)
530 {
531  Demuxer *d = arg;
532  InputFile *f = &d->f;
533  AVPacket *pkt;
534  unsigned flags = d->non_blocking ? AV_THREAD_MESSAGE_NONBLOCK : 0;
535  int ret = 0;
536 
537  pkt = av_packet_alloc();
538  if (!pkt) {
539  ret = AVERROR(ENOMEM);
540  goto finish;
541  }
542 
544 
546 
547  d->wallclock_start = av_gettime_relative();
548 
549  while (1) {
550  DemuxMsg msg = { NULL };
551 
552  ret = av_read_frame(f->ctx, pkt);
553 
554  if (ret == AVERROR(EAGAIN)) {
555  av_usleep(10000);
556  continue;
557  }
558  if (ret < 0) {
559  if (d->loop) {
560  /* signal looping to the consumer thread */
561  msg.looping = 1;
562  ret = av_thread_message_queue_send(d->in_thread_queue, &msg, 0);
563  if (ret >= 0)
564  ret = seek_to_start(d);
565  if (ret >= 0)
566  continue;
567 
568  /* fallthrough to the error path */
569  }
570 
571  if (ret == AVERROR_EOF)
572  av_log(d, AV_LOG_VERBOSE, "EOF while reading input\n");
573  else
574  av_log(d, AV_LOG_ERROR, "Error during demuxing: %s\n",
575  av_err2str(ret));
576 
577  break;
578  }
579 
580  if (do_pkt_dump) {
582  f->ctx->streams[pkt->stream_index]);
583  }
584 
585  /* the following test is needed in case new streams appear
586  dynamically in stream : we ignore them */
587  if (pkt->stream_index >= f->nb_streams ||
588  f->streams[pkt->stream_index]->discard) {
591  continue;
592  }
593 
594  if (pkt->flags & AV_PKT_FLAG_CORRUPT) {
596  "corrupt input packet in stream %d\n",
597  pkt->stream_index);
598  if (exit_on_error) {
601  break;
602  }
603  }
604 
605  ret = input_packet_process(d, &msg, pkt);
606  if (ret < 0)
607  break;
608 
609  if (f->readrate)
610  readrate_sleep(d);
611 
612  ret = av_thread_message_queue_send(d->in_thread_queue, &msg, flags);
613  if (flags && ret == AVERROR(EAGAIN)) {
614  flags = 0;
615  ret = av_thread_message_queue_send(d->in_thread_queue, &msg, flags);
617  "Thread message queue blocking; consider raising the "
618  "thread_queue_size option (current value: %d)\n",
619  d->thread_queue_size);
620  }
621  if (ret < 0) {
622  if (ret != AVERROR_EOF)
624  "Unable to send packet to main thread: %s\n",
625  av_err2str(ret));
626  av_packet_free(&msg.pkt);
627  break;
628  }
629  }
630 
631 finish:
632  av_assert0(ret < 0);
633  av_thread_message_queue_set_err_recv(d->in_thread_queue, ret);
634 
636 
637  av_log(d, AV_LOG_VERBOSE, "Terminating demuxer thread\n");
638 
639  return NULL;
640 }
641 
642 static void thread_stop(Demuxer *d)
643 {
644  InputFile *f = &d->f;
645  DemuxMsg msg;
646 
647  if (!d->in_thread_queue)
648  return;
650  while (av_thread_message_queue_recv(d->in_thread_queue, &msg, 0) >= 0)
651  av_packet_free(&msg.pkt);
652 
653  pthread_join(d->thread, NULL);
654  av_thread_message_queue_free(&d->in_thread_queue);
655  av_thread_message_queue_free(&f->audio_ts_queue);
656 }
657 
658 static int thread_start(Demuxer *d)
659 {
660  int ret;
661  InputFile *f = &d->f;
662 
663  if (d->thread_queue_size <= 0)
664  d->thread_queue_size = (nb_input_files > 1 ? 8 : 1);
665 
666  if (nb_input_files > 1 &&
667  (f->ctx->pb ? !f->ctx->pb->seekable :
668  strcmp(f->ctx->iformat->name, "lavfi")))
669  d->non_blocking = 1;
670  ret = av_thread_message_queue_alloc(&d->in_thread_queue,
671  d->thread_queue_size, sizeof(DemuxMsg));
672  if (ret < 0)
673  return ret;
674 
675  if (d->loop) {
676  int nb_audio_dec = 0;
677 
678  for (int i = 0; i < f->nb_streams; i++) {
679  InputStream *ist = f->streams[i];
680  nb_audio_dec += !!(ist->decoding_needed &&
682  }
683 
684  if (nb_audio_dec) {
685  ret = av_thread_message_queue_alloc(&f->audio_ts_queue,
686  nb_audio_dec, sizeof(Timestamp));
687  if (ret < 0)
688  goto fail;
689  f->audio_ts_queue_size = nb_audio_dec;
690  }
691  }
692 
693  if ((ret = pthread_create(&d->thread, NULL, input_thread, d))) {
694  av_log(d, AV_LOG_ERROR, "pthread_create failed: %s. Try to increase `ulimit -v` or decrease `ulimit -s`.\n", strerror(ret));
695  ret = AVERROR(ret);
696  goto fail;
697  }
698 
699  d->read_started = 1;
700 
701  return 0;
702 fail:
703  av_thread_message_queue_free(&d->in_thread_queue);
704  return ret;
705 }
706 
708 {
710  DemuxMsg msg;
711  int ret;
712 
713  if (!d->in_thread_queue) {
714  ret = thread_start(d);
715  if (ret < 0)
716  return ret;
717  }
718 
719  ret = av_thread_message_queue_recv(d->in_thread_queue, &msg,
720  d->non_blocking ?
722  if (ret < 0)
723  return ret;
724  if (msg.looping)
725  return 1;
726 
727  *pkt = msg.pkt;
728  return 0;
729 }
730 
732 {
733  InputFile *f = &d->f;
734  uint64_t total_packets = 0, total_size = 0;
735 
736  av_log(f, AV_LOG_VERBOSE, "Input file #%d (%s):\n",
737  f->index, f->ctx->url);
738 
739  for (int j = 0; j < f->nb_streams; j++) {
740  InputStream *ist = f->streams[j];
741  DemuxStream *ds = ds_from_ist(ist);
742  enum AVMediaType type = ist->par->codec_type;
743 
744  if (ist->discard || type == AVMEDIA_TYPE_ATTACHMENT)
745  continue;
746 
747  total_size += ds->data_size;
748  total_packets += ds->nb_packets;
749 
750  av_log(f, AV_LOG_VERBOSE, " Input stream #%d:%d (%s): ",
751  f->index, j, av_get_media_type_string(type));
752  av_log(f, AV_LOG_VERBOSE, "%"PRIu64" packets read (%"PRIu64" bytes); ",
753  ds->nb_packets, ds->data_size);
754 
755  if (ist->decoding_needed) {
757  "%"PRIu64" frames decoded; %"PRIu64" decode errors",
758  ist->frames_decoded, ist->decode_errors);
759  if (type == AVMEDIA_TYPE_AUDIO)
760  av_log(f, AV_LOG_VERBOSE, " (%"PRIu64" samples)", ist->samples_decoded);
761  av_log(f, AV_LOG_VERBOSE, "; ");
762  }
763 
764  av_log(f, AV_LOG_VERBOSE, "\n");
765  }
766 
767  av_log(f, AV_LOG_VERBOSE, " Total: %"PRIu64" packets (%"PRIu64" bytes) demuxed\n",
768  total_packets, total_size);
769 }
770 
771 static void ist_free(InputStream **pist)
772 {
773  InputStream *ist = *pist;
774 
775  if (!ist)
776  return;
777 
778  dec_free(&ist->decoder);
779 
780  av_dict_free(&ist->decoder_opts);
781  av_freep(&ist->filters);
782  av_freep(&ist->outputs);
783  av_freep(&ist->hwaccel_device);
784 
787 
788  av_freep(pist);
789 }
790 
792 {
793  InputFile *f = *pf;
795 
796  if (!f)
797  return;
798 
799  thread_stop(d);
800 
801  if (d->read_started)
803 
804  for (int i = 0; i < f->nb_streams; i++)
805  ist_free(&f->streams[i]);
806  av_freep(&f->streams);
807 
808  avformat_close_input(&f->ctx);
809 
810  av_freep(pf);
811 }
812 
813 static int ist_use(InputStream *ist, int decoding_needed)
814 {
815  DemuxStream *ds = ds_from_ist(ist);
816 
817  if (ist->user_set_discard == AVDISCARD_ALL) {
818  av_log(ist, AV_LOG_ERROR, "Cannot %s a disabled input stream\n",
819  decoding_needed ? "decode" : "streamcopy");
820  return AVERROR(EINVAL);
821  }
822 
823  ist->discard = 0;
824  ist->st->discard = ist->user_set_discard;
825  ist->decoding_needed |= decoding_needed;
826  ds->streamcopy_needed |= !decoding_needed;
827 
828  if (decoding_needed && !avcodec_is_open(ist->dec_ctx)) {
829  int ret = dec_open(ist);
830  if (ret < 0)
831  return ret;
832  }
833 
834  return 0;
835 }
836 
838 {
839  int ret;
840 
841  ret = ist_use(ist, ost->enc ? DECODING_FOR_OST : 0);
842  if (ret < 0)
843  return ret;
844 
845  ret = GROW_ARRAY(ist->outputs, ist->nb_outputs);
846  if (ret < 0)
847  return ret;
848 
849  ist->outputs[ist->nb_outputs - 1] = ost;
850 
851  return 0;
852 }
853 
854 int ist_filter_add(InputStream *ist, InputFilter *ifilter, int is_simple)
855 {
856  int ret;
857 
858  ret = ist_use(ist, is_simple ? DECODING_FOR_OST : DECODING_FOR_FILTER);
859  if (ret < 0)
860  return ret;
861 
862  ret = GROW_ARRAY(ist->filters, ist->nb_filters);
863  if (ret < 0)
864  return ret;
865 
866  ist->filters[ist->nb_filters - 1] = ifilter;
867 
868  // initialize fallback parameters for filtering
869  ret = ifilter_parameters_from_dec(ifilter, ist->dec_ctx);
870  if (ret < 0)
871  return ret;
872 
873  return 0;
874 }
875 
877  enum HWAccelID hwaccel_id, enum AVHWDeviceType hwaccel_device_type,
878  const AVCodec **pcodec)
879 
880 {
881  char *codec_name = NULL;
882 
883  MATCH_PER_STREAM_OPT(codec_names, str, codec_name, s, st);
884  if (codec_name) {
885  int ret = find_codec(NULL, codec_name, st->codecpar->codec_type, 0, pcodec);
886  if (ret < 0)
887  return ret;
888  st->codecpar->codec_id = (*pcodec)->id;
889  if (recast_media && st->codecpar->codec_type != (*pcodec)->type)
890  st->codecpar->codec_type = (*pcodec)->type;
891  return 0;
892  } else {
893  if (st->codecpar->codec_type == AVMEDIA_TYPE_VIDEO &&
894  hwaccel_id == HWACCEL_GENERIC &&
895  hwaccel_device_type != AV_HWDEVICE_TYPE_NONE) {
896  const AVCodec *c;
897  void *i = NULL;
898 
899  while ((c = av_codec_iterate(&i))) {
900  const AVCodecHWConfig *config;
901 
902  if (c->id != st->codecpar->codec_id ||
904  continue;
905 
906  for (int j = 0; config = avcodec_get_hw_config(c, j); j++) {
907  if (config->device_type == hwaccel_device_type) {
908  av_log(NULL, AV_LOG_VERBOSE, "Selecting decoder '%s' because of requested hwaccel method %s\n",
909  c->name, av_hwdevice_get_type_name(hwaccel_device_type));
910  *pcodec = c;
911  return 0;
912  }
913  }
914  }
915  }
916 
917  *pcodec = avcodec_find_decoder(st->codecpar->codec_id);
918  return 0;
919  }
920 }
921 
922 static int guess_input_channel_layout(InputStream *ist, int guess_layout_max)
923 {
924  AVCodecContext *dec = ist->dec_ctx;
925 
927  char layout_name[256];
928 
929  if (dec->ch_layout.nb_channels > guess_layout_max)
930  return 0;
933  return 0;
934  av_channel_layout_describe(&dec->ch_layout, layout_name, sizeof(layout_name));
935  av_log(ist, AV_LOG_WARNING, "Guessed Channel Layout: %s\n", layout_name);
936  }
937  return 1;
938 }
939 
942 {
943  AVStream *st = ist->st;
944  AVPacketSideData *sd;
945  double rotation = DBL_MAX;
946  int hflip = -1, vflip = -1;
947  int hflip_set = 0, vflip_set = 0, rotation_set = 0;
948  int32_t *buf;
949 
950  MATCH_PER_STREAM_OPT(display_rotations, dbl, rotation, ctx, st);
951  MATCH_PER_STREAM_OPT(display_hflips, i, hflip, ctx, st);
952  MATCH_PER_STREAM_OPT(display_vflips, i, vflip, ctx, st);
953 
954  rotation_set = rotation != DBL_MAX;
955  hflip_set = hflip != -1;
956  vflip_set = vflip != -1;
957 
958  if (!rotation_set && !hflip_set && !vflip_set)
959  return 0;
960 
964  sizeof(int32_t) * 9, 0);
965  if (!sd) {
966  av_log(ist, AV_LOG_FATAL, "Failed to generate a display matrix!\n");
967  return AVERROR(ENOMEM);
968  }
969 
970  buf = (int32_t *)sd->data;
972  rotation_set ? -(rotation) : -0.0f);
973 
975  hflip_set ? hflip : 0,
976  vflip_set ? vflip : 0);
977 
978  return 0;
979 }
980 
981 static const char *input_stream_item_name(void *obj)
982 {
983  const DemuxStream *ds = obj;
984 
985  return ds->log_name;
986 }
987 
988 static const AVClass input_stream_class = {
989  .class_name = "InputStream",
990  .version = LIBAVUTIL_VERSION_INT,
991  .item_name = input_stream_item_name,
992  .category = AV_CLASS_CATEGORY_DEMUXER,
993 };
994 
996 {
997  const char *type_str = av_get_media_type_string(st->codecpar->codec_type);
998  InputFile *f = &d->f;
999  DemuxStream *ds;
1000 
1001  ds = allocate_array_elem(&f->streams, sizeof(*ds), &f->nb_streams);
1002  if (!ds)
1003  return NULL;
1004 
1005  ds->ist.st = st;
1006  ds->ist.file_index = f->index;
1007  ds->ist.index = st->index;
1008  ds->ist.class = &input_stream_class;
1009 
1010  snprintf(ds->log_name, sizeof(ds->log_name), "%cist#%d:%d/%s",
1011  type_str ? *type_str : '?', d->f.index, st->index,
1013 
1014  return ds;
1015 }
1016 
1017 static int ist_add(const OptionsContext *o, Demuxer *d, AVStream *st)
1018 {
1019  AVFormatContext *ic = d->f.ctx;
1020  AVCodecParameters *par = st->codecpar;
1021  DemuxStream *ds;
1022  InputStream *ist;
1023  char *framerate = NULL, *hwaccel_device = NULL;
1024  const char *hwaccel = NULL;
1025  char *hwaccel_output_format = NULL;
1026  char *codec_tag = NULL;
1027  char *next;
1028  char *discard_str = NULL;
1029  int ret;
1030 
1031  ds = demux_stream_alloc(d, st);
1032  if (!ds)
1033  return AVERROR(ENOMEM);
1034 
1035  ist = &ds->ist;
1036 
1037  ist->discard = 1;
1038  st->discard = AVDISCARD_ALL;
1039  ds->first_dts = AV_NOPTS_VALUE;
1040  ds->next_dts = AV_NOPTS_VALUE;
1041 
1042  ds->ts_scale = 1.0;
1043  MATCH_PER_STREAM_OPT(ts_scale, dbl, ds->ts_scale, ic, st);
1044 
1045  ist->autorotate = 1;
1046  MATCH_PER_STREAM_OPT(autorotate, i, ist->autorotate, ic, st);
1047 
1048  MATCH_PER_STREAM_OPT(codec_tags, str, codec_tag, ic, st);
1049  if (codec_tag) {
1050  uint32_t tag = strtol(codec_tag, &next, 0);
1051  if (*next) {
1052  uint8_t buf[4] = { 0 };
1053  memcpy(buf, codec_tag, FFMIN(sizeof(buf), strlen(codec_tag)));
1054  tag = AV_RL32(buf);
1055  }
1056 
1057  st->codecpar->codec_tag = tag;
1058  }
1059 
1060  if (st->codecpar->codec_type == AVMEDIA_TYPE_VIDEO) {
1061  ret = add_display_matrix_to_stream(o, ic, ist);
1062  if (ret < 0)
1063  return ret;
1064 
1065  MATCH_PER_STREAM_OPT(hwaccels, str, hwaccel, ic, st);
1066  MATCH_PER_STREAM_OPT(hwaccel_output_formats, str,
1067  hwaccel_output_format, ic, st);
1068 
1069  if (!hwaccel_output_format && hwaccel && !strcmp(hwaccel, "cuvid")) {
1070  av_log(ist, AV_LOG_WARNING,
1071  "WARNING: defaulting hwaccel_output_format to cuda for compatibility "
1072  "with old commandlines. This behaviour is DEPRECATED and will be removed "
1073  "in the future. Please explicitly set \"-hwaccel_output_format cuda\".\n");
1075  } else if (!hwaccel_output_format && hwaccel && !strcmp(hwaccel, "qsv")) {
1076  av_log(ist, AV_LOG_WARNING,
1077  "WARNING: defaulting hwaccel_output_format to qsv for compatibility "
1078  "with old commandlines. This behaviour is DEPRECATED and will be removed "
1079  "in the future. Please explicitly set \"-hwaccel_output_format qsv\".\n");
1081  } else if (!hwaccel_output_format && hwaccel && !strcmp(hwaccel, "mediacodec")) {
1082  // There is no real AVHWFrameContext implementation. Set
1083  // hwaccel_output_format to avoid av_hwframe_transfer_data error.
1085  } else if (hwaccel_output_format) {
1086  ist->hwaccel_output_format = av_get_pix_fmt(hwaccel_output_format);
1087  if (ist->hwaccel_output_format == AV_PIX_FMT_NONE) {
1088  av_log(ist, AV_LOG_FATAL, "Unrecognised hwaccel output "
1089  "format: %s", hwaccel_output_format);
1090  }
1091  } else {
1093  }
1094 
1095  if (hwaccel) {
1096  // The NVDEC hwaccels use a CUDA device, so remap the name here.
1097  if (!strcmp(hwaccel, "nvdec") || !strcmp(hwaccel, "cuvid"))
1098  hwaccel = "cuda";
1099 
1100  if (!strcmp(hwaccel, "none"))
1101  ist->hwaccel_id = HWACCEL_NONE;
1102  else if (!strcmp(hwaccel, "auto"))
1103  ist->hwaccel_id = HWACCEL_AUTO;
1104  else {
1106  if (type != AV_HWDEVICE_TYPE_NONE) {
1107  ist->hwaccel_id = HWACCEL_GENERIC;
1108  ist->hwaccel_device_type = type;
1109  }
1110 
1111  if (!ist->hwaccel_id) {
1112  av_log(ist, AV_LOG_FATAL, "Unrecognized hwaccel: %s.\n",
1113  hwaccel);
1114  av_log(ist, AV_LOG_FATAL, "Supported hwaccels: ");
1116  while ((type = av_hwdevice_iterate_types(type)) !=
1118  av_log(ist, AV_LOG_FATAL, "%s ",
1120  av_log(ist, AV_LOG_FATAL, "\n");
1121  return AVERROR(EINVAL);
1122  }
1123  }
1124  }
1125 
1126  MATCH_PER_STREAM_OPT(hwaccel_devices, str, hwaccel_device, ic, st);
1127  if (hwaccel_device) {
1128  ist->hwaccel_device = av_strdup(hwaccel_device);
1129  if (!ist->hwaccel_device)
1130  return AVERROR(ENOMEM);
1131  }
1132  }
1133 
1134  ret = choose_decoder(o, ic, st, ist->hwaccel_id, ist->hwaccel_device_type,
1135  &ist->dec);
1136  if (ret < 0)
1137  return ret;
1138 
1140  ic, st, ist->dec, &ist->decoder_opts);
1141  if (ret < 0)
1142  return ret;
1143 
1144  ist->reinit_filters = -1;
1145  MATCH_PER_STREAM_OPT(reinit_filters, i, ist->reinit_filters, ic, st);
1146 
1147  MATCH_PER_STREAM_OPT(discard, str, discard_str, ic, st);
1149 
1150  if ((o->video_disable && ist->st->codecpar->codec_type == AVMEDIA_TYPE_VIDEO) ||
1155 
1156  ist->dec_ctx = avcodec_alloc_context3(ist->dec);
1157  if (!ist->dec_ctx)
1158  return AVERROR(ENOMEM);
1159 
1160  if (discard_str) {
1161  const AVOption *discard_opt = av_opt_find(ist->dec_ctx, "skip_frame",
1162  NULL, 0, 0);
1163  ret = av_opt_eval_int(ist->dec_ctx, discard_opt, discard_str, &ist->user_set_discard);
1164  if (ret < 0) {
1165  av_log(ist, AV_LOG_ERROR, "Error parsing discard %s.\n", discard_str);
1166  return ret;
1167  }
1168  }
1169 
1171  if (ret < 0) {
1172  av_log(ist, AV_LOG_ERROR, "Error initializing the decoder context.\n");
1173  return ret;
1174  }
1175 
1176  if (o->bitexact)
1178 
1179  switch (par->codec_type) {
1180  case AVMEDIA_TYPE_VIDEO:
1181  MATCH_PER_STREAM_OPT(frame_rates, str, framerate, ic, st);
1182  if (framerate) {
1184  if (ret < 0) {
1185  av_log(ist, AV_LOG_ERROR, "Error parsing framerate %s.\n",
1186  framerate);
1187  return ret;
1188  }
1189  }
1190 
1191 #if FFMPEG_OPT_TOP
1192  ist->top_field_first = -1;
1193  MATCH_PER_STREAM_OPT(top_field_first, i, ist->top_field_first, ic, st);
1194 #endif
1195 
1196  ist->framerate_guessed = av_guess_frame_rate(ic, st, NULL);
1197 
1198  break;
1199  case AVMEDIA_TYPE_AUDIO: {
1200  int guess_layout_max = INT_MAX;
1201  MATCH_PER_STREAM_OPT(guess_layout_max, i, guess_layout_max, ic, st);
1202  guess_input_channel_layout(ist, guess_layout_max);
1203  break;
1204  }
1205  case AVMEDIA_TYPE_DATA:
1206  case AVMEDIA_TYPE_SUBTITLE: {
1207  char *canvas_size = NULL;
1208  MATCH_PER_STREAM_OPT(fix_sub_duration, i, ist->fix_sub_duration, ic, st);
1209  MATCH_PER_STREAM_OPT(canvas_sizes, str, canvas_size, ic, st);
1210  if (canvas_size) {
1212  canvas_size);
1213  if (ret < 0) {
1214  av_log(ist, AV_LOG_FATAL, "Invalid canvas size: %s.\n", canvas_size);
1215  return ret;
1216  }
1217  }
1218 
1219  /* Compute the size of the canvas for the subtitles stream.
1220  If the subtitles codecpar has set a size, use it. Otherwise use the
1221  maximum dimensions of the video streams in the same file. */
1222  ist->sub2video.w = ist->dec_ctx->width;
1223  ist->sub2video.h = ist->dec_ctx->height;
1224  if (!(ist->sub2video.w && ist->sub2video.h)) {
1225  for (int j = 0; j < ic->nb_streams; j++) {
1226  AVCodecParameters *par1 = ic->streams[j]->codecpar;
1227  if (par1->codec_type == AVMEDIA_TYPE_VIDEO) {
1228  ist->sub2video.w = FFMAX(ist->sub2video.w, par1->width);
1229  ist->sub2video.h = FFMAX(ist->sub2video.h, par1->height);
1230  }
1231  }
1232  }
1233 
1234  if (!(ist->sub2video.w && ist->sub2video.h)) {
1235  ist->sub2video.w = FFMAX(ist->sub2video.w, 720);
1236  ist->sub2video.h = FFMAX(ist->sub2video.h, 576);
1237  }
1238 
1239  break;
1240  }
1242  case AVMEDIA_TYPE_UNKNOWN:
1243  break;
1244  default:
1245  abort();
1246  }
1247 
1248  ist->par = avcodec_parameters_alloc();
1249  if (!ist->par)
1250  return AVERROR(ENOMEM);
1251 
1253  if (ret < 0) {
1254  av_log(ist, AV_LOG_ERROR, "Error initializing the decoder context.\n");
1255  return ret;
1256  }
1257 
1259 
1260  return 0;
1261 }
1262 
1263 static int dump_attachment(InputStream *ist, const char *filename)
1264 {
1265  AVStream *st = ist->st;
1266  int ret;
1267  AVIOContext *out = NULL;
1268  const AVDictionaryEntry *e;
1269 
1270  if (!st->codecpar->extradata_size) {
1271  av_log(ist, AV_LOG_WARNING, "No extradata to dump.\n");
1272  return 0;
1273  }
1274  if (!*filename && (e = av_dict_get(st->metadata, "filename", NULL, 0)))
1275  filename = e->value;
1276  if (!*filename) {
1277  av_log(ist, AV_LOG_FATAL, "No filename specified and no 'filename' tag");
1278  return AVERROR(EINVAL);
1279  }
1280 
1281  ret = assert_file_overwrite(filename);
1282  if (ret < 0)
1283  return ret;
1284 
1285  if ((ret = avio_open2(&out, filename, AVIO_FLAG_WRITE, &int_cb, NULL)) < 0) {
1286  av_log(ist, AV_LOG_FATAL, "Could not open file %s for writing.\n",
1287  filename);
1288  return ret;
1289  }
1290 
1292  ret = avio_close(out);
1293 
1294  if (ret >= 0)
1295  av_log(ist, AV_LOG_INFO, "Wrote attachment (%d bytes) to '%s'\n",
1296  st->codecpar->extradata_size, filename);
1297 
1298  return ret;
1299 }
1300 
1301 static const char *input_file_item_name(void *obj)
1302 {
1303  const Demuxer *d = obj;
1304 
1305  return d->log_name;
1306 }
1307 
1308 static const AVClass input_file_class = {
1309  .class_name = "InputFile",
1310  .version = LIBAVUTIL_VERSION_INT,
1311  .item_name = input_file_item_name,
1312  .category = AV_CLASS_CATEGORY_DEMUXER,
1313 };
1314 
1315 static Demuxer *demux_alloc(void)
1316 {
1318 
1319  if (!d)
1320  return NULL;
1321 
1322  d->f.class = &input_file_class;
1323  d->f.index = nb_input_files - 1;
1324 
1325  snprintf(d->log_name, sizeof(d->log_name), "in#%d", d->f.index);
1326 
1327  return d;
1328 }
1329 
1330 int ifile_open(const OptionsContext *o, const char *filename)
1331 {
1332  Demuxer *d;
1333  InputFile *f;
1334  AVFormatContext *ic;
1335  const AVInputFormat *file_iformat = NULL;
1336  int err, i, ret = 0;
1337  int64_t timestamp;
1338  AVDictionary *unused_opts = NULL;
1339  const AVDictionaryEntry *e = NULL;
1340  char * video_codec_name = NULL;
1341  char * audio_codec_name = NULL;
1342  char *subtitle_codec_name = NULL;
1343  char * data_codec_name = NULL;
1344  int scan_all_pmts_set = 0;
1345 
1346  int64_t start_time = o->start_time;
1347  int64_t start_time_eof = o->start_time_eof;
1348  int64_t stop_time = o->stop_time;
1349  int64_t recording_time = o->recording_time;
1350 
1351  d = demux_alloc();
1352  if (!d)
1353  return AVERROR(ENOMEM);
1354 
1355  f = &d->f;
1356 
1357  if (stop_time != INT64_MAX && recording_time != INT64_MAX) {
1358  stop_time = INT64_MAX;
1359  av_log(d, AV_LOG_WARNING, "-t and -to cannot be used together; using -t.\n");
1360  }
1361 
1362  if (stop_time != INT64_MAX && recording_time == INT64_MAX) {
1363  int64_t start = start_time == AV_NOPTS_VALUE ? 0 : start_time;
1364  if (stop_time <= start) {
1365  av_log(d, AV_LOG_ERROR, "-to value smaller than -ss; aborting.\n");
1366  return AVERROR(EINVAL);
1367  } else {
1368  recording_time = stop_time - start;
1369  }
1370  }
1371 
1372  if (o->format) {
1373  if (!(file_iformat = av_find_input_format(o->format))) {
1374  av_log(d, AV_LOG_FATAL, "Unknown input format: '%s'\n", o->format);
1375  return AVERROR(EINVAL);
1376  }
1377  }
1378 
1379  if (!strcmp(filename, "-"))
1380  filename = "fd:";
1381 
1382  stdin_interaction &= strncmp(filename, "pipe:", 5) &&
1383  strcmp(filename, "fd:") &&
1384  strcmp(filename, "/dev/stdin");
1385 
1386  /* get default parameters from command line */
1387  ic = avformat_alloc_context();
1388  if (!ic)
1389  return AVERROR(ENOMEM);
1390  if (o->nb_audio_sample_rate) {
1391  av_dict_set_int(&o->g->format_opts, "sample_rate", o->audio_sample_rate[o->nb_audio_sample_rate - 1].u.i, 0);
1392  }
1393  if (o->nb_audio_channels) {
1394  const AVClass *priv_class;
1395  if (file_iformat && (priv_class = file_iformat->priv_class) &&
1396  av_opt_find(&priv_class, "ch_layout", NULL, 0,
1398  char buf[32];
1399  snprintf(buf, sizeof(buf), "%dC", o->audio_channels[o->nb_audio_channels - 1].u.i);
1400  av_dict_set(&o->g->format_opts, "ch_layout", buf, 0);
1401  }
1402  }
1403  if (o->nb_audio_ch_layouts) {
1404  const AVClass *priv_class;
1405  if (file_iformat && (priv_class = file_iformat->priv_class) &&
1406  av_opt_find(&priv_class, "ch_layout", NULL, 0,
1408  av_dict_set(&o->g->format_opts, "ch_layout", o->audio_ch_layouts[o->nb_audio_ch_layouts - 1].u.str, 0);
1409  }
1410  }
1411  if (o->nb_frame_rates) {
1412  const AVClass *priv_class;
1413  /* set the format-level framerate option;
1414  * this is important for video grabbers, e.g. x11 */
1415  if (file_iformat && (priv_class = file_iformat->priv_class) &&
1416  av_opt_find(&priv_class, "framerate", NULL, 0,
1418  av_dict_set(&o->g->format_opts, "framerate",
1419  o->frame_rates[o->nb_frame_rates - 1].u.str, 0);
1420  }
1421  }
1422  if (o->nb_frame_sizes) {
1423  av_dict_set(&o->g->format_opts, "video_size", o->frame_sizes[o->nb_frame_sizes - 1].u.str, 0);
1424  }
1425  if (o->nb_frame_pix_fmts)
1426  av_dict_set(&o->g->format_opts, "pixel_format", o->frame_pix_fmts[o->nb_frame_pix_fmts - 1].u.str, 0);
1427 
1428  MATCH_PER_TYPE_OPT(codec_names, str, video_codec_name, ic, "v");
1429  MATCH_PER_TYPE_OPT(codec_names, str, audio_codec_name, ic, "a");
1430  MATCH_PER_TYPE_OPT(codec_names, str, subtitle_codec_name, ic, "s");
1431  MATCH_PER_TYPE_OPT(codec_names, str, data_codec_name, ic, "d");
1432 
1433  if (video_codec_name)
1435  &ic->video_codec));
1436  if (audio_codec_name)
1438  &ic->audio_codec));
1439  if (subtitle_codec_name)
1441  &ic->subtitle_codec));
1442  if (data_codec_name)
1443  ret = err_merge(ret, find_codec(NULL, data_codec_name , AVMEDIA_TYPE_DATA, 0,
1444  &ic->data_codec));
1445  if (ret < 0) {
1447  return ret;
1448  }
1449 
1453  ic->data_codec_id = data_codec_name ? ic->data_codec->id : AV_CODEC_ID_NONE;
1454 
1455  ic->flags |= AVFMT_FLAG_NONBLOCK;
1456  if (o->bitexact)
1457  ic->flags |= AVFMT_FLAG_BITEXACT;
1458  ic->interrupt_callback = int_cb;
1459 
1460  if (!av_dict_get(o->g->format_opts, "scan_all_pmts", NULL, AV_DICT_MATCH_CASE)) {
1461  av_dict_set(&o->g->format_opts, "scan_all_pmts", "1", AV_DICT_DONT_OVERWRITE);
1462  scan_all_pmts_set = 1;
1463  }
1464  /* open the input file with generic avformat function */
1465  err = avformat_open_input(&ic, filename, file_iformat, &o->g->format_opts);
1466  if (err < 0) {
1468  "Error opening input: %s\n", av_err2str(err));
1469  if (err == AVERROR_PROTOCOL_NOT_FOUND)
1470  av_log(d, AV_LOG_ERROR, "Did you mean file:%s?\n", filename);
1471  return err;
1472  }
1473  f->ctx = ic;
1474 
1475  av_strlcat(d->log_name, "/", sizeof(d->log_name));
1476  av_strlcat(d->log_name, ic->iformat->name, sizeof(d->log_name));
1477 
1478  if (scan_all_pmts_set)
1479  av_dict_set(&o->g->format_opts, "scan_all_pmts", NULL, AV_DICT_MATCH_CASE);
1481 
1483  if (ret < 0)
1484  return ret;
1485 
1486  /* apply forced codec ids */
1487  for (i = 0; i < ic->nb_streams; i++) {
1488  const AVCodec *dummy;
1490  &dummy);
1491  if (ret < 0)
1492  return ret;
1493  }
1494 
1495  if (o->find_stream_info) {
1496  AVDictionary **opts;
1497  int orig_nb_streams = ic->nb_streams;
1498 
1500  if (ret < 0)
1501  return ret;
1502 
1503  /* If not enough info to get the stream parameters, we decode the
1504  first frames to get it. (used in mpeg case for example) */
1506 
1507  for (i = 0; i < orig_nb_streams; i++)
1508  av_dict_free(&opts[i]);
1509  av_freep(&opts);
1510 
1511  if (ret < 0) {
1512  av_log(d, AV_LOG_FATAL, "could not find codec parameters\n");
1513  if (ic->nb_streams == 0)
1514  return ret;
1515  }
1516  }
1517 
1518  if (start_time != AV_NOPTS_VALUE && start_time_eof != AV_NOPTS_VALUE) {
1519  av_log(d, AV_LOG_WARNING, "Cannot use -ss and -sseof both, using -ss\n");
1520  start_time_eof = AV_NOPTS_VALUE;
1521  }
1522 
1523  if (start_time_eof != AV_NOPTS_VALUE) {
1524  if (start_time_eof >= 0) {
1525  av_log(d, AV_LOG_ERROR, "-sseof value must be negative; aborting\n");
1526  return AVERROR(EINVAL);
1527  }
1528  if (ic->duration > 0) {
1529  start_time = start_time_eof + ic->duration;
1530  if (start_time < 0) {
1531  av_log(d, AV_LOG_WARNING, "-sseof value seeks to before start of file; ignored\n");
1533  }
1534  } else
1535  av_log(d, AV_LOG_WARNING, "Cannot use -sseof, file duration not known\n");
1536  }
1537  timestamp = (start_time == AV_NOPTS_VALUE) ? 0 : start_time;
1538  /* add the stream start time */
1539  if (!o->seek_timestamp && ic->start_time != AV_NOPTS_VALUE)
1540  timestamp += ic->start_time;
1541 
1542  /* if seeking requested, we execute it */
1543  if (start_time != AV_NOPTS_VALUE) {
1544  int64_t seek_timestamp = timestamp;
1545 
1546  if (!(ic->iformat->flags & AVFMT_SEEK_TO_PTS)) {
1547  int dts_heuristic = 0;
1548  for (i=0; i<ic->nb_streams; i++) {
1549  const AVCodecParameters *par = ic->streams[i]->codecpar;
1550  if (par->video_delay) {
1551  dts_heuristic = 1;
1552  break;
1553  }
1554  }
1555  if (dts_heuristic) {
1556  seek_timestamp -= 3*AV_TIME_BASE / 23;
1557  }
1558  }
1559  ret = avformat_seek_file(ic, -1, INT64_MIN, seek_timestamp, seek_timestamp, 0);
1560  if (ret < 0) {
1561  av_log(d, AV_LOG_WARNING, "could not seek to position %0.3f\n",
1562  (double)timestamp / AV_TIME_BASE);
1563  }
1564  }
1565 
1566  f->start_time = start_time;
1567  f->recording_time = recording_time;
1568  f->input_sync_ref = o->input_sync_ref;
1569  f->input_ts_offset = o->input_ts_offset;
1570  f->ts_offset = o->input_ts_offset - (copy_ts ? (start_at_zero && ic->start_time != AV_NOPTS_VALUE ? ic->start_time : 0) : timestamp);
1571  f->accurate_seek = o->accurate_seek;
1572  d->loop = o->loop;
1573  d->nb_streams_warn = ic->nb_streams;
1574 
1575  d->duration = (Timestamp){ .ts = 0, .tb = (AVRational){ 1, 1 } };
1576  d->min_pts = (Timestamp){ .ts = AV_NOPTS_VALUE, .tb = (AVRational){ 1, 1 } };
1577  d->max_pts = (Timestamp){ .ts = AV_NOPTS_VALUE, .tb = (AVRational){ 1, 1 } };
1578 
1579  f->format_nots = !!(ic->iformat->flags & AVFMT_NOTIMESTAMPS);
1580 
1581  f->readrate = o->readrate ? o->readrate : 0.0;
1582  if (f->readrate < 0.0f) {
1583  av_log(d, AV_LOG_ERROR, "Option -readrate is %0.3f; it must be non-negative.\n", f->readrate);
1584  return AVERROR(EINVAL);
1585  }
1586  if (o->rate_emu) {
1587  if (f->readrate) {
1588  av_log(d, AV_LOG_WARNING, "Both -readrate and -re set. Using -readrate %0.3f.\n", f->readrate);
1589  } else
1590  f->readrate = 1.0f;
1591  }
1592 
1593  if (f->readrate) {
1594  d->readrate_initial_burst = o->readrate_initial_burst ? o->readrate_initial_burst : 0.5;
1595  if (d->readrate_initial_burst < 0.0) {
1597  "Option -readrate_initial_burst is %0.3f; it must be non-negative.\n",
1598  d->readrate_initial_burst);
1599  return AVERROR(EINVAL);
1600  }
1601  } else if (o->readrate_initial_burst) {
1602  av_log(d, AV_LOG_WARNING, "Option -readrate_initial_burst ignored "
1603  "since neither -readrate nor -re were given\n");
1604  }
1605 
1606  d->thread_queue_size = o->thread_queue_size;
1607 
1608  /* Add all the streams from the given input file to the demuxer */
1609  for (int i = 0; i < ic->nb_streams; i++) {
1610  ret = ist_add(o, d, ic->streams[i]);
1611  if (ret < 0)
1612  return ret;
1613  }
1614 
1615  /* dump the file content */
1616  av_dump_format(ic, f->index, filename, 0);
1617 
1618  /* check if all codec options have been used */
1619  unused_opts = strip_specifiers(o->g->codec_opts);
1620  for (i = 0; i < f->nb_streams; i++) {
1621  e = NULL;
1622  while ((e = av_dict_iterate(f->streams[i]->decoder_opts, e)))
1623  av_dict_set(&unused_opts, e->key, NULL, 0);
1624  }
1625 
1626  e = NULL;
1627  while ((e = av_dict_iterate(unused_opts, e))) {
1628  const AVClass *class = avcodec_get_class();
1629  const AVOption *option = av_opt_find(&class, e->key, NULL, 0,
1631  const AVClass *fclass = avformat_get_class();
1632  const AVOption *foption = av_opt_find(&fclass, e->key, NULL, 0,
1634  if (!option || foption)
1635  continue;
1636 
1637 
1638  if (!(option->flags & AV_OPT_FLAG_DECODING_PARAM)) {
1639  av_log(d, AV_LOG_ERROR, "Codec AVOption %s (%s) is not a decoding "
1640  "option.\n", e->key, option->help ? option->help : "");
1641  return AVERROR(EINVAL);
1642  }
1643 
1644  av_log(d, AV_LOG_WARNING, "Codec AVOption %s (%s) has not been used "
1645  "for any stream. The most likely reason is either wrong type "
1646  "(e.g. a video option with no video streams) or that it is a "
1647  "private option of some decoder which was not actually used "
1648  "for any stream.\n", e->key, option->help ? option->help : "");
1649  }
1650  av_dict_free(&unused_opts);
1651 
1652  for (i = 0; i < o->nb_dump_attachment; i++) {
1653  int j;
1654 
1655  for (j = 0; j < f->nb_streams; j++) {
1656  InputStream *ist = f->streams[j];
1657 
1658  if (check_stream_specifier(ic, ist->st, o->dump_attachment[i].specifier) == 1) {
1659  ret = dump_attachment(ist, o->dump_attachment[i].u.str);
1660  if (ret < 0)
1661  return ret;
1662  }
1663  }
1664  }
1665 
1666  return 0;
1667 }
OptionsContext::readrate
float readrate
Definition: ffmpeg.h:140
input_thread
static void * input_thread(void *arg)
Definition: ffmpeg_demux.c:529
AV_PKT_DATA_DISPLAYMATRIX
@ AV_PKT_DATA_DISPLAYMATRIX
This side data contains a 3x3 transformation matrix describing an affine transformation that needs to...
Definition: packet.h:109
av_packet_unref
void av_packet_unref(AVPacket *pkt)
Wipe the packet.
Definition: avpacket.c:423
AVCodec
AVCodec.
Definition: codec.h:187
OptionsContext::input_ts_offset
int64_t input_ts_offset
Definition: ffmpeg.h:137
pthread_join
static av_always_inline int pthread_join(pthread_t thread, void **value_ptr)
Definition: os2threads.h:94
AVMEDIA_TYPE_SUBTITLE
@ AVMEDIA_TYPE_SUBTITLE
Definition: avutil.h:204
DemuxStream::ist
InputStream ist
Definition: ffmpeg_demux.c:57
av_gettime_relative
int64_t av_gettime_relative(void)
Get the current time in microseconds since some unspecified starting point.
Definition: time.c:56
AV_LOG_WARNING
#define AV_LOG_WARNING
Something somehow does not look correct.
Definition: log.h:186
AV_PIX_FMT_CUDA
@ AV_PIX_FMT_CUDA
HW acceleration through CUDA.
Definition: pixfmt.h:253
AVCodecParameters::extradata
uint8_t * extradata
Extra binary data needed for initializing the decoder, codec-dependent.
Definition: codec_par.h: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:173
demux_final_stats
static void demux_final_stats(Demuxer *d)
Definition: ffmpeg_demux.c:731
InputStream::hwaccel_device
char * hwaccel_device
Definition: ffmpeg.h:382
err_merge
static int err_merge(int err0, int err1)
Merge two return codes - return one of the error codes if at least one of them was negative,...
Definition: ffmpeg_utils.h:41
OptionsContext::dump_attachment
SpecifierOpt * dump_attachment
Definition: ffmpeg.h:149
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:125
opt.h
OptionsContext::nb_audio_sample_rate
int nb_audio_sample_rate
Definition: ffmpeg.h:126
InputFile::audio_ts_queue_size
int audio_ts_queue_size
Definition: ffmpeg.h:425
MATCH_PER_STREAM_OPT
#define MATCH_PER_STREAM_OPT(name, type, outvar, fmtctx, st)
Definition: ffmpeg.h:893
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:988
av_compare_ts
int av_compare_ts(int64_t ts_a, AVRational tb_a, int64_t ts_b, AVRational tb_b)
Compare two timestamps each in its own time base.
Definition: mathematics.c:147
InputStream::framerate_guessed
AVRational framerate_guessed
Definition: ffmpeg.h:348
ist_output_add
int ist_output_add(InputStream *ist, OutputStream *ost)
Definition: ffmpeg_demux.c:837
AVProgram::nb_stream_indexes
unsigned int nb_stream_indexes
Definition: avformat.h:1044
avio_close
int avio_close(AVIOContext *s)
Close the resource accessed by the AVIOContext s and free it.
Definition: aviobuf.c:1271
out
FILE * out
Definition: movenc.c:54
ifile_open
int ifile_open(const OptionsContext *o, const char *filename)
Definition: ffmpeg_demux.c:1330
is
The official guide to swscale for confused that is
Definition: swscale.txt:28
OptionsContext::nb_audio_ch_layouts
int nb_audio_ch_layouts
Definition: ffmpeg.h:122
AVCodecParameters
This struct describes the properties of an encoded stream.
Definition: codec_par.h:47
thread.h
AVERROR_EOF
#define AVERROR_EOF
End of file.
Definition: error.h:57
AVBufferRef::data
uint8_t * data
The data buffer.
Definition: buffer.h:90
AVStream::discard
enum AVDiscard discard
Selects which packets can be discarded at will and do not need to be demuxed.
Definition: avformat.h:912
MATCH_PER_TYPE_OPT
#define MATCH_PER_TYPE_OPT(name, type, outvar, fmtctx, mediatype)
Definition: ffmpeg.h:910
remove_avoptions
void remove_avoptions(AVDictionary **a, AVDictionary *b)
Definition: ffmpeg.c:447
InputStream::outputs
struct OutputStream ** outputs
Definition: ffmpeg.h:374
InputStream::dec_ctx
AVCodecContext * dec_ctx
Definition: ffmpeg.h:344
AVFMT_NOTIMESTAMPS
#define AVFMT_NOTIMESTAMPS
Format does not need / have any timestamps.
Definition: avformat.h:480
AV_TIME_BASE_Q
#define AV_TIME_BASE_Q
Internal time base represented as fractional value.
Definition: avutil.h:264
InputStream::user_set_discard
int user_set_discard
Definition: ffmpeg.h:332
avformat_get_class
const AVClass * avformat_get_class(void)
Get the AVClass for AVFormatContext.
Definition: options.c:205
ist_iter
InputStream * ist_iter(InputStream *prev)
Definition: ffmpeg.c:414
AV_THREAD_MESSAGE_NONBLOCK
@ AV_THREAD_MESSAGE_NONBLOCK
Perform non-blocking operation.
Definition: threadmessage.h:31
pixdesc.h
AVFormatContext::streams
AVStream ** streams
A list of all streams in the file.
Definition: avformat.h:1183
AVPacketSideData
This structure stores auxiliary information for decoding, presenting, or otherwise processing the cod...
Definition: packet.h:342
ifile_close
void ifile_close(InputFile **pf)
Definition: ffmpeg_demux.c:791
DemuxStream::streamcopy_needed
int streamcopy_needed
Definition: ffmpeg_demux.c:64
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:343
AV_HWDEVICE_TYPE_NONE
@ AV_HWDEVICE_TYPE_NONE
Definition: hwcontext.h:28
OptionsContext::subtitle_disable
int subtitle_disable
Definition: ffmpeg.h:183
demux_stream_alloc
static DemuxStream * demux_stream_alloc(Demuxer *d, AVStream *st)
Definition: ffmpeg_demux.c:995
ifilter_parameters_from_dec
int ifilter_parameters_from_dec(InputFilter *ifilter, const AVCodecContext *dec)
Set up fallback filtering parameters from a decoder context.
Definition: ffmpeg_filter.c:1757
AVOption
AVOption.
Definition: opt.h:251
AVStream::avg_frame_rate
AVRational avg_frame_rate
Average framerate.
Definition: avformat.h:930
InputStream::nb_filters
int nb_filters
Definition: ffmpeg.h:367
AVCodecParameters::framerate
AVRational framerate
Video only.
Definition: codec_par.h:218
av_hwdevice_find_type_by_name
enum AVHWDeviceType av_hwdevice_find_type_by_name(const char *name)
Look up an AVHWDeviceType by name.
Definition: hwcontext.c:83
ffmpeg.h
AV_LOG_VERBOSE
#define AV_LOG_VERBOSE
Detailed information.
Definition: log.h:196
float.h
AVFormatContext::programs
AVProgram ** programs
Definition: avformat.h:1283
av_hwdevice_iterate_types
enum AVHWDeviceType av_hwdevice_iterate_types(enum AVHWDeviceType prev)
Iterate over supported device types.
Definition: hwcontext.c:102
OptionsContext::bitexact
int bitexact
Definition: ffmpeg.h:179
autorotate
static int autorotate
Definition: ffplay.c:351
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:509
OptionsContext::audio_channels
SpecifierOpt * audio_channels
Definition: ffmpeg.h:123
DemuxMsg::pkt
AVPacket * pkt
Definition: ffmpeg_demux.c:119
OptionsContext::nb_frame_rates
int nb_frame_rates
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:314
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:1462
avcodec_is_open
int avcodec_is_open(AVCodecContext *s)
Definition: avcodec.c:708
AVFormatContext::video_codec_id
enum AVCodecID video_codec_id
Forced video codec_id.
Definition: avformat.h:1289
InputStream::decoding_needed
int decoding_needed
Definition: ffmpeg.h:333
OptionsContext::format
const char * format
Definition: ffmpeg.h:117
AVChannelLayout::nb_channels
int nb_channels
Number of channels in this layout.
Definition: channel_layout.h:319
Timestamp::ts
int64_t ts
Definition: ffmpeg_utils.h:31
ost
static AVStream * ost
Definition: vaapi_transcode.c:42
tf_sess_config.config
config
Definition: tf_sess_config.py:33
file_iformat
static const AVInputFormat * file_iformat
Definition: ffplay.c:308
av_packet_free
void av_packet_free(AVPacket **pkt)
Free the packet, if the packet is reference counted, it will be unreferenced first.
Definition: avpacket.c:74
InputStream::nb_outputs
int nb_outputs
Definition: ffmpeg.h:375
Demuxer::wallclock_start
int64_t wallclock_start
Definition: ffmpeg_demux.c:89
SpecifierOpt::i
int i
Definition: cmdutils.h:98
InputStream
Definition: ffmpeg.h:324
debug_ts
int debug_ts
Definition: ffmpeg_opt.c:81
avformat_close_input
void avformat_close_input(AVFormatContext **s)
Close an opened input AVFormatContext.
Definition: demux.c:374
AVFormatContext::interrupt_callback
AVIOInterruptCB interrupt_callback
Custom interrupt callbacks for the I/O layer.
Definition: avformat.h:1381
Demuxer
Definition: ffmpeg_demux.c:83
OptionsContext::rate_emu
int rate_emu
Definition: ffmpeg.h:139
opt_name_fix_sub_duration
static const char *const opt_name_fix_sub_duration[]
Definition: ffmpeg_demux.c:44
ist_filter_add
int ist_filter_add(InputStream *ist, InputFilter *ifilter, int is_simple)
Definition: ffmpeg_demux.c:854
dts_delta_threshold
float dts_delta_threshold
Definition: ffmpeg_opt.c:69
DemuxStream::data_size
uint64_t data_size
Definition: ffmpeg_demux.c:80
avio_open2
int avio_open2(AVIOContext **s, const char *url, int flags, const AVIOInterruptCB *int_cb, AVDictionary **options)
Create and initialize a AVIOContext for accessing the resource indicated by url.
Definition: aviobuf.c:1265
finish
static void finish(void)
Definition: movenc.c:342
AVPacket::opaque_ref
AVBufferRef * opaque_ref
AVBufferRef for free use by the API user.
Definition: packet.h:527
AVFMT_SEEK_TO_PTS
#define AVFMT_SEEK_TO_PTS
Seeking is based on PTS.
Definition: avformat.h:504
opt_name_display_vflips
static const char *const opt_name_display_vflips[]
Definition: ffmpeg_demux.c:54
OptionsContext::nb_dump_attachment
int nb_dump_attachment
Definition: ffmpeg.h:150
OptionsContext::g
OptionGroup * g
Definition: ffmpeg.h:111
AVCodecContext::ch_layout
AVChannelLayout ch_layout
Audio channel layout.
Definition: avcodec.h:2107
InputStream::sub2video
struct InputStream::sub2video sub2video
Demuxer::log_name
char log_name[32]
Definition: ffmpeg_demux.c:87
fail
#define fail()
Definition: checkasm.h:141
opt_name_hwaccel_output_formats
static const char *const opt_name_hwaccel_output_formats[]
Definition: ffmpeg_demux.c:50
dummy
int dummy
Definition: motion.c:66
InputStream::decoder_opts
AVDictionary * decoder_opts
Definition: ffmpeg.h:350
AVProgram::discard
enum AVDiscard discard
selects which program to discard and which to feed to the caller
Definition: avformat.h:1042
opt_name_autorotate
static const char *const opt_name_autorotate[]
Definition: ffmpeg_demux.c:51
input_file_item_name
static const char * input_file_item_name(void *obj)
Definition: ffmpeg_demux.c:1301
AVDISCARD_NONE
@ AVDISCARD_NONE
discard nothing
Definition: defs.h:213
AVCodecContext::flags
int flags
AV_CODEC_FLAG_*.
Definition: avcodec.h:521
type
it s the only field you need to keep assuming you have a context There is some magic you don t need to care about around this just let it vf type
Definition: writing_filters.txt:86
opt_name_display_hflips
static const char *const opt_name_display_hflips[]
Definition: ffmpeg_demux.c:53
DemuxPktData
Definition: ffmpeg.h:104
pts
static int64_t pts
Definition: transcode_aac.c:643
av_thread_message_queue_recv
int av_thread_message_queue_recv(AVThreadMessageQueue *mq, void *msg, unsigned flags)
Receive a message from the queue.
Definition: threadmessage.c:177
OptionsContext
Definition: ffmpeg.h:110
do_pkt_dump
int do_pkt_dump
Definition: ffmpeg_opt.c:77
Demuxer::ts_offset_discont
int64_t ts_offset_discont
Extra timestamp offset added by discontinuity handling.
Definition: ffmpeg_demux.c:94
AVRational::num
int num
Numerator.
Definition: rational.h:59
Demuxer::f
InputFile f
Definition: ffmpeg_demux.c:84
InputFile
Definition: ffmpeg.h:392
ifile_get_packet
int ifile_get_packet(InputFile *f, AVPacket **pkt)
Get next input packet from the demuxer.
Definition: ffmpeg_demux.c:707
DemuxStream::nb_packets
uint64_t nb_packets
Definition: ffmpeg_demux.c:78
OptionsContext::recording_time
int64_t recording_time
Definition: ffmpeg.h:172
OptionsContext::audio_disable
int audio_disable
Definition: ffmpeg.h:182
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:917
avassert.h
InputStream::codec_desc
const AVCodecDescriptor * codec_desc
Definition: ffmpeg.h:346
pkt
AVPacket * pkt
Definition: movenc.c:59
AV_LOG_ERROR
#define AV_LOG_ERROR
Something went wrong and cannot losslessly be recovered.
Definition: log.h:180
opt_name_display_rotations
static const char *const opt_name_display_rotations[]
Definition: ffmpeg_demux.c:52
AVInputFormat
Definition: avformat.h:549
ist_dts_update
static int ist_dts_update(DemuxStream *ds, AVPacket *pkt)
Definition: ffmpeg_demux.c:282
AV_PKT_FLAG_CORRUPT
#define AV_PKT_FLAG_CORRUPT
The packet content is corrupted.
Definition: packet.h:547
OptionGroup::codec_opts
AVDictionary * codec_opts
Definition: cmdutils.h:217
av_dump_format
void av_dump_format(AVFormatContext *ic, int index, const char *url, int is_output)
Print detailed information about the input or output format, such as duration, bitrate,...
Definition: dump.c:629
av_thread_message_queue_send
int av_thread_message_queue_send(AVThreadMessageQueue *mq, void *msg, unsigned flags)
Send a message on the queue.
Definition: threadmessage.c:161
duration
int64_t duration
Definition: movenc.c:64
avformat_open_input
int avformat_open_input(AVFormatContext **ps, const char *url, const AVInputFormat *fmt, AVDictionary **options)
Open an input stream and read the header.
Definition: demux.c:226
AVCodecParameters::frame_size
int frame_size
Audio only.
Definition: codec_par.h:182
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:788
HWACCEL_GENERIC
@ HWACCEL_GENERIC
Definition: ffmpeg.h:80
avcodec_alloc_context3
AVCodecContext * avcodec_alloc_context3(const AVCodec *codec)
Allocate an AVCodecContext and set its fields to default values.
Definition: options.c:153
assert_file_overwrite
int assert_file_overwrite(const char *filename)
Definition: ffmpeg_opt.c:704
opt_name_discard
static const char *const opt_name_discard[]
Definition: ffmpeg_demux.c:42
SpecifierOpt::specifier
char * specifier
stream/chapter/program/...
Definition: cmdutils.h:95
intreadwrite.h
AVFormatContext::video_codec
const struct AVCodec * video_codec
Forced video codec.
Definition: avformat.h:1583
s
#define s(width, name)
Definition: cbs_vp9.c:198
DemuxStream::first_dts
int64_t first_dts
Definition: ffmpeg_demux.c:69
InputStream::framerate
AVRational framerate
Definition: ffmpeg.h:351
opt_name_hwaccel_devices
static const char *const opt_name_hwaccel_devices[]
Definition: ffmpeg_demux.c:49
AVFormatContext::flags
int flags
Flags modifying the (de)muxer behaviour.
Definition: avformat.h:1233
AVFormatContext::nb_programs
unsigned int nb_programs
Definition: avformat.h:1282
AVInputFormat::name
const char * name
A comma separated list of short names for the format.
Definition: avformat.h:554
AVFormatContext::iformat
const struct AVInputFormat * iformat
The input container format.
Definition: avformat.h:1127
AVDictionaryEntry::key
char * key
Definition: dict.h:90
AVMEDIA_TYPE_AUDIO
@ AVMEDIA_TYPE_AUDIO
Definition: avutil.h:202
AVCodecParameters::width
int width
Video only.
Definition: codec_par.h:121
AV_CHANNEL_ORDER_UNSPEC
@ AV_CHANNEL_ORDER_UNSPEC
Only the channel count is specified, without any further information about the channel order.
Definition: channel_layout.h:112
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:108
InputFilter
Definition: ffmpeg.h:287
DemuxStream::ts_scale
double ts_scale
Definition: ffmpeg_demux.c:62
OptionsContext::audio_ch_layouts
SpecifierOpt * audio_ch_layouts
Definition: ffmpeg.h:121
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:637
setup_find_stream_info_opts
int setup_find_stream_info_opts(AVFormatContext *s, AVDictionary *codec_opts, AVDictionary ***dst)
Setup AVCodecContext options for avformat_find_stream_info().
Definition: cmdutils.c:990
discard_unused_programs
static void discard_unused_programs(InputFile *ifile)
Definition: ffmpeg_demux.c:507
AV_LOG_DEBUG
#define AV_LOG_DEBUG
Stuff which is only useful for libav* developers.
Definition: log.h:201
AVPacketSideData::data
uint8_t * data
Definition: packet.h:343
ist_add
static int ist_add(const OptionsContext *o, Demuxer *d, AVStream *st)
Definition: ffmpeg_demux.c:1017
ctx
AVFormatContext * ctx
Definition: movenc.c:48
InputStream::filters
InputFilter ** filters
Definition: ffmpeg.h:366
Demuxer::nb_streams_warn
int nb_streams_warn
Definition: ffmpeg_demux.c:106
av_rescale_q
int64_t av_rescale_q(int64_t a, AVRational bq, AVRational cq)
Rescale a 64-bit integer by 2 rational numbers.
Definition: mathematics.c:142
input_stream_item_name
static const char * input_stream_item_name(void *obj)
Definition: ffmpeg_demux.c:981
ffmpeg_utils.h
opt_name_canvas_sizes
static const char *const opt_name_canvas_sizes[]
Definition: ffmpeg_demux.c:45
av_hwdevice_get_type_name
const char * av_hwdevice_get_type_name(enum AVHWDeviceType type)
Get the string name of an AVHWDeviceType.
Definition: hwcontext.c:93
AVThreadMessageQueue
Definition: threadmessage.c:30
OptionsContext::accurate_seek
int accurate_seek
Definition: ffmpeg.h:142
filter_codec_opts
int filter_codec_opts(const AVDictionary *opts, enum AVCodecID codec_id, AVFormatContext *s, AVStream *st, const AVCodec *codec, AVDictionary **dst)
Filter out options for given codec.
Definition: cmdutils.c:925
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:231
AVMEDIA_TYPE_DATA
@ AVMEDIA_TYPE_DATA
Opaque data information usually continuous.
Definition: avutil.h:203
opt_name_ts_scale
static const char *const opt_name_ts_scale[]
Definition: ffmpeg_demux.c:47
AVFormatContext::data_codec
const struct AVCodec * data_codec
Forced data codec.
Definition: avformat.h:1607
Demuxer::duration
Timestamp duration
Definition: ffmpeg_demux.c:100
AV_PIX_FMT_MEDIACODEC
@ AV_PIX_FMT_MEDIACODEC
hardware decoding through MediaCodec
Definition: pixfmt.h:313
av_opt_find
const AVOption * av_opt_find(void *obj, const char *name, const char *unit, int opt_flags, int search_flags)
Look for an option in an object.
Definition: opt.c:1772
dec_open
int dec_open(InputStream *ist)
Definition: ffmpeg_dec.c:1065
arg
const char * arg
Definition: jacosubdec.c:67
pthread_create
static av_always_inline int pthread_create(pthread_t *thread, const pthread_attr_t *attr, void *(*start_routine)(void *), void *arg)
Definition: os2threads.h:80
AV_CLASS_CATEGORY_DEMUXER
@ AV_CLASS_CATEGORY_DEMUXER
Definition: log.h:33
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:65
if
if(ret)
Definition: filter_design.txt:179
option
option
Definition: libkvazaar.c:320
AVCodecParserContext::repeat_pict
int repeat_pict
This field is used for proper frame duration computation in lavf.
Definition: avcodec.h:2792
OptionsContext::start_time
int64_t start_time
Definition: ffmpeg.h:114
AVDISCARD_ALL
@ AVDISCARD_ALL
discard all
Definition: defs.h:219
AVFormatContext
Format I/O context.
Definition: avformat.h:1115
AVFormatContext::audio_codec_id
enum AVCodecID audio_codec_id
Forced audio codec_id.
Definition: avformat.h:1295
opts
AVDictionary * opts
Definition: movenc.c:50
OptionGroup::format_opts
AVDictionary * format_opts
Definition: cmdutils.h:218
opt_name_guess_layout_max
static const char *const opt_name_guess_layout_max[]
Definition: ffmpeg_demux.c:46
AVStream::codecpar
AVCodecParameters * codecpar
Codec parameters associated with this stream.
Definition: avformat.h:864
avcodec_parameters_to_context
int avcodec_parameters_to_context(AVCodecContext *codec, const struct AVCodecParameters *par)
Fill the codec context based on the values from the supplied codec parameters.
framerate
float framerate
Definition: av1_levels.c:29
LIBAVUTIL_VERSION_INT
#define LIBAVUTIL_VERSION_INT
Definition: version.h:85
demuxer_from_ifile
static Demuxer * demuxer_from_ifile(InputFile *f)
Definition: ffmpeg_demux.c:128
AVClass
Describe the class of an AVClass context structure.
Definition: log.h:66
avcodec_get_class
const AVClass * avcodec_get_class(void)
Get the AVClass for AVCodecContext.
Definition: options.c:187
ist_use
static int ist_use(InputStream *ist, int decoding_needed)
Definition: ffmpeg_demux.c:813
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:880
NULL
#define NULL
Definition: coverity.c:32
InputStream::sub2video::w
int w
Definition: ffmpeg.h:361
InputStream::top_field_first
int top_field_first
Definition: ffmpeg.h:353
InputStream::st
AVStream * st
Definition: ffmpeg.h:330
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
OptionsContext::frame_sizes
SpecifierOpt * frame_sizes
Definition: ffmpeg.h:131
InputFile::start_time_effective
int64_t start_time_effective
Effective format start time based on enabled streams.
Definition: ffmpeg.h:408
avcodec_free_context
void avcodec_free_context(AVCodecContext **avctx)
Free the codec context and everything associated with it and write NULL to the provided pointer.
Definition: options.c:168
AVRational
Rational number (pair of numerator and denominator).
Definition: rational.h:58
DemuxPktData::dts_est
int64_t dts_est
Definition: ffmpeg.h:107
parseutils.h
InputStream::hwaccel_id
enum HWAccelID hwaccel_id
Definition: ffmpeg.h:380
AVProgram::stream_index
unsigned int * stream_index
Definition: avformat.h:1043
AVStream::metadata
AVDictionary * metadata
Definition: avformat.h:921
AV_ROUND_NEAR_INF
@ AV_ROUND_NEAR_INF
Round to nearest and halfway cases away from zero.
Definition: mathematics.h:135
InputStream::fix_sub_duration
int fix_sub_duration
Definition: ffmpeg.h:358
InputStream::hwaccel_output_format
enum AVPixelFormat hwaccel_output_format
Definition: ffmpeg.h:383
AV_DICT_DONT_OVERWRITE
#define AV_DICT_DONT_OVERWRITE
Don't overwrite existing entries.
Definition: dict.h:81
time.h
AV_PIX_FMT_QSV
@ AV_PIX_FMT_QSV
HW acceleration through QSV, data[3] contains a pointer to the mfxFrameSurface1 structure.
Definition: pixfmt.h:240
Demuxer::read_started
int read_started
Definition: ffmpeg_demux.c:115
OptionsContext::input_sync_ref
int input_sync_ref
Definition: ffmpeg.h:144
av_packet_move_ref
void av_packet_move_ref(AVPacket *dst, AVPacket *src)
Move every field in src to dst and reset src.
Definition: avpacket.c:480
report_new_stream
static void report_new_stream(Demuxer *d, const AVPacket *pkt)
Definition: ffmpeg_demux.c:143
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:171
choose_decoder
static int choose_decoder(const OptionsContext *o, AVFormatContext *s, AVStream *st, enum HWAccelID hwaccel_id, enum AVHWDeviceType hwaccel_device_type, const AVCodec **pcodec)
Definition: ffmpeg_demux.c:876
find_codec
int find_codec(void *logctx, const char *name, enum AVMediaType type, int encoder, const AVCodec **codec)
Definition: ffmpeg_opt.c:671
AVFormatContext::audio_codec
const struct AVCodec * audio_codec
Forced audio codec.
Definition: avformat.h:1591
InputStream::par
AVCodecParameters * par
Codec parameters - to be used by the decoding/streamcopy code.
Definition: ffmpeg.h:342
input_files
InputFile ** input_files
Definition: ffmpeg.c:124
AV_OPT_SEARCH_FAKE_OBJ
#define AV_OPT_SEARCH_FAKE_OBJ
The obj passed to av_opt_find() is fake – only a double pointer to AVClass instead of a required poin...
Definition: opt.h:571
error.h
InputStream::frames_decoded
uint64_t frames_decoded
Definition: ffmpeg.h:387
avcodec_find_decoder
const AVCodec * avcodec_find_decoder(enum AVCodecID id)
Find a registered decoder with a matching codec ID.
Definition: allcodecs.c:979
recast_media
int recast_media
Definition: ffmpeg_opt.c:101
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:1171
DemuxStream::dts
int64_t dts
Definition: ffmpeg_demux.c:75
av_codec_is_decoder
int av_codec_is_decoder(const AVCodec *codec)
Definition: utils.c:86
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:2436
f
f
Definition: af_crystalizer.c:121
AVIOContext
Bytestream IO Context.
Definition: avio.h:166
av_ts2timestr
#define av_ts2timestr(ts, tb)
Convenience macro, the return value should be used only directly in function arguments but never stan...
Definition: timestamp.h:76
InputStream::hwaccel_device_type
enum AVHWDeviceType hwaccel_device_type
Definition: ffmpeg.h:381
OptionsContext::thread_queue_size
int thread_queue_size
Definition: ffmpeg.h:143
AVMediaType
AVMediaType
Definition: avutil.h:199
AVPacket::size
int size
Definition: packet.h:492
avformat_alloc_context
AVFormatContext * avformat_alloc_context(void)
Allocate an AVFormatContext.
Definition: options.c:166
AVDISCARD_DEFAULT
@ AVDISCARD_DEFAULT
discard useless packets like 0 size packets in avi
Definition: defs.h:214
threadmessage.h
InputStream::file_index
int file_index
Definition: ffmpeg.h:327
opt_name_hwaccels
static const char *const opt_name_hwaccels[]
Definition: ffmpeg_demux.c:48
av_err2str
#define av_err2str(errnum)
Convenience macro, the return value should be used only directly in function arguments but never stan...
Definition: error.h:121
start_time
static int64_t start_time
Definition: ffplay.c:329
copy_ts
int copy_ts
Definition: ffmpeg_opt.c:78
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:662
AV_NOPTS_VALUE
#define AV_NOPTS_VALUE
Undefined timestamp value.
Definition: avutil.h:248
check_avoptions
int check_avoptions(AVDictionary *m)
Definition: ffmpeg.c:456
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:116
DECODING_FOR_OST
#define DECODING_FOR_OST
Definition: ffmpeg.h:334
input_file_class
static const AVClass input_file_class
Definition: ffmpeg_demux.c:1308
Demuxer::thread
pthread_t thread
Definition: ffmpeg_demux.c:112
AVMEDIA_TYPE_UNKNOWN
@ AVMEDIA_TYPE_UNKNOWN
Usually treated as AVMEDIA_TYPE_DATA.
Definition: avutil.h:200
Demuxer::thread_queue_size
int thread_queue_size
Definition: ffmpeg_demux.c:111
OptionsContext::readrate_initial_burst
double readrate_initial_burst
Definition: ffmpeg.h:141
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:1039
AV_OPT_SEARCH_CHILDREN
#define AV_OPT_SEARCH_CHILDREN
Search in possible children of the given object first.
Definition: opt.h:563
AVPacket::dts
int64_t dts
Decompression timestamp in AVStream->time_base units; the time at which the packet is decompressed.
Definition: packet.h:490
avio_write
void avio_write(AVIOContext *s, const unsigned char *buf, int size)
Definition: aviobuf.c:248
InputStream::samples_decoded
uint64_t samples_decoded
Definition: ffmpeg.h:388
OptionsContext::find_stream_info
int find_stream_info
Definition: ffmpeg.h:145
strip_specifiers
AVDictionary * strip_specifiers(const AVDictionary *dict)
Definition: ffmpeg_opt.c:169
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
AVPacket::flags
int flags
A combination of AV_PKT_FLAG values.
Definition: packet.h:497
av_packet_alloc
AVPacket * av_packet_alloc(void)
Allocate an AVPacket and set its fields to default values.
Definition: avpacket.c:63
av_dict_free
void av_dict_free(AVDictionary **pm)
Free all the memory allocated for an AVDictionary struct and all keys and values.
Definition: dict.c:225
guess_input_channel_layout
static int guess_input_channel_layout(InputStream *ist, int guess_layout_max)
Definition: ffmpeg_demux.c:922
av_parse_video_size
int av_parse_video_size(int *width_ptr, int *height_ptr, const char *str)
Parse str and put in width_ptr and height_ptr the detected values.
Definition: parseutils.c:150
pthread_t
Definition: os2threads.h:44
OptionsContext::frame_rates
SpecifierOpt * frame_rates
Definition: ffmpeg.h:127
AV_LOG_INFO
#define AV_LOG_INFO
Standard information.
Definition: log.h:191
video_codec_name
static const char * video_codec_name
Definition: ffplay.c:344
av_thread_message_queue_alloc
int av_thread_message_queue_alloc(AVThreadMessageQueue **mq, unsigned nelem, unsigned elsize)
Allocate a new message queue.
Definition: threadmessage.c:45
DemuxStream::next_dts
int64_t next_dts
dts of the last packet read for this stream (in AV_TIME_BASE units)
Definition: ffmpeg_demux.c:73
AVCodec::id
enum AVCodecID id
Definition: codec.h:201
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:974
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
Demuxer::non_blocking
int non_blocking
Definition: ffmpeg_demux.c:113
avcodec_get_name
const char * avcodec_get_name(enum AVCodecID id)
Get the name of a codec.
Definition: utils.c:417
HWACCEL_AUTO
@ HWACCEL_AUTO
Definition: ffmpeg.h:79
DemuxStream
Definition: ffmpeg_demux.c:56
av_parse_video_rate
int av_parse_video_rate(AVRational *rate, const char *arg)
Parse str and store the detected values in *rate.
Definition: parseutils.c:181
DemuxMsg::looping
int looping
Definition: ffmpeg_demux.c:120
DECODING_FOR_FILTER
#define DECODING_FOR_FILTER
Definition: ffmpeg.h:335
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:245
AVPacket::pts
int64_t pts
Presentation timestamp in AVStream->time_base units; the time at which the decompressed packet will b...
Definition: packet.h:484
packet.h
AVFormatContext::subtitle_codec
const struct AVCodec * subtitle_codec
Forced subtitle codec.
Definition: avformat.h:1599
AVCodecParameters::height
int height
Definition: codec_par.h:122
AV_TIME_BASE
#define AV_TIME_BASE
Internal time base represented as integer.
Definition: avutil.h:254
SHOW_TS_DEBUG
#define SHOW_TS_DEBUG(tag_)
OptionsContext::audio_sample_rate
SpecifierOpt * audio_sample_rate
Definition: ffmpeg.h:125
OptionsContext::start_time_eof
int64_t start_time_eof
Definition: ffmpeg.h:115
display.h
av_thread_message_queue_set_err_send
void av_thread_message_queue_set_err_send(AVThreadMessageQueue *mq, int err)
Set the sending error code.
Definition: threadmessage.c:193
exit_on_error
int exit_on_error
Definition: ffmpeg_opt.c:82
av_assert1
#define av_assert1(cond)
assert() equivalent, that does not lie in speed critical code.
Definition: avassert.h:56
OptionsContext::nb_frame_pix_fmts
int nb_frame_pix_fmts
Definition: ffmpeg.h:134
delta
float delta
Definition: vorbis_enc_data.h:430
AVMEDIA_TYPE_ATTACHMENT
@ AVMEDIA_TYPE_ATTACHMENT
Opaque data information usually sparse.
Definition: avutil.h:205
AV_OPT_FLAG_DECODING_PARAM
#define AV_OPT_FLAG_DECODING_PARAM
a generic parameter which can be set by the user for demuxing or decoding
Definition: opt.h:282
InputFile::ctx
AVFormatContext * ctx
Definition: ffmpeg.h:400
FFMIN
#define FFMIN(a, b)
Definition: macros.h:49
thread_start
static int thread_start(Demuxer *d)
Definition: ffmpeg_demux.c:658
AVProgram
New fields can be added to the end with minor version bumps.
Definition: avformat.h:1039
av_inv_q
static av_always_inline AVRational av_inv_q(AVRational q)
Invert a rational.
Definition: rational.h:159
av_rescale
int64_t av_rescale(int64_t a, int64_t b, int64_t c)
Rescale a 64-bit integer with rounding to nearest.
Definition: mathematics.c:129
int_cb
const AVIOInterruptCB int_cb
Definition: ffmpeg.c:347
AVCodecContext::height
int height
Definition: avcodec.h:621
AVCodecParameters::coded_side_data
AVPacketSideData * coded_side_data
Additional data associated with the entire stream.
Definition: codec_par.h:226
AVFMT_FLAG_NONBLOCK
#define AVFMT_FLAG_NONBLOCK
Do not block when reading packets from input.
Definition: avformat.h:1236
av_codec_iterate
const AVCodec * av_codec_iterate(void **opaque)
Iterate over all registered codecs.
Definition: allcodecs.c:930
ist_find_unused
InputStream * ist_find_unused(enum AVMediaType type)
Find an unused input stream of given type.
Definition: ffmpeg_demux.c:133
Timestamp::tb
AVRational tb
Definition: ffmpeg_utils.h:32
InputStream::decoder
Decoder * decoder
Definition: ffmpeg.h:343
ts_discontinuity_process
static void ts_discontinuity_process(Demuxer *d, InputStream *ist, AVPacket *pkt)
Definition: ffmpeg_demux.c:262
av_buffer_allocz
AVBufferRef * av_buffer_allocz(size_t size)
Same as av_buffer_alloc(), except the returned buffer will be initialized to zero.
Definition: buffer.c:93
tag
uint32_t tag
Definition: movenc.c:1737
AVStream::id
int id
Format-specific stream ID.
Definition: avformat.h:853
AVFMT_FLAG_BITEXACT
#define AVFMT_FLAG_BITEXACT
When muxing, try to avoid writing any random/volatile data to the output.
Definition: avformat.h:1250
ret
ret
Definition: filter_design.txt:187
AVStream
Stream structure.
Definition: avformat.h:841
AV_LOG_FATAL
#define AV_LOG_FATAL
Something went wrong and recovery is not possible.
Definition: log.h:174
dec_free
void dec_free(Decoder **pdec)
Definition: ffmpeg_dec.c:98
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:655
DemuxStream::wrap_correction_done
int wrap_correction_done
Definition: ffmpeg_demux.c:66
input_packet_process
static int input_packet_process(Demuxer *d, DemuxMsg *msg, AVPacket *src)
Definition: ffmpeg_demux.c:445
AVClass::class_name
const char * class_name
The name of the class; usually it is the same name as the context structure type to which the AVClass...
Definition: log.h:71
av_strlcat
size_t av_strlcat(char *dst, const char *src, size_t size)
Append the string src to the string dst, but to a total length of no more than size - 1 bytes,...
Definition: avstring.c: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:98
InputFile::streams
InputStream ** streams
Definition: ffmpeg.h:416
add_display_matrix_to_stream
static int add_display_matrix_to_stream(const OptionsContext *o, AVFormatContext *ctx, InputStream *ist)
Definition: ffmpeg_demux.c:940
hwaccel
static const char * hwaccel
Definition: ffplay.c:356
InputStream::reinit_filters
int reinit_filters
Definition: ffmpeg.h:377
avformat.h
HWAccelID
HWAccelID
Definition: ffmpeg.h:77
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: avpacket.c:700
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:2896
AVFormatContext::data_codec_id
enum AVCodecID data_codec_id
Forced Data codec_id.
Definition: avformat.h:1645
av_get_media_type_string
const char * av_get_media_type_string(enum AVMediaType media_type)
Return a string describing the media_type enum, NULL if media_type is unknown.
Definition: utils.c:28
AVCodecContext
main external API structure.
Definition: avcodec.h:441
AVStream::index
int index
stream index in AVFormatContext
Definition: avformat.h:847
Demuxer::in_thread_queue
AVThreadMessageQueue * in_thread_queue
Definition: ffmpeg_demux.c:110
audio_codec_name
static const char * audio_codec_name
Definition: ffplay.c:342
ts_discontinuity_detect
static void ts_discontinuity_detect(Demuxer *d, InputStream *ist, AVPacket *pkt)
Definition: ffmpeg_demux.c:194
OptionsContext::nb_audio_channels
int nb_audio_channels
Definition: ffmpeg.h:124
AVInputFormat::flags
int flags
Can use flags: AVFMT_NOFILE, AVFMT_NEEDNUMBER, AVFMT_SHOW_IDS, AVFMT_NOTIMESTAMPS,...
Definition: avformat.h:568
SpecifierOpt::str
uint8_t * str
Definition: cmdutils.h:97
AV_PIX_FMT_NONE
@ AV_PIX_FMT_NONE
Definition: pixfmt.h:65
avformat_free_context
void avformat_free_context(AVFormatContext *s)
Free an AVFormatContext and all its streams.
Definition: avformat.c:102
OptionsContext::video_disable
int video_disable
Definition: ffmpeg.h:181
ds_from_ist
static DemuxStream * ds_from_ist(InputStream *ist)
Definition: ffmpeg_demux.c:123
OptionsContext::frame_pix_fmts
SpecifierOpt * frame_pix_fmts
Definition: ffmpeg.h:133
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:1315
AVFormatContext::duration
int64_t duration
Duration of the stream, in AV_TIME_BASE fractional seconds.
Definition: avformat.h:1217
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:493
GROW_ARRAY
#define GROW_ARRAY(array, nb_elems)
Definition: cmdutils.h:401
HWACCEL_NONE
@ HWACCEL_NONE
Definition: ffmpeg.h:78
seek_to_start
static int seek_to_start(Demuxer *d)
Definition: ffmpeg_demux.c:156
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:859
InputFile::ts_offset
int64_t ts_offset
Definition: ffmpeg.h:409
OptionsContext::nb_frame_sizes
int nb_frame_sizes
Definition: ffmpeg.h:132
InputStream::decode_errors
uint64_t decode_errors
Definition: ffmpeg.h:389
InputStream::discard
int discard
Definition: ffmpeg.h:331
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:169
av_strdup
char * av_strdup(const char *s)
Duplicate a string.
Definition: mem.c:270
AVMEDIA_TYPE_VIDEO
@ AVMEDIA_TYPE_VIDEO
Definition: avutil.h:201
start_at_zero
int start_at_zero
Definition: ffmpeg_opt.c:79
AVFMT_TS_DISCONT
#define AVFMT_TS_DISCONT
Format allows timestamp discontinuities.
Definition: avformat.h:482
SpecifierOpt::u
union SpecifierOpt::@0 u
AV_CODEC_FLAG_BITEXACT
#define AV_CODEC_FLAG_BITEXACT
Use only bitexact stuff (except (I)DCT).
Definition: avcodec.h:338
AVCodecParameters::video_delay
int video_delay
Video only.
Definition: codec_par.h:150
InputStream::sub2video::h
int h
Definition: ffmpeg.h:361
InputFile::audio_ts_queue
AVThreadMessageQueue * audio_ts_queue
Definition: ffmpeg.h:424
DemuxStream::log_name
char log_name[32]
Definition: ffmpeg_demux.c:60
thread_stop
static void thread_stop(Demuxer *d)
Definition: ffmpeg_demux.c:642
avcodec_parameters_from_context
int avcodec_parameters_from_context(struct AVCodecParameters *par, const AVCodecContext *codec)
Fill the parameters struct based on the values from the supplied codec context.
Definition: codec_par.c:137
InputStream::class
const AVClass * class
Definition: ffmpeg.h:325
ts_fixup
static int ts_fixup(Demuxer *d, AVPacket *pkt)
Definition: ffmpeg_demux.c:352
InputStream::index
int index
Definition: ffmpeg.h:328
readrate_sleep
static void readrate_sleep(Demuxer *d)
Definition: ffmpeg_demux.c:487
AVDictionaryEntry
Definition: dict.h:89
Demuxer::max_pts
Timestamp max_pts
Definition: ffmpeg_demux.c:103
stdin_interaction
int stdin_interaction
Definition: ffmpeg_opt.c:85
do_hex_dump
int do_hex_dump
Definition: ffmpeg_opt.c:76
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
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:468
DemuxMsg
Definition: ffmpeg_demux.c:118
av_thread_message_queue_free
void av_thread_message_queue_free(AVThreadMessageQueue **mq)
Free a message queue.
Definition: threadmessage.c:96
av_freep
#define av_freep(p)
Definition: tableprint_vlc.h:34
av_dict_set
int av_dict_set(AVDictionary **pm, const char *key, const char *value, int flags)
Set the given entry in *pm, overwriting an existing entry.
Definition: dict.c:88
src
INIT_CLIP pixel * src
Definition: h264pred_template.c:418
AVPacket::pos
int64_t pos
byte position in stream, -1 if unknown
Definition: packet.h:511
opt_name_reinit_filters
static const char *const opt_name_reinit_filters[]
Definition: ffmpeg_demux.c:43
OptionsContext::data_disable
int data_disable
Definition: ffmpeg.h:184
d
d
Definition: ffmpeg_filter.c:368
AVCodecContext::width
int width
picture width / height.
Definition: avcodec.h:621
int32_t
int32_t
Definition: audioconvert.c:56
ist_free
static void ist_free(InputStream **pist)
Definition: ffmpeg_demux.c:771
timestamp.h
OutputStream
Definition: mux.c:53
flags
#define flags(name, subs,...)
Definition: cbs_av1.c:474
Demuxer::min_pts
Timestamp min_pts
Definition: ffmpeg_demux.c:102
av_thread_message_queue_set_err_recv
void av_thread_message_queue_set_err_recv(AVThreadMessageQueue *mq, int err)
Set the receiving error code.
Definition: threadmessage.c:204
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:1207
dts_error_threshold
float dts_error_threshold
Definition: ffmpeg_opt.c:70
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:32
AVCodecHWConfig
Definition: codec.h:341
av_pkt_dump_log2
void av_pkt_dump_log2(void *avcl, int level, const AVPacket *pkt, int dump_payload, const AVStream *st)
Send a nice dump of a packet to the log.
Definition: dump.c:117
avcodec_descriptor_get
const AVCodecDescriptor * avcodec_descriptor_get(enum AVCodecID id)
Definition: codec_desc.c:3736
Demuxer::last_ts
int64_t last_ts
Definition: ffmpeg_demux.c:95
AVDictionaryEntry::value
char * value
Definition: dict.h:91
avstring.h
Timestamp
Definition: ffmpeg_utils.h:30
DemuxStream::saw_first_ts
int saw_first_ts
dts of the first packet read for this stream (in AV_TIME_BASE units)
Definition: ffmpeg_demux.c:67
AVStream::pts_wrap_bits
int pts_wrap_bits
Number of bits in timestamps.
Definition: avformat.h:1016
dump_attachment
static int dump_attachment(InputStream *ist, const char *filename)
Definition: ffmpeg_demux.c:1263
AVERROR_PROTOCOL_NOT_FOUND
#define AVERROR_PROTOCOL_NOT_FOUND
Protocol not found.
Definition: error.h:65
InputStream::dec
const AVCodec * dec
Definition: ffmpeg.h:345
snprintf
#define snprintf
Definition: snprintf.h:34
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
av_dict_iterate
const AVDictionaryEntry * av_dict_iterate(const AVDictionary *m, const AVDictionaryEntry *prev)
Iterate over a dictionary.
Definition: dict.c:44
AVInputFormat::priv_class
const AVClass * priv_class
AVClass for the private context.
Definition: avformat.h:579
AVPacket::time_base
AVRational time_base
Time base of the packet's timestamps.
Definition: packet.h:535
OptionsContext::loop
int loop
Definition: ffmpeg.h:138
InputStream::autorotate
int autorotate
Definition: ffmpeg.h:356
thread_set_name
static void thread_set_name(InputFile *f)
Definition: ffmpeg_demux.c:522
ff_thread_setname
static int ff_thread_setname(const char *name)
Definition: thread.h:214
AVFormatContext::subtitle_codec_id
enum AVCodecID subtitle_codec_id
Forced subtitle codec_id.
Definition: avformat.h:1301