diff --git a/BUILD.gn b/BUILD.gn index c45f6a631d..c0498ba72c 100644 --- a/BUILD.gn +++ b/BUILD.gn @@ -144,6 +144,7 @@ config("ffmpeg_config") { "-DOHOS_SDTP_BOX_EXT", "-DOHOS_NONSTANDARD_BOM", "-DOHOS_TIMED_META_TRACK", + "-DOHOS_SUBTITLE_DEMUXER", ] if (use_musl) { cflags += [ "-Wno-bool-operation" ] diff --git a/libavformat/isom.c b/libavformat/isom.c index de48eb3745..5f8078fc46 100644 --- a/libavformat/isom.c +++ b/libavformat/isom.c @@ -79,7 +79,9 @@ const AVCodecTag ff_codec_movsubtitle_tags[] = { { AV_CODEC_ID_MOV_TEXT, MKTAG('t', 'e', 'x', 't') }, { AV_CODEC_ID_MOV_TEXT, MKTAG('t', 'x', '3', 'g') }, { AV_CODEC_ID_EIA_608, MKTAG('c', '6', '0', '8') }, +#ifdef OHOS_SUBTITLE_DEMUXER { AV_CODEC_ID_WEBVTT, MKTAG('w', 'v', 't', 't') }, +#endif { AV_CODEC_ID_NONE, 0 }, }; diff --git a/libavformat/mov.c b/libavformat/mov.c index 69b5cab7b1..02e906c745 100644 --- a/libavformat/mov.c +++ b/libavformat/mov.c @@ -801,7 +801,11 @@ static int mov_read_hdlr(MOVContext *c, AVIOContext *pb, MOVAtom atom) st->codecpar->codec_type = AVMEDIA_TYPE_AUDIO; else if (type == MKTAG('m','1','a',' ')) st->codecpar->codec_id = AV_CODEC_ID_MP2; +#ifdef OHOS_SUBTITLE_DEMUXER else if ((type == MKTAG('s','u','b','p')) || (type == MKTAG('c','l','c','p')) || (type == MKTAG('t','e','x','t'))) +#else + else if ((type == MKTAG('s','u','b','p')) || (type == MKTAG('c','l','c','p'))) +#endif st->codecpar->codec_type = AVMEDIA_TYPE_SUBTITLE; #ifdef OHOS_TIMED_META_TRACK else if (type == MKTAG('m', 'e', 't', 'a')) @@ -9021,6 +9025,7 @@ static int mov_read_packet(AVFormatContext *s, AVPacket *pkt) } return ret; } +#ifdef OHOS_SUBTITLE_DEMUXER if (st->codecpar->codec_id == AV_CODEC_ID_WEBVTT) { if (pkt->size >= 8) { uint32_t type = AV_RL32(pkt->data + 4); @@ -9041,6 +9046,7 @@ static int mov_read_packet(AVFormatContext *s, AVPacket *pkt) } memmove(pkt->data, payload_data, move_size); pkt->size = payload_size; + pkt->data[pkt->size] = '\0'; break; } else { if (temp_size > payload_size) { @@ -9053,6 +9059,7 @@ static int mov_read_packet(AVFormatContext *s, AVPacket *pkt) } } } +#endif #if CONFIG_DV_DEMUXER if (mov->dv_demux && sc->dv_audio_container) { ret = avpriv_dv_produce_packet(mov->dv_demux, pkt, pkt->data, pkt->size, pkt->pos); diff --git a/libavformat/subtitles.c b/libavformat/subtitles.c index 3ba5e2b217..4181741c31 100644 --- a/libavformat/subtitles.c +++ b/libavformat/subtitles.c @@ -288,6 +288,22 @@ int ff_subtitles_queue_seek(FFDemuxSubtitlesQueue *q, AVFormatContext *s, int st break; } +#ifdef OHOS_SUBTITLE_DEMUXER + if (q->subs[idx]->pts + q->subs[idx]->duration < ts) { + if (idx < 1) + idx = 1; + for (i = idx - 1; i < q->nb_subs; i++) { + int64_t pts = q->subs[i]->pts; + if (q->subs[i]->duration <= 0 || + (stream_index != -1 && q->subs[i]->stream_index != stream_index)) + continue; + if (pts + q->subs[i]->duration >= ts) { + idx = i; + break; + } + } + } +#endif /* If the queue is used to store multiple subtitles streams (like with * VobSub) and the stream index is not specified, we need to make sure * to focus on the smallest file position offset for a same timestamp;