static int read_header(AVFormatContext *s) { AVDictionary **m = &s->metadata; uint8_t line[1024]; while(!avio_feof(s->pb)) { get_line(s->pb, line, sizeof(line)); if (!memcmp(line, ID_STREAM, strlen(ID_STREAM))) { AVStream *st = avformat_new_stream(s, NULL); if (!st) return AVERROR(ENOMEM); st->codec->codec_type = AVMEDIA_TYPE_DATA; st->codec->codec_id = AV_CODEC_ID_FFMETADATA; m = &st->metadata; } else if (!memcmp(line, ID_CHAPTER, strlen(ID_CHAPTER))) { AVChapter *ch = read_chapter(s); if (!ch) return AVERROR(ENOMEM); m = &ch->metadata; } else read_tag(line, m); } s->start_time = 0; if (s->nb_chapters) { #ifdef IDE_COMPILE AVRational tmp; tmp.num = 1; tmp.den = AV_TIME_BASE; s->duration = av_rescale_q(s->chapters[s->nb_chapters - 1]->end, s->chapters[s->nb_chapters - 1]->time_base, tmp); #else s->duration = av_rescale_q(s->chapters[s->nb_chapters - 1]->end, s->chapters[s->nb_chapters - 1]->time_base, AV_TIME_BASE_Q); #endif } return 0; }
static int read_header(AVFormatContext *s, AVFormatParameters *ap) { AVMetadata **m = &s->metadata; uint8_t line[1024]; while(!url_feof(s->pb)) { get_line(s->pb, line, sizeof(line)); if (!memcmp(line, ID_STREAM, strlen(ID_STREAM))) { AVStream *st = av_new_stream(s, 0); if (!st) return -1; st->codec->codec_type = AVMEDIA_TYPE_DATA; st->codec->codec_id = CODEC_ID_FFMETADATA; m = &st->metadata; } else if (!memcmp(line, ID_CHAPTER, strlen(ID_CHAPTER))) { AVChapter *ch = read_chapter(s); if (!ch) return -1; m = &ch->metadata; } else read_tag(line, m); } s->start_time = 0; if (s->nb_chapters) s->duration = av_rescale_q(s->chapters[s->nb_chapters - 1]->end, s->chapters[s->nb_chapters - 1]->time_base, AV_TIME_BASE_Q); return 0; }