FFmpeg
Loading...
Searching...
No Matches
ffmpeg_demux.c
Go to the documentation of this file.
1/*
2 * This file is part of FFmpeg.
3 *
4 * FFmpeg is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU Lesser General Public
6 * License as published by the Free Software Foundation; either
7 * version 2.1 of the License, or (at your option) any later version.
8 *
9 * FFmpeg is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * Lesser General Public License for more details.
13 *
14 * You should have received a copy of the GNU Lesser General Public
15 * License along with FFmpeg; if not, write to the Free Software
16 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
17 */
18
19#include <float.h>
20#include <stdint.h>
21
22#include "ffmpeg.h"
23#include "ffmpeg_sched.h"
24#include "ffmpeg_utils.h"
25
26#include "libavutil/avassert.h"
27#include "libavutil/avstring.h"
28#include "libavutil/display.h"
29#include "libavutil/error.h"
32#include "libavutil/mem.h"
33#include "libavutil/opt.h"
35#include "libavutil/pixdesc.h"
36#include "libavutil/time.h"
37#include "libavutil/timestamp.h"
38
39#include "libavcodec/bsf.h"
40#include "libavcodec/packet.h"
41
43
44typedef struct DemuxStreamGroup {
46
47 // name used for logging
48 char log_name[32];
49
50 // Temporary fields for LCEVC merging
56
57typedef struct DemuxStream {
59
60 // name used for logging
61 char log_name[32];
62
65
66 double ts_scale;
67
68 /* non zero if the packets must be decoded in 'raw_fifo', see DECODING_FOR_* */
70#define DECODING_FOR_OST 1
71#define DECODING_FOR_FILTER 2
72
73 /* true if stream data should be discarded */
75
76 // scheduler returned EOF for this stream
78
88
89
92 /// dts of the first packet read for this stream (in AV_TIME_BASE units)
94
95 /* predicted dts of the next packet read for this stream or (when there are
96 * several frames in a packet) of the next frame in current packet (in AV_TIME_BASE units) */
98 /// dts of the last packet read for this stream (in AV_TIME_BASE units)
100
102
105 char dec_name[16];
106 // decoded media properties, as estimated by opening the decoder
108
110
113
114 /* number of packets successfully read for this stream */
115 uint64_t nb_packets;
116 // combined size of all the packets read
117 uint64_t data_size;
119
120typedef struct Demuxer {
122
123 // name used for logging
124 char log_name[32];
125
127
128 /**
129 * Extra timestamp offset added by discontinuity handling.
130 */
133
136
137 /* number of times input stream should be looped */
138 int loop;
140 /* duration of the looped segment of the input file */
142 /* pts with the smallest/largest values ever seen */
145
146 /* number of streams that the user was warned of */
148
149 float readrate;
152
153 // latest wallclock time at which packet reading resumed after a stall - used for readrate
155 // relative timestamp of first packet sent after the latest stall - used for readrate
157 // measure of how far behind packet reading is against spceified readrate
159
161
163
167} Demuxer;
168
169typedef struct DemuxThreadContext {
170 // packet used for reading from the demuxer
172 // packet for reading from BSFs
175
177{
178 return (DemuxStreamGroup*)istg;
179}
180
182{
183 return (DemuxStream*)ist;
184}
185
187{
188 return (Demuxer*)f;
189}
190
192{
193 for (InputStream *ist = ist_iter(NULL); ist; ist = ist_iter(ist)) {
194 DemuxStream *ds = ds_from_ist(ist);
195 if (ist->par->codec_type == type && ds->discard &&
196 ist->user_set_discard != AVDISCARD_ALL)
197 return ist;
198 }
199 return NULL;
200}
201
202static void report_new_stream(Demuxer *d, const AVPacket *pkt)
203{
204 const AVStream *st = d->f.ctx->streams[pkt->stream_index];
205
206 if (pkt->stream_index < d->nb_streams_warn)
207 return;
209 "New %s stream with index %d at pos:%"PRId64" and DTS:%ss\n",
211 pkt->stream_index, pkt->pos, av_ts2timestr(pkt->dts, &st->time_base));
212 d->nb_streams_warn = pkt->stream_index + 1;
213}
214
215static int seek_to_start(Demuxer *d, Timestamp end_pts)
216{
217 InputFile *ifile = &d->f;
218 AVFormatContext *is = ifile->ctx;
219 int ret;
220
221 ret = avformat_seek_file(is, -1, INT64_MIN, is->start_time, is->start_time, 0);
222 if (ret < 0)
223 return ret;
224
225 if (end_pts.ts != AV_NOPTS_VALUE &&
226 (d->max_pts.ts == AV_NOPTS_VALUE ||
227 av_compare_ts(d->max_pts.ts, d->max_pts.tb, end_pts.ts, end_pts.tb) < 0))
228 d->max_pts = end_pts;
229
230 if (d->max_pts.ts != AV_NOPTS_VALUE) {
231 int64_t min_pts = d->min_pts.ts == AV_NOPTS_VALUE ? 0 : d->min_pts.ts;
232 d->duration.ts = d->max_pts.ts - av_rescale_q(min_pts, d->min_pts.tb, d->max_pts.tb);
233 }
234 d->duration.tb = d->max_pts.tb;
235
236 if (d->loop > 0)
237 d->loop--;
238
239 return ret;
240}
241
243 AVPacket *pkt)
244{
245 InputFile *ifile = &d->f;
246 DemuxStream *ds = ds_from_ist(ist);
247 const int fmt_is_discont = ifile->ctx->iformat->flags & AVFMT_TS_DISCONT;
248 int disable_discontinuity_correction = copy_ts;
249 int64_t pkt_dts = av_rescale_q_rnd(pkt->dts, pkt->time_base, AV_TIME_BASE_Q,
251
252 if (copy_ts && ds->next_dts != AV_NOPTS_VALUE &&
253 fmt_is_discont && ist->st->pts_wrap_bits < 60) {
254 int64_t wrap_dts = av_rescale_q_rnd(pkt->dts + (1LL<<ist->st->pts_wrap_bits),
255 pkt->time_base, AV_TIME_BASE_Q,
257 if (FFABS(wrap_dts - ds->next_dts) < FFABS(pkt_dts - ds->next_dts)/10)
258 disable_discontinuity_correction = 0;
259 }
260
261 if (ds->next_dts != AV_NOPTS_VALUE && !disable_discontinuity_correction) {
262 int64_t delta = pkt_dts - ds->next_dts;
263 if (fmt_is_discont) {
265 pkt_dts + AV_TIME_BASE/10 < ds->dts) {
268 "timestamp discontinuity "
269 "(stream id=%d): %"PRId64", new offset= %"PRId64"\n",
270 ist->st->id, delta, d->ts_offset_discont);
271 pkt->dts -= av_rescale_q(delta, AV_TIME_BASE_Q, pkt->time_base);
272 if (pkt->pts != AV_NOPTS_VALUE)
273 pkt->pts -= av_rescale_q(delta, AV_TIME_BASE_Q, pkt->time_base);
274 }
275 } else {
278 "DTS %"PRId64", next:%"PRId64" st:%d invalid dropping\n",
279 pkt->dts, ds->next_dts, pkt->stream_index);
280 pkt->dts = AV_NOPTS_VALUE;
281 }
282 if (pkt->pts != AV_NOPTS_VALUE){
283 int64_t pkt_pts = av_rescale_q(pkt->pts, pkt->time_base, AV_TIME_BASE_Q);
284 delta = pkt_pts - ds->next_dts;
287 "PTS %"PRId64", next:%"PRId64" invalid dropping st:%d\n",
288 pkt->pts, ds->next_dts, pkt->stream_index);
289 pkt->pts = AV_NOPTS_VALUE;
290 }
291 }
292 }
293 } else if (ds->next_dts == AV_NOPTS_VALUE && !copy_ts &&
294 fmt_is_discont && d->last_ts != AV_NOPTS_VALUE) {
295 int64_t delta = pkt_dts - d->last_ts;
298 av_log(ist, AV_LOG_DEBUG,
299 "Inter stream timestamp discontinuity %"PRId64", new offset= %"PRId64"\n",
301 pkt->dts -= av_rescale_q(delta, AV_TIME_BASE_Q, pkt->time_base);
302 if (pkt->pts != AV_NOPTS_VALUE)
303 pkt->pts -= av_rescale_q(delta, AV_TIME_BASE_Q, pkt->time_base);
304 }
305 }
306
307 d->last_ts = av_rescale_q(pkt->dts, pkt->time_base, AV_TIME_BASE_Q);
308}
309
311 AVPacket *pkt)
312{
314 pkt->time_base);
315
316 // apply previously-detected timestamp-discontinuity offset
317 // (to all streams, not just audio/video)
318 if (pkt->dts != AV_NOPTS_VALUE)
319 pkt->dts += offset;
320 if (pkt->pts != AV_NOPTS_VALUE)
321 pkt->pts += offset;
322
323 // detect timestamp discontinuities for audio/video
324 if ((ist->par->codec_type == AVMEDIA_TYPE_VIDEO ||
326 pkt->dts != AV_NOPTS_VALUE)
328}
329
331{
332 InputStream *ist = &ds->ist;
333 const AVCodecParameters *par = ist->par;
334
335 if (!ds->saw_first_ts) {
336 ds->first_dts =
337 ds->dts = ist->st->avg_frame_rate.num ? - ist->par->video_delay * AV_TIME_BASE / av_q2d(ist->st->avg_frame_rate) : 0;
338 if (pkt->pts != AV_NOPTS_VALUE) {
339 ds->first_dts =
340 ds->dts += av_rescale_q(pkt->pts, pkt->time_base, AV_TIME_BASE_Q);
341 }
342 ds->saw_first_ts = 1;
343 }
344
345 if (ds->next_dts == AV_NOPTS_VALUE)
346 ds->next_dts = ds->dts;
347
348 if (pkt->dts != AV_NOPTS_VALUE)
349 ds->next_dts = ds->dts = av_rescale_q(pkt->dts, pkt->time_base, AV_TIME_BASE_Q);
350
351 ds->dts = ds->next_dts;
352 switch (par->codec_type) {
354 av_assert1(pkt->duration >= 0);
355 if (par->sample_rate) {
356 ds->next_dts += ((int64_t)AV_TIME_BASE * par->frame_size) /
357 par->sample_rate;
358 } else {
359 ds->next_dts += av_rescale_q(pkt->duration, pkt->time_base, AV_TIME_BASE_Q);
360 }
361 break;
363 if (ist->framerate.num) {
364 // TODO: Remove work-around for c99-to-c89 issue 7
365 AVRational time_base_q = AV_TIME_BASE_Q;
366 int64_t next_dts = av_rescale_q(ds->next_dts, time_base_q, av_inv_q(ist->framerate));
367 ds->next_dts = av_rescale_q(next_dts + 1, av_inv_q(ist->framerate), time_base_q);
368 } else if (pkt->duration) {
369 ds->next_dts += av_rescale_q(pkt->duration, pkt->time_base, AV_TIME_BASE_Q);
370 } else if (ist->par->framerate.num != 0) {
371 AVRational field_rate = av_mul_q(ist->par->framerate,
372 (AVRational){ 2, 1 });
373 int fields = 2;
374
375 if (ds->codec_desc &&
378 fields = 1 + av_stream_get_parser(ist->st)->repeat_pict;
379
380 ds->next_dts += av_rescale_q(fields, av_inv_q(field_rate), AV_TIME_BASE_Q);
381 }
382 break;
383 }
384
385 fd->dts_est = ds->dts;
386
387 return 0;
388}
389
390static int ts_fixup(Demuxer *d, AVPacket *pkt, FrameData *fd)
391{
392 InputFile *ifile = &d->f;
393 InputStream *ist = ifile->streams[pkt->stream_index];
394 DemuxStream *ds = ds_from_ist(ist);
397 int ret;
398
399 pkt->time_base = ist->st->time_base;
400
401#define SHOW_TS_DEBUG(tag_) \
402 if (debug_ts) { \
403 av_log(ist, AV_LOG_INFO, "%s -> ist_index:%d:%d type:%s " \
404 "pkt_pts:%s pkt_pts_time:%s pkt_dts:%s pkt_dts_time:%s duration:%s duration_time:%s\n", \
405 tag_, ifile->index, pkt->stream_index, \
406 av_get_media_type_string(ist->st->codecpar->codec_type), \
407 av_ts2str(pkt->pts), av_ts2timestr(pkt->pts, &pkt->time_base), \
408 av_ts2str(pkt->dts), av_ts2timestr(pkt->dts, &pkt->time_base), \
409 av_ts2str(pkt->duration), av_ts2timestr(pkt->duration, &pkt->time_base)); \
410 }
411
412 SHOW_TS_DEBUG("demuxer");
413
415 ist->st->pts_wrap_bits < 64) {
416 int64_t stime, stime2;
417
418 stime = av_rescale_q(start_time, AV_TIME_BASE_Q, pkt->time_base);
419 stime2= stime + (1ULL<<ist->st->pts_wrap_bits);
420 ds->wrap_correction_done = 1;
421
422 if(stime2 > stime && pkt->dts != AV_NOPTS_VALUE && pkt->dts > stime + (1LL<<(ist->st->pts_wrap_bits-1))) {
423 pkt->dts -= 1ULL<<ist->st->pts_wrap_bits;
424 ds->wrap_correction_done = 0;
425 }
426 if(stime2 > stime && pkt->pts != AV_NOPTS_VALUE && pkt->pts > stime + (1LL<<(ist->st->pts_wrap_bits-1))) {
427 pkt->pts -= 1ULL<<ist->st->pts_wrap_bits;
428 ds->wrap_correction_done = 0;
429 }
430 }
431
432 if (pkt->dts != AV_NOPTS_VALUE)
433 pkt->dts += av_rescale_q(ifile->ts_offset, AV_TIME_BASE_Q, pkt->time_base);
434 if (pkt->pts != AV_NOPTS_VALUE)
435 pkt->pts += av_rescale_q(ifile->ts_offset, AV_TIME_BASE_Q, pkt->time_base);
436
437 if (pkt->pts != AV_NOPTS_VALUE)
438 pkt->pts *= ds->ts_scale;
439 if (pkt->dts != AV_NOPTS_VALUE)
440 pkt->dts *= ds->ts_scale;
441
442 duration = av_rescale_q(d->duration.ts, d->duration.tb, pkt->time_base);
443 if (pkt->pts != AV_NOPTS_VALUE) {
444 // audio decoders take precedence for estimating total file duration
445 int64_t pkt_duration = d->have_audio_dec ? 0 : pkt->duration;
446
447 pkt->pts += duration;
448
449 // update max/min pts that will be used to compute total file duration
450 // when using -stream_loop
451 if (d->max_pts.ts == AV_NOPTS_VALUE ||
453 pkt->pts + pkt_duration, pkt->time_base) < 0) {
454 d->max_pts = (Timestamp){ .ts = pkt->pts + pkt_duration,
455 .tb = pkt->time_base };
456 }
457 if (d->min_pts.ts == AV_NOPTS_VALUE ||
459 pkt->pts, pkt->time_base) > 0) {
460 d->min_pts = (Timestamp){ .ts = pkt->pts,
461 .tb = pkt->time_base };
462 }
463 }
464
465 if (pkt->dts != AV_NOPTS_VALUE)
466 pkt->dts += duration;
467
468 SHOW_TS_DEBUG("demuxer+tsfixup");
469
470 // detect and try to correct for timestamp discontinuities
472
473 // update estimated/predicted dts
474 ret = ist_dts_update(ds, pkt, fd);
475 if (ret < 0)
476 return ret;
477
478 return 0;
479}
480
481static int input_packet_process(Demuxer *d, AVPacket *pkt, unsigned *send_flags)
482{
483 InputFile *f = &d->f;
484 InputStream *ist = f->streams[pkt->stream_index];
485 DemuxStream *ds = ds_from_ist(ist);
486 FrameData *fd;
487 int ret = 0;
488
489 fd = packet_data(pkt);
490 if (!fd)
491 return AVERROR(ENOMEM);
492
493 ret = ts_fixup(d, pkt, fd);
494 if (ret < 0)
495 return ret;
496
497 if (d->recording_time != INT64_MAX) {
499 if (copy_ts) {
500 start_time += f->start_time != AV_NOPTS_VALUE ? f->start_time : 0;
501 start_time += start_at_zero ? 0 : f->start_time_effective;
502 }
503 if (ds->dts >= d->recording_time + start_time)
504 *send_flags |= DEMUX_SEND_STREAMCOPY_EOF;
505 }
506
507 ds->data_size += pkt->size;
508 ds->nb_packets++;
509
511
512 if (debug_ts) {
513 av_log(ist, AV_LOG_INFO, "demuxer+ffmpeg -> ist_index:%d:%d type:%s pkt_pts:%s pkt_pts_time:%s pkt_dts:%s pkt_dts_time:%s duration:%s duration_time:%s off:%s off_time:%s\n",
514 f->index, pkt->stream_index,
516 av_ts2str(pkt->pts), av_ts2timestr(pkt->pts, &pkt->time_base),
517 av_ts2str(pkt->dts), av_ts2timestr(pkt->dts, &pkt->time_base),
518 av_ts2str(pkt->duration), av_ts2timestr(pkt->duration, &pkt->time_base),
519 av_ts2str(f->ts_offset), av_ts2timestr(f->ts_offset, &AV_TIME_BASE_Q));
520 }
521
522 return 0;
523}
524
525static 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 initial_burst = AV_TIME_BASE * d->readrate_initial_burst;
533 int resume_warn = 0;
534
535 DemuxStream *slowest = NULL;
536 int64_t progress = INT64_MAX;
537
538 for (int i = 0; i < f->nb_streams; i++) {
539 InputStream *ist = f->streams[i];
540 DemuxStream *ds = ds_from_ist(ist);
541 int64_t stream_ts_offset, pts, pts_diff;
542 if (ds->discard || ds->finished || ds->first_dts == AV_NOPTS_VALUE)
543 continue;
544
545 stream_ts_offset = FFMAX(ds->first_dts, file_start);
546 pts = av_rescale(ds->dts, 1000000, AV_TIME_BASE);
547 pts_diff = pts - stream_ts_offset;
548 if (pts_diff < progress) {
549 progress = pts_diff;
550 slowest = ds;
551 }
552 }
553
554 if (!slowest || progress <= initial_burst)
555 return;
556
558 int64_t wc_elapsed = now - d->wallclock_start;
559 int64_t max_prog = initial_burst + (int64_t)(wc_elapsed * d->readrate);
560 int64_t lag = FFMAX(max_prog - progress, 0);
562
563 if ( (!d->lag && lag > 0.3 * AV_TIME_BASE) || ( lag > d->lag + 0.3 * AV_TIME_BASE) ) {
564 d->lag = lag;
565 d->resume_wc = now;
566 d->resume_progress = progress;
567
568 int64_t pts = FFMAX(slowest->first_dts, file_start) + progress;
569 av_log_once(slowest, AV_LOG_WARNING, AV_LOG_DEBUG, &resume_warn,
570 "Resumed reading at pts %0.3f with rate %0.3f after a lag of %0.3fs\n",
571 (float)pts/AV_TIME_BASE, d->readrate_catchup, (float)lag/AV_TIME_BASE);
572 }
573 if (d->lag && !lag)
574 d->lag = d->resume_wc = d->resume_progress = 0;
575 if (d->resume_wc) {
576 int64_t elapsed = now - d->resume_wc;
577 limit = d->resume_progress + (int64_t)(elapsed * d->readrate_catchup);
578 } else {
579 limit = max_prog;
580 }
581
582 if (progress > limit)
583 av_usleep(progress - limit);
584}
585
586static int do_send(Demuxer *d, DemuxStream *ds, AVPacket *pkt, unsigned flags,
587 const char *pkt_desc)
588{
589 int ret;
590
591 pkt->stream_index = ds->sch_idx_stream;
592
593 ret = sch_demux_send(d->sch, d->f.index, pkt, flags);
594 if (ret == AVERROR_EOF) {
596
597 av_log(ds, AV_LOG_VERBOSE, "All consumers of this stream are done\n");
598 ds->finished = 1;
599
600 if (++d->nb_streams_finished == d->nb_streams_used) {
601 av_log(d, AV_LOG_VERBOSE, "All consumers are done\n");
602 return AVERROR_EOF;
603 }
604 } else if (ret < 0) {
605 if (ret != AVERROR_EXIT)
607 "Unable to send %s packet to consumers: %s\n",
608 pkt_desc, av_err2str(ret));
609 return ret;
610 }
611
612 return 0;
613}
614
617{
618 const AVStreamGroup *stg = dsg->istg.stg;
620 const int enhancement = ds->ist.index == stg->streams[lcevc->el_index]->index;
621 AVBitStreamFilterContext *source = dsg->lcevc[enhancement];
623
624 if (enhancement)
626
627 ret = av_bsf_source_add_packet(source, pkt, flags);
628 if (ret < 0) {
629 if (pkt)
631 av_log(dsg, AV_LOG_ERROR, "Error submitting a packet for filtering: %s\n",
632 av_err2str(ret));
633 return ret;
634 }
635
636 if (pkt && enhancement) {
637 if (ds->discard)
639 else {
640 ret = do_send(d, ds, pkt, 0, "filtered");
641 if (ret < 0) {
643 return ret;
644 }
645 }
646 return 0;
647 }
648
649 while (1) {
650 ret = av_bsf_sink_get_packet(dsg->sink, dt->pkt_bsf, 0);
651 if (ret == AVERROR(EAGAIN))
652 return 0;
653 else if (ret < 0) {
654 if (ret != AVERROR_EOF)
655 av_log(dsg, AV_LOG_ERROR,
656 "Error applying bitstream filters to a packet: %s\n",
657 av_err2str(ret));
658 return ret;
659 }
660
662
663 ret = do_send(d, ds, dt->pkt_bsf, 0, "filtered");
664 if (ret < 0) {
666 return ret;
667 }
668 }
669
670 return 0;
671}
672
674 AVPacket *pkt, unsigned flags)
675{
676 InputFile *f = &d->f;
677 DemuxStreamGroup *dsg = NULL;
678 int ret;
679
680 for (int i = 0; i < ds->nb_dsg; i++) {
681 const InputStreamGroup *istg = &ds->dsg[i]->istg;
682
684 continue;
685 dsg = ds->dsg[i];
686 break;
687 }
688
689 // pkt can be NULL only when flushing BSFs
690 av_assert0(ds->bsf || (dsg && dsg->graph) || pkt);
691
692 // send heartbeat for sub2video streams
693 if (d->pkt_heartbeat && pkt && pkt->pts != AV_NOPTS_VALUE) {
694 for (int i = 0; i < f->nb_streams; i++) {
695 DemuxStream *ds1 = ds_from_ist(f->streams[i]);
696
697 if (ds1->finished || !ds1->have_sub2video)
698 continue;
699
700 d->pkt_heartbeat->pts = pkt->pts;
701 d->pkt_heartbeat->time_base = pkt->time_base;
702 d->pkt_heartbeat->opaque = (void*)(intptr_t)PKT_OPAQUE_SUB_HEARTBEAT;
703
704 ret = do_send(d, ds1, d->pkt_heartbeat, 0, "heartbeat");
705 if (ret < 0)
706 return ret;
707 }
708 }
709
710 if (dsg && dsg->graph_enabled) {
711 ret = do_bsf_graph(d, dt, dsg, ds, pkt);
712 if (ret < 0)
713 return ret;
714 }
715 if (ds->bsf) {
716 if (pkt)
717 av_packet_rescale_ts(pkt, pkt->time_base, ds->bsf->time_base_in);
718
719 ret = av_bsf_send_packet(ds->bsf, pkt);
720 if (ret < 0) {
721 if (pkt)
723 av_log(ds, AV_LOG_ERROR, "Error submitting a packet for filtering: %s\n",
724 av_err2str(ret));
725 return ret;
726 }
727
728 while (1) {
729 ret = av_bsf_receive_packet(ds->bsf, dt->pkt_bsf);
730 if (ret == AVERROR(EAGAIN))
731 return 0;
732 else if (ret < 0) {
733 if (ret != AVERROR_EOF)
735 "Error applying bitstream filters to a packet: %s\n",
736 av_err2str(ret));
737 return ret;
738 }
739
741
742 ret = do_send(d, ds, dt->pkt_bsf, 0, "filtered");
743 if (ret < 0) {
745 return ret;
746 }
747 }
748 } else if (ds->discard && pkt) {
750 } else if (!dsg || !dsg->graph_enabled) {
751 ret = do_send(d, ds, pkt, flags, "demuxed");
752 if (ret < 0)
753 return ret;
754 }
755
756 return 0;
757}
758
760{
761 InputFile *f = &d->f;
762 int ret;
763
764 for (unsigned i = 0; i < f->nb_streams; i++) {
765 DemuxStream *ds = ds_from_ist(f->streams[i]);
766 DemuxStreamGroup *dsg = NULL;
767
768 for (int j = 0; j < ds->nb_dsg; j++) {
769 const InputStreamGroup *istg = &ds->dsg[j]->istg;
770
772 continue;
773 dsg = ds->dsg[j];
774 break;
775 }
776
777 if (!ds->bsf && (!dsg || !dsg->graph_enabled))
778 continue;
779
780 ret = demux_send(d, dt, ds, NULL, 0);
781 ret = (ret == AVERROR_EOF) ? 0 : (ret < 0) ? ret : AVERROR_BUG;
782 if (ret < 0) {
783 av_log(ds, AV_LOG_ERROR, "Error flushing BSFs: %s\n",
784 av_err2str(ret));
785 return ret;
786 }
787
788 if (ds->bsf)
789 av_bsf_flush(ds->bsf);
790 }
791
792 return 0;
793}
794
796{
797 for (int j = 0; j < ifile->ctx->nb_programs; j++) {
798 AVProgram *p = ifile->ctx->programs[j];
799 int discard = AVDISCARD_ALL;
800
801 for (int k = 0; k < p->nb_stream_indexes; k++) {
802 DemuxStream *ds = ds_from_ist(ifile->streams[p->stream_index[k]]);
803
804 if (!ds->discard) {
805 discard = AVDISCARD_DEFAULT;
806 break;
807 }
808 }
809 p->discard = discard;
810 }
811}
812
814{
815 char name[16];
816 snprintf(name, sizeof(name), "dmx%d:%s", f->index, f->ctx->iformat->name);
818}
819
821{
824
825 memset(dt, 0, sizeof(*dt));
826}
827
829{
830 memset(dt, 0, sizeof(*dt));
831
833 if (!dt->pkt_demux)
834 return AVERROR(ENOMEM);
835
836 dt->pkt_bsf = av_packet_alloc();
837 if (!dt->pkt_bsf)
838 return AVERROR(ENOMEM);
839
840 return 0;
841}
842
843static int input_thread(void *arg)
844{
845 Demuxer *d = arg;
846 InputFile *f = &d->f;
847
849
850 int ret = 0;
851
852 ret = demux_thread_init(&dt);
853 if (ret < 0)
854 goto finish;
855
857
859
860 d->read_started = 1;
862
863 while (1) {
864 DemuxStream *ds;
865 unsigned send_flags = 0;
866
867 ret = av_read_frame(f->ctx, dt.pkt_demux);
868
869 if (ret == AVERROR(EAGAIN)) {
870 av_usleep(10000);
871 continue;
872 }
873 if (ret < 0) {
874 int ret_bsf;
875
876 if (ret == AVERROR_EOF)
877 av_log(d, AV_LOG_VERBOSE, "EOF while reading input\n");
878 else {
879 av_log(d, AV_LOG_ERROR, "Error during demuxing: %s\n",
880 av_err2str(ret));
881 ret = exit_on_error ? ret : 0;
882 }
883
884 ret_bsf = demux_bsf_flush(d, &dt);
885 ret = err_merge(ret == AVERROR_EOF ? 0 : ret, ret_bsf);
886
887 if (d->loop) {
888 /* signal looping to our consumers */
889 dt.pkt_demux->stream_index = -1;
890 ret = sch_demux_send(d->sch, f->index, dt.pkt_demux, 0);
891 if (ret >= 0)
892 ret = seek_to_start(d, (Timestamp){ .ts = dt.pkt_demux->pts,
893 .tb = dt.pkt_demux->time_base });
894 if (ret >= 0)
895 continue;
896
897 /* fallthrough to the error path */
898 }
899
900 break;
901 }
902
903 if (do_pkt_dump) {
905 f->ctx->streams[dt.pkt_demux->stream_index]);
906 }
907
908 /* the following test is needed in case new streams appear
909 dynamically in stream : we ignore them */
910 ds = dt.pkt_demux->stream_index < f->nb_streams ?
911 ds_from_ist(f->streams[dt.pkt_demux->stream_index]) : NULL;
912 if (!ds || ds->finished) {
915 continue;
916 }
917
920 "corrupt input packet in stream %d\n",
922 if (exit_on_error) {
925 break;
926 }
927 }
928
929 ret = input_packet_process(d, dt.pkt_demux, &send_flags);
930 if (ret < 0)
931 break;
932
933 if (d->readrate)
935
936 ret = demux_send(d, &dt, ds, dt.pkt_demux, send_flags);
937 if (ret < 0)
938 break;
939 }
940
941 // EOF/EXIT is normal termination
942 if (ret == AVERROR_EOF || ret == AVERROR_EXIT)
943 ret = 0;
944
945finish:
947
948 return ret;
949}
950
952{
953 InputFile *f = &d->f;
954 uint64_t total_packets = 0, total_size = 0;
955
956 av_log(f, AV_LOG_VERBOSE, "Input file #%d (%s):\n",
957 f->index, f->ctx->url);
958
959 for (int j = 0; j < f->nb_streams; j++) {
960 InputStream *ist = f->streams[j];
961 DemuxStream *ds = ds_from_ist(ist);
962 enum AVMediaType type = ist->par->codec_type;
963
965 continue;
966
967 total_size += ds->data_size;
968 total_packets += ds->nb_packets;
969
970 av_log(f, AV_LOG_VERBOSE, " Input stream #%d:%d (%s): ",
971 f->index, j, av_get_media_type_string(type));
972 av_log(f, AV_LOG_VERBOSE, "%"PRIu64" packets read (%"PRIu64" bytes); ",
973 ds->nb_packets, ds->data_size);
974
975 if (ds->decoding_needed) {
977 "%"PRIu64" frames decoded; %"PRIu64" decode errors",
980 av_log(f, AV_LOG_VERBOSE, " (%"PRIu64" samples)", ist->decoder->samples_decoded);
981 av_log(f, AV_LOG_VERBOSE, "; ");
982 }
983
984 av_log(f, AV_LOG_VERBOSE, "\n");
985 }
986
987 av_log(f, AV_LOG_VERBOSE, " Total: %"PRIu64" packets (%"PRIu64" bytes) demuxed\n",
988 total_packets, total_size);
989}
990
991static void ist_free(InputStream **pist)
992{
993 InputStream *ist = *pist;
994 DemuxStream *ds;
995
996 if (!ist)
997 return;
998 ds = ds_from_ist(ist);
999
1000 dec_free(&ist->decoder);
1001
1003 av_freep(&ist->filters);
1005
1007
1009
1010 av_freep(&ds->dsg);
1011 av_bsf_free(&ds->bsf);
1012
1013 av_freep(pist);
1014}
1015
1016static void istg_free(InputStreamGroup **pistg)
1017{
1018 InputStreamGroup *istg = *pistg;
1019 DemuxStreamGroup *dsg;
1020
1021 if (!istg)
1022 return;
1023
1024 dsg = dsg_from_istg(istg);
1025
1026 av_bsf_graph_free(&dsg->graph);
1027
1028 av_freep(pistg);
1029}
1030
1032{
1033 InputFile *f = *pf;
1035
1036 if (!f)
1037 return;
1038
1039 if (d->read_started)
1041
1042 for (int i = 0; i < f->nb_streams; i++)
1043 ist_free(&f->streams[i]);
1044 av_freep(&f->streams);
1045
1046 for (int i = 0; i < f->nb_stream_groups; i++)
1047 istg_free(&f->stream_groups[i]);
1048 av_freep(&f->stream_groups);
1049
1050 avformat_close_input(&f->ctx);
1051
1053
1054 av_freep(pf);
1055}
1056
1057int ist_use(InputStream *ist, int decoding_needed,
1058 const ViewSpecifier *vs, SchedulerNode *src)
1059{
1060 Demuxer *d = demuxer_from_ifile(ist->file);
1061 DemuxStream *ds = ds_from_ist(ist);
1062 int ret;
1063
1064 if (ist->user_set_discard == AVDISCARD_ALL) {
1065 av_log(ist, AV_LOG_ERROR, "Cannot %s a disabled input stream\n",
1066 decoding_needed ? "decode" : "streamcopy");
1067 return AVERROR(EINVAL);
1068 }
1069
1070 if (decoding_needed && !ist->dec) {
1071 av_log(ist, AV_LOG_ERROR,
1072 "Decoding requested, but no decoder found for: %s\n",
1074 return AVERROR(EINVAL);
1075 }
1076
1077 if (ds->sch_idx_stream < 0) {
1078 ret = sch_add_demux_stream(d->sch, d->f.index);
1079 if (ret < 0)
1080 return ret;
1081 ds->sch_idx_stream = ret;
1082 }
1083
1084 if (ds->discard) {
1085 ds->discard = 0;
1086 d->nb_streams_used++;
1087 }
1088
1089 ist->st->discard = ist->user_set_discard;
1090 ds->decoding_needed |= decoding_needed;
1091 ds->streamcopy_needed |= !decoding_needed;
1092
1093 for (int i = 0; i < ds->nb_dsg; i++) {
1094 DemuxStreamGroup *dsg = ds->dsg[i];
1095 const InputStreamGroup *istg = &dsg->istg;
1096
1097 if (!dsg->graph || istg->stg->type != AV_STREAM_GROUP_PARAMS_LCEVC)
1098 continue;
1099 const AVStreamGroupLayeredVideo *lcevc = istg->stg->params.layered_video;
1100 if (ist->st->index == istg->stg->streams[lcevc->el_index]->index)
1101 break;
1102
1104
1105 for (int j = 0; j < 2; j++) {
1106 ret = av_bsf_init_dict(dsg->lcevc[j], NULL);
1107 if (ret < 0)
1108 return ret;
1109 }
1110
1112 if (ret < 0)
1113 return ret;
1114 ret = av_bsf_init_dict(dsg->sink, NULL);
1115 if (ret < 0)
1116 return ret;
1117
1118 ret = av_bsf_link(dsg->lcevc[0], 0, lcevc_merge, 0);
1119 if (ret < 0)
1120 return ret;
1121 ret = av_bsf_link(dsg->lcevc[1], 0, lcevc_merge, 1);
1122 if (ret < 0)
1123 return ret;
1124 ret = av_bsf_link(lcevc_merge, 0, dsg->sink, 0);
1125 if (ret < 0)
1126 return ret;
1127
1128 ret = av_bsf_graph_config(dsg->graph, d);
1129 if (ret < 0)
1130 return ret;
1131
1132 InputStream *lcevc_ist = d->f.streams[istg->stg->streams[lcevc->el_index]->index];
1133 lcevc_ist->st->discard = 0;
1134
1135 dsg->graph_enabled = 1;
1136
1137 break;
1138 }
1139
1140 if (decoding_needed && ds->sch_idx_dec < 0) {
1141 int is_audio = ist->st->codecpar->codec_type == AVMEDIA_TYPE_AUDIO;
1142 int is_unreliable = !!(d->f.ctx->iformat->flags & AVFMT_NOTIMESTAMPS);
1143 int64_t use_wallclock_as_timestamps;
1144
1145 ret = av_opt_get_int(d->f.ctx, "use_wallclock_as_timestamps", 0, &use_wallclock_as_timestamps);
1146 if (ret < 0)
1147 return ret;
1148
1149 if (use_wallclock_as_timestamps)
1150 is_unreliable = 0;
1151
1153 (!!is_unreliable * DECODER_FLAG_TS_UNRELIABLE) |
1154 (!!(d->loop && is_audio) * DECODER_FLAG_SEND_END_TS);
1155
1156 if (ist->framerate.num) {
1158 ds->dec_opts.framerate = ist->framerate;
1159 } else
1160 ds->dec_opts.framerate = ist->st->avg_frame_rate;
1161
1162 if (ist->dec->id == AV_CODEC_ID_DVB_SUBTITLE &&
1164 av_dict_set(&ds->decoder_opts, "compute_edt", "1", AV_DICT_DONT_OVERWRITE);
1167 "Warning using DVB subtitles for filtering and output at the "
1168 "same time is not fully supported, also see -compute_edt [0|1]\n");
1169 }
1170
1171 snprintf(ds->dec_name, sizeof(ds->dec_name), "%d:%d", ist->file->index, ist->index);
1172 ds->dec_opts.name = ds->dec_name;
1173
1174 ds->dec_opts.codec = ist->dec;
1175 ds->dec_opts.par = ist->par;
1176
1177 ds->dec_opts.log_parent = ist;
1178
1180 if (!ds->decoded_params)
1181 return AVERROR(ENOMEM);
1182
1183 ret = dec_init(&ist->decoder, d->sch,
1184 &ds->decoder_opts, &ds->dec_opts, ds->decoded_params);
1185 if (ret < 0)
1186 return ret;
1187 ds->sch_idx_dec = ret;
1188
1189 ret = sch_connect(d->sch, SCH_DSTREAM(d->f.index, ds->sch_idx_stream),
1190 SCH_DEC_IN(ds->sch_idx_dec));
1191 if (ret < 0)
1192 return ret;
1193
1194 d->have_audio_dec |= is_audio;
1195 }
1196
1197 if (decoding_needed && ist->par->codec_type == AVMEDIA_TYPE_VIDEO) {
1198 ret = dec_request_view(ist->decoder, vs, src);
1199 if (ret < 0)
1200 return ret;
1201 } else {
1202 *src = decoding_needed ?
1203 SCH_DEC_OUT(ds->sch_idx_dec, 0) :
1205 }
1206
1207 return 0;
1208}
1209
1210int ist_filter_add(InputStream *ist, InputFilter *ifilter, int is_simple,
1213{
1214 Demuxer *d = demuxer_from_ifile(ist->file);
1215 DemuxStream *ds = ds_from_ist(ist);
1216 int64_t tsoffset = 0;
1217 int ret;
1218
1219 ret = ist_use(ist, is_simple ? DECODING_FOR_OST : DECODING_FOR_FILTER,
1220 vs, src);
1221 if (ret < 0)
1222 return ret;
1223
1224 ret = GROW_ARRAY(ist->filters, ist->nb_filters);
1225 if (ret < 0)
1226 return ret;
1227
1228 ist->filters[ist->nb_filters - 1] = ifilter;
1229
1230 if (ist->par->codec_type == AVMEDIA_TYPE_VIDEO) {
1232 ist->par->nb_coded_side_data,
1234 if (ist->framerate.num > 0 && ist->framerate.den > 0) {
1235 opts->framerate = ist->framerate;
1236 opts->flags |= IFILTER_FLAG_CFR;
1237 } else
1238 opts->framerate = av_guess_frame_rate(d->f.ctx, ist->st, NULL);
1239 if (sd && sd->size >= sizeof(uint32_t) * 4) {
1240 opts->crop_top = AV_RL32(sd->data + 0);
1241 opts->crop_bottom = AV_RL32(sd->data + 4);
1242 opts->crop_left = AV_RL32(sd->data + 8);
1243 opts->crop_right = AV_RL32(sd->data + 12);
1244 if (ds->apply_cropping && ds->apply_cropping != CROP_CODEC &&
1245 (opts->crop_top | opts->crop_bottom | opts->crop_left | opts->crop_right))
1246 opts->flags |= IFILTER_FLAG_CROP;
1247 }
1248 } else if (ist->par->codec_type == AVMEDIA_TYPE_SUBTITLE) {
1249 /* Compute the size of the canvas for the subtitles stream.
1250 If the subtitles codecpar has set a size, use it. Otherwise use the
1251 maximum dimensions of the video streams in the same file. */
1252 opts->sub2video_width = ist->par->width;
1253 opts->sub2video_height = ist->par->height;
1254 if (!(opts->sub2video_width && opts->sub2video_height)) {
1255 for (int j = 0; j < d->f.nb_streams; j++) {
1256 AVCodecParameters *par1 = d->f.streams[j]->par;
1257 if (par1->codec_type == AVMEDIA_TYPE_VIDEO) {
1258 opts->sub2video_width = FFMAX(opts->sub2video_width, par1->width);
1259 opts->sub2video_height = FFMAX(opts->sub2video_height, par1->height);
1260 }
1261 }
1262 }
1263
1264 if (!(opts->sub2video_width && opts->sub2video_height)) {
1265 opts->sub2video_width = FFMAX(opts->sub2video_width, 720);
1266 opts->sub2video_height = FFMAX(opts->sub2video_height, 576);
1267 }
1268
1269 if (!d->pkt_heartbeat) {
1271 if (!d->pkt_heartbeat)
1272 return AVERROR(ENOMEM);
1273 }
1274 ds->have_sub2video = 1;
1275 }
1276
1277 ret = av_frame_copy_props(opts->fallback, ds->decoded_params);
1278 if (ret < 0)
1279 return ret;
1280 opts->fallback->format = ds->decoded_params->format;
1281 opts->fallback->width = ds->decoded_params->width;
1282 opts->fallback->height = ds->decoded_params->height;
1283
1284 ret = av_channel_layout_copy(&opts->fallback->ch_layout, &ds->decoded_params->ch_layout);
1285 if (ret < 0)
1286 return ret;
1287
1288 if (copy_ts) {
1289 tsoffset = d->f.start_time == AV_NOPTS_VALUE ? 0 : d->f.start_time;
1291 tsoffset += d->f.ctx->start_time;
1292 }
1293 opts->trim_start_us = ((d->f.start_time == AV_NOPTS_VALUE) || !d->accurate_seek) ?
1294 AV_NOPTS_VALUE : tsoffset;
1295 opts->trim_end_us = d->recording_time;
1296
1297 opts->name = av_strdup(ds->dec_name);
1298 if (!opts->name)
1299 return AVERROR(ENOMEM);
1300
1301 opts->flags |= IFILTER_FLAG_AUTOROTATE * !!(ds->autorotate) |
1304
1305 return 0;
1306}
1307
1308static int choose_decoder(const OptionsContext *o, void *logctx,
1310 enum HWAccelID hwaccel_id, enum AVHWDeviceType hwaccel_device_type,
1311 const AVCodec **pcodec)
1312
1313{
1314 const char *codec_name = NULL;
1315
1316 opt_match_per_stream_str(logctx, &o->codec_names, s, st, &codec_name);
1317 if (codec_name) {
1318 int ret = find_codec(NULL, codec_name, st->codecpar->codec_type, 0, pcodec);
1319 if (ret < 0)
1320 return ret;
1321 st->codecpar->codec_id = (*pcodec)->id;
1322 if (recast_media && st->codecpar->codec_type != (*pcodec)->type)
1323 st->codecpar->codec_type = (*pcodec)->type;
1324 return 0;
1325 } else {
1327 hwaccel_id == HWACCEL_GENERIC &&
1328 hwaccel_device_type != AV_HWDEVICE_TYPE_NONE) {
1329 const AVCodec *c;
1330 void *i = NULL;
1331
1332 while ((c = av_codec_iterate(&i))) {
1333 const AVCodecHWConfig *config;
1334
1335 if (c->id != st->codecpar->codec_id ||
1337 continue;
1338
1339 for (int j = 0; config = avcodec_get_hw_config(c, j); j++) {
1340 if (config->device_type == hwaccel_device_type) {
1341 av_log(logctx, AV_LOG_VERBOSE, "Selecting decoder '%s' because of requested hwaccel method %s\n",
1342 c->name, av_hwdevice_get_type_name(hwaccel_device_type));
1343 *pcodec = c;
1344 return 0;
1345 }
1346 }
1347 }
1348 }
1349
1350 *pcodec = avcodec_find_decoder(st->codecpar->codec_id);
1351 return 0;
1352 }
1353}
1354
1356 int guess_layout_max)
1357{
1359 char layout_name[256];
1360
1361 if (par->ch_layout.nb_channels > guess_layout_max)
1362 return 0;
1365 return 0;
1366 av_channel_layout_describe(&par->ch_layout, layout_name, sizeof(layout_name));
1367 av_log(ist, AV_LOG_WARNING, "Guessed Channel Layout: %s\n", layout_name);
1368 }
1369 return 1;
1370}
1371
1374{
1375 AVStream *st = ist->st;
1376 DemuxStream *ds = ds_from_ist(ist);
1377 AVPacketSideData *sd;
1378 double rotation = DBL_MAX;
1379 int hflip = -1, vflip = -1;
1380 int hflip_set = 0, vflip_set = 0, rotation_set = 0;
1381 int32_t *buf;
1382
1383 opt_match_per_stream_dbl(ist, &o->display_rotations, ctx, st, &rotation);
1384 opt_match_per_stream_int(ist, &o->display_hflips, ctx, st, &hflip);
1385 opt_match_per_stream_int(ist, &o->display_vflips, ctx, st, &vflip);
1386
1387 rotation_set = rotation != DBL_MAX;
1388 hflip_set = hflip != -1;
1389 vflip_set = vflip != -1;
1390
1391 if (!rotation_set && !hflip_set && !vflip_set)
1392 return 0;
1393
1397 sizeof(int32_t) * 9, 0);
1398 if (!sd) {
1399 av_log(ist, AV_LOG_FATAL, "Failed to generate a display matrix!\n");
1400 return AVERROR(ENOMEM);
1401 }
1402
1403 buf = (int32_t *)sd->data;
1405 rotation_set ? -(rotation) : -0.0f);
1406
1408 hflip_set ? hflip : 0,
1409 vflip_set ? vflip : 0);
1410
1411 ds->force_display_matrix = 1;
1412
1413 return 0;
1414}
1415
1418{
1419 AVStream *st = ist->st;
1420 DemuxStream *ds = ds_from_ist(ist);
1421 AVMasteringDisplayMetadata *master_display;
1422 AVPacketSideData *sd;
1423 const char *p = NULL;
1424 const int chroma_den = 50000;
1425 const int luma_den = 10000;
1426 size_t size;
1427 int ret;
1428
1430
1431 if (!p)
1432 return 0;
1433
1435 if (!master_display)
1436 return AVERROR(ENOMEM);
1437
1438 ret = sscanf(p,
1439 "G(%u,%u)B(%u,%u)R(%u,%u)WP(%u,%u)L(%u,%u)",
1440 (unsigned*)&master_display->display_primaries[1][0].num,
1441 (unsigned*)&master_display->display_primaries[1][1].num,
1442 (unsigned*)&master_display->display_primaries[2][0].num,
1443 (unsigned*)&master_display->display_primaries[2][1].num,
1444 (unsigned*)&master_display->display_primaries[0][0].num,
1445 (unsigned*)&master_display->display_primaries[0][1].num,
1446 (unsigned*)&master_display->white_point[0].num,
1447 (unsigned*)&master_display->white_point[1].num,
1448 (unsigned*)&master_display->max_luminance.num,
1449 (unsigned*)&master_display->min_luminance.num);
1450
1451 if (ret != 10 ||
1452 (unsigned)(master_display->display_primaries[1][0].num | master_display->display_primaries[1][1].num |
1453 master_display->display_primaries[2][0].num | master_display->display_primaries[2][1].num |
1454 master_display->display_primaries[0][0].num | master_display->display_primaries[0][1].num |
1455 master_display->white_point[0].num | master_display->white_point[1].num) > UINT16_MAX ||
1456 (unsigned)(master_display->max_luminance.num | master_display->min_luminance.num) > INT_MAX ||
1457 master_display->min_luminance.num > master_display->max_luminance.num) {
1458 av_freep(&master_display);
1459 av_log(ist, AV_LOG_ERROR, "Failed to parse mastering display option\n");
1460 return AVERROR(EINVAL);
1461 }
1462
1463 master_display->display_primaries[1][0].den = chroma_den;
1464 master_display->display_primaries[1][1].den = chroma_den;
1465 master_display->display_primaries[2][0].den = chroma_den;
1466 master_display->display_primaries[2][1].den = chroma_den;
1467 master_display->display_primaries[0][0].den = chroma_den;
1468 master_display->display_primaries[0][1].den = chroma_den;
1469 master_display->white_point[0].den = chroma_den;
1470 master_display->white_point[1].den = chroma_den;
1471 master_display->max_luminance.den = luma_den;
1472 master_display->min_luminance.den = luma_den;
1473
1474 master_display->has_primaries = 1;
1475 master_display->has_luminance = 1;
1476
1480 (uint8_t *)master_display, size, 0);
1481 if (!sd) {
1482 av_freep(&master_display);
1483 return AVERROR(ENOMEM);
1484 }
1485
1487
1488 return 0;
1489}
1490
1493{
1494 AVStream *st = ist->st;
1495 DemuxStream *ds = ds_from_ist(ist);
1497 AVPacketSideData *sd;
1498 const char *p = NULL;
1499 size_t size;
1500 int ret;
1501
1502 opt_match_per_stream_str(ist, &o->content_lights, ctx, st, &p);
1503
1504 if (!p)
1505 return 0;
1506
1508 if (!cll)
1509 return AVERROR(ENOMEM);
1510
1511 ret = sscanf(p, "%u,%u",
1512 (unsigned*)&cll->MaxCLL,
1513 (unsigned*)&cll->MaxFALL);
1514
1515 if (ret != 2 || (unsigned)(cll->MaxCLL | cll->MaxFALL) > UINT16_MAX) {
1516 av_freep(&cll);
1517 av_log(ist, AV_LOG_ERROR, "Failed to parse content light option\n");
1518 return AVERROR(EINVAL);
1519 }
1520
1524 (uint8_t *)cll, size, 0);
1525 if (!sd) {
1526 av_freep(&cll);
1527 return AVERROR(ENOMEM);
1528 }
1529
1530 ds->force_content_light = 1;
1531
1532 return 0;
1533}
1534
1535static const char *input_stream_item_name(void *obj)
1536{
1537 const DemuxStream *ds = obj;
1538
1539 return ds->log_name;
1540}
1541
1543 .class_name = "InputStream",
1544 .version = LIBAVUTIL_VERSION_INT,
1545 .item_name = input_stream_item_name,
1546 .category = AV_CLASS_CATEGORY_DEMUXER,
1547};
1548
1550{
1551 const char *type_str = av_get_media_type_string(st->codecpar->codec_type);
1552 InputFile *f = &d->f;
1553 DemuxStream *ds;
1554
1555 ds = allocate_array_elem(&f->streams, sizeof(*ds), &f->nb_streams);
1556 if (!ds)
1557 return NULL;
1558
1559 ds->sch_idx_stream = -1;
1560 ds->sch_idx_dec = -1;
1561
1562 ds->ist.st = st;
1563 ds->ist.file = f;
1564 ds->ist.index = st->index;
1566
1567 snprintf(ds->log_name, sizeof(ds->log_name), "%cist#%d:%d/%s",
1568 type_str ? *type_str : '?', d->f.index, st->index,
1570
1571 return ds;
1572}
1573
1574static int ist_add(const OptionsContext *o, Demuxer *d, AVStream *st, AVDictionary **opts_used)
1575{
1576 AVFormatContext *ic = d->f.ctx;
1577 AVCodecParameters *par = st->codecpar;
1578 DemuxStream *ds;
1579 InputStream *ist;
1580 const char *framerate = NULL, *hwaccel_device = NULL;
1581 const char *hwaccel = NULL;
1582 const char *apply_cropping = NULL;
1583 const char *hwaccel_output_format = NULL;
1584 const char *codec_tag = NULL;
1585 const char *bsfs = NULL;
1586 char *next;
1587 const char *discard_str = NULL;
1588 AVBPrint bp;
1589 int ret;
1590
1591 ds = demux_stream_alloc(d, st);
1592 if (!ds)
1593 return AVERROR(ENOMEM);
1594
1595 ist = &ds->ist;
1596
1597 ds->discard = 1;
1598 st->discard = AVDISCARD_ALL;
1601
1602 ds->dec_opts.time_base = st->time_base;
1603
1604 ds->ts_scale = 1.0;
1605 opt_match_per_stream_dbl(ist, &o->ts_scale, ic, st, &ds->ts_scale);
1606
1607 ds->autorotate = 1;
1608 opt_match_per_stream_int(ist, &o->autorotate, ic, st, &ds->autorotate);
1609
1612 if (apply_cropping) {
1613 const AVOption opts[] = {
1614 { "apply_cropping", NULL, 0, AV_OPT_TYPE_INT,
1615 { .i64 = CROP_ALL }, CROP_DISABLED, CROP_CONTAINER, AV_OPT_FLAG_DECODING_PARAM, .unit = "apply_cropping" },
1616 { "none", NULL, 0, AV_OPT_TYPE_CONST, { .i64 = CROP_DISABLED }, .unit = "apply_cropping" },
1617 { "all", NULL, 0, AV_OPT_TYPE_CONST, { .i64 = CROP_ALL }, .unit = "apply_cropping" },
1618 { "codec", NULL, 0, AV_OPT_TYPE_CONST, { .i64 = CROP_CODEC }, .unit = "apply_cropping" },
1619 { "container", NULL, 0, AV_OPT_TYPE_CONST, { .i64 = CROP_CONTAINER }, .unit = "apply_cropping" },
1620 { NULL },
1621 };
1622 const AVClass class = {
1623 .class_name = "apply_cropping",
1624 .item_name = av_default_item_name,
1625 .option = opts,
1626 .version = LIBAVUTIL_VERSION_INT,
1627 };
1628 const AVClass *pclass = &class;
1629
1630 ret = av_opt_eval_int(&pclass, opts, apply_cropping, &ds->apply_cropping);
1631 if (ret < 0) {
1632 av_log(ist, AV_LOG_ERROR, "Invalid apply_cropping value '%s'.\n", apply_cropping);
1633 return ret;
1634 }
1635 }
1636
1637 opt_match_per_stream_str(ist, &o->codec_tags, ic, st, &codec_tag);
1638 if (codec_tag) {
1639 uint32_t tag = strtol(codec_tag, &next, 0);
1640 if (*next) {
1641 uint8_t buf[4] = { 0 };
1642 memcpy(buf, codec_tag, FFMIN(sizeof(buf), strlen(codec_tag)));
1643 tag = AV_RL32(buf);
1644 }
1645
1646 st->codecpar->codec_tag = tag;
1647 }
1648
1650 ret = add_display_matrix_to_stream(o, ic, ist);
1651 if (ret < 0)
1652 return ret;
1653
1654 ret = add_mastering_display_to_stream(o, ic, ist);
1655 if (ret < 0)
1656 return ret;
1657
1658 ret = add_content_light_to_stream(o, ic, ist);
1659 if (ret < 0)
1660 return ret;
1661
1662 opt_match_per_stream_str(ist, &o->hwaccels, ic, st, &hwaccel);
1664 &hwaccel_output_format);
1665 if (!hwaccel_output_format && hwaccel && !strcmp(hwaccel, "cuvid")) {
1667 "WARNING: defaulting hwaccel_output_format to cuda for compatibility "
1668 "with old commandlines. This behaviour is DEPRECATED and will be removed "
1669 "in the future. Please explicitly set \"-hwaccel_output_format cuda\".\n");
1671 } else if (!hwaccel_output_format && hwaccel && !strcmp(hwaccel, "qsv")) {
1673 "WARNING: defaulting hwaccel_output_format to qsv for compatibility "
1674 "with old commandlines. This behaviour is DEPRECATED and will be removed "
1675 "in the future. Please explicitly set \"-hwaccel_output_format qsv\".\n");
1677 } else if (!hwaccel_output_format && hwaccel && !strcmp(hwaccel, "mediacodec")) {
1678 // There is no real AVHWFrameContext implementation. Set
1679 // hwaccel_output_format to avoid av_hwframe_transfer_data error.
1681 } else if (hwaccel_output_format) {
1682 ds->dec_opts.hwaccel_output_format = av_get_pix_fmt(hwaccel_output_format);
1684 av_log(ist, AV_LOG_FATAL, "Unrecognised hwaccel output "
1685 "format: %s", hwaccel_output_format);
1686 }
1687 } else {
1689 }
1690
1691 if (hwaccel) {
1692 // The NVDEC hwaccels use a CUDA device, so remap the name here.
1693 if (!strcmp(hwaccel, "nvdec") || !strcmp(hwaccel, "cuvid"))
1694 hwaccel = "cuda";
1695
1696 if (!strcmp(hwaccel, "none"))
1698 else if (!strcmp(hwaccel, "auto"))
1700 else {
1702 if (type != AV_HWDEVICE_TYPE_NONE) {
1705 }
1706
1707 if (!ds->dec_opts.hwaccel_id) {
1708 av_log(ist, AV_LOG_FATAL, "Unrecognized hwaccel: %s.\n",
1709 hwaccel);
1710 av_log(ist, AV_LOG_FATAL, "Supported hwaccels: ");
1712 while ((type = av_hwdevice_iterate_types(type)) !=
1714 av_log(ist, AV_LOG_FATAL, "%s ",
1716 av_log(ist, AV_LOG_FATAL, "\n");
1717 return AVERROR(EINVAL);
1718 }
1719 }
1720 }
1721
1722 opt_match_per_stream_str(ist, &o->hwaccel_devices, ic, st, &hwaccel_device);
1723 if (hwaccel_device) {
1724 ds->dec_opts.hwaccel_device = av_strdup(hwaccel_device);
1725 if (!ds->dec_opts.hwaccel_device)
1726 return AVERROR(ENOMEM);
1727 }
1728 }
1729
1730 ret = choose_decoder(o, ist, ic, st, ds->dec_opts.hwaccel_id,
1731 ds->dec_opts.hwaccel_device_type, &ist->dec);
1732 if (ret < 0)
1733 return ret;
1734
1735 if (ist->dec) {
1737 ic, st, ist->dec, &ds->decoder_opts, opts_used);
1738 if (ret < 0)
1739 return ret;
1740 }
1741
1742 ds->reinit_filters = -1;
1744
1745 ds->drop_changed = 0;
1746 opt_match_per_stream_int(ist, &o->drop_changed, ic, st, &ds->drop_changed);
1747
1748 if (ds->drop_changed && ds->reinit_filters) {
1749 if (ds->reinit_filters > 0) {
1750 av_log(ist, AV_LOG_ERROR, "drop_changed and reinit_filters both enabled. These are mutually exclusive.\n");
1751 return AVERROR(EINVAL);
1752 }
1753 ds->reinit_filters = 0;
1754 }
1755
1757
1758 if ((o->video_disable && ist->st->codecpar->codec_type == AVMEDIA_TYPE_VIDEO) ||
1763
1764 opt_match_per_stream_str(ist, &o->discard, ic, st, &discard_str);
1765 if (discard_str) {
1766 ret = av_opt_set(ist->st, "discard", discard_str, 0);
1767 if (ret < 0) {
1768 av_log(ist, AV_LOG_ERROR, "Error parsing discard %s.\n", discard_str);
1769 return ret;
1770 }
1771 ist->user_set_discard = ist->st->discard;
1772 }
1773
1775
1776 av_dict_set_int(&ds->decoder_opts, "apply_cropping",
1778
1780 if (ds->force_display_matrix) {
1781 if (av_dict_get(ds->decoder_opts, "side_data_prefer_packet", NULL, 0))
1782 av_bprintf(&bp, ",");
1783 av_bprintf(&bp, "displaymatrix");
1784 }
1785 if (ds->force_mastering_display) {
1786 if (bp.len || av_dict_get(ds->decoder_opts, "side_data_prefer_packet", NULL, 0))
1787 av_bprintf(&bp, ",");
1788 av_bprintf(&bp, "mastering_display_metadata");
1789 }
1790 if (ds->force_content_light) {
1791 if (bp.len || av_dict_get(ds->decoder_opts, "side_data_prefer_packet", NULL, 0))
1792 av_bprintf(&bp, ",");
1793 av_bprintf(&bp, "content_light_level");
1794 }
1795 if (bp.len)
1796 av_dict_set(&ds->decoder_opts, "side_data_prefer_packet", bp.str, AV_DICT_APPEND);
1798
1799 /* Attached pics are sparse, therefore we would not want to delay their decoding
1800 * till EOF. */
1802 av_dict_set(&ds->decoder_opts, "thread_type", "-frame", 0);
1803
1804 switch (par->codec_type) {
1805 case AVMEDIA_TYPE_VIDEO:
1807 if (framerate) {
1809 if (ret < 0) {
1810 av_log(ist, AV_LOG_ERROR, "Error parsing framerate %s.\n",
1811 framerate);
1812 return ret;
1813 }
1814 }
1815 break;
1816 case AVMEDIA_TYPE_AUDIO: {
1817 const char *ch_layout_str = NULL;
1818
1819 opt_match_per_stream_str(ist, &o->audio_ch_layouts, ic, st, &ch_layout_str);
1820 if (ch_layout_str) {
1821 AVChannelLayout ch_layout;
1822 ret = av_channel_layout_from_string(&ch_layout, ch_layout_str);
1823 if (ret < 0) {
1824 av_log(ist, AV_LOG_ERROR, "Error parsing channel layout %s.\n", ch_layout_str);
1825 return ret;
1826 }
1827 if (par->ch_layout.nb_channels <= 0 || par->ch_layout.nb_channels == ch_layout.nb_channels) {
1829 par->ch_layout = ch_layout;
1830 } else {
1831 av_log(ist, AV_LOG_ERROR,
1832 "Specified channel layout '%s' has %d channels, but input has %d channels.\n",
1833 ch_layout_str, ch_layout.nb_channels, par->ch_layout.nb_channels);
1834 av_channel_layout_uninit(&ch_layout);
1835 return AVERROR(EINVAL);
1836 }
1837 } else {
1838 int guess_layout_max = INT_MAX;
1839 opt_match_per_stream_int(ist, &o->guess_layout_max, ic, st, &guess_layout_max);
1840 guess_input_channel_layout(ist, par, guess_layout_max);
1841 }
1842 break;
1843 }
1844 case AVMEDIA_TYPE_DATA:
1845 case AVMEDIA_TYPE_SUBTITLE: {
1846 const char *canvas_size = NULL;
1847
1849 opt_match_per_stream_str(ist, &o->canvas_sizes, ic, st, &canvas_size);
1850 if (canvas_size) {
1851 ret = av_parse_video_size(&par->width, &par->height,
1852 canvas_size);
1853 if (ret < 0) {
1854 av_log(ist, AV_LOG_FATAL, "Invalid canvas size: %s.\n", canvas_size);
1855 return ret;
1856 }
1857 }
1858 break;
1859 }
1862 break;
1863 default: av_assert0(0);
1864 }
1865
1867 if (!ist->par)
1868 return AVERROR(ENOMEM);
1869
1870 ret = avcodec_parameters_copy(ist->par, par);
1871 if (ret < 0) {
1872 av_log(ist, AV_LOG_ERROR, "Error exporting stream parameters.\n");
1873 return ret;
1874 }
1875
1876 if (ist->st->sample_aspect_ratio.num)
1878
1879 opt_match_per_stream_str(ist, &o->bitstream_filters, ic, st, &bsfs);
1880 if (bsfs) {
1881 ret = av_bsf_list_parse_str(bsfs, &ds->bsf);
1882 if (ret < 0) {
1883 av_log(ist, AV_LOG_ERROR,
1884 "Error parsing bitstream filter sequence '%s': %s\n",
1885 bsfs, av_err2str(ret));
1886 return ret;
1887 }
1888
1889 ret = avcodec_parameters_copy(ds->bsf->par_in, ist->par);
1890 if (ret < 0)
1891 return ret;
1892 ds->bsf->time_base_in = ist->st->time_base;
1893
1894 ret = av_bsf_init(ds->bsf);
1895 if (ret < 0) {
1896 av_log(ist, AV_LOG_ERROR, "Error initializing bitstream filters: %s\n",
1897 av_err2str(ret));
1898 return ret;
1899 }
1900
1901 ret = avcodec_parameters_copy(ist->par, ds->bsf->par_out);
1902 if (ret < 0)
1903 return ret;
1904 }
1905
1907
1908 return 0;
1909}
1910
1911static const char *input_stream_group_item_name(void *obj)
1912{
1913 const DemuxStreamGroup *dsg = obj;
1914
1915 return dsg->log_name;
1916}
1917
1919 .class_name = "InputStreamGroup",
1920 .version = LIBAVUTIL_VERSION_INT,
1921 .item_name = input_stream_group_item_name,
1922 .category = AV_CLASS_CATEGORY_DEMUXER,
1923};
1924
1926{
1927 InputFile *f = &d->f;
1928 DemuxStreamGroup *dsg;
1929
1930 dsg = allocate_array_elem(&f->stream_groups, sizeof(*dsg), &f->nb_stream_groups);
1931 if (!dsg)
1932 return NULL;
1933
1934 dsg->istg.stg = stg;
1935 dsg->istg.file = f;
1936 dsg->istg.index = stg->index;
1938
1939 snprintf(dsg->log_name, sizeof(dsg->log_name), "istg#%d:%d/%s",
1940 d->f.index, stg->index, avformat_stream_group_name(stg->type));
1941
1942 return dsg;
1943}
1944
1946{
1947 InputFile *f = &d->f;
1948 AVFormatContext *ic = d->f.ctx;
1949 AVStreamGroup *stg = istg->stg;
1950 const AVStreamGroupTileGrid *tg = stg->params.tile_grid;
1952 AVBPrint bp;
1953 char *graph_str;
1954 int autorotate = 1;
1955 const char *apply_cropping = NULL;
1956 int ret;
1957
1958 if (tg->nb_tiles == 1)
1959 return 0;
1960 if (!tg->nb_tiles) {
1961 av_log(istg, AV_LOG_FATAL, "A demuxer exported an invalid tile group stream group. "
1962 "This is a bug, please report it.\n");
1963 return AVERROR_BUG;
1964 }
1965
1966 memset(&opts, 0, sizeof(opts));
1967
1969 if (autorotate)
1971
1972 opts.flags |= OFILTER_FLAG_CROP;
1974 if (apply_cropping) {
1975 char *p;
1976 int crop = strtol(apply_cropping, &p, 0);
1977 if (*p)
1978 return AVERROR(EINVAL);
1979 if (!crop)
1980 opts.flags &= ~OFILTER_FLAG_CROP;
1981 }
1982
1984 for (int i = 0; i < tg->nb_tiles; i++)
1985 av_bprintf(&bp, "[%d:g:%d:%d]", f->index, stg->index, tg->offsets[i].idx);
1986 av_bprintf(&bp, "xstack=inputs=%d:layout=", tg->nb_tiles);
1987 for (int i = 0; i < tg->nb_tiles - 1; i++)
1988 av_bprintf(&bp, "%d_%d|", tg->offsets[i].horizontal,
1989 tg->offsets[i].vertical);
1990 av_bprintf(&bp, "%d_%d:fill=0x%02X%02X%02X@0x%02X", tg->offsets[tg->nb_tiles - 1].horizontal,
1991 tg->offsets[tg->nb_tiles - 1].vertical,
1992 tg->background[0], tg->background[1],
1993 tg->background[2], tg->background[3]);
1994 av_bprintf(&bp, "[%d:g:%d]", f->index, stg->index);
1995 ret = av_bprint_finalize(&bp, &graph_str);
1996 if (ret < 0)
1997 return ret;
1998
1999 if (tg->coded_width != tg->width || tg->coded_height != tg->height) {
2000 opts.crop_top = tg->vertical_offset;
2001 opts.crop_bottom = tg->coded_height - tg->height - tg->vertical_offset;
2002 opts.crop_left = tg->horizontal_offset;
2003 opts.crop_right = tg->coded_width - tg->width - tg->horizontal_offset;
2004 }
2005
2006 for (int i = 0; i < tg->nb_coded_side_data; i++) {
2007 const AVPacketSideData *sd = &tg->coded_side_data[i];
2008
2009 ret = av_packet_side_data_to_frame(&opts.side_data, &opts.nb_side_data, sd, 0);
2010 if (ret < 0 && ret != AVERROR(EINVAL))
2011 goto fail;
2012 }
2013
2014 ret = fg_create(NULL, &graph_str, d->sch, &opts);
2015 if (ret < 0)
2016 goto fail;
2017
2018 istg->fg = filtergraphs[nb_filtergraphs-1];
2019 istg->fg->is_internal = 1;
2020
2021 ret = 0;
2022fail:
2023 if (ret < 0)
2024 av_freep(&graph_str);
2025
2026 return ret;
2027}
2028
2030{
2031 InputFile *f = &d->f;
2032 const AVStreamGroup *stg = dsg->istg.stg;
2034 const AVBitStreamFilter *filter, *lcevc_filter = av_bsf_get_by_name("lcevc_merge");
2035 const InputStream *lcevc_ist = f->streams[stg->streams[lcevc->el_index]->index];
2036 const InputStream *base_ist = f->streams[stg->streams[!lcevc->el_index]->index];
2037 int ret;
2038
2039 if (!lcevc_filter || stg->nb_streams != 2)
2040 return 0;
2041
2042 dsg->graph = av_bsf_graph_alloc();
2043 if(!dsg->graph)
2044 return AVERROR(ENOMEM);
2045
2046 filter = av_bsf_get_by_name("source");
2047 if (!filter)
2048 return AVERROR_BUG;
2049
2050 ret = av_bsf_graph_alloc_filter(&dsg->lcevc[0], filter, "lcevc_merge_base", dsg->graph);
2051 if (ret < 0)
2052 return ret;
2053 av_opt_set_q(dsg->lcevc[0]->priv_data, "time_base", base_ist->st->time_base, 0);
2054 ret = av_bsf_source_parameters_set(dsg->lcevc[0], base_ist->par);
2055 if (ret < 0)
2056 return ret;
2057
2058 ret = av_bsf_graph_alloc_filter(&dsg->lcevc[1], filter, "lcevc_merge_enhancement", dsg->graph);
2059 if (ret < 0)
2060 return ret;
2061 av_opt_set_q(dsg->lcevc[1]->priv_data, "time_base", lcevc_ist->st->time_base, 0);
2062 ret = av_bsf_source_parameters_set(dsg->lcevc[1], lcevc_ist->par);
2063 if (ret < 0)
2064 return ret;
2065
2066 ret = av_bsf_graph_alloc_filter(NULL, lcevc_filter, "lcevc_merge", dsg->graph);
2067 if (ret < 0)
2068 return ret;
2069
2070 filter = av_bsf_get_by_name("sink");
2071 if (!filter)
2072 return AVERROR_BUG;
2073 ret = av_bsf_graph_alloc_filter(&dsg->sink, filter, "lcevc_merge_sink", dsg->graph);
2074 if (ret < 0)
2075 return ret;
2076
2077 return 0;
2078}
2079
2080static int istg_add(const OptionsContext *o, Demuxer *d, AVStreamGroup *stg)
2081{
2082 InputFile *f = &d->f;
2083 DemuxStreamGroup *dsg;
2084 InputStreamGroup *istg;
2085 int ret;
2086
2087 dsg = demux_stream_group_alloc(d, stg);
2088 if (!dsg)
2089 return AVERROR(ENOMEM);
2090
2091 istg = &dsg->istg;
2092
2093 switch (stg->type) {
2095 for (int i = 0; i < istg->stg->nb_streams; i++) {
2096 DemuxStream *ds = ds_from_ist(f->streams[istg->stg->streams[i]->index]);
2097 ret = av_dynarray_add_nofree(&ds->dsg, &ds->nb_dsg, dsg);
2098 if (ret < 0)
2099 return ret;
2100 }
2101 break;
2102 default:
2103 break;
2104 }
2105
2106 switch (stg->type) {
2108 ret = istg_parse_tile_grid(o, d, istg);
2109 if (ret < 0)
2110 return ret;
2111 break;
2113 ret = istg_parse_lcevc(o, d, dsg);
2114 if (ret < 0)
2115 return ret;
2116 break;
2117 default:
2118 break;
2119 }
2120
2121 return 0;
2122}
2123
2124static int is_windows_reserved_device_name(const char *f)
2125{
2126#if HAVE_DOS_PATHS
2127 for (const char *p = f; p && *p; ) {
2128 char stem[6], *s;
2129 av_strlcpy(stem, p, sizeof(stem));
2130 if ((s = strchr(stem, '.')))
2131 *s = 0;
2132 if ((s = strpbrk(stem, "123456789")))
2133 *s = '1';
2134
2135 if( !av_strcasecmp(stem, "AUX") ||
2136 !av_strcasecmp(stem, "CON") ||
2137 !av_strcasecmp(stem, "NUL") ||
2138 !av_strcasecmp(stem, "PRN") ||
2139 !av_strcasecmp(stem, "COM1") ||
2140 !av_strcasecmp(stem, "LPT1")
2141 )
2142 return 1;
2143
2144 p = strchr(p, '/');
2145 if (p)
2146 p++;
2147 }
2148#endif
2149 return 0;
2150}
2151
2152static int safe_filename(const char *f, int allow_subdir)
2153{
2154 const char *start = f;
2155
2157 return 0;
2158
2159 for (; *f; f++) {
2160 /* A-Za-z0-9_- */
2161 if (!((unsigned)((*f | 32) - 'a') < 26 ||
2162 (unsigned)(*f - '0') < 10 || *f == '_' || *f == '-')) {
2163 if (f == start)
2164 return 0;
2165 else if (allow_subdir && *f == '/')
2166 start = f + 1;
2167 else if (*f != '.')
2168 return 0;
2169 }
2170 }
2171 return 1;
2172}
2173
2174static int dump_attachment(InputStream *ist, const char *filename)
2175{
2176 AVStream *st = ist->st;
2177 int ret;
2178 AVIOContext *out = NULL;
2179 const AVDictionaryEntry *e;
2180
2181 if (!st->codecpar->extradata_size) {
2182 av_log(ist, AV_LOG_WARNING, "No extradata to dump.\n");
2183 return 0;
2184 }
2185 if (!*filename && (e = av_dict_get(st->metadata, "filename", NULL, 0))) {
2186 filename = e->value;
2187 if (!safe_filename(filename, 0)) {
2188 av_log(ist, AV_LOG_ERROR, "Filename %s is unsafe\n", filename);
2189 return AVERROR(EINVAL);
2190 }
2191 }
2192 if (!*filename) {
2193 av_log(ist, AV_LOG_FATAL, "No filename specified and no 'filename' tag");
2194 return AVERROR(EINVAL);
2195 }
2196
2197 ret = assert_file_overwrite(filename);
2198 if (ret < 0)
2199 return ret;
2200
2201 if ((ret = avio_open2(&out, filename, AVIO_FLAG_WRITE, &int_cb, NULL)) < 0) {
2202 av_log(ist, AV_LOG_FATAL, "Could not open file %s for writing.\n",
2203 filename);
2204 return ret;
2205 }
2206
2208 ret = avio_close(out);
2209
2210 if (ret >= 0)
2211 av_log(ist, AV_LOG_INFO, "Wrote attachment (%d bytes) to '%s'\n",
2212 st->codecpar->extradata_size, filename);
2213
2214 return ret;
2215}
2216
2217static const char *input_file_item_name(void *obj)
2218{
2219 const Demuxer *d = obj;
2220
2221 return d->log_name;
2222}
2223
2225 .class_name = "InputFile",
2226 .version = LIBAVUTIL_VERSION_INT,
2227 .item_name = input_file_item_name,
2228 .category = AV_CLASS_CATEGORY_DEMUXER,
2229};
2230
2232{
2234
2235 if (!d)
2236 return NULL;
2237
2238 d->f.class = &input_file_class;
2239 d->f.index = nb_input_files - 1;
2240
2241 snprintf(d->log_name, sizeof(d->log_name), "in#%d", d->f.index);
2242
2243 return d;
2244}
2245
2246int ifile_open(const OptionsContext *o, const char *filename, Scheduler *sch)
2247{
2248 Demuxer *d;
2249 InputFile *f;
2250 AVFormatContext *ic;
2252 int err, ret = 0;
2253 int64_t timestamp;
2254 AVDictionary *opts_used = NULL;
2255 const char* video_codec_name = NULL;
2256 const char* audio_codec_name = NULL;
2257 const char* subtitle_codec_name = NULL;
2258 const char* data_codec_name = NULL;
2259 int scan_all_pmts_set = 0;
2260
2262 int64_t start_time_eof = o->start_time_eof;
2263 int64_t stop_time = o->stop_time;
2264 int64_t recording_time = o->recording_time;
2265
2266 d = demux_alloc();
2267 if (!d)
2268 return AVERROR(ENOMEM);
2269
2270 f = &d->f;
2271
2272 ret = sch_add_demux(sch, input_thread, d);
2273 if (ret < 0)
2274 return ret;
2275 d->sch = sch;
2276
2277 if (stop_time != INT64_MAX && recording_time != INT64_MAX) {
2278 stop_time = INT64_MAX;
2279 av_log(d, AV_LOG_WARNING, "-t and -to cannot be used together; using -t.\n");
2280 }
2281
2282 if (stop_time != INT64_MAX && recording_time == INT64_MAX) {
2284 if (stop_time <= start) {
2285 av_log(d, AV_LOG_ERROR, "-to value smaller than -ss; aborting.\n");
2286 return AVERROR(EINVAL);
2287 } else {
2288 recording_time = stop_time - start;
2289 }
2290 }
2291
2292 if (recording_time < 0) {
2293 av_log(d, AV_LOG_ERROR, "-t value must be non-negative; aborting.\n");
2294 return AVERROR(EINVAL);
2295 }
2296
2297 if (o->format) {
2299 av_log(d, AV_LOG_FATAL, "Unknown input format: '%s'\n", o->format);
2300 return AVERROR(EINVAL);
2301 }
2302 }
2303
2304 if (!strcmp(filename, "-"))
2305 filename = "fd:";
2306
2307 stdin_interaction &= strncmp(filename, "pipe:", 5) &&
2308 strcmp(filename, "fd:") &&
2309 strcmp(filename, "/dev/stdin");
2310
2311 /* get default parameters from command line */
2313 if (!ic)
2314 return AVERROR(ENOMEM);
2315 ic->name = av_strdup(d->log_name);
2316 if (o->audio_sample_rate.nb_opt) {
2317 av_dict_set_int(&o->g->format_opts, "sample_rate", o->audio_sample_rate.opt[o->audio_sample_rate.nb_opt - 1].u.i, 0);
2318 }
2319 if (o->audio_channels.nb_opt) {
2320 const AVClass *priv_class;
2321 if (file_iformat && (priv_class = file_iformat->priv_class) &&
2322 av_opt_find(&priv_class, "ch_layout", NULL, 0,
2324 char buf[32];
2325 snprintf(buf, sizeof(buf), "%dC", o->audio_channels.opt[o->audio_channels.nb_opt - 1].u.i);
2326 av_dict_set(&o->g->format_opts, "ch_layout", buf, 0);
2327 }
2328 }
2329 if (o->audio_ch_layouts.nb_opt) {
2330 const AVClass *priv_class;
2331 if (file_iformat && (priv_class = file_iformat->priv_class) &&
2332 av_opt_find(&priv_class, "ch_layout", NULL, 0,
2334 av_dict_set(&o->g->format_opts, "ch_layout", o->audio_ch_layouts.opt[o->audio_ch_layouts.nb_opt - 1].u.str, 0);
2335 }
2336 }
2337 if (o->frame_rates.nb_opt) {
2338 const AVClass *priv_class;
2339 /* set the format-level framerate option;
2340 * this is important for video grabbers, e.g. x11 */
2341 if (file_iformat && (priv_class = file_iformat->priv_class) &&
2342 av_opt_find(&priv_class, "framerate", NULL, 0,
2344 av_dict_set(&o->g->format_opts, "framerate",
2345 o->frame_rates.opt[o->frame_rates.nb_opt - 1].u.str, 0);
2346 }
2347 }
2348 if (o->frame_sizes.nb_opt) {
2349 av_dict_set(&o->g->format_opts, "video_size", o->frame_sizes.opt[o->frame_sizes.nb_opt - 1].u.str, 0);
2350 }
2351 if (o->frame_pix_fmts.nb_opt)
2352 av_dict_set(&o->g->format_opts, "pixel_format", o->frame_pix_fmts.opt[o->frame_pix_fmts.nb_opt - 1].u.str, 0);
2353
2358
2359 if (video_codec_name)
2361 &ic->video_codec));
2362 if (audio_codec_name)
2364 &ic->audio_codec));
2367 &ic->subtitle_codec));
2368 if (data_codec_name)
2370 &ic->data_codec));
2371 if (ret < 0) {
2373 return ret;
2374 }
2375
2380
2382 if (o->bitexact)
2385
2386 if (!av_dict_get(o->g->format_opts, "scan_all_pmts", NULL, AV_DICT_MATCH_CASE)) {
2387 av_dict_set(&o->g->format_opts, "scan_all_pmts", "1", AV_DICT_DONT_OVERWRITE);
2388 scan_all_pmts_set = 1;
2389 }
2390 /* open the input file with generic avformat function */
2391 err = avformat_open_input(&ic, filename, file_iformat, &o->g->format_opts);
2392 if (err < 0) {
2393 if (err != AVERROR_EXIT)
2395 "Error opening input: %s\n", av_err2str(err));
2396 if (err == AVERROR_PROTOCOL_NOT_FOUND)
2397 av_log(d, AV_LOG_ERROR, "Did you mean file:%s?\n", filename);
2398 return err;
2399 }
2400 f->ctx = ic;
2401
2402 av_strlcat(d->log_name, "/", sizeof(d->log_name));
2403 av_strlcat(d->log_name, ic->iformat->name, sizeof(d->log_name));
2404 av_freep(&ic->name);
2405 ic->name = av_strdup(d->log_name);
2406
2407 if (scan_all_pmts_set)
2408 av_dict_set(&o->g->format_opts, "scan_all_pmts", NULL, AV_DICT_MATCH_CASE);
2410
2411 ret = check_avoptions(o->g->format_opts);
2412 if (ret < 0)
2413 return ret;
2414
2415 /* apply forced codec ids */
2416 for (int i = 0; i < ic->nb_streams; i++) {
2417 const AVCodec *dummy;
2419 &dummy);
2420 if (ret < 0)
2421 return ret;
2422 }
2423
2424 if (o->find_stream_info) {
2426 int orig_nb_streams = ic->nb_streams;
2427
2429 if (ret < 0)
2430 return ret;
2431
2432 /* If not enough info to get the stream parameters, we decode the
2433 first frames to get it. (used in mpeg case for example) */
2435
2436 for (int i = 0; i < orig_nb_streams; i++)
2437 av_dict_free(&opts[i]);
2438 av_freep(&opts);
2439
2440 if (ret < 0) {
2441 av_log(d, AV_LOG_FATAL, "could not find codec parameters\n");
2442 if (ic->nb_streams == 0)
2443 return ret;
2444 }
2445 }
2446
2447 if (start_time != AV_NOPTS_VALUE && start_time_eof != AV_NOPTS_VALUE) {
2448 av_log(d, AV_LOG_WARNING, "Cannot use -ss and -sseof both, using -ss\n");
2449 start_time_eof = AV_NOPTS_VALUE;
2450 }
2451
2452 if (start_time_eof != AV_NOPTS_VALUE) {
2453 if (start_time_eof >= 0) {
2454 av_log(d, AV_LOG_ERROR, "-sseof value must be negative; aborting\n");
2455 return AVERROR(EINVAL);
2456 }
2457 if (ic->duration > 0) {
2458 start_time = start_time_eof + ic->duration;
2459 if (start_time < 0) {
2460 av_log(d, AV_LOG_WARNING, "-sseof value seeks to before start of file; ignored\n");
2462 }
2463 } else
2464 av_log(d, AV_LOG_WARNING, "Cannot use -sseof, file duration not known\n");
2465 }
2466 timestamp = (start_time == AV_NOPTS_VALUE) ? 0 : start_time;
2467 /* add the stream start time */
2468 if (!o->seek_timestamp && ic->start_time != AV_NOPTS_VALUE)
2469 timestamp += ic->start_time;
2470
2471 /* if seeking requested, we execute it */
2472 if (start_time != AV_NOPTS_VALUE) {
2473 int64_t seek_timestamp = timestamp;
2474
2475 if (!(ic->iformat->flags & AVFMT_SEEK_TO_PTS)) {
2476 int dts_heuristic = 0;
2477 for (int i = 0; i < ic->nb_streams; i++) {
2478 const AVCodecParameters *par = ic->streams[i]->codecpar;
2479 if (par->video_delay) {
2480 dts_heuristic = 1;
2481 break;
2482 }
2483 }
2484 if (dts_heuristic) {
2485 seek_timestamp -= 3*AV_TIME_BASE / 23;
2486 }
2487 }
2488 ret = avformat_seek_file(ic, -1, INT64_MIN, seek_timestamp, seek_timestamp, 0);
2489 if (ret < 0) {
2490 av_log(d, AV_LOG_WARNING, "could not seek to position %0.3f\n",
2491 (double)timestamp / AV_TIME_BASE);
2492 }
2493 }
2494
2495 f->start_time = start_time;
2496 d->recording_time = recording_time;
2497 f->input_sync_ref = o->input_sync_ref;
2498 f->input_ts_offset = o->input_ts_offset;
2499 f->ts_offset = o->input_ts_offset - (copy_ts ? (start_at_zero && ic->start_time != AV_NOPTS_VALUE ? ic->start_time : 0) : timestamp);
2501 d->loop = o->loop;
2502 d->nb_streams_warn = ic->nb_streams;
2503
2504 d->duration = (Timestamp){ .ts = 0, .tb = (AVRational){ 1, 1 } };
2505 d->min_pts = (Timestamp){ .ts = AV_NOPTS_VALUE, .tb = (AVRational){ 1, 1 } };
2506 d->max_pts = (Timestamp){ .ts = AV_NOPTS_VALUE, .tb = (AVRational){ 1, 1 } };
2507
2508 d->readrate = o->readrate ? o->readrate : 0.0;
2509 if (d->readrate < 0.0f) {
2510 av_log(d, AV_LOG_ERROR, "Option -readrate is %0.3f; it must be non-negative.\n", d->readrate);
2511 return AVERROR(EINVAL);
2512 }
2513 if (o->rate_emu) {
2514 if (d->readrate) {
2515 av_log(d, AV_LOG_WARNING, "Both -readrate and -re set. Using -readrate %0.3f.\n", d->readrate);
2516 } else
2517 d->readrate = 1.0f;
2518 }
2519
2520 if (d->readrate) {
2522 if (d->readrate_initial_burst < 0.0) {
2524 "Option -readrate_initial_burst is %0.3f; it must be non-negative.\n",
2526 return AVERROR(EINVAL);
2527 }
2529 if (d->readrate_catchup < d->readrate) {
2531 "Option -readrate_catchup is %0.3f; it must be at least equal to %0.3f.\n",
2532 d->readrate_catchup, d->readrate);
2533 return AVERROR(EINVAL);
2534 }
2535 } else {
2536 if (o->readrate_initial_burst) {
2537 av_log(d, AV_LOG_WARNING, "Option -readrate_initial_burst ignored "
2538 "since neither -readrate nor -re were given\n");
2539 }
2540 if (o->readrate_catchup) {
2541 av_log(d, AV_LOG_WARNING, "Option -readrate_catchup ignored "
2542 "since neither -readrate nor -re were given\n");
2543 }
2544 }
2545
2546 /* Add all the streams from the given input file to the demuxer */
2547 for (int i = 0; i < ic->nb_streams; i++) {
2548 ret = ist_add(o, d, ic->streams[i], &opts_used);
2549 if (ret < 0) {
2550 av_dict_free(&opts_used);
2551 return ret;
2552 }
2553 }
2554
2555 /* Add all the stream groups from the given input file to the demuxer */
2556 for (int i = 0; i < ic->nb_stream_groups; i++) {
2557 ret = istg_add(o, d, ic->stream_groups[i]);
2558 if (ret < 0)
2559 return ret;
2560 }
2561
2562 /* dump the file content */
2563 av_dump_format(ic, f->index, filename, 0);
2564
2565 /* check if all codec options have been used */
2566 ret = check_avoptions_used(o->g->codec_opts, opts_used, d, 1);
2567 av_dict_free(&opts_used);
2568 if (ret < 0)
2569 return ret;
2570
2571 for (int i = 0; i < o->dump_attachment.nb_opt; i++) {
2572 for (int j = 0; j < f->nb_streams; j++) {
2573 InputStream *ist = f->streams[j];
2574
2575 if (check_stream_specifier(ic, ist->st, o->dump_attachment.opt[i].specifier) == 1) {
2576 ret = dump_attachment(ist, o->dump_attachment.opt[i].u.str);
2577 if (ret < 0)
2578 return ret;
2579 }
2580 }
2581 }
2582
2583 return 0;
2584}
int32_t
simple assert() macros that are a bit more flexible than ISO C assert().
#define av_assert1(cond)
assert() equivalent, that does not lie in speed critical code.
Definition avassert.h:58
#define av_assert0(cond)
assert() equivalent, that is always enabled.
Definition avassert.h:42
Main libavformat public API header.
#define AVFMT_FLAG_BITEXACT
When muxing, try to avoid writing any random/volatile data to the output.
Definition avformat.h:1501
@ AV_STREAM_GROUP_PARAMS_TILE_GRID
Definition avformat.h:1150
@ AV_STREAM_GROUP_PARAMS_LCEVC
Definition avformat.h:1151
#define AVFMT_TS_DISCONT
Format allows timestamp discontinuities.
Definition avformat.h:500
#define AVFMT_FLAG_NONBLOCK
Do not block when reading packets from input.
Definition avformat.h:1487
#define AV_DISPOSITION_ATTACHED_PIC
The stream is stored in the file as an attached picture/"cover art" (e.g.
Definition avformat.h:692
#define AVFMT_SEEK_TO_PTS
Seeking is based on PTS.
Definition avformat.h:520
struct AVCodecParserContext * av_stream_get_parser(const AVStream *s)
Definition demux_utils.c:33
#define AVFMT_NOTIMESTAMPS
Format does not need / have any timestamps.
Definition avformat.h:498
int avio_close(AVIOContext *s)
Close the resource accessed by the AVIOContext s and free it.
Definition avio.c:684
int avio_open2(AVIOContext **s, const char *filename, int flags, const AVIOInterruptCB *int_cb, AVDictionary **options)
Create and initialize a AVIOContext for accessing the resource indicated by url.
Definition avio.c:559
#define AVIO_FLAG_WRITE
write-only
Definition avio.h:618
void avio_write(AVIOContext *s, const unsigned char *buf, int size)
Definition aviobuf.c:206
void av_bprintf(AVBPrint *buf, const char *fmt,...)
Definition bprint.c:122
void av_bprint_init(AVBPrint *buf, unsigned size_init, unsigned size_max)
Definition bprint.c:69
#define AV_BPRINT_SIZE_UNLIMITED
#define AV_BPRINT_SIZE_AUTOMATIC
#define is(width, name, range_min, range_max, subs,...)
Definition cbs_h264.c:78
#define flags(name, subs,...)
Definition cbs_h264.c:74
#define i(width, name, range_min, range_max)
Definition cbs_h264.c:63
#define f(width, name)
Definition cbs_vp8.c:236
#define s(width, name)
Definition cbs_vp9.c:198
int check_avoptions(AVDictionary *m)
Definition cmdutils.c:1605
int check_stream_specifier(AVFormatContext *s, AVStream *st, const char *spec)
Check if the given stream matches a stream specifier.
Definition cmdutils.c:1338
void * allocate_array_elem(void *ptr, size_t elem_size, int *nb_elems)
Atomically add a new element to an array of pointers, i.e.
Definition cmdutils.c:1540
int filter_codec_opts(const AVDictionary *opts, enum AVCodecID codec_id, AVFormatContext *s, AVStream *st, const AVCodec *codec, AVDictionary **dst, AVDictionary **opts_used)
Filter out options for given codec.
Definition cmdutils.c:1423
void remove_avoptions(AVDictionary **a, AVDictionary *b)
Definition cmdutils.c:1596
int setup_find_stream_info_opts(AVFormatContext *s, AVDictionary *local_codec_opts, AVDictionary ***dst)
Setup AVCodecContext options for avformat_find_stream_info().
Definition cmdutils.c:1491
#define GROW_ARRAY(array, nb_elems)
Definition cmdutils.h:536
AVCodecParameters * avcodec_parameters_alloc(void)
Definition codec_par.c:57
int avcodec_parameters_copy(AVCodecParameters *dst, const AVCodecParameters *src)
Definition codec_par.c:107
void avcodec_parameters_free(AVCodecParameters **ppar)
Definition codec_par.c:67
#define FFABS(a)
Absolute value, Note, INT_MIN / INT64_MIN result in undefined behavior as they are not representable ...
Definition common.h:74
#define NULL
Definition coverity.c:32
long long int64_t
Definition coverity.c:34
static int apply_cropping(AVCodecContext *avctx, AVFrame *frame)
Definition decode.c:763
static AVPacket * pkt
Display matrix.
error code definitions
FrameData * packet_data(AVPacket *pkt)
Definition ffmpeg.c:503
int nb_filtergraphs
Definition ffmpeg.c:115
InputFile ** input_files
Definition ffmpeg.c:108
const AVIOInterruptCB int_cb
Definition ffmpeg.c:322
int nb_input_files
Definition ffmpeg.c:109
FilterGraph ** filtergraphs
Definition ffmpeg.c:114
int check_avoptions_used(const AVDictionary *opts, const AVDictionary *opts_used, void *logctx, int decode)
Definition ffmpeg.c:515
InputStream * ist_iter(InputStream *prev)
Definition ffmpeg.c:397
int debug_ts
Definition ffmpeg_opt.c:67
void dec_free(Decoder **pdec)
Definition ffmpeg_dec.c:118
HWAccelID
Definition ffmpeg.h:69
@ HWACCEL_NONE
Definition ffmpeg.h:70
@ HWACCEL_GENERIC
Definition ffmpeg.h:72
@ HWACCEL_AUTO
Definition ffmpeg.h:71
int start_at_zero
Definition ffmpeg_opt.c:65
int dec_request_view(Decoder *dec, const ViewSpecifier *vs, SchedulerNode *src)
@ IFILTER_FLAG_CFR
Definition ffmpeg.h:253
@ IFILTER_FLAG_DROPCHANGED
Definition ffmpeg.h:255
@ IFILTER_FLAG_REINIT
Definition ffmpeg.h:252
@ IFILTER_FLAG_CROP
Definition ffmpeg.h:254
@ IFILTER_FLAG_AUTOROTATE
Definition ffmpeg.h:251
@ PKT_OPAQUE_SUB_HEARTBEAT
Definition ffmpeg.h:82
void opt_match_per_stream_group_int(void *logctx, const SpecifierOptList *sol, AVFormatContext *fc, AVStreamGroup *stg, int *out)
int stdin_interaction
Definition ffmpeg_opt.c:71
int do_hex_dump
Definition ffmpeg_opt.c:62
@ LATENCY_PROBE_DEMUX
Definition ffmpeg.h:87
float dts_error_threshold
Definition ffmpeg_opt.c:57
int find_codec(void *logctx, const char *name, enum AVMediaType type, int encoder, const AVCodec **codec)
Definition ffmpeg_opt.c:783
@ CROP_CODEC
Definition ffmpeg.h:631
@ CROP_DISABLED
Definition ffmpeg.h:629
@ CROP_CONTAINER
Definition ffmpeg.h:632
@ CROP_ALL
Definition ffmpeg.h:630
int recast_media
Definition ffmpeg_opt.c:88
void opt_match_per_stream_int(void *logctx, const SpecifierOptList *sol, AVFormatContext *fc, AVStream *st, int *out)
int assert_file_overwrite(const char *filename)
Definition ffmpeg_opt.c:816
void opt_match_per_stream_dbl(void *logctx, const SpecifierOptList *sol, AVFormatContext *fc, AVStream *st, double *out)
void opt_match_per_stream_group_str(void *logctx, const SpecifierOptList *sol, AVFormatContext *fc, AVStreamGroup *stg, const char **out)
const char * opt_match_per_type_str(const SpecifierOptList *sol, char mediatype)
Definition ffmpeg_opt.c:165
@ OFILTER_FLAG_AUTOROTATE
Definition ffmpeg.h:290
@ OFILTER_FLAG_CROP
Definition ffmpeg.h:291
int dec_init(Decoder **pdec, Scheduler *sch, AVDictionary **dec_opts, const DecoderOpts *o, AVFrame *param_out)
int fg_create(FilterGraph **pfg, char **graph_desc, Scheduler *sch, const OutputFilterOptions *opts)
Create a new filtergraph in the global filtergraph list.
float dts_delta_threshold
Definition ffmpeg_opt.c:56
int copy_ts
Definition ffmpeg_opt.c:64
int exit_on_error
Definition ffmpeg_opt.c:68
int do_pkt_dump
Definition ffmpeg_opt.c:63
@ DECODER_FLAG_SEND_END_TS
Definition ffmpeg.h:424
@ DECODER_FLAG_BITEXACT
Definition ffmpeg.h:426
@ DECODER_FLAG_FIX_SUB_DURATION
Definition ffmpeg.h:418
@ DECODER_FLAG_FRAMERATE_FORCED
Definition ffmpeg.h:423
@ DECODER_FLAG_TS_UNRELIABLE
Definition ffmpeg.h:420
void opt_match_per_stream_str(void *logctx, const SpecifierOptList *sol, AVFormatContext *fc, AVStream *st, const char **out)
static DemuxStream * demux_stream_alloc(Demuxer *d, AVStream *st)
static int input_packet_process(Demuxer *d, AVPacket *pkt, unsigned *send_flags)
static void thread_set_name(InputFile *f)
static DemuxStream * ds_from_ist(InputStream *ist)
static int choose_decoder(const OptionsContext *o, void *logctx, AVFormatContext *s, AVStream *st, enum HWAccelID hwaccel_id, enum AVHWDeviceType hwaccel_device_type, const AVCodec **pcodec)
static void demux_final_stats(Demuxer *d)
static const AVClass input_file_class
static int add_display_matrix_to_stream(const OptionsContext *o, AVFormatContext *ctx, InputStream *ist)
static const char * input_file_item_name(void *obj)
static int seek_to_start(Demuxer *d, Timestamp end_pts)
int ist_filter_add(InputStream *ist, InputFilter *ifilter, int is_simple, const ViewSpecifier *vs, InputFilterOptions *opts, SchedulerNode *src)
static const char * input_stream_group_item_name(void *obj)
static int ist_dts_update(DemuxStream *ds, AVPacket *pkt, FrameData *fd)
static int add_mastering_display_to_stream(const OptionsContext *o, AVFormatContext *ctx, InputStream *ist)
static int guess_input_channel_layout(InputStream *ist, AVCodecParameters *par, int guess_layout_max)
int ist_use(InputStream *ist, int decoding_needed, const ViewSpecifier *vs, SchedulerNode *src)
static Demuxer * demux_alloc(void)
static int do_bsf_graph(Demuxer *d, DemuxThreadContext *dt, DemuxStreamGroup *dsg, DemuxStream *ds, AVPacket *pkt)
#define SHOW_TS_DEBUG(tag_)
#define DECODING_FOR_FILTER
static int is_windows_reserved_device_name(const char *f)
static DemuxStreamGroup * dsg_from_istg(InputStreamGroup *istg)
static int istg_add(const OptionsContext *o, Demuxer *d, AVStreamGroup *stg)
static int dump_attachment(InputStream *ist, const char *filename)
static int demux_thread_init(DemuxThreadContext *dt)
static Demuxer * demuxer_from_ifile(InputFile *f)
static int istg_parse_tile_grid(const OptionsContext *o, Demuxer *d, InputStreamGroup *istg)
static void ts_discontinuity_detect(Demuxer *d, InputStream *ist, AVPacket *pkt)
static int ts_fixup(Demuxer *d, AVPacket *pkt, FrameData *fd)
InputStream * ist_find_unused(enum AVMediaType type)
Find an unused input stream of given type.
static DemuxStreamGroup * demux_stream_group_alloc(Demuxer *d, AVStreamGroup *stg)
static void istg_free(InputStreamGroup **pistg)
static void report_new_stream(Demuxer *d, const AVPacket *pkt)
static int istg_parse_lcevc(const OptionsContext *o, Demuxer *d, DemuxStreamGroup *dsg)
static void ts_discontinuity_process(Demuxer *d, InputStream *ist, AVPacket *pkt)
static void ist_free(InputStream **pist)
static void discard_unused_programs(InputFile *ifile)
int ifile_open(const OptionsContext *o, const char *filename, Scheduler *sch)
static int input_thread(void *arg)
static int add_content_light_to_stream(const OptionsContext *o, AVFormatContext *ctx, InputStream *ist)
void ifile_close(InputFile **pf)
static int demux_bsf_flush(Demuxer *d, DemuxThreadContext *dt)
#define DECODING_FOR_OST
static void readrate_sleep(Demuxer *d)
static void demux_thread_uninit(DemuxThreadContext *dt)
static const char * input_stream_item_name(void *obj)
static int demux_send(Demuxer *d, DemuxThreadContext *dt, DemuxStream *ds, AVPacket *pkt, unsigned flags)
static int ist_add(const OptionsContext *o, Demuxer *d, AVStream *st, AVDictionary **opts_used)
static const AVClass input_stream_group_class
static const AVClass input_stream_class
static int safe_filename(const char *f, int allow_subdir)
static int do_send(Demuxer *d, DemuxStream *ds, AVPacket *pkt, unsigned flags, const char *pkt_desc)
int sch_demux_send(Scheduler *sch, unsigned demux_idx, AVPacket *pkt, unsigned flags)
Called by demuxer tasks to communicate with their downstreams.
int sch_add_demux_stream(Scheduler *sch, unsigned demux_idx)
Add a demuxed stream for a previously added demuxer.
int sch_connect(Scheduler *sch, SchedulerNode src, SchedulerNode dst)
int sch_add_demux(Scheduler *sch, SchThreadFunc func, void *ctx)
Add a demuxer to the scheduler.
#define SCH_DSTREAM(file, stream)
@ DEMUX_SEND_STREAMCOPY_EOF
Treat the packet as an EOF for SCH_NODE_TYPE_MUX destinations send normally to other types.
#define SCH_DEC_OUT(decoder, out_idx)
#define SCH_DEC_IN(decoder)
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,...
static int autorotate
Definition ffplay.c:351
static const char * hwaccel
Definition ffplay.c:357
static int64_t duration
Definition ffplay.c:330
static const AVInputFormat * file_iformat
Definition ffplay.c:308
static const char * video_codec_name
Definition ffplay.c:344
static const char * audio_codec_name
Definition ffplay.c:342
static int dummy
Definition ffplay.c:3754
static const char * subtitle_codec_name
Definition ffplay.c:343
static int64_t start_time
Definition ffplay.c:329
static const char * data_codec_name
Definition ffprobe.c:136
#define fail
Definition test.h:479
#define AV_OPT_FLAG_DECODING_PARAM
A generic parameter which can be set by the user for demuxing or decoding.
Definition opt.h:355
@ AV_OPT_TYPE_CONST
Special option type for declaring named constants.
Definition opt.h:298
@ AV_OPT_TYPE_INT
Underlying C type is int.
Definition opt.h:258
void av_bsf_free(AVBSFContext **pctx)
Free a bitstream filter context and everything associated with it; write NULL into the supplied point...
Definition bsf.c:47
int av_bsf_init(AVBSFContext *ctx)
Prepare the filter for use, after all the parameters and options have been set.
Definition bsf.c:147
void av_bsf_flush(AVBSFContext *ctx)
Reset the internal bitstream filter state.
Definition bsf.c:188
int av_bsf_receive_packet(AVBSFContext *ctx, AVPacket *pkt)
Retrieve a filtered packet.
Definition bsf.c:228
int av_bsf_send_packet(AVBSFContext *ctx, AVPacket *pkt)
Submit a packet for filtering.
Definition bsf.c:200
int av_bsf_list_parse_str(const char *str, AVBSFContext **bsf_lst)
Parse string describing list of bitstream filters and create single AVBSFContext describing the whole...
Definition bsf.c:524
const AVBitStreamFilter * av_bsf_get_by_name(const char *name)
int av_bsf_sink_get_packet(AVBitStreamFilterContext *ctx, AVPacket *pkt, int flags)
Get a packet with filtered data from sink and put it in packet.
Definition sink.c:52
AVRational av_bsf_sink_get_time_base(const AVBitStreamFilterContext *ctx)
Definition sink.c:126
int av_bsf_source_parameters_set(AVBitStreamFilterContext *ctx, const AVCodecParameters *par)
Initialize the source filter with the provided parameters.
Definition source.c:46
av_warn_unused_result int av_bsf_source_add_packet(AVBitStreamFilterContext *ctx, AVPacket *pkt, int flags)
Add a packet to the buffer source.
Definition source.c:67
@ AV_BSF_SOURCE_FLAG_PUSH
Immediately push the packet to the output.
Definition bsf.h:594
@ AV_BSF_SOURCE_FLAG_KEEP_REF
Keep a reference to the packet.
Definition bsf.h:599
int av_bsf_init_dict(AVBitStreamFilterContext *ctx, AVDictionary **options)
Initialize a filter with the supplied dictionary of options.
AVBitStreamFilterGraph * av_bsf_graph_alloc(void)
Allocate a filter graph.
Definition bsfgraph.c:48
int av_bsf_link(AVBitStreamFilterContext *src, unsigned srcpad, AVBitStreamFilterContext *dst, unsigned dstpad)
Link two filters together.
int av_bsf_graph_config(AVBitStreamFilterGraph *graphctx, void *log_ctx)
Check validity and configure all the links and formats in the graph.
Definition bsfgraph.c:294
void av_bsf_graph_free(AVBitStreamFilterGraph **graph)
Free a graph, destroy its links, and set *graph to NULL.
Definition bsfgraph.c:93
AVBitStreamFilterContext * av_bsf_graph_get_filter(AVBitStreamFilterGraph *graph, const char *name)
Get a filter instance identified by instance name from graph.
Definition bsfgraph.c:82
int av_bsf_graph_alloc_filter(AVBitStreamFilterContext **filt_ctx, const AVBitStreamFilter *filter, const char *name, AVBitStreamFilterGraph *graph)
Create a new filter instance in a filter graph.
Definition bsfgraph.c:139
const AVCodecDescriptor * avcodec_descriptor_get(enum AVCodecID id)
#define AV_CODEC_PROP_FIELDS
Video codec supports separate coding of fields in interlaced frames.
Definition codec_desc.h:97
int av_codec_is_decoder(const AVCodec *codec)
Definition utils.c:85
const AVCodec * avcodec_find_decoder(enum AVCodecID id)
Find a registered decoder with a matching codec ID.
Definition allcodecs.c:990
const char * avcodec_get_name(enum AVCodecID id)
Get the name of a codec.
Definition utils.c:421
const AVCodecHWConfig * avcodec_get_hw_config(const AVCodec *codec, int index)
Retrieve supported hardware configurations for a codec.
Definition utils.c:857
const AVCodec * av_codec_iterate(void **opaque)
Iterate over all registered codecs.
Definition allcodecs.c:943
@ AV_CODEC_ID_DVB_SUBTITLE
Definition codec_id.h:567
@ AV_CODEC_ID_NONE
Definition codec_id.h:48
@ AVDISCARD_ALL
discard all
Definition defs.h:232
@ AVDISCARD_DEFAULT
discard useless packets like 0 size packets in avi
Definition defs.h:227
@ AVDISCARD_NONE
discard nothing
Definition defs.h:226
AVPacketSideData * av_packet_side_data_new(AVPacketSideData **psd, int *pnb_sd, enum AVPacketSideDataType type, size_t size, int flags)
Allocate a new packet side data.
Definition packet.c:620
int av_packet_side_data_to_frame(AVFrameSideData ***psd, int *pnb_sd, const AVPacketSideData *src, unsigned int flags)
Add a new frame side data entry to an array based on existing packet side data, if a matching type ex...
Definition avcodec.c:862
AVPacketSideData * av_packet_side_data_add(AVPacketSideData **psd, int *pnb_sd, enum AVPacketSideDataType type, void *data, size_t size, int flags)
Wrap existing data as packet side data.
Definition packet.c:613
const AVPacketSideData * av_packet_side_data_get(const AVPacketSideData *sd, int nb_sd, enum AVPacketSideDataType type)
Get side information from a side data array.
Definition packet.c:570
@ AV_PKT_DATA_MASTERING_DISPLAY_METADATA
Mastering display metadata (based on SMPTE-2086:2014).
Definition packet.h:219
@ AV_PKT_DATA_DISPLAYMATRIX
This side data contains a 3x3 transformation matrix describing an affine transformation that needs to...
Definition packet.h:105
@ AV_PKT_DATA_FRAME_CROPPING
The number of pixels to discard from the top/bottom/left/right border of the decoded frame to obtain ...
Definition packet.h:340
@ AV_PKT_DATA_CONTENT_LIGHT_LEVEL
Content light level (based on CTA-861.3).
Definition packet.h:232
void av_packet_free(AVPacket **pkt)
Free the packet, if the packet is reference counted, it will be unreferenced first.
Definition packet.c:74
#define AV_PKT_FLAG_CORRUPT
The packet content is corrupted.
Definition packet.h:651
void av_packet_unref(AVPacket *pkt)
Wipe the packet.
Definition packet.c:434
AVPacket * av_packet_alloc(void)
Allocate an AVPacket and set its fields to default values.
Definition packet.c:63
void av_packet_rescale_ts(AVPacket *pkt, AVRational src_tb, AVRational dst_tb)
Convert valid timing fields (timestamps / durations) in a packet from one timebase to another.
Definition packet.c:538
const char * avformat_stream_group_name(enum AVStreamGroupParamsType type)
Definition avformat.c:269
AVFormatContext * avformat_alloc_context(void)
Allocate an AVFormatContext.
Definition options.c:165
void avformat_free_context(AVFormatContext *s)
Free an AVFormatContext and all its streams.
Definition avformat.c:150
const AVInputFormat * av_find_input_format(const char *short_name)
Find AVInputFormat based on the short name of the input format.
Definition format.c:146
int avformat_seek_file(AVFormatContext *s, int stream_index, int64_t min_ts, int64_t ts, int64_t max_ts, int flags)
Seek to timestamp ts.
Definition seek.c:664
int av_read_frame(AVFormatContext *s, AVPacket *pkt)
Return the next frame of a stream.
Definition demux.c:1588
int avformat_open_input(AVFormatContext **ps, const char *url, const AVInputFormat *fmt, AVDictionary **options)
Open an input stream and read the header.
Definition demux.c:231
int avformat_find_stream_info(AVFormatContext *ic, AVDictionary **options)
Read packets of a media file to get stream information.
Definition demux.c:2606
void avformat_close_input(AVFormatContext **s)
Close an opened input AVFormatContext.
Definition demux.c:377
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:811
void av_pkt_dump_log2(void *avcl, int level, const AVPacket *pkt, int dump_payload, const AVStream *st)
Send a nice dump of a packet to the log.
Definition dump.c:122
void av_dump_format(AVFormatContext *ic, int index, const char *url, int is_output)
Print detailed information about the input or output format, such as duration, bitrate,...
Definition dump.c:852
void av_channel_layout_default(AVChannelLayout *ch_layout, int nb_channels)
Get the default channel layout for a given number of channels.
int av_channel_layout_from_string(AVChannelLayout *channel_layout, const char *str)
Initialize a channel layout from a given string description.
void av_channel_layout_uninit(AVChannelLayout *channel_layout)
Free any allocated data in the channel layout and reset the channel count to 0.
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.
int av_channel_layout_copy(AVChannelLayout *dst, const AVChannelLayout *src)
Make a copy of a channel layout.
@ AV_CHANNEL_ORDER_UNSPEC
Only the channel count is specified, without any further information about the channel order.
int av_bprint_finalize(AVBPrint *buf, char **ret_str)
Finalize a print buffer.
Definition bprint.c:235
void av_dict_free(AVDictionary **pm)
Free all the memory allocated for an AVDictionary struct and all keys and values.
Definition dict.c:233
AVDictionaryEntry * av_dict_get(const AVDictionary *m, const char *key, const AVDictionaryEntry *prev, int flags)
Get a dictionary entry with matching key.
Definition dict.c:60
#define AV_DICT_APPEND
If the entry already exists, append to it.
Definition dict.h:82
int av_dict_set(AVDictionary **pm, const char *key, const char *value, int flags)
Set the given entry in *pm, overwriting an existing entry.
Definition dict.c:86
#define AV_DICT_DONT_OVERWRITE
Don't overwrite existing entries.
Definition dict.h:81
#define AV_DICT_MATCH_CASE
Only get an entry with exact-case key match.
Definition dict.h:74
int av_dict_set_int(AVDictionary **pm, const char *key, int64_t value, int flags)
Convenience wrapper for av_dict_set() that converts the value to a string and stores it.
Definition dict.c:177
#define AVERROR_EXIT
Immediate exit was requested; the called function should not be restarted.
Definition error.h:58
#define AVERROR_PROTOCOL_NOT_FOUND
Protocol not found.
Definition error.h:65
#define AVERROR_BUG
Internal bug, also see AVERROR_BUG2.
Definition error.h:52
#define AVERROR_INVALIDDATA
Invalid data found when processing input.
Definition error.h:61
#define AVERROR_EOF
End of file.
Definition error.h:57
#define av_err2str(errnum)
Convenience macro, the return value should be used only directly in function arguments but never stan...
Definition error.h:122
#define AVERROR(e)
Definition error.h:45
void av_frame_free(AVFrame **frame)
Free the frame and any dynamically allocated objects in it, e.g.
Definition frame.c:64
int av_frame_copy_props(AVFrame *dst, const AVFrame *src)
Copy only "metadata" fields from src to dst.
Definition frame.c:599
AVFrame * av_frame_alloc(void)
Allocate an AVFrame and set its fields to default values.
Definition frame.c:52
#define AV_LOG_DEBUG
Stuff which is only useful for libav* developers.
Definition log.h:231
#define AV_LOG_WARNING
Something somehow does not look correct.
Definition log.h:216
#define AV_LOG_FATAL
Something went wrong and recovery is not possible.
Definition log.h:204
#define AV_LOG_VERBOSE
Detailed information.
Definition log.h:226
#define AV_LOG_INFO
Standard information.
Definition log.h:221
#define AV_LOG_ERROR
Something went wrong and cannot losslessly be recovered.
Definition log.h:210
const char * av_default_item_name(void *ptr)
Return the context name.
Definition log.c:241
AVRational av_mul_q(AVRational b, AVRational c)
Multiply two rationals.
Definition rational.c:80
static double av_q2d(AVRational a)
Convert an AVRational to a double.
Definition rational.h:104
static av_always_inline AVRational av_inv_q(AVRational q)
Invert a rational.
Definition rational.h:159
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.
int64_t av_rescale(int64_t a, int64_t b, int64_t c)
Rescale a 64-bit integer with rounding to nearest.
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.
int64_t av_rescale_q(int64_t a, AVRational bq, AVRational cq)
Rescale a 64-bit integer by 2 rational numbers.
@ AV_ROUND_PASS_MINMAX
Flag telling rescaling functions to pass INT64_MIN/MAX through unchanged, avoiding special cases for ...
@ AV_ROUND_NEAR_INF
Round to nearest and halfway cases away from zero.
int av_dynarray_add_nofree(void *tab_ptr, int *nb_ptr, void *elem)
Add an element to a dynamic array.
Definition mem.c:313
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
AVMediaType
Definition avutil.h:198
@ AVMEDIA_TYPE_ATTACHMENT
Opaque data information usually sparse.
Definition avutil.h:204
@ AVMEDIA_TYPE_AUDIO
Definition avutil.h:201
@ AVMEDIA_TYPE_SUBTITLE
Definition avutil.h:203
@ AVMEDIA_TYPE_VIDEO
Definition avutil.h:200
@ AVMEDIA_TYPE_DATA
Opaque data information usually continuous.
Definition avutil.h:202
@ AVMEDIA_TYPE_UNKNOWN
Usually treated as AVMEDIA_TYPE_DATA.
Definition avutil.h:199
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
int av_strcasecmp(const char *a, const char *b)
Locale-independent case-insensitive compare.
Definition avstring.c:208
size_t av_strlcpy(char *dst, const char *src, size_t size)
Copy the string src to dst, but no more than size - 1 bytes, and null-terminate dst.
Definition avstring.c:85
#define AV_NOPTS_VALUE
Undefined timestamp value.
Definition avutil.h:247
#define AV_TIME_BASE
Internal time base represented as integer.
Definition avutil.h:253
#define AV_TIME_BASE_Q
Internal time base represented as fractional value.
Definition avutil.h:263
#define LIBAVUTIL_VERSION_INT
Definition version.h:85
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
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
int av_opt_eval_int(void *obj, const AVOption *o, const char *val, int *int_out)
int av_opt_get_int(void *obj, const char *name, int search_flags, int64_t *out_val)
Definition opt.c:1345
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:2067
#define AV_OPT_SEARCH_FAKE_OBJ
The obj passed to av_opt_find() or av_opt_set() is fake – only a double pointer to AVClass instead of...
Definition opt.h:612
int av_opt_set_q(void *obj, const char *name, AVRational val, int search_flags)
Definition opt.c:944
int av_opt_set(void *obj, const char *name, const char *val, int search_flags)
Definition opt.c:887
enum AVHWDeviceType av_hwdevice_iterate_types(enum AVHWDeviceType prev)
Iterate over supported device types.
Definition hwcontext.c:129
const char * av_hwdevice_get_type_name(enum AVHWDeviceType type)
Get the string name of an AVHWDeviceType.
Definition hwcontext.c:120
enum AVHWDeviceType av_hwdevice_find_type_by_name(const char *name)
Look up an AVHWDeviceType by name.
Definition hwcontext.c:110
AVHWDeviceType
Definition hwcontext.h:27
@ AV_HWDEVICE_TYPE_NONE
Definition hwcontext.h:28
cl_device_type type
#define AV_RL32(p)
static int lcevc_merge(FFPacketSync *fs)
Definition lcevc_merge.c:85
unsigned offset
Definition libaomenc.c:763
const char * arg
Definition jacosubdec.c:65
static int ff_thread_setname(const char *name)
Definition thread.h:216
void av_log_once(void *avcl, int initial_level, int subsequent_level, int *state, const char *fmt,...)
Definition log.c:450
@ AV_CLASS_CATEGORY_DEMUXER
Definition log.h:33
#define FFMIN(a, b)
Definition macros.h:49
#define FFMAX(a, b)
Definition macros.h:47
AVContentLightMetadata * av_content_light_metadata_alloc(size_t *size)
Allocate an AVContentLightMetadata structure and set its fields to default values.
AVMasteringDisplayMetadata * av_mastering_display_metadata_alloc_size(size_t *size)
Allocate an AVMasteringDisplayMetadata structure and set its fields to default values.
Memory handling functions.
uint32_t tag
Definition movenc.c:2073
#define av_strdup(s)
Definition ops_static.c:55
AVOptions.
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
int av_parse_video_rate(AVRational *rate, const char *arg)
Parse str and store the detected values in *rate.
Definition parseutils.c:181
misc parsing utilities
enum AVPixelFormat av_get_pix_fmt(const char *name)
Return the pixel format corresponding to name.
Definition pixdesc.c:3392
@ AV_PIX_FMT_NONE
Definition pixfmt.h:72
@ AV_PIX_FMT_CUDA
HW acceleration through CUDA.
Definition pixfmt.h:260
@ AV_PIX_FMT_QSV
HW acceleration through QSV, data[3] contains a pointer to the mfxFrameSurface1 structure.
Definition pixfmt.h:247
@ AV_PIX_FMT_MEDIACODEC
hardware decoding through MediaCodec
Definition pixfmt.h:316
const char * name
Definition qsvenc.c:142
#define snprintf
Definition snprintf.h:34
The bitstream filter state.
Definition bsf.h:68
AVRational time_base_out
The timebase used for the timestamps of the output packets.
Definition bsf.h:108
AVCodecParameters * par_in
Parameters of the input stream.
Definition bsf.h:90
AVCodecParameters * par_out
Parameters of the output stream.
Definition bsf.h:96
AVRational time_base_in
The timebase used for the timestamps of the input packets.
Definition bsf.h:102
An instance of a filter.
Definition bsf.h:347
void * priv_data
Opaque filter-specific private data.
Definition bsf.h:375
An AVChannelLayout holds information about the channel layout of audio data.
enum AVChannelOrder order
Channel order used in this layout.
int nb_channels
Number of channels in this layout.
Describe the class of an AVClass context structure.
Definition log.h:76
const char * class_name
The name of the class; usually it is the same name as the context structure type to which the AVClass...
Definition log.h:81
This struct describes the properties of a single codec described by an AVCodecID.
Definition codec_desc.h:38
int props
Codec properties, a combination of AV_CODEC_PROP_* flags.
Definition codec_desc.h:54
This struct describes the properties of an encoded stream.
Definition codec_par.h:49
int extradata_size
Size of the extradata content in bytes.
Definition codec_par.h:75
int frame_size
Audio frame size, if known.
Definition codec_par.h:227
int height
The height of the video frame in pixels.
Definition codec_par.h:150
int nb_coded_side_data
Amount of entries in coded_side_data.
Definition codec_par.h:88
AVChannelLayout ch_layout
The channel layout and number of channels.
Definition codec_par.h:207
int width
The width of the video frame in pixels.
Definition codec_par.h:143
enum AVMediaType codec_type
General type of the encoded data.
Definition codec_par.h:53
AVRational framerate
Number of frames per second, for streams with constant frame durations.
Definition codec_par.h:175
AVRational sample_aspect_ratio
The aspect ratio (width/height) which a single pixel should have when displayed.
Definition codec_par.h:161
int video_delay
Number of delayed frames.
Definition codec_par.h:200
uint32_t codec_tag
Additional information about the codec (corresponds to the AVI FOURCC).
Definition codec_par.h:61
uint8_t * extradata
Extra binary data needed for initializing the decoder, codec-dependent.
Definition codec_par.h:71
enum AVCodecID codec_id
Specific type of the encoded data (the codec used).
Definition codec_par.h:57
int sample_rate
The number of audio samples per second.
Definition codec_par.h:213
AVPacketSideData * coded_side_data
Additional data associated with the entire stream.
Definition codec_par.h:83
int repeat_pict
This field is used for proper frame duration computation in lavf.
Definition avcodec.h:2635
AVCodec.
Definition codec.h:175
enum AVCodecID id
Definition codec.h:189
Content light level needed by to transmit HDR over HDMI (CTA-861.3).
unsigned MaxFALL
Max average light level per frame (cd/m^2).
unsigned MaxCLL
Max content light level (cd/m^2).
char * value
Definition dict.h:92
Format I/O context.
Definition avformat.h:1333
unsigned int nb_streams
Number of elements in AVFormatContext.streams.
Definition avformat.h:1389
AVStreamGroup ** stream_groups
A list of all stream groups in the file.
Definition avformat.h:1420
enum AVCodecID audio_codec_id
Forced audio codec_id.
Definition avformat.h:1558
enum AVCodecID data_codec_id
Forced Data codec_id.
Definition avformat.h:1570
int64_t start_time
Position of the first frame of the component, in AV_TIME_BASE fractional seconds.
Definition avformat.h:1458
const struct AVCodec * data_codec
Forced data codec.
Definition avformat.h:1899
int flags
Flags modifying the (de)muxer behaviour.
Definition avformat.h:1484
AVProgram ** programs
Definition avformat.h:1546
const struct AVCodec * audio_codec
Forced audio codec.
Definition avformat.h:1883
unsigned int nb_programs
Definition avformat.h:1545
AVIOInterruptCB interrupt_callback
Custom interrupt callbacks for the I/O layer.
Definition avformat.h:1618
const struct AVInputFormat * iformat
The input container format.
Definition avformat.h:1345
enum AVCodecID video_codec_id
Forced video codec_id.
Definition avformat.h:1552
unsigned int nb_stream_groups
Number of elements in AVFormatContext.stream_groups.
Definition avformat.h:1408
enum AVCodecID subtitle_codec_id
Forced subtitle codec_id.
Definition avformat.h:1564
AVStream ** streams
A list of all streams in the file.
Definition avformat.h:1401
int64_t duration
Duration of the stream, in AV_TIME_BASE fractional seconds.
Definition avformat.h:1468
const struct AVCodec * subtitle_codec
Forced subtitle codec.
Definition avformat.h:1891
const struct AVCodec * video_codec
Forced video codec.
Definition avformat.h:1875
char * name
Name of this format context, only used for logging purposes.
Definition avformat.h:1978
This structure describes decoded (raw) audio or video data.
Definition frame.h:472
int width
Definition frame.h:544
int height
Definition frame.h:544
AVChannelLayout ch_layout
Channel layout of the audio data.
Definition frame.h:815
int format
format of the frame, -1 if unknown or unset Values correspond to enum AVPixelFormat for video frames,...
Definition frame.h:559
Bytestream IO Context.
Definition avio.h:160
int flags
Can use flags: AVFMT_NOFILE, AVFMT_NEEDNUMBER, AVFMT_EXPERIMENTAL, AVFMT_SHOW_IDS,...
Definition avformat.h:585
const char * name
A comma separated list of short names for the format.
Definition avformat.h:570
Mastering display metadata capable of representing the color volume of the display used to master the...
int has_primaries
Flag indicating whether the display primaries (and white point) are set.
AVRational max_luminance
Max luminance of mastering display (cd/m^2).
AVRational min_luminance
Min luminance of mastering display (cd/m^2).
AVRational display_primaries[3][2]
CIE 1931 xy chromaticity coords of color primaries (r, g, b order).
AVRational white_point[2]
CIE 1931 xy chromaticity coords of white point.
int has_luminance
Flag indicating whether the luminance (min_ and max_) have been set.
AVOption.
Definition opt.h:428
This structure stores auxiliary information for decoding, presenting, or otherwise processing the cod...
Definition packet.h:424
uint8_t * data
Definition packet.h:425
This structure stores compressed data.
Definition packet.h:580
int stream_index
Definition packet.h:605
int flags
A combination of AV_PKT_FLAG values.
Definition packet.h:609
int64_t pts
Presentation timestamp in AVStream->time_base units; the time at which the decompressed packet will b...
Definition packet.h:596
void * opaque
for some private data of the user
Definition packet.h:628
AVRational time_base
Time base of the packet's timestamps.
Definition packet.h:647
New fields can be added to the end with minor version bumps.
Definition avformat.h:1257
Rational number (pair of numerator and denominator).
Definition rational.h:58
int num
Numerator.
Definition rational.h:59
int den
Denominator.
Definition rational.h:60
AVStreamGroupLayeredVideo is meant to define the relation between a base layer video stream and a sep...
Definition avformat.h:1093
unsigned int el_index
Index of the enhancement layer stream in AVStreamGroup.
Definition avformat.h:1102
AVStreamGroupTileGrid holds information on how to combine several independent images on a single canv...
Definition avformat.h:973
int nb_coded_side_data
Amount of entries in coded_side_data.
Definition avformat.h:1081
int width
Width of the final image for presentation.
Definition avformat.h:1058
int height
Height of the final image for presentation.
Definition avformat.h:1068
int coded_width
Width of the canvas.
Definition avformat.h:988
struct AVStreamGroupTileGrid::@036353327352337314037001273105074056331305251354 * offsets
An nb_tiles sized array of offsets in pixels from the topleft edge of the canvas, indicating where ea...
unsigned int nb_tiles
Amount of tiles in the grid.
Definition avformat.h:981
uint8_t background[4]
The pixel value per channel in RGBA format used if no pixel of any tile is located at a particular pi...
Definition avformat.h:1032
int horizontal_offset
Offset in pixels from the left edge of the canvas where the actual image meant for presentation start...
Definition avformat.h:1040
int horizontal
Offset in pixels from the left edge of the canvas where the tile should be placed.
Definition avformat.h:1017
unsigned int idx
Index of the stream in the group this tile references.
Definition avformat.h:1012
int vertical_offset
Offset in pixels from the top edge of the canvas where the actual image meant for presentation starts...
Definition avformat.h:1047
int coded_height
Width of the canvas.
Definition avformat.h:994
AVPacketSideData * coded_side_data
Additional data associated with the grid.
Definition avformat.h:1076
int vertical
Offset in pixels from the top edge of the canvas where the tile should be placed.
Definition avformat.h:1022
union AVStreamGroup::@166361102046003066253145020066347265153020354020 params
Group type-specific parameters.
enum AVStreamGroupParamsType type
Group type.
Definition avformat.h:1186
struct AVStreamGroupTileGrid * tile_grid
Definition avformat.h:1194
unsigned int nb_streams
Number of elements in AVStreamGroup.streams.
Definition avformat.h:1221
unsigned int index
Group index in AVFormatContext.
Definition avformat.h:1170
AVStream ** streams
A list of streams in the group.
Definition avformat.h:1234
struct AVStreamGroupLayeredVideo * layered_video
Definition avformat.h:1195
Stream structure.
Definition avformat.h:766
AVCodecParameters * codecpar
Codec parameters associated with this stream.
Definition avformat.h:789
AVRational sample_aspect_ratio
sample aspect ratio (0 if unknown)
Definition avformat.h:844
enum AVDiscard discard
Selects which packets can be discarded at will and do not need to be demuxed.
Definition avformat.h:837
AVDictionary * metadata
Definition avformat.h:846
int id
Format-specific stream ID.
Definition avformat.h:778
int index
stream index in AVFormatContext
Definition avformat.h:772
int pts_wrap_bits
Number of bits in timestamps.
Definition avformat.h:909
AVRational avg_frame_rate
Average framerate.
Definition avformat.h:855
AVRational time_base
This is the fundamental unit of time (in seconds) in terms of which frame timestamps are represented.
Definition avformat.h:805
int disposition
Stream disposition - a combination of AV_DISPOSITION_* flags.
Definition avformat.h:835
const AVCodec * codec
Definition ffmpeg.h:435
int flags
Definition ffmpeg.h:430
enum AVHWDeviceType hwaccel_device_type
Definition ffmpeg.h:440
const AVCodecParameters * par
Definition ffmpeg.h:436
void * log_parent
Definition ffmpeg.h:433
char * hwaccel_device
Definition ffmpeg.h:441
char * name
Definition ffmpeg.h:432
enum AVPixelFormat hwaccel_output_format
Definition ffmpeg.h:442
enum HWAccelID hwaccel_id
Definition ffmpeg.h:439
AVRational time_base
Definition ffmpeg.h:444
AVRational framerate
Definition ffmpeg.h:448
uint64_t decode_errors
Definition ffmpeg.h:462
uint64_t frames_decoded
Definition ffmpeg.h:460
uint64_t samples_decoded
Definition ffmpeg.h:461
AVBitStreamFilterGraph * graph
AVBitStreamFilterContext * sink
AVBitStreamFilterContext * lcevc[2]
InputStreamGroup istg
AVDictionary * decoder_opts
const AVCodecDescriptor * codec_desc
int64_t dts
dts of the last packet read for this stream (in AV_TIME_BASE units)
int force_content_light
double ts_scale
DecoderOpts dec_opts
int force_mastering_display
int wrap_correction_done
DemuxStreamGroup ** dsg
uint64_t nb_packets
InputStream ist
uint64_t data_size
int64_t first_dts
dts of the first packet read for this stream (in AV_TIME_BASE units)
AVBSFContext * bsf
int64_t next_dts
int decoding_needed
int streamcopy_needed
AVFrame * decoded_params
char log_name[32]
int force_display_matrix
char dec_name[16]
int64_t lag
int64_t ts_offset_discont
Extra timestamp offset added by discontinuity handling.
int64_t wallclock_start
int have_audio_dec
float readrate
int nb_streams_warn
InputFile f
double readrate_initial_burst
int64_t resume_progress
int read_started
int nb_streams_used
Timestamp duration
int accurate_seek
float readrate_catchup
int64_t resume_wc
Timestamp min_pts
AVPacket * pkt_heartbeat
int nb_streams_finished
Scheduler * sch
char log_name[32]
Timestamp max_pts
int64_t last_ts
int64_t recording_time
int is_internal
Definition ffmpeg.h:411
int64_t dts_est
Definition ffmpeg.h:707
int64_t wallclock[LATENCY_PROBE_NB]
Definition ffmpeg.h:721
int64_t ts_offset
Definition ffmpeg.h:520
AVFormatContext * ctx
Definition ffmpeg.h:513
int index
Definition ffmpeg.h:511
int64_t start_time_effective
Effective format start time based on enabled streams.
Definition ffmpeg.h:519
const AVClass * class
Definition ffmpeg.h:509
InputStream ** streams
Definition ffmpeg.h:527
int64_t start_time
Definition ffmpeg.h:522
int nb_streams
Definition ffmpeg.h:528
FilterGraph * fg
Definition ffmpeg.h:504
struct InputFile * file
Definition ffmpeg.h:500
const AVClass * class
Definition ffmpeg.h:497
AVStreamGroup * stg
Definition ffmpeg.h:505
int fix_sub_duration
Definition ffmpeg.h:488
int index
Definition ffmpeg.h:471
struct InputFile * file
Definition ffmpeg.h:469
Decoder * decoder
Definition ffmpeg.h:482
const AVClass * class
Definition ffmpeg.h:466
int nb_filters
Definition ffmpeg.h:493
int user_set_discard
Definition ffmpeg.h:474
AVCodecParameters * par
Codec parameters - to be used by the decoding/streamcopy code.
Definition ffmpeg.h:481
AVStream * st
Definition ffmpeg.h:473
InputFilter ** filters
Definition ffmpeg.h:492
const AVCodec * dec
Definition ffmpeg.h:483
AVRational framerate
Definition ffmpeg.h:486
AVDictionary * codec_opts
Definition cmdutils.h:347
AVDictionary * format_opts
Definition cmdutils.h:348
SpecifierOptList mastering_displays
Definition ffmpeg.h:209
SpecifierOptList canvas_sizes
Definition ffmpeg.h:224
SpecifierOptList frame_pix_fmts
Definition ffmpeg.h:148
SpecifierOptList autorotate
Definition ffmpeg.h:167
SpecifierOptList codec_tags
Definition ffmpeg.h:199
SpecifierOptList hwaccel_devices
Definition ffmpeg.h:165
int64_t start_time
Definition ffmpeg.h:136
SpecifierOptList codec_names
Definition ffmpeg.h:141
const char * format
Definition ffmpeg.h:139
SpecifierOptList discard
Definition ffmpeg.h:231
int64_t input_ts_offset
Definition ffmpeg.h:151
SpecifierOptList ts_scale
Definition ffmpeg.h:162
int input_sync_ref
Definition ffmpeg.h:159
SpecifierOptList audio_channels
Definition ffmpeg.h:143
SpecifierOptList hwaccels
Definition ffmpeg.h:164
int accurate_seek
Definition ffmpeg.h:157
SpecifierOptList dump_attachment
Definition ffmpeg.h:163
float readrate
Definition ffmpeg.h:154
int find_stream_info
Definition ffmpeg.h:160
int64_t recording_time
Definition ffmpeg.h:178
SpecifierOptList frame_rates
Definition ffmpeg.h:145
SpecifierOptList drop_changed
Definition ffmpeg.h:221
SpecifierOptList display_vflips
Definition ffmpeg.h:208
int64_t start_time_eof
Definition ffmpeg.h:137
SpecifierOptList display_hflips
Definition ffmpeg.h:207
int data_disable
Definition ffmpeg.h:190
int video_disable
Definition ffmpeg.h:187
int audio_disable
Definition ffmpeg.h:188
SpecifierOptList hwaccel_output_formats
Definition ffmpeg.h:166
SpecifierOptList guess_layout_max
Definition ffmpeg.h:229
int64_t stop_time
Definition ffmpeg.h:179
float readrate_catchup
Definition ffmpeg.h:155
SpecifierOptList display_rotations
Definition ffmpeg.h:206
SpecifierOptList apply_cropping
Definition ffmpeg.h:168
SpecifierOptList reinit_filters
Definition ffmpeg.h:220
SpecifierOptList audio_sample_rate
Definition ffmpeg.h:144
double readrate_initial_burst
Definition ffmpeg.h:156
SpecifierOptList fix_sub_duration
Definition ffmpeg.h:222
SpecifierOptList bitstream_filters
Definition ffmpeg.h:198
SpecifierOptList content_lights
Definition ffmpeg.h:210
int subtitle_disable
Definition ffmpeg.h:189
SpecifierOptList frame_sizes
Definition ffmpeg.h:147
int seek_timestamp
Definition ffmpeg.h:138
SpecifierOptList audio_ch_layouts
Definition ffmpeg.h:142
OptionGroup * g
Definition ffmpeg.h:133
SpecifierOpt * opt
Definition cmdutils.h:184
union SpecifierOpt::@356325016025214271156003270003007057215065005026 u
uint8_t * str
Definition cmdutils.h:174
char * specifier
Definition cmdutils.h:169
int64_t ts
AVRational tb
#define av_freep(p)
#define av_log(a,...)
float framerate
Definition av1_levels.c:29
void(* filter)(uint8_t *src, ptrdiff_t stride, int qscale)
Definition h263dsp.c:29
#define src
Definition vp8dsp.c:248
static FILE * out
Definition movenc.c:55
static AVFormatContext * ctx
Definition movenc.c:49
static void finish(void)
Definition movenc.c:374
static AVDictionary * opts
Definition movenc.c:51
int av_usleep(unsigned usec)
Sleep for a period of time.
Definition time.c:93
int64_t av_gettime_relative(void)
Get the current time in microseconds since some unspecified starting point.
Definition time.c:57
timestamp utils, mostly useful for debugging/logging purposes
#define av_ts2str(ts)
Convenience macro, the return value should be used only directly in function arguments but never stan...
Definition timestamp.h:54
#define av_ts2timestr(ts, tb)
Convenience macro, the return value should be used only directly in function arguments but never stan...
Definition timestamp.h:83
static int64_t pts
int size
static double limit(double x)
float delta
static double c[64]