FFmpeg
ffmpeg_demux.c
Go to the documentation of this file.
1 /*
2  * This file is part of FFmpeg.
3  *
4  * FFmpeg is free software; you can redistribute it and/or
5  * modify it under the terms of the GNU Lesser General Public
6  * License as published by the Free Software Foundation; either
7  * version 2.1 of the License, or (at your option) any later version.
8  *
9  * FFmpeg is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12  * Lesser General Public License for more details.
13  *
14  * You should have received a copy of the GNU Lesser General Public
15  * License along with FFmpeg; if not, write to the Free Software
16  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
17  */
18 
19 #include <float.h>
20 #include <stdint.h>
21 
22 #include "ffmpeg.h"
23 
24 #include "libavutil/avassert.h"
25 #include "libavutil/avstring.h"
26 #include "libavutil/display.h"
27 #include "libavutil/error.h"
28 #include "libavutil/intreadwrite.h"
29 #include "libavutil/opt.h"
30 #include "libavutil/parseutils.h"
31 #include "libavutil/pixdesc.h"
32 #include "libavutil/time.h"
33 #include "libavutil/timestamp.h"
34 #include "libavutil/thread.h"
36 
37 #include "libavcodec/packet.h"
38 
39 #include "libavformat/avformat.h"
40 
41 static const char *const opt_name_discard[] = {"discard", NULL};
42 static const char *const opt_name_reinit_filters[] = {"reinit_filter", NULL};
43 static const char *const opt_name_fix_sub_duration[] = {"fix_sub_duration", NULL};
44 static const char *const opt_name_canvas_sizes[] = {"canvas_size", NULL};
45 static const char *const opt_name_guess_layout_max[] = {"guess_layout_max", NULL};
46 static const char *const opt_name_ts_scale[] = {"itsscale", NULL};
47 static const char *const opt_name_hwaccels[] = {"hwaccel", NULL};
48 static const char *const opt_name_hwaccel_devices[] = {"hwaccel_device", NULL};
49 static const char *const opt_name_hwaccel_output_formats[] = {"hwaccel_output_format", NULL};
50 static const char *const opt_name_autorotate[] = {"autorotate", NULL};
51 static const char *const opt_name_display_rotations[] = {"display_rotation", NULL};
52 static const char *const opt_name_display_hflips[] = {"display_hflip", NULL};
53 static const char *const opt_name_display_vflips[] = {"display_vflip", NULL};
54 
55 typedef struct DemuxStream {
57 
58  // name used for logging
59  char log_name[32];
60 
61  double ts_scale;
62 
64 
67  ///< dts of the first packet read for this stream (in AV_TIME_BASE units)
68  int64_t first_dts;
69 
70  /* predicted dts of the next packet read for this stream or (when there are
71  * several frames in a packet) of the next frame in current packet (in AV_TIME_BASE units) */
72  int64_t next_dts;
73  ///< dts of the last packet read for this stream (in AV_TIME_BASE units)
74  int64_t dts;
75 
76  int64_t min_pts; /* pts with the smallest value in a current stream */
77  int64_t max_pts; /* pts with the higher value in a current stream */
78 
79  /* number of packets successfully read for this stream */
80  uint64_t nb_packets;
81  // combined size of all the packets read
82  uint64_t data_size;
83 } DemuxStream;
84 
85 typedef struct Demuxer {
87 
88  // name used for logging
89  char log_name[32];
90 
91  int64_t wallclock_start;
92 
93  /**
94  * Extra timestamp offset added by discontinuity handling.
95  */
97  int64_t last_ts;
98 
99  /* number of times input stream should be looped */
100  int loop;
101  /* actual duration of the longest stream in a file at the moment when
102  * looping happens */
103  int64_t duration;
104  /* time base of the duration */
106 
107  /* number of streams that the user was warned of */
109 
111 
116 
118 } Demuxer;
119 
120 typedef struct DemuxMsg {
122  int looping;
123 } DemuxMsg;
124 
126 {
127  return (DemuxStream*)ist;
128 }
129 
131 {
132  return (Demuxer*)f;
133 }
134 
136 {
137  for (InputStream *ist = ist_iter(NULL); ist; ist = ist_iter(ist)) {
138  if (ist->par->codec_type == type && ist->discard &&
139  ist->user_set_discard != AVDISCARD_ALL)
140  return ist;
141  }
142  return NULL;
143 }
144 
145 static void report_new_stream(Demuxer *d, const AVPacket *pkt)
146 {
147  AVStream *st = d->f.ctx->streams[pkt->stream_index];
148 
149  if (pkt->stream_index < d->nb_streams_warn)
150  return;
152  "New %s stream with index %d at pos:%"PRId64" and DTS:%ss\n",
155  d->nb_streams_warn = pkt->stream_index + 1;
156 }
157 
159  int64_t last_duration)
160 {
161  /* the total duration of the stream, max_pts - min_pts is
162  * the duration of the stream without the last frame */
163  if (ds->max_pts > ds->min_pts &&
164  ds->max_pts - (uint64_t)ds->min_pts < INT64_MAX - last_duration)
165  last_duration += ds->max_pts - ds->min_pts;
166 
167  if (!d->duration ||
168  av_compare_ts(d->duration, d->time_base,
169  last_duration, ds->ist.st->time_base) < 0) {
170  d->duration = last_duration;
171  d->time_base = ds->ist.st->time_base;
172  }
173 }
174 
175 static int seek_to_start(Demuxer *d)
176 {
177  InputFile *ifile = &d->f;
178  AVFormatContext *is = ifile->ctx;
179  int ret;
180 
181  ret = avformat_seek_file(is, -1, INT64_MIN, is->start_time, is->start_time, 0);
182  if (ret < 0)
183  return ret;
184 
185  if (ifile->audio_duration_queue_size) {
186  /* duration is the length of the last frame in a stream
187  * when audio stream is present we don't care about
188  * last video frame length because it's not defined exactly */
189  int got_durations = 0;
190 
191  while (got_durations < ifile->audio_duration_queue_size) {
192  DemuxStream *ds;
193  LastFrameDuration dur;
195  if (ret < 0)
196  return ret;
197  got_durations++;
198 
199  ds = ds_from_ist(ifile->streams[dur.stream_idx]);
200  ifile_duration_update(d, ds, dur.duration);
201  }
202  } else {
203  for (int i = 0; i < ifile->nb_streams; i++) {
204  int64_t duration = 0;
205  InputStream *ist = ifile->streams[i];
206  DemuxStream *ds = ds_from_ist(ist);
207 
208  if (ist->framerate.num) {
209  duration = av_rescale_q(1, av_inv_q(ist->framerate), ist->st->time_base);
210  } else if (ist->st->avg_frame_rate.num) {
212  } else {
213  duration = 1;
214  }
215 
217  }
218  }
219 
220  if (d->loop > 0)
221  d->loop--;
222 
223  return ret;
224 }
225 
227  AVPacket *pkt)
228 {
229  InputFile *ifile = &d->f;
230  DemuxStream *ds = ds_from_ist(ist);
231  const int fmt_is_discont = ifile->ctx->iformat->flags & AVFMT_TS_DISCONT;
232  int disable_discontinuity_correction = copy_ts;
233  int64_t pkt_dts = av_rescale_q_rnd(pkt->dts, pkt->time_base, AV_TIME_BASE_Q,
235 
236  if (copy_ts && ds->next_dts != AV_NOPTS_VALUE &&
237  fmt_is_discont && ist->st->pts_wrap_bits < 60) {
238  int64_t wrap_dts = av_rescale_q_rnd(pkt->dts + (1LL<<ist->st->pts_wrap_bits),
241  if (FFABS(wrap_dts - ds->next_dts) < FFABS(pkt_dts - ds->next_dts)/10)
242  disable_discontinuity_correction = 0;
243  }
244 
245  if (ds->next_dts != AV_NOPTS_VALUE && !disable_discontinuity_correction) {
246  int64_t delta = pkt_dts - ds->next_dts;
247  if (fmt_is_discont) {
248  if (FFABS(delta) > 1LL * dts_delta_threshold * AV_TIME_BASE ||
249  pkt_dts + AV_TIME_BASE/10 < ds->dts) {
250  d->ts_offset_discont -= delta;
251  av_log(ist, AV_LOG_WARNING,
252  "timestamp discontinuity "
253  "(stream id=%d): %"PRId64", new offset= %"PRId64"\n",
254  ist->st->id, delta, d->ts_offset_discont);
256  if (pkt->pts != AV_NOPTS_VALUE)
258  }
259  } else {
260  if (FFABS(delta) > 1LL * dts_error_threshold * AV_TIME_BASE) {
262  "DTS %"PRId64", next:%"PRId64" st:%d invalid dropping\n",
263  pkt->dts, ds->next_dts, pkt->stream_index);
265  }
266  if (pkt->pts != AV_NOPTS_VALUE){
267  int64_t pkt_pts = av_rescale_q(pkt->pts, pkt->time_base, AV_TIME_BASE_Q);
268  delta = pkt_pts - ds->next_dts;
269  if (FFABS(delta) > 1LL * dts_error_threshold * AV_TIME_BASE) {
271  "PTS %"PRId64", next:%"PRId64" invalid dropping st:%d\n",
272  pkt->pts, ds->next_dts, pkt->stream_index);
274  }
275  }
276  }
277  } else if (ds->next_dts == AV_NOPTS_VALUE && !copy_ts &&
278  fmt_is_discont && d->last_ts != AV_NOPTS_VALUE) {
279  int64_t delta = pkt_dts - d->last_ts;
280  if (FFABS(delta) > 1LL * dts_delta_threshold * AV_TIME_BASE) {
281  d->ts_offset_discont -= delta;
283  "Inter stream timestamp discontinuity %"PRId64", new offset= %"PRId64"\n",
284  delta, d->ts_offset_discont);
286  if (pkt->pts != AV_NOPTS_VALUE)
288  }
289  }
290 
291  d->last_ts = av_rescale_q(pkt->dts, pkt->time_base, AV_TIME_BASE_Q);
292 }
293 
295  AVPacket *pkt)
296 {
297  int64_t offset = av_rescale_q(d->ts_offset_discont, AV_TIME_BASE_Q,
298  pkt->time_base);
299 
300  // apply previously-detected timestamp-discontinuity offset
301  // (to all streams, not just audio/video)
302  if (pkt->dts != AV_NOPTS_VALUE)
303  pkt->dts += offset;
304  if (pkt->pts != AV_NOPTS_VALUE)
305  pkt->pts += offset;
306 
307  // detect timestamp discontinuities for audio/video
308  if ((ist->par->codec_type == AVMEDIA_TYPE_VIDEO ||
309  ist->par->codec_type == AVMEDIA_TYPE_AUDIO) &&
310  pkt->dts != AV_NOPTS_VALUE)
312 }
313 
315 {
316  InputStream *ist = &ds->ist;
317  const AVCodecParameters *par = ist->par;
318 
319  if (!ds->saw_first_ts) {
320  ds->first_dts =
321  ds->dts = ist->st->avg_frame_rate.num ? - ist->par->video_delay * AV_TIME_BASE / av_q2d(ist->st->avg_frame_rate) : 0;
322  if (pkt->pts != AV_NOPTS_VALUE) {
323  ds->first_dts =
325  }
326  ds->saw_first_ts = 1;
327  }
328 
329  if (ds->next_dts == AV_NOPTS_VALUE)
330  ds->next_dts = ds->dts;
331 
332  if (pkt->dts != AV_NOPTS_VALUE)
334 
335  ds->dts = ds->next_dts;
336  switch (par->codec_type) {
337  case AVMEDIA_TYPE_AUDIO:
338  av_assert1(pkt->duration >= 0);
339  if (par->sample_rate) {
340  ds->next_dts += ((int64_t)AV_TIME_BASE * par->frame_size) /
341  par->sample_rate;
342  } else {
344  }
345  break;
346  case AVMEDIA_TYPE_VIDEO:
347  if (ist->framerate.num) {
348  // TODO: Remove work-around for c99-to-c89 issue 7
349  AVRational time_base_q = AV_TIME_BASE_Q;
350  int64_t next_dts = av_rescale_q(ds->next_dts, time_base_q, av_inv_q(ist->framerate));
351  ds->next_dts = av_rescale_q(next_dts + 1, av_inv_q(ist->framerate), time_base_q);
352  } else if (pkt->duration) {
354  } else if (ist->par->framerate.num != 0) {
355  AVRational field_rate = av_mul_q(ist->par->framerate,
356  (AVRational){ 2, 1 });
357  int fields = 2;
358 
359  if (ist->codec_desc &&
361  av_stream_get_parser(ist->st))
363 
364  ds->next_dts += av_rescale_q(fields, av_inv_q(field_rate), AV_TIME_BASE_Q);
365  }
366  break;
367  }
368 
370  if (ds->streamcopy_needed) {
371  DemuxPktData *pd;
372 
373  pkt->opaque_ref = av_buffer_allocz(sizeof(*pd));
374  if (!pkt->opaque_ref)
375  return AVERROR(ENOMEM);
376  pd = (DemuxPktData*)pkt->opaque_ref->data;
377 
378  pd->dts_est = ds->dts;
379  }
380 
381  return 0;
382 }
383 
384 static int ts_fixup(Demuxer *d, AVPacket *pkt)
385 {
386  InputFile *ifile = &d->f;
387  InputStream *ist = ifile->streams[pkt->stream_index];
388  DemuxStream *ds = ds_from_ist(ist);
389  const int64_t start_time = ifile->start_time_effective;
390  int64_t duration;
391  int ret;
392 
393  pkt->time_base = ist->st->time_base;
394 
395 #define SHOW_TS_DEBUG(tag_) \
396  if (debug_ts) { \
397  av_log(ist, AV_LOG_INFO, "%s -> ist_index:%d:%d type:%s " \
398  "pkt_pts:%s pkt_pts_time:%s pkt_dts:%s pkt_dts_time:%s duration:%s duration_time:%s\n", \
399  tag_, ifile->index, pkt->stream_index, \
400  av_get_media_type_string(ist->st->codecpar->codec_type), \
401  av_ts2str(pkt->pts), av_ts2timestr(pkt->pts, &pkt->time_base), \
402  av_ts2str(pkt->dts), av_ts2timestr(pkt->dts, &pkt->time_base), \
403  av_ts2str(pkt->duration), av_ts2timestr(pkt->duration, &pkt->time_base)); \
404  }
405 
406  SHOW_TS_DEBUG("demuxer");
407 
409  ist->st->pts_wrap_bits < 64) {
410  int64_t stime, stime2;
411 
413  stime2= stime + (1ULL<<ist->st->pts_wrap_bits);
414  ds->wrap_correction_done = 1;
415 
416  if(stime2 > stime && pkt->dts != AV_NOPTS_VALUE && pkt->dts > stime + (1LL<<(ist->st->pts_wrap_bits-1))) {
417  pkt->dts -= 1ULL<<ist->st->pts_wrap_bits;
418  ds->wrap_correction_done = 0;
419  }
420  if(stime2 > stime && pkt->pts != AV_NOPTS_VALUE && pkt->pts > stime + (1LL<<(ist->st->pts_wrap_bits-1))) {
421  pkt->pts -= 1ULL<<ist->st->pts_wrap_bits;
422  ds->wrap_correction_done = 0;
423  }
424  }
425 
426  if (pkt->dts != AV_NOPTS_VALUE)
428  if (pkt->pts != AV_NOPTS_VALUE)
430 
431  if (pkt->pts != AV_NOPTS_VALUE)
432  pkt->pts *= ds->ts_scale;
433  if (pkt->dts != AV_NOPTS_VALUE)
434  pkt->dts *= ds->ts_scale;
435 
436  duration = av_rescale_q(d->duration, d->time_base, pkt->time_base);
437  if (pkt->pts != AV_NOPTS_VALUE) {
438  pkt->pts += duration;
439  ds->max_pts = FFMAX(pkt->pts, ds->max_pts);
440  ds->min_pts = FFMIN(pkt->pts, ds->min_pts);
441  }
442 
443  if (pkt->dts != AV_NOPTS_VALUE)
444  pkt->dts += duration;
445 
446  SHOW_TS_DEBUG("demuxer+tsfixup");
447 
448  // detect and try to correct for timestamp discontinuities
450 
451  // update estimated/predicted dts
452  ret = ist_dts_update(ds, pkt);
453  if (ret < 0)
454  return ret;
455 
456  return 0;
457 }
458 
459 // process an input packet into a message to send to the consumer thread
460 // src is always cleared by this function
462 {
463  InputFile *f = &d->f;
464  InputStream *ist = f->streams[src->stream_index];
465  DemuxStream *ds = ds_from_ist(ist);
466  AVPacket *pkt;
467  int ret = 0;
468 
469  pkt = av_packet_alloc();
470  if (!pkt) {
472  return AVERROR(ENOMEM);
473  }
475 
476  ret = ts_fixup(d, pkt);
477  if (ret < 0)
478  goto fail;
479 
480  ds->data_size += pkt->size;
481  ds->nb_packets++;
482 
483  if (debug_ts) {
484  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",
485  f->index, pkt->stream_index,
492  }
493 
494  msg->pkt = pkt;
495  pkt = NULL;
496 
497 fail:
499 
500  return ret;
501 }
502 
503 static void readrate_sleep(Demuxer *d)
504 {
505  InputFile *f = &d->f;
506  int64_t file_start = copy_ts * (
507  (f->start_time_effective != AV_NOPTS_VALUE ? f->start_time_effective * !start_at_zero : 0) +
508  (f->start_time != AV_NOPTS_VALUE ? f->start_time : 0)
509  );
510  int64_t burst_until = AV_TIME_BASE * d->readrate_initial_burst;
511  for (int i = 0; i < f->nb_streams; i++) {
512  InputStream *ist = f->streams[i];
513  DemuxStream *ds = ds_from_ist(ist);
514  int64_t stream_ts_offset, pts, now;
515  stream_ts_offset = FFMAX(ds->first_dts != AV_NOPTS_VALUE ? ds->first_dts : 0, file_start);
516  pts = av_rescale(ds->dts, 1000000, AV_TIME_BASE);
517  now = (av_gettime_relative() - d->wallclock_start) * f->readrate + stream_ts_offset;
518  if (pts - burst_until > now)
519  av_usleep(pts - burst_until - now);
520  }
521 }
522 
524 {
525  for (int j = 0; j < ifile->ctx->nb_programs; j++) {
526  AVProgram *p = ifile->ctx->programs[j];
527  int discard = AVDISCARD_ALL;
528 
529  for (int k = 0; k < p->nb_stream_indexes; k++)
530  if (!ifile->streams[p->stream_index[k]]->discard) {
531  discard = AVDISCARD_DEFAULT;
532  break;
533  }
534  p->discard = discard;
535  }
536 }
537 
539 {
540  char name[16];
541  snprintf(name, sizeof(name), "dmx%d:%s", f->index, f->ctx->iformat->name);
543 }
544 
545 static void *input_thread(void *arg)
546 {
547  Demuxer *d = arg;
548  InputFile *f = &d->f;
549  AVPacket *pkt;
550  unsigned flags = d->non_blocking ? AV_THREAD_MESSAGE_NONBLOCK : 0;
551  int ret = 0;
552 
553  pkt = av_packet_alloc();
554  if (!pkt) {
555  ret = AVERROR(ENOMEM);
556  goto finish;
557  }
558 
560 
562 
563  d->wallclock_start = av_gettime_relative();
564 
565  while (1) {
566  DemuxMsg msg = { NULL };
567 
568  ret = av_read_frame(f->ctx, pkt);
569 
570  if (ret == AVERROR(EAGAIN)) {
571  av_usleep(10000);
572  continue;
573  }
574  if (ret < 0) {
575  if (d->loop) {
576  /* signal looping to the consumer thread */
577  msg.looping = 1;
578  ret = av_thread_message_queue_send(d->in_thread_queue, &msg, 0);
579  if (ret >= 0)
580  ret = seek_to_start(d);
581  if (ret >= 0)
582  continue;
583 
584  /* fallthrough to the error path */
585  }
586 
587  if (ret == AVERROR_EOF)
588  av_log(d, AV_LOG_VERBOSE, "EOF while reading input\n");
589  else
590  av_log(d, AV_LOG_ERROR, "Error during demuxing: %s\n",
591  av_err2str(ret));
592 
593  break;
594  }
595 
596  if (do_pkt_dump) {
598  f->ctx->streams[pkt->stream_index]);
599  }
600 
601  /* the following test is needed in case new streams appear
602  dynamically in stream : we ignore them */
603  if (pkt->stream_index >= f->nb_streams ||
604  f->streams[pkt->stream_index]->discard) {
607  continue;
608  }
609 
610  if (pkt->flags & AV_PKT_FLAG_CORRUPT) {
612  "corrupt input packet in stream %d\n",
613  pkt->stream_index);
614  if (exit_on_error) {
617  break;
618  }
619  }
620 
621  ret = input_packet_process(d, &msg, pkt);
622  if (ret < 0)
623  break;
624 
625  if (f->readrate)
626  readrate_sleep(d);
627 
628  ret = av_thread_message_queue_send(d->in_thread_queue, &msg, flags);
629  if (flags && ret == AVERROR(EAGAIN)) {
630  flags = 0;
631  ret = av_thread_message_queue_send(d->in_thread_queue, &msg, flags);
633  "Thread message queue blocking; consider raising the "
634  "thread_queue_size option (current value: %d)\n",
635  d->thread_queue_size);
636  }
637  if (ret < 0) {
638  if (ret != AVERROR_EOF)
640  "Unable to send packet to main thread: %s\n",
641  av_err2str(ret));
642  av_packet_free(&msg.pkt);
643  break;
644  }
645  }
646 
647 finish:
648  av_assert0(ret < 0);
649  av_thread_message_queue_set_err_recv(d->in_thread_queue, ret);
650 
652 
653  av_log(d, AV_LOG_VERBOSE, "Terminating demuxer thread\n");
654 
655  return NULL;
656 }
657 
658 static void thread_stop(Demuxer *d)
659 {
660  InputFile *f = &d->f;
661  DemuxMsg msg;
662 
663  if (!d->in_thread_queue)
664  return;
666  while (av_thread_message_queue_recv(d->in_thread_queue, &msg, 0) >= 0)
667  av_packet_free(&msg.pkt);
668 
669  pthread_join(d->thread, NULL);
670  av_thread_message_queue_free(&d->in_thread_queue);
671  av_thread_message_queue_free(&f->audio_duration_queue);
672 }
673 
674 static int thread_start(Demuxer *d)
675 {
676  int ret;
677  InputFile *f = &d->f;
678 
679  if (d->thread_queue_size <= 0)
680  d->thread_queue_size = (nb_input_files > 1 ? 8 : 1);
681 
682  if (nb_input_files > 1 &&
683  (f->ctx->pb ? !f->ctx->pb->seekable :
684  strcmp(f->ctx->iformat->name, "lavfi")))
685  d->non_blocking = 1;
686  ret = av_thread_message_queue_alloc(&d->in_thread_queue,
687  d->thread_queue_size, sizeof(DemuxMsg));
688  if (ret < 0)
689  return ret;
690 
691  if (d->loop) {
692  int nb_audio_dec = 0;
693 
694  for (int i = 0; i < f->nb_streams; i++) {
695  InputStream *ist = f->streams[i];
696  nb_audio_dec += !!(ist->decoding_needed &&
698  }
699 
700  if (nb_audio_dec) {
701  ret = av_thread_message_queue_alloc(&f->audio_duration_queue,
702  nb_audio_dec, sizeof(LastFrameDuration));
703  if (ret < 0)
704  goto fail;
705  f->audio_duration_queue_size = nb_audio_dec;
706  }
707  }
708 
709  if ((ret = pthread_create(&d->thread, NULL, input_thread, d))) {
710  av_log(d, AV_LOG_ERROR, "pthread_create failed: %s. Try to increase `ulimit -v` or decrease `ulimit -s`.\n", strerror(ret));
711  ret = AVERROR(ret);
712  goto fail;
713  }
714 
715  d->read_started = 1;
716 
717  return 0;
718 fail:
719  av_thread_message_queue_free(&d->in_thread_queue);
720  return ret;
721 }
722 
724 {
726  DemuxMsg msg;
727  int ret;
728 
729  if (!d->in_thread_queue) {
730  ret = thread_start(d);
731  if (ret < 0)
732  return ret;
733  }
734 
735  ret = av_thread_message_queue_recv(d->in_thread_queue, &msg,
736  d->non_blocking ?
738  if (ret < 0)
739  return ret;
740  if (msg.looping)
741  return 1;
742 
743  *pkt = msg.pkt;
744  return 0;
745 }
746 
748 {
749  InputFile *f = &d->f;
750  uint64_t total_packets = 0, total_size = 0;
751 
752  av_log(f, AV_LOG_VERBOSE, "Input file #%d (%s):\n",
753  f->index, f->ctx->url);
754 
755  for (int j = 0; j < f->nb_streams; j++) {
756  InputStream *ist = f->streams[j];
757  DemuxStream *ds = ds_from_ist(ist);
758  enum AVMediaType type = ist->par->codec_type;
759 
760  if (ist->discard || type == AVMEDIA_TYPE_ATTACHMENT)
761  continue;
762 
763  total_size += ds->data_size;
764  total_packets += ds->nb_packets;
765 
766  av_log(f, AV_LOG_VERBOSE, " Input stream #%d:%d (%s): ",
767  f->index, j, av_get_media_type_string(type));
768  av_log(f, AV_LOG_VERBOSE, "%"PRIu64" packets read (%"PRIu64" bytes); ",
769  ds->nb_packets, ds->data_size);
770 
771  if (ist->decoding_needed) {
773  "%"PRIu64" frames decoded; %"PRIu64" decode errors",
774  ist->frames_decoded, ist->decode_errors);
775  if (type == AVMEDIA_TYPE_AUDIO)
776  av_log(f, AV_LOG_VERBOSE, " (%"PRIu64" samples)", ist->samples_decoded);
777  av_log(f, AV_LOG_VERBOSE, "; ");
778  }
779 
780  av_log(f, AV_LOG_VERBOSE, "\n");
781  }
782 
783  av_log(f, AV_LOG_VERBOSE, " Total: %"PRIu64" packets (%"PRIu64" bytes) demuxed\n",
784  total_packets, total_size);
785 }
786 
787 static void ist_free(InputStream **pist)
788 {
789  InputStream *ist = *pist;
790 
791  if (!ist)
792  return;
793 
794  dec_free(&ist->decoder);
795 
796  av_dict_free(&ist->decoder_opts);
797  av_freep(&ist->filters);
798  av_freep(&ist->outputs);
799  av_freep(&ist->hwaccel_device);
800 
803 
804  av_freep(pist);
805 }
806 
808 {
809  InputFile *f = *pf;
811 
812  if (!f)
813  return;
814 
815  thread_stop(d);
816 
817  if (d->read_started)
819 
820  for (int i = 0; i < f->nb_streams; i++)
821  ist_free(&f->streams[i]);
822  av_freep(&f->streams);
823 
824  avformat_close_input(&f->ctx);
825 
826  av_freep(pf);
827 }
828 
829 static int ist_use(InputStream *ist, int decoding_needed)
830 {
831  DemuxStream *ds = ds_from_ist(ist);
832 
833  if (ist->user_set_discard == AVDISCARD_ALL) {
834  av_log(ist, AV_LOG_ERROR, "Cannot %s a disabled input stream\n",
835  decoding_needed ? "decode" : "streamcopy");
836  return AVERROR(EINVAL);
837  }
838 
839  ist->discard = 0;
840  ist->st->discard = ist->user_set_discard;
841  ist->decoding_needed |= decoding_needed;
842  ds->streamcopy_needed |= !decoding_needed;
843 
844  if (decoding_needed && !avcodec_is_open(ist->dec_ctx)) {
845  int ret = dec_open(ist);
846  if (ret < 0)
847  return ret;
848  }
849 
850  return 0;
851 }
852 
854 {
855  int ret;
856 
857  ret = ist_use(ist, ost->enc ? DECODING_FOR_OST : 0);
858  if (ret < 0)
859  return ret;
860 
861  ret = GROW_ARRAY(ist->outputs, ist->nb_outputs);
862  if (ret < 0)
863  return ret;
864 
865  ist->outputs[ist->nb_outputs - 1] = ost;
866 
867  return 0;
868 }
869 
870 int ist_filter_add(InputStream *ist, InputFilter *ifilter, int is_simple)
871 {
872  int ret;
873 
874  ret = ist_use(ist, is_simple ? DECODING_FOR_OST : DECODING_FOR_FILTER);
875  if (ret < 0)
876  return ret;
877 
878  ret = GROW_ARRAY(ist->filters, ist->nb_filters);
879  if (ret < 0)
880  return ret;
881 
882  ist->filters[ist->nb_filters - 1] = ifilter;
883 
884  // initialize fallback parameters for filtering
885  ret = ifilter_parameters_from_dec(ifilter, ist->dec_ctx);
886  if (ret < 0)
887  return ret;
888 
889  return 0;
890 }
891 
893  enum HWAccelID hwaccel_id, enum AVHWDeviceType hwaccel_device_type,
894  const AVCodec **pcodec)
895 
896 {
897  char *codec_name = NULL;
898 
899  MATCH_PER_STREAM_OPT(codec_names, str, codec_name, s, st);
900  if (codec_name) {
901  int ret = find_codec(NULL, codec_name, st->codecpar->codec_type, 0, pcodec);
902  if (ret < 0)
903  return ret;
904  st->codecpar->codec_id = (*pcodec)->id;
905  if (recast_media && st->codecpar->codec_type != (*pcodec)->type)
906  st->codecpar->codec_type = (*pcodec)->type;
907  return 0;
908  } else {
909  if (st->codecpar->codec_type == AVMEDIA_TYPE_VIDEO &&
910  hwaccel_id == HWACCEL_GENERIC &&
911  hwaccel_device_type != AV_HWDEVICE_TYPE_NONE) {
912  const AVCodec *c;
913  void *i = NULL;
914 
915  while ((c = av_codec_iterate(&i))) {
916  const AVCodecHWConfig *config;
917 
918  if (c->id != st->codecpar->codec_id ||
920  continue;
921 
922  for (int j = 0; config = avcodec_get_hw_config(c, j); j++) {
923  if (config->device_type == hwaccel_device_type) {
924  av_log(NULL, AV_LOG_VERBOSE, "Selecting decoder '%s' because of requested hwaccel method %s\n",
925  c->name, av_hwdevice_get_type_name(hwaccel_device_type));
926  *pcodec = c;
927  return 0;
928  }
929  }
930  }
931  }
932 
933  *pcodec = avcodec_find_decoder(st->codecpar->codec_id);
934  return 0;
935  }
936 }
937 
938 static int guess_input_channel_layout(InputStream *ist, int guess_layout_max)
939 {
940  AVCodecContext *dec = ist->dec_ctx;
941 
943  char layout_name[256];
944 
945  if (dec->ch_layout.nb_channels > guess_layout_max)
946  return 0;
949  return 0;
950  av_channel_layout_describe(&dec->ch_layout, layout_name, sizeof(layout_name));
951  av_log(ist, AV_LOG_WARNING, "Guessed Channel Layout: %s\n", layout_name);
952  }
953  return 1;
954 }
955 
958 {
959  AVStream *st = ist->st;
960  AVPacketSideData *sd;
961  double rotation = DBL_MAX;
962  int hflip = -1, vflip = -1;
963  int hflip_set = 0, vflip_set = 0, rotation_set = 0;
964  int32_t *buf;
965 
966  MATCH_PER_STREAM_OPT(display_rotations, dbl, rotation, ctx, st);
967  MATCH_PER_STREAM_OPT(display_hflips, i, hflip, ctx, st);
968  MATCH_PER_STREAM_OPT(display_vflips, i, vflip, ctx, st);
969 
970  rotation_set = rotation != DBL_MAX;
971  hflip_set = hflip != -1;
972  vflip_set = vflip != -1;
973 
974  if (!rotation_set && !hflip_set && !vflip_set)
975  return 0;
976 
980  sizeof(int32_t) * 9, 0);
981  if (!sd) {
982  av_log(ist, AV_LOG_FATAL, "Failed to generate a display matrix!\n");
983  return AVERROR(ENOMEM);
984  }
985 
986  buf = (int32_t *)sd->data;
988  rotation_set ? -(rotation) : -0.0f);
989 
991  hflip_set ? hflip : 0,
992  vflip_set ? vflip : 0);
993 
994  return 0;
995 }
996 
997 static const char *input_stream_item_name(void *obj)
998 {
999  const DemuxStream *ds = obj;
1000 
1001  return ds->log_name;
1002 }
1003 
1004 static const AVClass input_stream_class = {
1005  .class_name = "InputStream",
1006  .version = LIBAVUTIL_VERSION_INT,
1007  .item_name = input_stream_item_name,
1008  .category = AV_CLASS_CATEGORY_DEMUXER,
1009 };
1010 
1012 {
1013  const char *type_str = av_get_media_type_string(st->codecpar->codec_type);
1014  InputFile *f = &d->f;
1015  DemuxStream *ds;
1016 
1017  ds = allocate_array_elem(&f->streams, sizeof(*ds), &f->nb_streams);
1018  if (!ds)
1019  return NULL;
1020 
1021  ds->ist.st = st;
1022  ds->ist.file_index = f->index;
1023  ds->ist.index = st->index;
1024  ds->ist.class = &input_stream_class;
1025 
1026  snprintf(ds->log_name, sizeof(ds->log_name), "%cist#%d:%d/%s",
1027  type_str ? *type_str : '?', d->f.index, st->index,
1029 
1030  return ds;
1031 }
1032 
1033 static int ist_add(const OptionsContext *o, Demuxer *d, AVStream *st)
1034 {
1035  AVFormatContext *ic = d->f.ctx;
1036  AVCodecParameters *par = st->codecpar;
1037  DemuxStream *ds;
1038  InputStream *ist;
1039  char *framerate = NULL, *hwaccel_device = NULL;
1040  const char *hwaccel = NULL;
1041  char *hwaccel_output_format = NULL;
1042  char *codec_tag = NULL;
1043  char *next;
1044  char *discard_str = NULL;
1045  int ret;
1046 
1047  ds = demux_stream_alloc(d, st);
1048  if (!ds)
1049  return AVERROR(ENOMEM);
1050 
1051  ist = &ds->ist;
1052 
1053  ist->discard = 1;
1054  st->discard = AVDISCARD_ALL;
1055  ist->nb_samples = 0;
1056  ds->first_dts = AV_NOPTS_VALUE;
1057  ds->next_dts = AV_NOPTS_VALUE;
1058 
1059  ds->min_pts = INT64_MAX;
1060  ds->max_pts = INT64_MIN;
1061 
1062  ds->ts_scale = 1.0;
1063  MATCH_PER_STREAM_OPT(ts_scale, dbl, ds->ts_scale, ic, st);
1064 
1065  ist->autorotate = 1;
1066  MATCH_PER_STREAM_OPT(autorotate, i, ist->autorotate, ic, st);
1067 
1068  MATCH_PER_STREAM_OPT(codec_tags, str, codec_tag, ic, st);
1069  if (codec_tag) {
1070  uint32_t tag = strtol(codec_tag, &next, 0);
1071  if (*next) {
1072  uint8_t buf[4] = { 0 };
1073  memcpy(buf, codec_tag, FFMIN(sizeof(buf), strlen(codec_tag)));
1074  tag = AV_RL32(buf);
1075  }
1076 
1077  st->codecpar->codec_tag = tag;
1078  }
1079 
1080  if (st->codecpar->codec_type == AVMEDIA_TYPE_VIDEO) {
1081  ret = add_display_matrix_to_stream(o, ic, ist);
1082  if (ret < 0)
1083  return ret;
1084 
1085  MATCH_PER_STREAM_OPT(hwaccels, str, hwaccel, ic, st);
1086  MATCH_PER_STREAM_OPT(hwaccel_output_formats, str,
1087  hwaccel_output_format, ic, st);
1088 
1089  if (!hwaccel_output_format && hwaccel && !strcmp(hwaccel, "cuvid")) {
1090  av_log(ist, AV_LOG_WARNING,
1091  "WARNING: defaulting hwaccel_output_format to cuda for compatibility "
1092  "with old commandlines. This behaviour is DEPRECATED and will be removed "
1093  "in the future. Please explicitly set \"-hwaccel_output_format cuda\".\n");
1095  } else if (!hwaccel_output_format && hwaccel && !strcmp(hwaccel, "qsv")) {
1096  av_log(ist, AV_LOG_WARNING,
1097  "WARNING: defaulting hwaccel_output_format to qsv for compatibility "
1098  "with old commandlines. This behaviour is DEPRECATED and will be removed "
1099  "in the future. Please explicitly set \"-hwaccel_output_format qsv\".\n");
1101  } else if (!hwaccel_output_format && hwaccel && !strcmp(hwaccel, "mediacodec")) {
1102  // There is no real AVHWFrameContext implementation. Set
1103  // hwaccel_output_format to avoid av_hwframe_transfer_data error.
1105  } else if (hwaccel_output_format) {
1106  ist->hwaccel_output_format = av_get_pix_fmt(hwaccel_output_format);
1107  if (ist->hwaccel_output_format == AV_PIX_FMT_NONE) {
1108  av_log(ist, AV_LOG_FATAL, "Unrecognised hwaccel output "
1109  "format: %s", hwaccel_output_format);
1110  }
1111  } else {
1113  }
1114 
1115  if (hwaccel) {
1116  // The NVDEC hwaccels use a CUDA device, so remap the name here.
1117  if (!strcmp(hwaccel, "nvdec") || !strcmp(hwaccel, "cuvid"))
1118  hwaccel = "cuda";
1119 
1120  if (!strcmp(hwaccel, "none"))
1121  ist->hwaccel_id = HWACCEL_NONE;
1122  else if (!strcmp(hwaccel, "auto"))
1123  ist->hwaccel_id = HWACCEL_AUTO;
1124  else {
1126  if (type != AV_HWDEVICE_TYPE_NONE) {
1127  ist->hwaccel_id = HWACCEL_GENERIC;
1128  ist->hwaccel_device_type = type;
1129  }
1130 
1131  if (!ist->hwaccel_id) {
1132  av_log(ist, AV_LOG_FATAL, "Unrecognized hwaccel: %s.\n",
1133  hwaccel);
1134  av_log(ist, AV_LOG_FATAL, "Supported hwaccels: ");
1136  while ((type = av_hwdevice_iterate_types(type)) !=
1138  av_log(ist, AV_LOG_FATAL, "%s ",
1140  av_log(ist, AV_LOG_FATAL, "\n");
1141  return AVERROR(EINVAL);
1142  }
1143  }
1144  }
1145 
1146  MATCH_PER_STREAM_OPT(hwaccel_devices, str, hwaccel_device, ic, st);
1147  if (hwaccel_device) {
1148  ist->hwaccel_device = av_strdup(hwaccel_device);
1149  if (!ist->hwaccel_device)
1150  return AVERROR(ENOMEM);
1151  }
1152  }
1153 
1154  ret = choose_decoder(o, ic, st, ist->hwaccel_id, ist->hwaccel_device_type,
1155  &ist->dec);
1156  if (ret < 0)
1157  return ret;
1158 
1160  ic, st, ist->dec, &ist->decoder_opts);
1161  if (ret < 0)
1162  return ret;
1163 
1164  ist->reinit_filters = -1;
1165  MATCH_PER_STREAM_OPT(reinit_filters, i, ist->reinit_filters, ic, st);
1166 
1167  MATCH_PER_STREAM_OPT(discard, str, discard_str, ic, st);
1169 
1170  if ((o->video_disable && ist->st->codecpar->codec_type == AVMEDIA_TYPE_VIDEO) ||
1175 
1176  ist->dec_ctx = avcodec_alloc_context3(ist->dec);
1177  if (!ist->dec_ctx)
1178  return AVERROR(ENOMEM);
1179 
1180  if (discard_str) {
1181  const AVOption *discard_opt = av_opt_find(ist->dec_ctx, "skip_frame",
1182  NULL, 0, 0);
1183  ret = av_opt_eval_int(ist->dec_ctx, discard_opt, discard_str, &ist->user_set_discard);
1184  if (ret < 0) {
1185  av_log(ist, AV_LOG_ERROR, "Error parsing discard %s.\n", discard_str);
1186  return ret;
1187  }
1188  }
1189 
1191  if (ret < 0) {
1192  av_log(ist, AV_LOG_ERROR, "Error initializing the decoder context.\n");
1193  return ret;
1194  }
1195 
1196  if (o->bitexact)
1198 
1199  switch (par->codec_type) {
1200  case AVMEDIA_TYPE_VIDEO:
1201  MATCH_PER_STREAM_OPT(frame_rates, str, framerate, ic, st);
1202  if (framerate) {
1204  if (ret < 0) {
1205  av_log(ist, AV_LOG_ERROR, "Error parsing framerate %s.\n",
1206  framerate);
1207  return ret;
1208  }
1209  }
1210 
1211 #if FFMPEG_OPT_TOP
1212  ist->top_field_first = -1;
1213  MATCH_PER_STREAM_OPT(top_field_first, i, ist->top_field_first, ic, st);
1214 #endif
1215 
1216  ist->framerate_guessed = av_guess_frame_rate(ic, st, NULL);
1217 
1218  break;
1219  case AVMEDIA_TYPE_AUDIO: {
1220  int guess_layout_max = INT_MAX;
1221  MATCH_PER_STREAM_OPT(guess_layout_max, i, guess_layout_max, ic, st);
1222  guess_input_channel_layout(ist, guess_layout_max);
1223  break;
1224  }
1225  case AVMEDIA_TYPE_DATA:
1226  case AVMEDIA_TYPE_SUBTITLE: {
1227  char *canvas_size = NULL;
1228  MATCH_PER_STREAM_OPT(fix_sub_duration, i, ist->fix_sub_duration, ic, st);
1229  MATCH_PER_STREAM_OPT(canvas_sizes, str, canvas_size, ic, st);
1230  if (canvas_size) {
1232  canvas_size);
1233  if (ret < 0) {
1234  av_log(ist, AV_LOG_FATAL, "Invalid canvas size: %s.\n", canvas_size);
1235  return ret;
1236  }
1237  }
1238 
1239  /* Compute the size of the canvas for the subtitles stream.
1240  If the subtitles codecpar has set a size, use it. Otherwise use the
1241  maximum dimensions of the video streams in the same file. */
1242  ist->sub2video.w = ist->dec_ctx->width;
1243  ist->sub2video.h = ist->dec_ctx->height;
1244  if (!(ist->sub2video.w && ist->sub2video.h)) {
1245  for (int j = 0; j < ic->nb_streams; j++) {
1246  AVCodecParameters *par1 = ic->streams[j]->codecpar;
1247  if (par1->codec_type == AVMEDIA_TYPE_VIDEO) {
1248  ist->sub2video.w = FFMAX(ist->sub2video.w, par1->width);
1249  ist->sub2video.h = FFMAX(ist->sub2video.h, par1->height);
1250  }
1251  }
1252  }
1253 
1254  if (!(ist->sub2video.w && ist->sub2video.h)) {
1255  ist->sub2video.w = FFMAX(ist->sub2video.w, 720);
1256  ist->sub2video.h = FFMAX(ist->sub2video.h, 576);
1257  }
1258 
1259  break;
1260  }
1262  case AVMEDIA_TYPE_UNKNOWN:
1263  break;
1264  default:
1265  abort();
1266  }
1267 
1268  ist->par = avcodec_parameters_alloc();
1269  if (!ist->par)
1270  return AVERROR(ENOMEM);
1271 
1273  if (ret < 0) {
1274  av_log(ist, AV_LOG_ERROR, "Error initializing the decoder context.\n");
1275  return ret;
1276  }
1277 
1279 
1280  return 0;
1281 }
1282 
1283 static int dump_attachment(InputStream *ist, const char *filename)
1284 {
1285  AVStream *st = ist->st;
1286  int ret;
1287  AVIOContext *out = NULL;
1288  const AVDictionaryEntry *e;
1289 
1290  if (!st->codecpar->extradata_size) {
1291  av_log(ist, AV_LOG_WARNING, "No extradata to dump.\n");
1292  return 0;
1293  }
1294  if (!*filename && (e = av_dict_get(st->metadata, "filename", NULL, 0)))
1295  filename = e->value;
1296  if (!*filename) {
1297  av_log(ist, AV_LOG_FATAL, "No filename specified and no 'filename' tag");
1298  return AVERROR(EINVAL);
1299  }
1300 
1301  ret = assert_file_overwrite(filename);
1302  if (ret < 0)
1303  return ret;
1304 
1305  if ((ret = avio_open2(&out, filename, AVIO_FLAG_WRITE, &int_cb, NULL)) < 0) {
1306  av_log(ist, AV_LOG_FATAL, "Could not open file %s for writing.\n",
1307  filename);
1308  return ret;
1309  }
1310 
1312  ret = avio_close(out);
1313 
1314  if (ret >= 0)
1315  av_log(ist, AV_LOG_INFO, "Wrote attachment (%d bytes) to '%s'\n",
1316  st->codecpar->extradata_size, filename);
1317 
1318  return ret;
1319 }
1320 
1321 static const char *input_file_item_name(void *obj)
1322 {
1323  const Demuxer *d = obj;
1324 
1325  return d->log_name;
1326 }
1327 
1328 static const AVClass input_file_class = {
1329  .class_name = "InputFile",
1330  .version = LIBAVUTIL_VERSION_INT,
1331  .item_name = input_file_item_name,
1332  .category = AV_CLASS_CATEGORY_DEMUXER,
1333 };
1334 
1335 static Demuxer *demux_alloc(void)
1336 {
1338 
1339  if (!d)
1340  return NULL;
1341 
1342  d->f.class = &input_file_class;
1343  d->f.index = nb_input_files - 1;
1344 
1345  snprintf(d->log_name, sizeof(d->log_name), "in#%d", d->f.index);
1346 
1347  return d;
1348 }
1349 
1350 int ifile_open(const OptionsContext *o, const char *filename)
1351 {
1352  Demuxer *d;
1353  InputFile *f;
1354  AVFormatContext *ic;
1355  const AVInputFormat *file_iformat = NULL;
1356  int err, i, ret = 0;
1357  int64_t timestamp;
1358  AVDictionary *unused_opts = NULL;
1359  const AVDictionaryEntry *e = NULL;
1360  char * video_codec_name = NULL;
1361  char * audio_codec_name = NULL;
1362  char *subtitle_codec_name = NULL;
1363  char * data_codec_name = NULL;
1364  int scan_all_pmts_set = 0;
1365 
1366  int64_t start_time = o->start_time;
1367  int64_t start_time_eof = o->start_time_eof;
1368  int64_t stop_time = o->stop_time;
1369  int64_t recording_time = o->recording_time;
1370 
1371  d = demux_alloc();
1372  if (!d)
1373  return AVERROR(ENOMEM);
1374 
1375  f = &d->f;
1376 
1377  if (stop_time != INT64_MAX && recording_time != INT64_MAX) {
1378  stop_time = INT64_MAX;
1379  av_log(d, AV_LOG_WARNING, "-t and -to cannot be used together; using -t.\n");
1380  }
1381 
1382  if (stop_time != INT64_MAX && recording_time == INT64_MAX) {
1383  int64_t start = start_time == AV_NOPTS_VALUE ? 0 : start_time;
1384  if (stop_time <= start) {
1385  av_log(d, AV_LOG_ERROR, "-to value smaller than -ss; aborting.\n");
1386  return AVERROR(EINVAL);
1387  } else {
1388  recording_time = stop_time - start;
1389  }
1390  }
1391 
1392  if (o->format) {
1393  if (!(file_iformat = av_find_input_format(o->format))) {
1394  av_log(d, AV_LOG_FATAL, "Unknown input format: '%s'\n", o->format);
1395  return AVERROR(EINVAL);
1396  }
1397  }
1398 
1399  if (!strcmp(filename, "-"))
1400  filename = "fd:";
1401 
1402  stdin_interaction &= strncmp(filename, "pipe:", 5) &&
1403  strcmp(filename, "fd:") &&
1404  strcmp(filename, "/dev/stdin");
1405 
1406  /* get default parameters from command line */
1407  ic = avformat_alloc_context();
1408  if (!ic)
1409  return AVERROR(ENOMEM);
1410  if (o->nb_audio_sample_rate) {
1411  av_dict_set_int(&o->g->format_opts, "sample_rate", o->audio_sample_rate[o->nb_audio_sample_rate - 1].u.i, 0);
1412  }
1413  if (o->nb_audio_channels) {
1414  const AVClass *priv_class;
1415  if (file_iformat && (priv_class = file_iformat->priv_class) &&
1416  av_opt_find(&priv_class, "ch_layout", NULL, 0,
1418  char buf[32];
1419  snprintf(buf, sizeof(buf), "%dC", o->audio_channels[o->nb_audio_channels - 1].u.i);
1420  av_dict_set(&o->g->format_opts, "ch_layout", buf, 0);
1421  }
1422  }
1423  if (o->nb_audio_ch_layouts) {
1424  const AVClass *priv_class;
1425  if (file_iformat && (priv_class = file_iformat->priv_class) &&
1426  av_opt_find(&priv_class, "ch_layout", NULL, 0,
1428  av_dict_set(&o->g->format_opts, "ch_layout", o->audio_ch_layouts[o->nb_audio_ch_layouts - 1].u.str, 0);
1429  }
1430  }
1431  if (o->nb_frame_rates) {
1432  const AVClass *priv_class;
1433  /* set the format-level framerate option;
1434  * this is important for video grabbers, e.g. x11 */
1435  if (file_iformat && (priv_class = file_iformat->priv_class) &&
1436  av_opt_find(&priv_class, "framerate", NULL, 0,
1438  av_dict_set(&o->g->format_opts, "framerate",
1439  o->frame_rates[o->nb_frame_rates - 1].u.str, 0);
1440  }
1441  }
1442  if (o->nb_frame_sizes) {
1443  av_dict_set(&o->g->format_opts, "video_size", o->frame_sizes[o->nb_frame_sizes - 1].u.str, 0);
1444  }
1445  if (o->nb_frame_pix_fmts)
1446  av_dict_set(&o->g->format_opts, "pixel_format", o->frame_pix_fmts[o->nb_frame_pix_fmts - 1].u.str, 0);
1447 
1448  MATCH_PER_TYPE_OPT(codec_names, str, video_codec_name, ic, "v");
1449  MATCH_PER_TYPE_OPT(codec_names, str, audio_codec_name, ic, "a");
1450  MATCH_PER_TYPE_OPT(codec_names, str, subtitle_codec_name, ic, "s");
1451  MATCH_PER_TYPE_OPT(codec_names, str, data_codec_name, ic, "d");
1452 
1453  if (video_codec_name)
1455  &ic->video_codec));
1456  if (audio_codec_name)
1458  &ic->audio_codec));
1459  if (subtitle_codec_name)
1461  &ic->subtitle_codec));
1462  if (data_codec_name)
1463  ret = err_merge(ret, find_codec(NULL, data_codec_name , AVMEDIA_TYPE_DATA, 0,
1464  &ic->data_codec));
1465  if (ret < 0) {
1467  return ret;
1468  }
1469 
1473  ic->data_codec_id = data_codec_name ? ic->data_codec->id : AV_CODEC_ID_NONE;
1474 
1475  ic->flags |= AVFMT_FLAG_NONBLOCK;
1476  if (o->bitexact)
1477  ic->flags |= AVFMT_FLAG_BITEXACT;
1478  ic->interrupt_callback = int_cb;
1479 
1480  if (!av_dict_get(o->g->format_opts, "scan_all_pmts", NULL, AV_DICT_MATCH_CASE)) {
1481  av_dict_set(&o->g->format_opts, "scan_all_pmts", "1", AV_DICT_DONT_OVERWRITE);
1482  scan_all_pmts_set = 1;
1483  }
1484  /* open the input file with generic avformat function */
1485  err = avformat_open_input(&ic, filename, file_iformat, &o->g->format_opts);
1486  if (err < 0) {
1488  "Error opening input: %s\n", av_err2str(err));
1489  if (err == AVERROR_PROTOCOL_NOT_FOUND)
1490  av_log(d, AV_LOG_ERROR, "Did you mean file:%s?\n", filename);
1491  return err;
1492  }
1493  f->ctx = ic;
1494 
1495  av_strlcat(d->log_name, "/", sizeof(d->log_name));
1496  av_strlcat(d->log_name, ic->iformat->name, sizeof(d->log_name));
1497 
1498  if (scan_all_pmts_set)
1499  av_dict_set(&o->g->format_opts, "scan_all_pmts", NULL, AV_DICT_MATCH_CASE);
1501 
1503  if (ret < 0)
1504  return ret;
1505 
1506  /* apply forced codec ids */
1507  for (i = 0; i < ic->nb_streams; i++) {
1508  const AVCodec *dummy;
1510  &dummy);
1511  if (ret < 0)
1512  return ret;
1513  }
1514 
1515  if (o->find_stream_info) {
1516  AVDictionary **opts;
1517  int orig_nb_streams = ic->nb_streams;
1518 
1520  if (ret < 0)
1521  return ret;
1522 
1523  /* If not enough info to get the stream parameters, we decode the
1524  first frames to get it. (used in mpeg case for example) */
1526 
1527  for (i = 0; i < orig_nb_streams; i++)
1528  av_dict_free(&opts[i]);
1529  av_freep(&opts);
1530 
1531  if (ret < 0) {
1532  av_log(d, AV_LOG_FATAL, "could not find codec parameters\n");
1533  if (ic->nb_streams == 0)
1534  return ret;
1535  }
1536  }
1537 
1538  if (start_time != AV_NOPTS_VALUE && start_time_eof != AV_NOPTS_VALUE) {
1539  av_log(d, AV_LOG_WARNING, "Cannot use -ss and -sseof both, using -ss\n");
1540  start_time_eof = AV_NOPTS_VALUE;
1541  }
1542 
1543  if (start_time_eof != AV_NOPTS_VALUE) {
1544  if (start_time_eof >= 0) {
1545  av_log(d, AV_LOG_ERROR, "-sseof value must be negative; aborting\n");
1546  return AVERROR(EINVAL);
1547  }
1548  if (ic->duration > 0) {
1549  start_time = start_time_eof + ic->duration;
1550  if (start_time < 0) {
1551  av_log(d, AV_LOG_WARNING, "-sseof value seeks to before start of file; ignored\n");
1553  }
1554  } else
1555  av_log(d, AV_LOG_WARNING, "Cannot use -sseof, file duration not known\n");
1556  }
1557  timestamp = (start_time == AV_NOPTS_VALUE) ? 0 : start_time;
1558  /* add the stream start time */
1559  if (!o->seek_timestamp && ic->start_time != AV_NOPTS_VALUE)
1560  timestamp += ic->start_time;
1561 
1562  /* if seeking requested, we execute it */
1563  if (start_time != AV_NOPTS_VALUE) {
1564  int64_t seek_timestamp = timestamp;
1565 
1566  if (!(ic->iformat->flags & AVFMT_SEEK_TO_PTS)) {
1567  int dts_heuristic = 0;
1568  for (i=0; i<ic->nb_streams; i++) {
1569  const AVCodecParameters *par = ic->streams[i]->codecpar;
1570  if (par->video_delay) {
1571  dts_heuristic = 1;
1572  break;
1573  }
1574  }
1575  if (dts_heuristic) {
1576  seek_timestamp -= 3*AV_TIME_BASE / 23;
1577  }
1578  }
1579  ret = avformat_seek_file(ic, -1, INT64_MIN, seek_timestamp, seek_timestamp, 0);
1580  if (ret < 0) {
1581  av_log(d, AV_LOG_WARNING, "could not seek to position %0.3f\n",
1582  (double)timestamp / AV_TIME_BASE);
1583  }
1584  }
1585 
1586  f->start_time = start_time;
1587  f->recording_time = recording_time;
1588  f->input_sync_ref = o->input_sync_ref;
1589  f->input_ts_offset = o->input_ts_offset;
1590  f->ts_offset = o->input_ts_offset - (copy_ts ? (start_at_zero && ic->start_time != AV_NOPTS_VALUE ? ic->start_time : 0) : timestamp);
1591  f->accurate_seek = o->accurate_seek;
1592  d->loop = o->loop;
1593  d->duration = 0;
1594  d->time_base = (AVRational){ 1, 1 };
1595  d->nb_streams_warn = ic->nb_streams;
1596 
1597  f->format_nots = !!(ic->iformat->flags & AVFMT_NOTIMESTAMPS);
1598 
1599  f->readrate = o->readrate ? o->readrate : 0.0;
1600  if (f->readrate < 0.0f) {
1601  av_log(d, AV_LOG_ERROR, "Option -readrate is %0.3f; it must be non-negative.\n", f->readrate);
1602  return AVERROR(EINVAL);
1603  }
1604  if (o->rate_emu) {
1605  if (f->readrate) {
1606  av_log(d, AV_LOG_WARNING, "Both -readrate and -re set. Using -readrate %0.3f.\n", f->readrate);
1607  } else
1608  f->readrate = 1.0f;
1609  }
1610 
1611  if (f->readrate) {
1612  d->readrate_initial_burst = o->readrate_initial_burst ? o->readrate_initial_burst : 0.5;
1613  if (d->readrate_initial_burst < 0.0) {
1615  "Option -readrate_initial_burst is %0.3f; it must be non-negative.\n",
1616  d->readrate_initial_burst);
1617  return AVERROR(EINVAL);
1618  }
1619  } else if (o->readrate_initial_burst) {
1620  av_log(d, AV_LOG_WARNING, "Option -readrate_initial_burst ignored "
1621  "since neither -readrate nor -re were given\n");
1622  }
1623 
1624  d->thread_queue_size = o->thread_queue_size;
1625 
1626  /* Add all the streams from the given input file to the demuxer */
1627  for (int i = 0; i < ic->nb_streams; i++) {
1628  ret = ist_add(o, d, ic->streams[i]);
1629  if (ret < 0)
1630  return ret;
1631  }
1632 
1633  /* dump the file content */
1634  av_dump_format(ic, f->index, filename, 0);
1635 
1636  /* check if all codec options have been used */
1637  unused_opts = strip_specifiers(o->g->codec_opts);
1638  for (i = 0; i < f->nb_streams; i++) {
1639  e = NULL;
1640  while ((e = av_dict_iterate(f->streams[i]->decoder_opts, e)))
1641  av_dict_set(&unused_opts, e->key, NULL, 0);
1642  }
1643 
1644  e = NULL;
1645  while ((e = av_dict_iterate(unused_opts, e))) {
1646  const AVClass *class = avcodec_get_class();
1647  const AVOption *option = av_opt_find(&class, e->key, NULL, 0,
1649  const AVClass *fclass = avformat_get_class();
1650  const AVOption *foption = av_opt_find(&fclass, e->key, NULL, 0,
1652  if (!option || foption)
1653  continue;
1654 
1655 
1656  if (!(option->flags & AV_OPT_FLAG_DECODING_PARAM)) {
1657  av_log(d, AV_LOG_ERROR, "Codec AVOption %s (%s) is not a decoding "
1658  "option.\n", e->key, option->help ? option->help : "");
1659  return AVERROR(EINVAL);
1660  }
1661 
1662  av_log(d, AV_LOG_WARNING, "Codec AVOption %s (%s) has not been used "
1663  "for any stream. The most likely reason is either wrong type "
1664  "(e.g. a video option with no video streams) or that it is a "
1665  "private option of some decoder which was not actually used "
1666  "for any stream.\n", e->key, option->help ? option->help : "");
1667  }
1668  av_dict_free(&unused_opts);
1669 
1670  for (i = 0; i < o->nb_dump_attachment; i++) {
1671  int j;
1672 
1673  for (j = 0; j < f->nb_streams; j++) {
1674  InputStream *ist = f->streams[j];
1675 
1676  if (check_stream_specifier(ic, ist->st, o->dump_attachment[i].specifier) == 1) {
1677  ret = dump_attachment(ist, o->dump_attachment[i].u.str);
1678  if (ret < 0)
1679  return ret;
1680  }
1681  }
1682  }
1683 
1684  return 0;
1685 }
OptionsContext::readrate
float readrate
Definition: ffmpeg.h:140
input_thread
static void * input_thread(void *arg)
Definition: ffmpeg_demux.c:545
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:56
av_gettime_relative
int64_t av_gettime_relative(void)
Get the current time in microseconds since some unspecified starting point.
Definition: time.c:56
AV_LOG_WARNING
#define AV_LOG_WARNING
Something somehow does not look correct.
Definition: log.h:186
AV_PIX_FMT_CUDA
@ AV_PIX_FMT_CUDA
HW acceleration through CUDA.
Definition: pixfmt.h:253
AVCodecParameters::extradata
uint8_t * extradata
Extra binary data needed for initializing the decoder, codec-dependent.
Definition: codec_par.h: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:747
InputStream::hwaccel_device
char * hwaccel_device
Definition: ffmpeg.h:384
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:124
opt.h
OptionsContext::nb_audio_sample_rate
int nb_audio_sample_rate
Definition: ffmpeg.h:126
MATCH_PER_STREAM_OPT
#define MATCH_PER_STREAM_OPT(name, type, outvar, fmtctx, st)
Definition: ffmpeg.h:911
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:1004
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:853
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:1350
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:928
remove_avoptions
void remove_avoptions(AVDictionary **a, AVDictionary *b)
Definition: ffmpeg.c:446
InputStream::outputs
struct OutputStream ** outputs
Definition: ffmpeg.h:376
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:413
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:807
DemuxStream::streamcopy_needed
int streamcopy_needed
Definition: ffmpeg_demux.c:63
av_display_matrix_flip
void av_display_matrix_flip(int32_t matrix[9], int hflip, int vflip)
Flip the input matrix horizontally and/or vertically.
Definition: display.c:66
subtitle_codec_name
static const char * subtitle_codec_name
Definition: ffplay.c:342
AV_HWDEVICE_TYPE_NONE
@ AV_HWDEVICE_TYPE_NONE
Definition: hwcontext.h:28
LastFrameDuration::stream_idx
int stream_idx
Definition: ffmpeg.h:395
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:1011
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:1749
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:369
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:350
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:121
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:312
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
LastFrameDuration
Definition: ffmpeg.h:394
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:317
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:307
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:377
Demuxer::wallclock_start
int64_t wallclock_start
Definition: ffmpeg_demux.c:91
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:85
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:43
ist_filter_add
int ist_filter_add(InputStream *ist, InputFilter *ifilter, int is_simple)
Definition: ffmpeg_demux.c:870
dts_delta_threshold
float dts_delta_threshold
Definition: ffmpeg_opt.c:69
DemuxStream::data_size
uint64_t data_size
Definition: ffmpeg_demux.c:82
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
InputFile::audio_duration_queue_size
int audio_duration_queue_size
Definition: ffmpeg.h:432
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:53
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:89
fail
#define fail()
Definition: checkasm.h:138
opt_name_hwaccel_output_formats
static const char *const opt_name_hwaccel_output_formats[]
Definition: ffmpeg_demux.c:49
dummy
int dummy
Definition: motion.c:66
InputStream::decoder_opts
AVDictionary * decoder_opts
Definition: ffmpeg.h:352
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:50
input_file_item_name
static const char * input_file_item_name(void *obj)
Definition: ffmpeg_demux.c:1321
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:52
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:96
AVRational::num
int num
Numerator.
Definition: rational.h:59
Demuxer::f
InputFile f
Definition: ffmpeg_demux.c:86
InputFile
Definition: ffmpeg.h:399
ifile_get_packet
int ifile_get_packet(InputFile *f, AVPacket **pkt)
Get next input packet from the demuxer.
Definition: ffmpeg_demux.c:723
DemuxStream::nb_packets
uint64_t nb_packets
Definition: ffmpeg_demux.c:80
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:51
AVInputFormat
Definition: avformat.h:549
ist_dts_update
static int ist_dts_update(DemuxStream *ds, AVPacket *pkt)
Definition: ffmpeg_demux.c:314
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:786
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:41
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:68
InputStream::framerate
AVRational framerate
Definition: ffmpeg.h:353
opt_name_hwaccel_devices
static const char *const opt_name_hwaccel_devices[]
Definition: ffmpeg_demux.c:48
AVFormatContext::flags
int flags
Flags modifying the (de)muxer behaviour.
Definition: avformat.h: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:110
InputFilter
Definition: ffmpeg.h:287
DemuxStream::ts_scale
double ts_scale
Definition: ffmpeg_demux.c:61
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:523
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:1033
ctx
AVFormatContext * ctx
Definition: movenc.c:48
InputStream::filters
InputFilter ** filters
Definition: ffmpeg.h:368
Demuxer::nb_streams_warn
int nb_streams_warn
Definition: ffmpeg_demux.c:108
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:997
opt_name_canvas_sizes
static const char *const opt_name_canvas_sizes[]
Definition: ffmpeg_demux.c:44
av_hwdevice_get_type_name
const char * av_hwdevice_get_type_name(enum AVHWDeviceType type)
Get the string name of an AVHWDeviceType.
Definition: hwcontext.c:93
AVThreadMessageQueue
Definition: threadmessage.c: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:228
AVMEDIA_TYPE_DATA
@ AVMEDIA_TYPE_DATA
Opaque data information usually continuous.
Definition: avutil.h:203
opt_name_ts_scale
static const char *const opt_name_ts_scale[]
Definition: ffmpeg_demux.c:46
AVFormatContext::data_codec
const struct AVCodec * data_codec
Forced data codec.
Definition: avformat.h:1607
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:1070
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:45
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:130
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:829
ifile_duration_update
static void ifile_duration_update(Demuxer *d, DemuxStream *ds, int64_t last_duration)
Definition: ffmpeg_demux.c:158
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:363
InputStream::top_field_first
int top_field_first
Definition: ffmpeg.h:355
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:415
avcodec_free_context
void avcodec_free_context(AVCodecContext **avctx)
Free the codec context and everything associated with it and write NULL to the provided pointer.
Definition: options.c:168
AVRational
Rational number (pair of numerator and denominator).
Definition: rational.h:58
DemuxStream::max_pts
int64_t max_pts
Definition: ffmpeg_demux.c:77
DemuxPktData::dts_est
int64_t dts_est
Definition: ffmpeg.h:107
parseutils.h
InputStream::hwaccel_id
enum HWAccelID hwaccel_id
Definition: ffmpeg.h:382
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:360
InputStream::hwaccel_output_format
enum AVPixelFormat hwaccel_output_format
Definition: ffmpeg.h:385
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:117
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:145
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:892
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:123
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:389
avcodec_find_decoder
const AVCodec * avcodec_find_decoder(enum AVCodecID id)
Find a registered decoder with a matching codec ID.
Definition: allcodecs.c:975
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:74
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:383
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:47
av_err2str
#define av_err2str(errnum)
Convenience macro, the return value should be used only directly in function arguments but never stan...
Definition: error.h:121
start_time
static int64_t start_time
Definition: ffplay.c:328
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:455
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:1328
Demuxer::thread
pthread_t thread
Definition: ffmpeg_demux.c:114
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:113
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:390
OptionsContext::find_stream_info
int find_stream_info
Definition: ffmpeg.h:145
DemuxStream::min_pts
int64_t min_pts
Definition: ffmpeg_demux.c:76
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:938
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:343
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:72
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:972
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:115
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:55
av_parse_video_rate
int av_parse_video_rate(AVRational *rate, const char *arg)
Parse str and store the detected values in *rate.
Definition: parseutils.c:181
DemuxMsg::looping
int looping
Definition: ffmpeg_demux.c:122
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:255
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:407
FFMIN
#define FFMIN(a, b)
Definition: macros.h:49
thread_start
static int thread_start(Demuxer *d)
Definition: ffmpeg_demux.c:674
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:346
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:223
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:926
ist_find_unused
InputStream * ist_find_unused(enum AVMediaType type)
Find an unused input stream of given type.
Definition: ffmpeg_demux.c:135
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:294
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:97
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:65
input_packet_process
static int input_packet_process(Demuxer *d, DemuxMsg *msg, AVPacket *src)
Definition: ffmpeg_demux.c:461
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:100
InputFile::streams
InputStream ** streams
Definition: ffmpeg.h:423
add_display_matrix_to_stream
static int add_display_matrix_to_stream(const OptionsContext *o, AVFormatContext *ctx, InputStream *ist)
Definition: ffmpeg_demux.c:956
InputStream::reinit_filters
int reinit_filters
Definition: ffmpeg.h:379
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
Demuxer::duration
int64_t duration
Definition: ffmpeg_demux.c:103
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:112
audio_codec_name
static const char * audio_codec_name
Definition: ffplay.c:341
ts_discontinuity_detect
static void ts_discontinuity_detect(Demuxer *d, InputStream *ist, AVPacket *pkt)
Definition: ffmpeg_demux.c:226
OptionsContext::nb_audio_channels
int nb_audio_channels
Definition: ffmpeg.h:124
InputFile::audio_duration_queue
AVThreadMessageQueue * audio_duration_queue
Definition: ffmpeg.h:431
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:125
InputStream::nb_samples
int64_t nb_samples
Definition: ffmpeg.h:350
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:1335
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:175
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:416
OptionsContext::nb_frame_sizes
int nb_frame_sizes
Definition: ffmpeg.h:132
InputStream::decode_errors
uint64_t decode_errors
Definition: ffmpeg.h:391
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:363
DemuxStream::log_name
char log_name[32]
Definition: ffmpeg_demux.c:59
thread_stop
static void thread_stop(Demuxer *d)
Definition: ffmpeg_demux.c:658
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:384
InputStream::index
int index
Definition: ffmpeg.h:328
readrate_sleep
static void readrate_sleep(Demuxer *d)
Definition: ffmpeg_demux.c:503
AVDictionaryEntry
Definition: dict.h:89
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
LastFrameDuration::duration
int64_t duration
Definition: ffmpeg.h:396
AVPacket
This structure stores compressed data.
Definition: packet.h:468
DemuxMsg
Definition: ffmpeg_demux.c:120
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:42
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:787
timestamp.h
OutputStream
Definition: mux.c:53
flags
#define flags(name, subs,...)
Definition: cbs_av1.c:474
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
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.h:889
avcodec_descriptor_get
const AVCodecDescriptor * avcodec_descriptor_get(enum AVCodecID id)
Definition: codec_desc.c:3722
Demuxer::last_ts
int64_t last_ts
Definition: ffmpeg_demux.c:97
AVDictionaryEntry::value
char * value
Definition: dict.h:91
avstring.h
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:66
InputFile::nb_streams
int nb_streams
Definition: ffmpeg.h:424
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:1283
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
Demuxer::time_base
AVRational time_base
Definition: ffmpeg_demux.c:105
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:358
thread_set_name
static void thread_set_name(InputFile *f)
Definition: ffmpeg_demux.c:538
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