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  /* add the stream-global side data to the first packet */
484  if (ds->nb_packets == 1) {
485  for (int i = 0; i < ist->st->nb_side_data; i++) {
486  AVPacketSideData *src_sd = &ist->st->side_data[i];
487  uint8_t *dst_data;
488 
489  if (src_sd->type == AV_PKT_DATA_DISPLAYMATRIX)
490  continue;
491 
492  if (av_packet_get_side_data(pkt, src_sd->type, NULL))
493  continue;
494 
495  dst_data = av_packet_new_side_data(pkt, src_sd->type, src_sd->size);
496  if (!dst_data) {
497  ret = AVERROR(ENOMEM);
498  goto fail;
499  }
500 
501  memcpy(dst_data, src_sd->data, src_sd->size);
502  }
503  }
504 
505  if (debug_ts) {
506  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",
507  f->index, pkt->stream_index,
514  }
515 
516  msg->pkt = pkt;
517  pkt = NULL;
518 
519 fail:
521 
522  return ret;
523 }
524 
525 static void readrate_sleep(Demuxer *d)
526 {
527  InputFile *f = &d->f;
528  int64_t file_start = copy_ts * (
529  (f->start_time_effective != AV_NOPTS_VALUE ? f->start_time_effective * !start_at_zero : 0) +
530  (f->start_time != AV_NOPTS_VALUE ? f->start_time : 0)
531  );
532  int64_t burst_until = AV_TIME_BASE * d->readrate_initial_burst;
533  for (int i = 0; i < f->nb_streams; i++) {
534  InputStream *ist = f->streams[i];
535  DemuxStream *ds = ds_from_ist(ist);
536  int64_t stream_ts_offset, pts, now;
537  stream_ts_offset = FFMAX(ds->first_dts != AV_NOPTS_VALUE ? ds->first_dts : 0, file_start);
538  pts = av_rescale(ds->dts, 1000000, AV_TIME_BASE);
539  now = (av_gettime_relative() - d->wallclock_start) * f->readrate + stream_ts_offset;
540  if (pts - burst_until > now)
541  av_usleep(pts - burst_until - now);
542  }
543 }
544 
546 {
547  for (int j = 0; j < ifile->ctx->nb_programs; j++) {
548  AVProgram *p = ifile->ctx->programs[j];
549  int discard = AVDISCARD_ALL;
550 
551  for (int k = 0; k < p->nb_stream_indexes; k++)
552  if (!ifile->streams[p->stream_index[k]]->discard) {
553  discard = AVDISCARD_DEFAULT;
554  break;
555  }
556  p->discard = discard;
557  }
558 }
559 
561 {
562  char name[16];
563  snprintf(name, sizeof(name), "dmx%d:%s", f->index, f->ctx->iformat->name);
565 }
566 
567 static void *input_thread(void *arg)
568 {
569  Demuxer *d = arg;
570  InputFile *f = &d->f;
571  AVPacket *pkt;
572  unsigned flags = d->non_blocking ? AV_THREAD_MESSAGE_NONBLOCK : 0;
573  int ret = 0;
574 
575  pkt = av_packet_alloc();
576  if (!pkt) {
577  ret = AVERROR(ENOMEM);
578  goto finish;
579  }
580 
582 
584 
585  d->wallclock_start = av_gettime_relative();
586 
587  while (1) {
588  DemuxMsg msg = { NULL };
589 
590  ret = av_read_frame(f->ctx, pkt);
591 
592  if (ret == AVERROR(EAGAIN)) {
593  av_usleep(10000);
594  continue;
595  }
596  if (ret < 0) {
597  if (d->loop) {
598  /* signal looping to the consumer thread */
599  msg.looping = 1;
600  ret = av_thread_message_queue_send(d->in_thread_queue, &msg, 0);
601  if (ret >= 0)
602  ret = seek_to_start(d);
603  if (ret >= 0)
604  continue;
605 
606  /* fallthrough to the error path */
607  }
608 
609  if (ret == AVERROR_EOF)
610  av_log(d, AV_LOG_VERBOSE, "EOF while reading input\n");
611  else
612  av_log(d, AV_LOG_ERROR, "Error during demuxing: %s\n",
613  av_err2str(ret));
614 
615  break;
616  }
617 
618  if (do_pkt_dump) {
620  f->ctx->streams[pkt->stream_index]);
621  }
622 
623  /* the following test is needed in case new streams appear
624  dynamically in stream : we ignore them */
625  if (pkt->stream_index >= f->nb_streams ||
626  f->streams[pkt->stream_index]->discard) {
629  continue;
630  }
631 
632  if (pkt->flags & AV_PKT_FLAG_CORRUPT) {
634  "corrupt input packet in stream %d\n",
635  pkt->stream_index);
636  if (exit_on_error) {
639  break;
640  }
641  }
642 
643  ret = input_packet_process(d, &msg, pkt);
644  if (ret < 0)
645  break;
646 
647  if (f->readrate)
648  readrate_sleep(d);
649 
650  ret = av_thread_message_queue_send(d->in_thread_queue, &msg, flags);
651  if (flags && ret == AVERROR(EAGAIN)) {
652  flags = 0;
653  ret = av_thread_message_queue_send(d->in_thread_queue, &msg, flags);
655  "Thread message queue blocking; consider raising the "
656  "thread_queue_size option (current value: %d)\n",
657  d->thread_queue_size);
658  }
659  if (ret < 0) {
660  if (ret != AVERROR_EOF)
662  "Unable to send packet to main thread: %s\n",
663  av_err2str(ret));
664  av_packet_free(&msg.pkt);
665  break;
666  }
667  }
668 
669 finish:
670  av_assert0(ret < 0);
671  av_thread_message_queue_set_err_recv(d->in_thread_queue, ret);
672 
674 
675  av_log(d, AV_LOG_VERBOSE, "Terminating demuxer thread\n");
676 
677  return NULL;
678 }
679 
680 static void thread_stop(Demuxer *d)
681 {
682  InputFile *f = &d->f;
683  DemuxMsg msg;
684 
685  if (!d->in_thread_queue)
686  return;
688  while (av_thread_message_queue_recv(d->in_thread_queue, &msg, 0) >= 0)
689  av_packet_free(&msg.pkt);
690 
691  pthread_join(d->thread, NULL);
692  av_thread_message_queue_free(&d->in_thread_queue);
693  av_thread_message_queue_free(&f->audio_duration_queue);
694 }
695 
696 static int thread_start(Demuxer *d)
697 {
698  int ret;
699  InputFile *f = &d->f;
700 
701  if (d->thread_queue_size <= 0)
702  d->thread_queue_size = (nb_input_files > 1 ? 8 : 1);
703 
704  if (nb_input_files > 1 &&
705  (f->ctx->pb ? !f->ctx->pb->seekable :
706  strcmp(f->ctx->iformat->name, "lavfi")))
707  d->non_blocking = 1;
708  ret = av_thread_message_queue_alloc(&d->in_thread_queue,
709  d->thread_queue_size, sizeof(DemuxMsg));
710  if (ret < 0)
711  return ret;
712 
713  if (d->loop) {
714  int nb_audio_dec = 0;
715 
716  for (int i = 0; i < f->nb_streams; i++) {
717  InputStream *ist = f->streams[i];
718  nb_audio_dec += !!(ist->decoding_needed &&
720  }
721 
722  if (nb_audio_dec) {
723  ret = av_thread_message_queue_alloc(&f->audio_duration_queue,
724  nb_audio_dec, sizeof(LastFrameDuration));
725  if (ret < 0)
726  goto fail;
727  f->audio_duration_queue_size = nb_audio_dec;
728  }
729  }
730 
731  if ((ret = pthread_create(&d->thread, NULL, input_thread, d))) {
732  av_log(d, AV_LOG_ERROR, "pthread_create failed: %s. Try to increase `ulimit -v` or decrease `ulimit -s`.\n", strerror(ret));
733  ret = AVERROR(ret);
734  goto fail;
735  }
736 
737  d->read_started = 1;
738 
739  return 0;
740 fail:
741  av_thread_message_queue_free(&d->in_thread_queue);
742  return ret;
743 }
744 
746 {
748  DemuxMsg msg;
749  int ret;
750 
751  if (!d->in_thread_queue) {
752  ret = thread_start(d);
753  if (ret < 0)
754  return ret;
755  }
756 
757  ret = av_thread_message_queue_recv(d->in_thread_queue, &msg,
758  d->non_blocking ?
760  if (ret < 0)
761  return ret;
762  if (msg.looping)
763  return 1;
764 
765  *pkt = msg.pkt;
766  return 0;
767 }
768 
770 {
771  InputFile *f = &d->f;
772  uint64_t total_packets = 0, total_size = 0;
773 
774  av_log(f, AV_LOG_VERBOSE, "Input file #%d (%s):\n",
775  f->index, f->ctx->url);
776 
777  for (int j = 0; j < f->nb_streams; j++) {
778  InputStream *ist = f->streams[j];
779  DemuxStream *ds = ds_from_ist(ist);
780  enum AVMediaType type = ist->par->codec_type;
781 
782  if (ist->discard || type == AVMEDIA_TYPE_ATTACHMENT)
783  continue;
784 
785  total_size += ds->data_size;
786  total_packets += ds->nb_packets;
787 
788  av_log(f, AV_LOG_VERBOSE, " Input stream #%d:%d (%s): ",
789  f->index, j, av_get_media_type_string(type));
790  av_log(f, AV_LOG_VERBOSE, "%"PRIu64" packets read (%"PRIu64" bytes); ",
791  ds->nb_packets, ds->data_size);
792 
793  if (ist->decoding_needed) {
795  "%"PRIu64" frames decoded; %"PRIu64" decode errors",
796  ist->frames_decoded, ist->decode_errors);
797  if (type == AVMEDIA_TYPE_AUDIO)
798  av_log(f, AV_LOG_VERBOSE, " (%"PRIu64" samples)", ist->samples_decoded);
799  av_log(f, AV_LOG_VERBOSE, "; ");
800  }
801 
802  av_log(f, AV_LOG_VERBOSE, "\n");
803  }
804 
805  av_log(f, AV_LOG_VERBOSE, " Total: %"PRIu64" packets (%"PRIu64" bytes) demuxed\n",
806  total_packets, total_size);
807 }
808 
809 static void ist_free(InputStream **pist)
810 {
811  InputStream *ist = *pist;
812 
813  if (!ist)
814  return;
815 
816  dec_free(&ist->decoder);
817 
818  av_dict_free(&ist->decoder_opts);
819  av_freep(&ist->filters);
820  av_freep(&ist->outputs);
821  av_freep(&ist->hwaccel_device);
822 
825 
826  av_freep(pist);
827 }
828 
830 {
831  InputFile *f = *pf;
833 
834  if (!f)
835  return;
836 
837  thread_stop(d);
838 
839  if (d->read_started)
841 
842  for (int i = 0; i < f->nb_streams; i++)
843  ist_free(&f->streams[i]);
844  av_freep(&f->streams);
845 
846  avformat_close_input(&f->ctx);
847 
848  av_freep(pf);
849 }
850 
851 static int ist_use(InputStream *ist, int decoding_needed)
852 {
853  DemuxStream *ds = ds_from_ist(ist);
854 
855  if (ist->user_set_discard == AVDISCARD_ALL) {
856  av_log(ist, AV_LOG_ERROR, "Cannot %s a disabled input stream\n",
857  decoding_needed ? "decode" : "streamcopy");
858  return AVERROR(EINVAL);
859  }
860 
861  ist->discard = 0;
862  ist->st->discard = ist->user_set_discard;
863  ist->decoding_needed |= decoding_needed;
864  ds->streamcopy_needed |= !decoding_needed;
865 
866  if (decoding_needed && !avcodec_is_open(ist->dec_ctx)) {
867  int ret = dec_open(ist);
868  if (ret < 0)
869  return ret;
870  }
871 
872  return 0;
873 }
874 
876 {
877  int ret;
878 
879  ret = ist_use(ist, ost->enc ? DECODING_FOR_OST : 0);
880  if (ret < 0)
881  return ret;
882 
883  ret = GROW_ARRAY(ist->outputs, ist->nb_outputs);
884  if (ret < 0)
885  return ret;
886 
887  ist->outputs[ist->nb_outputs - 1] = ost;
888 
889  return 0;
890 }
891 
892 int ist_filter_add(InputStream *ist, InputFilter *ifilter, int is_simple)
893 {
894  int ret;
895 
896  ret = ist_use(ist, is_simple ? DECODING_FOR_OST : DECODING_FOR_FILTER);
897  if (ret < 0)
898  return ret;
899 
900  ret = GROW_ARRAY(ist->filters, ist->nb_filters);
901  if (ret < 0)
902  return ret;
903 
904  ist->filters[ist->nb_filters - 1] = ifilter;
905 
906  // initialize fallback parameters for filtering
907  ret = ifilter_parameters_from_dec(ifilter, ist->dec_ctx);
908  if (ret < 0)
909  return ret;
910 
911  return 0;
912 }
913 
915  enum HWAccelID hwaccel_id, enum AVHWDeviceType hwaccel_device_type,
916  const AVCodec **pcodec)
917 
918 {
919  char *codec_name = NULL;
920 
921  MATCH_PER_STREAM_OPT(codec_names, str, codec_name, s, st);
922  if (codec_name) {
923  int ret = find_codec(NULL, codec_name, st->codecpar->codec_type, 0, pcodec);
924  if (ret < 0)
925  return ret;
926  st->codecpar->codec_id = (*pcodec)->id;
927  if (recast_media && st->codecpar->codec_type != (*pcodec)->type)
928  st->codecpar->codec_type = (*pcodec)->type;
929  return 0;
930  } else {
931  if (st->codecpar->codec_type == AVMEDIA_TYPE_VIDEO &&
932  hwaccel_id == HWACCEL_GENERIC &&
933  hwaccel_device_type != AV_HWDEVICE_TYPE_NONE) {
934  const AVCodec *c;
935  void *i = NULL;
936 
937  while ((c = av_codec_iterate(&i))) {
938  const AVCodecHWConfig *config;
939 
940  if (c->id != st->codecpar->codec_id ||
942  continue;
943 
944  for (int j = 0; config = avcodec_get_hw_config(c, j); j++) {
945  if (config->device_type == hwaccel_device_type) {
946  av_log(NULL, AV_LOG_VERBOSE, "Selecting decoder '%s' because of requested hwaccel method %s\n",
947  c->name, av_hwdevice_get_type_name(hwaccel_device_type));
948  *pcodec = c;
949  return 0;
950  }
951  }
952  }
953  }
954 
955  *pcodec = avcodec_find_decoder(st->codecpar->codec_id);
956  return 0;
957  }
958 }
959 
960 static int guess_input_channel_layout(InputStream *ist, int guess_layout_max)
961 {
962  AVCodecContext *dec = ist->dec_ctx;
963 
965  char layout_name[256];
966 
967  if (dec->ch_layout.nb_channels > guess_layout_max)
968  return 0;
971  return 0;
972  av_channel_layout_describe(&dec->ch_layout, layout_name, sizeof(layout_name));
973  av_log(ist, AV_LOG_WARNING, "Guessed Channel Layout: %s\n", layout_name);
974  }
975  return 1;
976 }
977 
980 {
981  AVStream *st = ist->st;
982  double rotation = DBL_MAX;
983  int hflip = -1, vflip = -1;
984  int hflip_set = 0, vflip_set = 0, rotation_set = 0;
985  int32_t *buf;
986 
987  MATCH_PER_STREAM_OPT(display_rotations, dbl, rotation, ctx, st);
988  MATCH_PER_STREAM_OPT(display_hflips, i, hflip, ctx, st);
989  MATCH_PER_STREAM_OPT(display_vflips, i, vflip, ctx, st);
990 
991  rotation_set = rotation != DBL_MAX;
992  hflip_set = hflip != -1;
993  vflip_set = vflip != -1;
994 
995  if (!rotation_set && !hflip_set && !vflip_set)
996  return 0;
997 
999  if (!buf) {
1000  av_log(ist, AV_LOG_FATAL, "Failed to generate a display matrix!\n");
1001  return AVERROR(ENOMEM);
1002  }
1003 
1005  rotation_set ? -(rotation) : -0.0f);
1006 
1008  hflip_set ? hflip : 0,
1009  vflip_set ? vflip : 0);
1010 
1011  return 0;
1012 }
1013 
1014 static const char *input_stream_item_name(void *obj)
1015 {
1016  const DemuxStream *ds = obj;
1017 
1018  return ds->log_name;
1019 }
1020 
1021 static const AVClass input_stream_class = {
1022  .class_name = "InputStream",
1023  .version = LIBAVUTIL_VERSION_INT,
1024  .item_name = input_stream_item_name,
1025  .category = AV_CLASS_CATEGORY_DEMUXER,
1026 };
1027 
1029 {
1030  const char *type_str = av_get_media_type_string(st->codecpar->codec_type);
1031  InputFile *f = &d->f;
1032  DemuxStream *ds;
1033 
1034  ds = allocate_array_elem(&f->streams, sizeof(*ds), &f->nb_streams);
1035  if (!ds)
1036  return NULL;
1037 
1038  ds->ist.st = st;
1039  ds->ist.file_index = f->index;
1040  ds->ist.index = st->index;
1041  ds->ist.class = &input_stream_class;
1042 
1043  snprintf(ds->log_name, sizeof(ds->log_name), "%cist#%d:%d/%s",
1044  type_str ? *type_str : '?', d->f.index, st->index,
1046 
1047  return ds;
1048 }
1049 
1050 static int ist_add(const OptionsContext *o, Demuxer *d, AVStream *st)
1051 {
1052  AVFormatContext *ic = d->f.ctx;
1053  AVCodecParameters *par = st->codecpar;
1054  DemuxStream *ds;
1055  InputStream *ist;
1056  char *framerate = NULL, *hwaccel_device = NULL;
1057  const char *hwaccel = NULL;
1058  char *hwaccel_output_format = NULL;
1059  char *codec_tag = NULL;
1060  char *next;
1061  char *discard_str = NULL;
1062  const AVClass *cc = avcodec_get_class();
1063  const AVOption *discard_opt = av_opt_find(&cc, "skip_frame", NULL,
1065  int ret;
1066 
1067  ds = demux_stream_alloc(d, st);
1068  if (!ds)
1069  return AVERROR(ENOMEM);
1070 
1071  ist = &ds->ist;
1072 
1073  ist->discard = 1;
1074  st->discard = AVDISCARD_ALL;
1075  ist->nb_samples = 0;
1076  ds->first_dts = AV_NOPTS_VALUE;
1077  ds->next_dts = AV_NOPTS_VALUE;
1078 
1079  ds->min_pts = INT64_MAX;
1080  ds->max_pts = INT64_MIN;
1081 
1082  ds->ts_scale = 1.0;
1083  MATCH_PER_STREAM_OPT(ts_scale, dbl, ds->ts_scale, ic, st);
1084 
1085  ist->autorotate = 1;
1086  MATCH_PER_STREAM_OPT(autorotate, i, ist->autorotate, ic, st);
1087 
1088  MATCH_PER_STREAM_OPT(codec_tags, str, codec_tag, ic, st);
1089  if (codec_tag) {
1090  uint32_t tag = strtol(codec_tag, &next, 0);
1091  if (*next) {
1092  uint8_t buf[4] = { 0 };
1093  memcpy(buf, codec_tag, FFMIN(sizeof(buf), strlen(codec_tag)));
1094  tag = AV_RL32(buf);
1095  }
1096 
1097  st->codecpar->codec_tag = tag;
1098  }
1099 
1100  if (st->codecpar->codec_type == AVMEDIA_TYPE_VIDEO) {
1101  ret = add_display_matrix_to_stream(o, ic, ist);
1102  if (ret < 0)
1103  return ret;
1104 
1105  MATCH_PER_STREAM_OPT(hwaccels, str, hwaccel, ic, st);
1106  MATCH_PER_STREAM_OPT(hwaccel_output_formats, str,
1107  hwaccel_output_format, ic, st);
1108 
1109  if (!hwaccel_output_format && hwaccel && !strcmp(hwaccel, "cuvid")) {
1110  av_log(ist, AV_LOG_WARNING,
1111  "WARNING: defaulting hwaccel_output_format to cuda for compatibility "
1112  "with old commandlines. This behaviour is DEPRECATED and will be removed "
1113  "in the future. Please explicitly set \"-hwaccel_output_format cuda\".\n");
1115  } else if (!hwaccel_output_format && hwaccel && !strcmp(hwaccel, "qsv")) {
1116  av_log(ist, AV_LOG_WARNING,
1117  "WARNING: defaulting hwaccel_output_format to qsv for compatibility "
1118  "with old commandlines. This behaviour is DEPRECATED and will be removed "
1119  "in the future. Please explicitly set \"-hwaccel_output_format qsv\".\n");
1121  } else if (!hwaccel_output_format && hwaccel && !strcmp(hwaccel, "mediacodec")) {
1122  // There is no real AVHWFrameContext implementation. Set
1123  // hwaccel_output_format to avoid av_hwframe_transfer_data error.
1125  } else if (hwaccel_output_format) {
1126  ist->hwaccel_output_format = av_get_pix_fmt(hwaccel_output_format);
1127  if (ist->hwaccel_output_format == AV_PIX_FMT_NONE) {
1128  av_log(ist, AV_LOG_FATAL, "Unrecognised hwaccel output "
1129  "format: %s", hwaccel_output_format);
1130  }
1131  } else {
1133  }
1134 
1135  if (hwaccel) {
1136  // The NVDEC hwaccels use a CUDA device, so remap the name here.
1137  if (!strcmp(hwaccel, "nvdec") || !strcmp(hwaccel, "cuvid"))
1138  hwaccel = "cuda";
1139 
1140  if (!strcmp(hwaccel, "none"))
1141  ist->hwaccel_id = HWACCEL_NONE;
1142  else if (!strcmp(hwaccel, "auto"))
1143  ist->hwaccel_id = HWACCEL_AUTO;
1144  else {
1146  if (type != AV_HWDEVICE_TYPE_NONE) {
1147  ist->hwaccel_id = HWACCEL_GENERIC;
1148  ist->hwaccel_device_type = type;
1149  }
1150 
1151  if (!ist->hwaccel_id) {
1152  av_log(ist, AV_LOG_FATAL, "Unrecognized hwaccel: %s.\n",
1153  hwaccel);
1154  av_log(ist, AV_LOG_FATAL, "Supported hwaccels: ");
1156  while ((type = av_hwdevice_iterate_types(type)) !=
1158  av_log(ist, AV_LOG_FATAL, "%s ",
1160  av_log(ist, AV_LOG_FATAL, "\n");
1161  return AVERROR(EINVAL);
1162  }
1163  }
1164  }
1165 
1166  MATCH_PER_STREAM_OPT(hwaccel_devices, str, hwaccel_device, ic, st);
1167  if (hwaccel_device) {
1168  ist->hwaccel_device = av_strdup(hwaccel_device);
1169  if (!ist->hwaccel_device)
1170  return AVERROR(ENOMEM);
1171  }
1172  }
1173 
1174  ret = choose_decoder(o, ic, st, ist->hwaccel_id, ist->hwaccel_device_type,
1175  &ist->dec);
1176  if (ret < 0)
1177  return ret;
1178 
1180  ic, st, ist->dec, &ist->decoder_opts);
1181  if (ret < 0)
1182  return ret;
1183 
1184  ist->reinit_filters = -1;
1185  MATCH_PER_STREAM_OPT(reinit_filters, i, ist->reinit_filters, ic, st);
1186 
1187  MATCH_PER_STREAM_OPT(discard, str, discard_str, ic, st);
1189 
1190  if ((o->video_disable && ist->st->codecpar->codec_type == AVMEDIA_TYPE_VIDEO) ||
1195 
1196  if (discard_str) {
1197  ret = av_opt_eval_int(&cc, discard_opt, discard_str, &ist->user_set_discard);
1198  if (ret < 0) {
1199  av_log(ist, AV_LOG_ERROR, "Error parsing discard %s.\n", discard_str);
1200  return ret;
1201  }
1202  }
1203 
1204  ist->dec_ctx = avcodec_alloc_context3(ist->dec);
1205  if (!ist->dec_ctx)
1206  return AVERROR(ENOMEM);
1207 
1209  if (ret < 0) {
1210  av_log(ist, AV_LOG_ERROR, "Error initializing the decoder context.\n");
1211  return ret;
1212  }
1213 
1214  if (o->bitexact)
1216 
1217  switch (par->codec_type) {
1218  case AVMEDIA_TYPE_VIDEO:
1219  MATCH_PER_STREAM_OPT(frame_rates, str, framerate, ic, st);
1220  if (framerate) {
1222  if (ret < 0) {
1223  av_log(ist, AV_LOG_ERROR, "Error parsing framerate %s.\n",
1224  framerate);
1225  return ret;
1226  }
1227  }
1228 
1229 #if FFMPEG_OPT_TOP
1230  ist->top_field_first = -1;
1231  MATCH_PER_STREAM_OPT(top_field_first, i, ist->top_field_first, ic, st);
1232 #endif
1233 
1234  ist->framerate_guessed = av_guess_frame_rate(ic, st, NULL);
1235 
1236  break;
1237  case AVMEDIA_TYPE_AUDIO: {
1238  int guess_layout_max = INT_MAX;
1239  MATCH_PER_STREAM_OPT(guess_layout_max, i, guess_layout_max, ic, st);
1240  guess_input_channel_layout(ist, guess_layout_max);
1241  break;
1242  }
1243  case AVMEDIA_TYPE_DATA:
1244  case AVMEDIA_TYPE_SUBTITLE: {
1245  char *canvas_size = NULL;
1246  MATCH_PER_STREAM_OPT(fix_sub_duration, i, ist->fix_sub_duration, ic, st);
1247  MATCH_PER_STREAM_OPT(canvas_sizes, str, canvas_size, ic, st);
1248  if (canvas_size) {
1250  canvas_size);
1251  if (ret < 0) {
1252  av_log(ist, AV_LOG_FATAL, "Invalid canvas size: %s.\n", canvas_size);
1253  return ret;
1254  }
1255  }
1256 
1257  /* Compute the size of the canvas for the subtitles stream.
1258  If the subtitles codecpar has set a size, use it. Otherwise use the
1259  maximum dimensions of the video streams in the same file. */
1260  ist->sub2video.w = ist->dec_ctx->width;
1261  ist->sub2video.h = ist->dec_ctx->height;
1262  if (!(ist->sub2video.w && ist->sub2video.h)) {
1263  for (int j = 0; j < ic->nb_streams; j++) {
1264  AVCodecParameters *par1 = ic->streams[j]->codecpar;
1265  if (par1->codec_type == AVMEDIA_TYPE_VIDEO) {
1266  ist->sub2video.w = FFMAX(ist->sub2video.w, par1->width);
1267  ist->sub2video.h = FFMAX(ist->sub2video.h, par1->height);
1268  }
1269  }
1270  }
1271 
1272  if (!(ist->sub2video.w && ist->sub2video.h)) {
1273  ist->sub2video.w = FFMAX(ist->sub2video.w, 720);
1274  ist->sub2video.h = FFMAX(ist->sub2video.h, 576);
1275  }
1276 
1277  break;
1278  }
1280  case AVMEDIA_TYPE_UNKNOWN:
1281  break;
1282  default:
1283  abort();
1284  }
1285 
1286  ist->par = avcodec_parameters_alloc();
1287  if (!ist->par)
1288  return AVERROR(ENOMEM);
1289 
1291  if (ret < 0) {
1292  av_log(ist, AV_LOG_ERROR, "Error initializing the decoder context.\n");
1293  return ret;
1294  }
1295 
1297 
1298  return 0;
1299 }
1300 
1301 static int dump_attachment(InputStream *ist, const char *filename)
1302 {
1303  AVStream *st = ist->st;
1304  int ret;
1305  AVIOContext *out = NULL;
1306  const AVDictionaryEntry *e;
1307 
1308  if (!st->codecpar->extradata_size) {
1309  av_log(ist, AV_LOG_WARNING, "No extradata to dump.\n");
1310  return 0;
1311  }
1312  if (!*filename && (e = av_dict_get(st->metadata, "filename", NULL, 0)))
1313  filename = e->value;
1314  if (!*filename) {
1315  av_log(ist, AV_LOG_FATAL, "No filename specified and no 'filename' tag");
1316  return AVERROR(EINVAL);
1317  }
1318 
1319  ret = assert_file_overwrite(filename);
1320  if (ret < 0)
1321  return ret;
1322 
1323  if ((ret = avio_open2(&out, filename, AVIO_FLAG_WRITE, &int_cb, NULL)) < 0) {
1324  av_log(ist, AV_LOG_FATAL, "Could not open file %s for writing.\n",
1325  filename);
1326  return ret;
1327  }
1328 
1330  ret = avio_close(out);
1331 
1332  if (ret >= 0)
1333  av_log(ist, AV_LOG_INFO, "Wrote attachment (%d bytes) to '%s'\n",
1334  st->codecpar->extradata_size, filename);
1335 
1336  return ret;
1337 }
1338 
1339 static const char *input_file_item_name(void *obj)
1340 {
1341  const Demuxer *d = obj;
1342 
1343  return d->log_name;
1344 }
1345 
1346 static const AVClass input_file_class = {
1347  .class_name = "InputFile",
1348  .version = LIBAVUTIL_VERSION_INT,
1349  .item_name = input_file_item_name,
1350  .category = AV_CLASS_CATEGORY_DEMUXER,
1351 };
1352 
1353 static Demuxer *demux_alloc(void)
1354 {
1356 
1357  if (!d)
1358  return NULL;
1359 
1360  d->f.class = &input_file_class;
1361  d->f.index = nb_input_files - 1;
1362 
1363  snprintf(d->log_name, sizeof(d->log_name), "in#%d", d->f.index);
1364 
1365  return d;
1366 }
1367 
1368 int ifile_open(const OptionsContext *o, const char *filename)
1369 {
1370  Demuxer *d;
1371  InputFile *f;
1372  AVFormatContext *ic;
1373  const AVInputFormat *file_iformat = NULL;
1374  int err, i, ret = 0;
1375  int64_t timestamp;
1376  AVDictionary *unused_opts = NULL;
1377  const AVDictionaryEntry *e = NULL;
1378  char * video_codec_name = NULL;
1379  char * audio_codec_name = NULL;
1380  char *subtitle_codec_name = NULL;
1381  char * data_codec_name = NULL;
1382  int scan_all_pmts_set = 0;
1383 
1384  int64_t start_time = o->start_time;
1385  int64_t start_time_eof = o->start_time_eof;
1386  int64_t stop_time = o->stop_time;
1387  int64_t recording_time = o->recording_time;
1388 
1389  d = demux_alloc();
1390  if (!d)
1391  return AVERROR(ENOMEM);
1392 
1393  f = &d->f;
1394 
1395  if (stop_time != INT64_MAX && recording_time != INT64_MAX) {
1396  stop_time = INT64_MAX;
1397  av_log(d, AV_LOG_WARNING, "-t and -to cannot be used together; using -t.\n");
1398  }
1399 
1400  if (stop_time != INT64_MAX && recording_time == INT64_MAX) {
1401  int64_t start = start_time == AV_NOPTS_VALUE ? 0 : start_time;
1402  if (stop_time <= start) {
1403  av_log(d, AV_LOG_ERROR, "-to value smaller than -ss; aborting.\n");
1404  return AVERROR(EINVAL);
1405  } else {
1406  recording_time = stop_time - start;
1407  }
1408  }
1409 
1410  if (o->format) {
1411  if (!(file_iformat = av_find_input_format(o->format))) {
1412  av_log(d, AV_LOG_FATAL, "Unknown input format: '%s'\n", o->format);
1413  return AVERROR(EINVAL);
1414  }
1415  }
1416 
1417  if (!strcmp(filename, "-"))
1418  filename = "fd:";
1419 
1420  stdin_interaction &= strncmp(filename, "pipe:", 5) &&
1421  strcmp(filename, "fd:") &&
1422  strcmp(filename, "/dev/stdin");
1423 
1424  /* get default parameters from command line */
1425  ic = avformat_alloc_context();
1426  if (!ic)
1427  return AVERROR(ENOMEM);
1428  if (o->nb_audio_sample_rate) {
1429  av_dict_set_int(&o->g->format_opts, "sample_rate", o->audio_sample_rate[o->nb_audio_sample_rate - 1].u.i, 0);
1430  }
1431  if (o->nb_audio_channels) {
1432  const AVClass *priv_class;
1433  if (file_iformat && (priv_class = file_iformat->priv_class) &&
1434  av_opt_find(&priv_class, "ch_layout", NULL, 0,
1436  char buf[32];
1437  snprintf(buf, sizeof(buf), "%dC", o->audio_channels[o->nb_audio_channels - 1].u.i);
1438  av_dict_set(&o->g->format_opts, "ch_layout", buf, 0);
1439  }
1440  }
1441  if (o->nb_audio_ch_layouts) {
1442  const AVClass *priv_class;
1443  if (file_iformat && (priv_class = file_iformat->priv_class) &&
1444  av_opt_find(&priv_class, "ch_layout", NULL, 0,
1446  av_dict_set(&o->g->format_opts, "ch_layout", o->audio_ch_layouts[o->nb_audio_ch_layouts - 1].u.str, 0);
1447  }
1448  }
1449  if (o->nb_frame_rates) {
1450  const AVClass *priv_class;
1451  /* set the format-level framerate option;
1452  * this is important for video grabbers, e.g. x11 */
1453  if (file_iformat && (priv_class = file_iformat->priv_class) &&
1454  av_opt_find(&priv_class, "framerate", NULL, 0,
1456  av_dict_set(&o->g->format_opts, "framerate",
1457  o->frame_rates[o->nb_frame_rates - 1].u.str, 0);
1458  }
1459  }
1460  if (o->nb_frame_sizes) {
1461  av_dict_set(&o->g->format_opts, "video_size", o->frame_sizes[o->nb_frame_sizes - 1].u.str, 0);
1462  }
1463  if (o->nb_frame_pix_fmts)
1464  av_dict_set(&o->g->format_opts, "pixel_format", o->frame_pix_fmts[o->nb_frame_pix_fmts - 1].u.str, 0);
1465 
1466  MATCH_PER_TYPE_OPT(codec_names, str, video_codec_name, ic, "v");
1467  MATCH_PER_TYPE_OPT(codec_names, str, audio_codec_name, ic, "a");
1468  MATCH_PER_TYPE_OPT(codec_names, str, subtitle_codec_name, ic, "s");
1469  MATCH_PER_TYPE_OPT(codec_names, str, data_codec_name, ic, "d");
1470 
1471  if (video_codec_name)
1473  &ic->video_codec));
1474  if (audio_codec_name)
1476  &ic->audio_codec));
1477  if (subtitle_codec_name)
1479  &ic->subtitle_codec));
1480  if (data_codec_name)
1481  ret = err_merge(ret, find_codec(NULL, data_codec_name , AVMEDIA_TYPE_DATA, 0,
1482  &ic->data_codec));
1483  if (ret < 0)
1484  return ret;
1485 
1489  ic->data_codec_id = data_codec_name ? ic->data_codec->id : AV_CODEC_ID_NONE;
1490 
1491  ic->flags |= AVFMT_FLAG_NONBLOCK;
1492  if (o->bitexact)
1493  ic->flags |= AVFMT_FLAG_BITEXACT;
1494  ic->interrupt_callback = int_cb;
1495 
1496  if (!av_dict_get(o->g->format_opts, "scan_all_pmts", NULL, AV_DICT_MATCH_CASE)) {
1497  av_dict_set(&o->g->format_opts, "scan_all_pmts", "1", AV_DICT_DONT_OVERWRITE);
1498  scan_all_pmts_set = 1;
1499  }
1500  /* open the input file with generic avformat function */
1501  err = avformat_open_input(&ic, filename, file_iformat, &o->g->format_opts);
1502  if (err < 0) {
1504  "Error opening input: %s\n", av_err2str(err));
1505  if (err == AVERROR_PROTOCOL_NOT_FOUND)
1506  av_log(d, AV_LOG_ERROR, "Did you mean file:%s?\n", filename);
1507  return err;
1508  }
1509 
1510  av_strlcat(d->log_name, "/", sizeof(d->log_name));
1511  av_strlcat(d->log_name, ic->iformat->name, sizeof(d->log_name));
1512 
1513  if (scan_all_pmts_set)
1514  av_dict_set(&o->g->format_opts, "scan_all_pmts", NULL, AV_DICT_MATCH_CASE);
1516 
1518  if (ret < 0)
1519  return ret;
1520 
1521  /* apply forced codec ids */
1522  for (i = 0; i < ic->nb_streams; i++) {
1523  const AVCodec *dummy;
1525  &dummy);
1526  if (ret < 0)
1527  return ret;
1528  }
1529 
1530  if (o->find_stream_info) {
1531  AVDictionary **opts;
1532  int orig_nb_streams = ic->nb_streams;
1533 
1535  if (ret < 0)
1536  return ret;
1537 
1538  /* If not enough info to get the stream parameters, we decode the
1539  first frames to get it. (used in mpeg case for example) */
1541 
1542  for (i = 0; i < orig_nb_streams; i++)
1543  av_dict_free(&opts[i]);
1544  av_freep(&opts);
1545 
1546  if (ret < 0) {
1547  av_log(d, AV_LOG_FATAL, "could not find codec parameters\n");
1548  if (ic->nb_streams == 0) {
1549  avformat_close_input(&ic);
1550  return ret;
1551  }
1552  }
1553  }
1554 
1555  if (start_time != AV_NOPTS_VALUE && start_time_eof != AV_NOPTS_VALUE) {
1556  av_log(d, AV_LOG_WARNING, "Cannot use -ss and -sseof both, using -ss\n");
1557  start_time_eof = AV_NOPTS_VALUE;
1558  }
1559 
1560  if (start_time_eof != AV_NOPTS_VALUE) {
1561  if (start_time_eof >= 0) {
1562  av_log(d, AV_LOG_ERROR, "-sseof value must be negative; aborting\n");
1563  return AVERROR(EINVAL);
1564  }
1565  if (ic->duration > 0) {
1566  start_time = start_time_eof + ic->duration;
1567  if (start_time < 0) {
1568  av_log(d, AV_LOG_WARNING, "-sseof value seeks to before start of file; ignored\n");
1570  }
1571  } else
1572  av_log(d, AV_LOG_WARNING, "Cannot use -sseof, file duration not known\n");
1573  }
1574  timestamp = (start_time == AV_NOPTS_VALUE) ? 0 : start_time;
1575  /* add the stream start time */
1576  if (!o->seek_timestamp && ic->start_time != AV_NOPTS_VALUE)
1577  timestamp += ic->start_time;
1578 
1579  /* if seeking requested, we execute it */
1580  if (start_time != AV_NOPTS_VALUE) {
1581  int64_t seek_timestamp = timestamp;
1582 
1583  if (!(ic->iformat->flags & AVFMT_SEEK_TO_PTS)) {
1584  int dts_heuristic = 0;
1585  for (i=0; i<ic->nb_streams; i++) {
1586  const AVCodecParameters *par = ic->streams[i]->codecpar;
1587  if (par->video_delay) {
1588  dts_heuristic = 1;
1589  break;
1590  }
1591  }
1592  if (dts_heuristic) {
1593  seek_timestamp -= 3*AV_TIME_BASE / 23;
1594  }
1595  }
1596  ret = avformat_seek_file(ic, -1, INT64_MIN, seek_timestamp, seek_timestamp, 0);
1597  if (ret < 0) {
1598  av_log(d, AV_LOG_WARNING, "could not seek to position %0.3f\n",
1599  (double)timestamp / AV_TIME_BASE);
1600  }
1601  }
1602 
1603  f->ctx = ic;
1604  f->start_time = start_time;
1605  f->recording_time = recording_time;
1606  f->input_sync_ref = o->input_sync_ref;
1607  f->input_ts_offset = o->input_ts_offset;
1608  f->ts_offset = o->input_ts_offset - (copy_ts ? (start_at_zero && ic->start_time != AV_NOPTS_VALUE ? ic->start_time : 0) : timestamp);
1609  f->accurate_seek = o->accurate_seek;
1610  d->loop = o->loop;
1611  d->duration = 0;
1612  d->time_base = (AVRational){ 1, 1 };
1613  d->nb_streams_warn = ic->nb_streams;
1614 
1615  f->format_nots = !!(ic->iformat->flags & AVFMT_NOTIMESTAMPS);
1616 
1617  f->readrate = o->readrate ? o->readrate : 0.0;
1618  if (f->readrate < 0.0f) {
1619  av_log(d, AV_LOG_ERROR, "Option -readrate is %0.3f; it must be non-negative.\n", f->readrate);
1620  return AVERROR(EINVAL);
1621  }
1622  if (o->rate_emu) {
1623  if (f->readrate) {
1624  av_log(d, AV_LOG_WARNING, "Both -readrate and -re set. Using -readrate %0.3f.\n", f->readrate);
1625  } else
1626  f->readrate = 1.0f;
1627  }
1628 
1629  if (f->readrate) {
1630  d->readrate_initial_burst = o->readrate_initial_burst ? o->readrate_initial_burst : 0.5;
1631  if (d->readrate_initial_burst < 0.0) {
1633  "Option -readrate_initial_burst is %0.3f; it must be non-negative.\n",
1634  d->readrate_initial_burst);
1635  return AVERROR(EINVAL);
1636  }
1637  } else if (o->readrate_initial_burst) {
1638  av_log(d, AV_LOG_WARNING, "Option -readrate_initial_burst ignored "
1639  "since neither -readrate nor -re were given\n");
1640  }
1641 
1642  d->thread_queue_size = o->thread_queue_size;
1643 
1644  /* Add all the streams from the given input file to the demuxer */
1645  for (int i = 0; i < ic->nb_streams; i++) {
1646  ret = ist_add(o, d, ic->streams[i]);
1647  if (ret < 0)
1648  return ret;
1649  }
1650 
1651  /* dump the file content */
1652  av_dump_format(ic, f->index, filename, 0);
1653 
1654  /* check if all codec options have been used */
1655  unused_opts = strip_specifiers(o->g->codec_opts);
1656  for (i = 0; i < f->nb_streams; i++) {
1657  e = NULL;
1658  while ((e = av_dict_iterate(f->streams[i]->decoder_opts, e)))
1659  av_dict_set(&unused_opts, e->key, NULL, 0);
1660  }
1661 
1662  e = NULL;
1663  while ((e = av_dict_iterate(unused_opts, e))) {
1664  const AVClass *class = avcodec_get_class();
1665  const AVOption *option = av_opt_find(&class, e->key, NULL, 0,
1667  const AVClass *fclass = avformat_get_class();
1668  const AVOption *foption = av_opt_find(&fclass, e->key, NULL, 0,
1670  if (!option || foption)
1671  continue;
1672 
1673 
1674  if (!(option->flags & AV_OPT_FLAG_DECODING_PARAM)) {
1675  av_log(d, AV_LOG_ERROR, "Codec AVOption %s (%s) is not a decoding "
1676  "option.\n", e->key, option->help ? option->help : "");
1677  return AVERROR(EINVAL);
1678  }
1679 
1680  av_log(d, AV_LOG_WARNING, "Codec AVOption %s (%s) has not been used "
1681  "for any stream. The most likely reason is either wrong type "
1682  "(e.g. a video option with no video streams) or that it is a "
1683  "private option of some decoder which was not actually used "
1684  "for any stream.\n", e->key, option->help ? option->help : "");
1685  }
1686  av_dict_free(&unused_opts);
1687 
1688  for (i = 0; i < o->nb_dump_attachment; i++) {
1689  int j;
1690 
1691  for (j = 0; j < f->nb_streams; j++) {
1692  InputStream *ist = f->streams[j];
1693 
1694  if (check_stream_specifier(ic, ist->st, o->dump_attachment[i].specifier) == 1) {
1695  ret = dump_attachment(ist, o->dump_attachment[i].u.str);
1696  if (ret < 0)
1697  return ret;
1698  }
1699  }
1700  }
1701 
1702  return 0;
1703 }
OptionsContext::readrate
float readrate
Definition: ffmpeg.h:139
input_thread
static void * input_thread(void *arg)
Definition: ffmpeg_demux.c:567
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:136
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:76
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:172
demux_final_stats
static void demux_final_stats(Demuxer *d)
Definition: ffmpeg_demux.c:769
InputStream::hwaccel_device
char * hwaccel_device
Definition: ffmpeg.h:380
OptionsContext::dump_attachment
SpecifierOpt * dump_attachment
Definition: ffmpeg.h:148
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:125
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:58
input_stream_class
static const AVClass input_stream_class
Definition: ffmpeg_demux.c:1021
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:344
ist_output_add
int ist_output_add(InputStream *ist, OutputStream *ost)
Definition: ffmpeg_demux.c:875
AVProgram::nb_stream_indexes
unsigned int nb_stream_indexes
Definition: avformat.h:1034
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:1368
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:121
AVCodecParameters
This struct describes the properties of an encoded stream.
Definition: codec_par.h:54
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:910
MATCH_PER_TYPE_OPT
#define MATCH_PER_TYPE_OPT(name, type, outvar, fmtctx, mediatype)
Definition: ffmpeg.h:928
avcodec_parameters_from_context
int avcodec_parameters_from_context(AVCodecParameters *par, const AVCodecContext *codec)
Fill the parameters struct based on the values from the supplied codec context.
Definition: codec_par.c:100
remove_avoptions
void remove_avoptions(AVDictionary **a, AVDictionary *b)
Definition: ffmpeg.c:446
InputStream::outputs
struct OutputStream ** outputs
Definition: ffmpeg.h:372
InputStream::dec_ctx
AVCodecContext * dec_ctx
Definition: ffmpeg.h:340
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:328
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:1173
AVPacketSideData
Definition: packet.h:315
ifile_close
void ifile_close(InputFile **pf)
Definition: ffmpeg_demux.c:829
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:391
OptionsContext::subtitle_disable
int subtitle_disable
Definition: ffmpeg.h:182
demux_stream_alloc
static DemuxStream * demux_stream_alloc(Demuxer *d, AVStream *st)
Definition: ffmpeg_demux.c:1028
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:1675
AVOption
AVOption.
Definition: opt.h:251
AVStream::avg_frame_rate
AVRational avg_frame_rate
Average framerate.
Definition: avformat.h:928
InputStream::nb_filters
int nb_filters
Definition: ffmpeg.h:365
AVCodecParameters::framerate
AVRational framerate
Video only.
Definition: codec_par.h:225
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:1273
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:178
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:392
OptionsContext::audio_channels
SpecifierOpt * audio_channels
Definition: ffmpeg.h:122
DemuxMsg::pkt
AVPacket * pkt
Definition: ffmpeg_demux.c:121
OptionsContext::nb_frame_rates
int nb_frame_rates
Definition: ffmpeg.h:127
AVCodecParameters::codec_tag
uint32_t codec_tag
Additional information about the codec (corresponds to the AVI FOURCC).
Definition: codec_par.h:66
AVDictionary
Definition: dict.c:34
AVChannelLayout::order
enum AVChannelOrder order
Channel order used in this layout.
Definition: channel_layout.h:306
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:1460
avcodec_is_open
int avcodec_is_open(AVCodecContext *s)
Definition: avcodec.c:706
AVFormatContext::video_codec_id
enum AVCodecID video_codec_id
Forced video codec_id.
Definition: avformat.h:1279
InputStream::decoding_needed
int decoding_needed
Definition: ffmpeg.h:329
LastFrameDuration
Definition: ffmpeg.h:390
OptionsContext::format
const char * format
Definition: ffmpeg.h:116
AVChannelLayout::nb_channels
int nb_channels
Number of channels in this layout.
Definition: channel_layout.h:311
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:373
Demuxer::wallclock_start
int64_t wallclock_start
Definition: ffmpeg_demux.c:91
SpecifierOpt::i
int i
Definition: cmdutils.h:98
InputStream
Definition: ffmpeg.h:320
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
AVPacketSideData::size
size_t size
Definition: packet.h:317
AVFormatContext::interrupt_callback
AVIOInterruptCB interrupt_callback
Custom interrupt callbacks for the I/O layer.
Definition: avformat.h:1371
Demuxer
Definition: ffmpeg_demux.c:85
OptionsContext::rate_emu
int rate_emu
Definition: ffmpeg.h:138
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:892
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:428
AVPacket::opaque_ref
AVBufferRef * opaque_ref
AVBufferRef for free use by the API user.
Definition: packet.h:410
AVFMT_SEEK_TO_PTS
#define AVFMT_SEEK_TO_PTS
Seeking is based on PTS.
Definition: avformat.h:502
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:149
OptionsContext::g
OptionGroup * g
Definition: ffmpeg.h:110
AVCodecContext::ch_layout
AVChannelLayout ch_layout
Audio channel layout.
Definition: avcodec.h:2101
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:348
AVProgram::discard
enum AVDiscard discard
selects which program to discard and which to feed to the caller
Definition: avformat.h:1032
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:1339
AVDISCARD_NONE
@ AVDISCARD_NONE
discard nothing
Definition: defs.h:205
AVCodecContext::flags
int flags
AV_CODEC_FLAG_*.
Definition: avcodec.h:517
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:103
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:109
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
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:395
ifile_get_packet
int ifile_get_packet(InputFile *f, AVPacket **pkt)
Get next input packet from the demuxer.
Definition: ffmpeg_demux.c:745
DemuxStream::nb_packets
uint64_t nb_packets
Definition: ffmpeg_demux.c:80
OptionsContext::recording_time
int64_t recording_time
Definition: ffmpeg.h:171
OptionsContext::audio_disable
int audio_disable
Definition: ffmpeg.h:181
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:342
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:547
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:430
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:189
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:782
HWACCEL_GENERIC
@ HWACCEL_GENERIC
Definition: ffmpeg.h:79
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:1573
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:349
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:1223
AVFormatContext::nb_programs
unsigned int nb_programs
Definition: avformat.h:1272
AVInputFormat::name
const char * name
A comma separated list of short names for the format.
Definition: avformat.h:552
AVFormatContext::iformat
const struct AVInputFormat * iformat
The input container format.
Definition: avformat.h:1117
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:128
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:286
DemuxStream::ts_scale
double ts_scale
Definition: ffmpeg_demux.c:61
OptionsContext::audio_ch_layouts
SpecifierOpt * audio_ch_layouts
Definition: ffmpeg.h:120
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:545
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:316
ist_add
static int ist_add(const OptionsContext *o, Demuxer *d, AVStream *st)
Definition: ffmpeg_demux.c:1050
ctx
AVFormatContext * ctx
Definition: movenc.c:48
InputStream::filters
InputFilter ** filters
Definition: ffmpeg.h:364
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:1014
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:141
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
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:1597
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:1064
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:313
AVCodecParserContext::repeat_pict
int repeat_pict
This field is used for proper frame duration computation in lavf.
Definition: avcodec.h:2786
OptionsContext::start_time
int64_t start_time
Definition: ffmpeg.h:113
AVDISCARD_ALL
@ AVDISCARD_ALL
discard all
Definition: defs.h:211
AVFormatContext
Format I/O context.
Definition: avformat.h:1105
AVFormatContext::audio_codec_id
enum AVCodecID audio_codec_id
Forced audio codec_id.
Definition: avformat.h:1285
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:862
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:851
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:878
NULL
#define NULL
Definition: coverity.c:32
InputStream::sub2video::w
int w
Definition: ffmpeg.h:359
InputStream::top_field_first
int top_field_first
Definition: ffmpeg.h:351
InputStream::st
AVStream * st
Definition: ffmpeg.h:326
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:64
OptionsContext::frame_sizes
SpecifierOpt * frame_sizes
Definition: ffmpeg.h:130
InputFile::start_time_effective
int64_t start_time_effective
Effective format start time based on enabled streams.
Definition: ffmpeg.h:411
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
AVPacketSideData::type
enum AVPacketSideDataType type
Definition: packet.h:318
DemuxStream::max_pts
int64_t max_pts
Definition: ffmpeg_demux.c:77
DemuxPktData::dts_est
int64_t dts_est
Definition: ffmpeg.h:106
parseutils.h
InputStream::hwaccel_id
enum HWAccelID hwaccel_id
Definition: ffmpeg.h:378
AVProgram::stream_index
unsigned int * stream_index
Definition: avformat.h:1033
AVStream::metadata
AVDictionary * metadata
Definition: avformat.h:919
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:356
InputStream::hwaccel_output_format
enum AVPixelFormat hwaccel_output_format
Definition: ffmpeg.h:381
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:143
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:178
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:914
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:1581
InputStream::par
AVCodecParameters * par
Codec parameters - to be used by the decoding/streamcopy code.
Definition: ffmpeg.h:338
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:385
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:80
AVFormatContext::nb_streams
unsigned int nb_streams
Number of elements in AVFormatContext.streams.
Definition: avformat.h:1161
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:83
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:2447
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:379
OptionsContext::thread_queue_size
int thread_queue_size
Definition: ffmpeg.h:142
AVMediaType
AVMediaType
Definition: avutil.h:199
AVPacket::size
int size
Definition: packet.h:375
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:206
threadmessage.h
InputStream::file_index
int file_index
Definition: ffmpeg.h:323
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:115
DECODING_FOR_OST
#define DECODING_FOR_OST
Definition: ffmpeg.h:330
input_file_class
static const AVClass input_file_class
Definition: ffmpeg_demux.c:1346
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:140
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:373
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:386
OptionsContext::find_stream_info
int find_stream_info
Definition: ffmpeg.h:144
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:380
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:960
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:126
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
AVStream::side_data
AVPacketSideData * side_data
An array of side data that applies to the whole stream (i.e.
Definition: avformat.h:957
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:968
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:54
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:414
HWACCEL_AUTO
@ HWACCEL_AUTO
Definition: ffmpeg.h:78
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:331
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:244
AVPacket::pts
int64_t pts
Presentation timestamp in AVStream->time_base units; the time at which the decompressed packet will b...
Definition: packet.h:367
packet.h
av_packet_get_side_data
uint8_t * av_packet_get_side_data(const AVPacket *pkt, enum AVPacketSideDataType type, size_t *size)
Get side information from packet.
Definition: avpacket.c:252
AVFormatContext::subtitle_codec
const struct AVCodec * subtitle_codec
Forced subtitle codec.
Definition: avformat.h:1589
AVCodecParameters::height
int height
Definition: codec_par.h:129
avcodec_parameters_to_context
int avcodec_parameters_to_context(AVCodecContext *codec, const AVCodecParameters *par)
Fill the codec context based on the values from the supplied codec parameters.
Definition: codec_par.c:184
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:124
OptionsContext::start_time_eof
int64_t start_time_eof
Definition: ffmpeg.h:114
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:133
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:403
FFMIN
#define FFMIN(a, b)
Definition: macros.h:49
thread_start
static int thread_start(Demuxer *d)
Definition: ffmpeg_demux.c:696
AVProgram
New fields can be added to the end with minor version bumps.
Definition: avformat.h:1029
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:617
AVFMT_FLAG_NONBLOCK
#define AVFMT_FLAG_NONBLOCK
Do not block when reading packets from input.
Definition: avformat.h:1226
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:339
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:851
AVFMT_FLAG_BITEXACT
#define AVFMT_FLAG_BITEXACT
When muxing, try to avoid writing any random/volatile data to the output.
Definition: avformat.h:1240
ret
ret
Definition: filter_design.txt:187
AVStream
Stream structure.
Definition: avformat.h:839
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:681
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
AVStream::nb_side_data
int nb_side_data
The number of elements in the AVStream.side_data array.
Definition: avformat.h:961
InputFile::streams
InputStream ** streams
Definition: ffmpeg.h:419
add_display_matrix_to_stream
static int add_display_matrix_to_stream(const OptionsContext *o, AVFormatContext *ctx, InputStream *ist)
Definition: ffmpeg_demux.c:978
InputStream::reinit_filters
int reinit_filters
Definition: ffmpeg.h:375
avformat.h
HWAccelID
HWAccelID
Definition: ffmpeg.h:76
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:2868
AVFormatContext::data_codec_id
enum AVCodecID data_codec_id
Forced Data codec_id.
Definition: avformat.h:1635
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:437
AVStream::index
int index
stream index in AVFormatContext
Definition: avformat.h:845
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
av_packet_new_side_data
uint8_t * av_packet_new_side_data(AVPacket *pkt, enum AVPacketSideDataType type, size_t size)
Allocate new information of a packet.
Definition: avpacket.c:231
OptionsContext::nb_audio_channels
int nb_audio_channels
Definition: ffmpeg.h:123
InputFile::audio_duration_queue
AVThreadMessageQueue * audio_duration_queue
Definition: ffmpeg.h:427
AVInputFormat::flags
int flags
Can use flags: AVFMT_NOFILE, AVFMT_NEEDNUMBER, AVFMT_SHOW_IDS, AVFMT_NOTIMESTAMPS,...
Definition: avformat.h:566
SpecifierOpt::str
uint8_t * str
Definition: cmdutils.h:97
AV_PIX_FMT_NONE
@ AV_PIX_FMT_NONE
Definition: pixfmt.h:65
OptionsContext::video_disable
int video_disable
Definition: ffmpeg.h:180
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:346
OptionsContext::frame_pix_fmts
SpecifierOpt * frame_pix_fmts
Definition: ffmpeg.h:132
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:1353
AVFormatContext::duration
int64_t duration
Duration of the stream, in AV_TIME_BASE fractional seconds.
Definition: avformat.h:1207
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:376
GROW_ARRAY
#define GROW_ARRAY(array, nb_elems)
Definition: cmdutils.h:401
HWACCEL_NONE
@ HWACCEL_NONE
Definition: ffmpeg.h:77
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:856
InputFile::ts_offset
int64_t ts_offset
Definition: ffmpeg.h:412
OptionsContext::nb_frame_sizes
int nb_frame_sizes
Definition: ffmpeg.h:131
InputStream::decode_errors
uint64_t decode_errors
Definition: ffmpeg.h:387
InputStream::discard
int discard
Definition: ffmpeg.h:327
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:334
AVCodecParameters::video_delay
int video_delay
Video only.
Definition: codec_par.h:157
InputStream::sub2video::h
int h
Definition: ffmpeg.h:359
DemuxStream::log_name
char log_name[32]
Definition: ffmpeg_demux.c:59
thread_stop
static void thread_stop(Demuxer *d)
Definition: ffmpeg_demux.c:680
InputStream::class
const AVClass * class
Definition: ffmpeg.h:321
ts_fixup
static int ts_fixup(Demuxer *d, AVPacket *pkt)
Definition: ffmpeg_demux.c:384
InputStream::index
int index
Definition: ffmpeg.h:324
readrate_sleep
static void readrate_sleep(Demuxer *d)
Definition: ffmpeg_demux.c:525
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:62
LastFrameDuration::duration
int64_t duration
Definition: ffmpeg.h:392
AVPacket
This structure stores compressed data.
Definition: packet.h:351
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:394
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:183
av_stream_new_side_data
uint8_t * av_stream_new_side_data(AVStream *st, enum AVPacketSideDataType type, size_t size)
Allocate new information from stream.
Definition: avformat.c:193
d
d
Definition: ffmpeg_filter.c:331
AVCodecContext::width
int width
picture width / height.
Definition: avcodec.h:617
int32_t
int32_t
Definition: audioconvert.c:56
ist_free
static void ist_free(InputStream **pist)
Definition: ffmpeg_demux.c:809
timestamp.h
OutputStream
Definition: mux.c:53
flags
#define flags(name, subs,...)
Definition: cbs_av1.c:467
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:1197
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:420
AVStream::pts_wrap_bits
int pts_wrap_bits
Number of bits in timestamps.
Definition: avformat.h:1006
dump_attachment
static int dump_attachment(InputStream *ist, const char *filename)
Definition: ffmpeg_demux.c:1301
AVERROR_PROTOCOL_NOT_FOUND
#define AVERROR_PROTOCOL_NOT_FOUND
Protocol not found.
Definition: error.h:65
InputStream::dec
const AVCodec * dec
Definition: ffmpeg.h:341
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:577
AVPacket::time_base
AVRational time_base
Time base of the packet's timestamps.
Definition: packet.h:418
OptionsContext::loop
int loop
Definition: ffmpeg.h:137
InputStream::autorotate
int autorotate
Definition: ffmpeg.h:354
thread_set_name
static void thread_set_name(InputFile *f)
Definition: ffmpeg_demux.c:560
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:1291