MCPcopy Create free account
hub / github.com/FFmpeg/FFmpeg / select_reference_stream

Function select_reference_stream

libavformat/segment.c:597–652  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

595}
596
597static int select_reference_stream(AVFormatContext *s)
598{
599 SegmentContext *seg = s->priv_data;
600 int ret, i;
601
602 seg->reference_stream_index = -1;
603 if (!strcmp(seg->reference_stream_specifier, "auto")) {
604 /* select first index of type with highest priority */
605 int type_index_map[AVMEDIA_TYPE_NB];
606 static const enum AVMediaType type_priority_list[] = {
607 AVMEDIA_TYPE_VIDEO,
608 AVMEDIA_TYPE_AUDIO,
609 AVMEDIA_TYPE_SUBTITLE,
610 AVMEDIA_TYPE_DATA,
611 AVMEDIA_TYPE_ATTACHMENT
612 };
613 enum AVMediaType type;
614
615 for (i = 0; i < AVMEDIA_TYPE_NB; i++)
616 type_index_map[i] = -1;
617
618 /* select first index for each type */
619 for (i = 0; i < s->nb_streams; i++) {
620 type = s->streams[i]->codecpar->codec_type;
621 if ((unsigned)type < AVMEDIA_TYPE_NB && type_index_map[type] == -1
622 /* ignore attached pictures/cover art streams */
623 && !(s->streams[i]->disposition & AV_DISPOSITION_ATTACHED_PIC))
624 type_index_map[type] = i;
625 }
626
627 for (i = 0; i < FF_ARRAY_ELEMS(type_priority_list); i++) {
628 type = type_priority_list[i];
629 if ((seg->reference_stream_index = type_index_map[type]) >= 0)
630 break;
631 }
632 } else {
633 for (i = 0; i < s->nb_streams; i++) {
634 ret = avformat_match_stream_specifier(s, s->streams[i],
635 seg->reference_stream_specifier);
636 if (ret < 0)
637 return ret;
638 if (ret > 0) {
639 seg->reference_stream_index = i;
640 break;
641 }
642 }
643 }
644
645 if (seg->reference_stream_index < 0) {
646 av_log(s, AV_LOG_ERROR, "Could not select stream matching identifier '%s'\n",
647 seg->reference_stream_specifier);
648 return AVERROR(EINVAL);
649 }
650
651 return 0;
652}
653
654static void seg_free(AVFormatContext *s)

Callers 1

seg_initFunction · 0.85

Calls 2

av_logFunction · 0.85

Tested by

no test coverage detected