From: ffmpegagent <ffmpegagent@gmail.com> To: ffmpeg-devel@ffmpeg.org Cc: Soft Works <softworkz-at-hotmail.com@ffmpeg.org>, softworkz <softworkz@hotmail.com>, Andreas Rheinhardt <andreas.rheinhardt@outlook.com> Subject: [FFmpeg-devel] [PATCH v2 0/2] avformat/hls demuxer: Add WebVTT subtitle support Date: Fri, 21 Feb 2025 15:13:20 +0000 Message-ID: <pull.53.v2.ffstaging.FFmpeg.1740150802.ffmpegagent@gmail.com> (raw) In-Reply-To: <pull.53.ffstaging.FFmpeg.1739974227.ffmpegagent@gmail.com> This add support for WebVTT subtitles in HLS streams. similar like for separate audio streams, it supports all available WebVTT streams in all renditions. No new options are added, it just works and provides subtitles streams like other demuxers. The code prevents downloading subtitle segments which are much farther in the future than the main segments to avoid loading hundreds of subtitle segments in advance. orig, 2022/10; scenarios tested: ffmpeg transcoding, ffprobe, MPV player Example command for testing: ffmpeg -i https://playertest.longtailvideo.com/adaptive/elephants_dream_v4/index.m3u8 -map v:0 -map a:0 -map s:1 -map s:0 -c:v copy -c:a copy -c:s srt -to 120s test1.mkv ...produces an MKV with two SRT sub tracks from WebVTT subs via HLS. Update V2 * Remove unnecessary assignment * Fixed indentation, reorder if-block * Inline string constant in code (as per review by Andreas Reinhardt) softworkz (2): avformat/hls demuxer: Add WebVTT subtitle support avformat/webvttdec: Add webvtt extension and MIME type libavformat/hls.c | 213 +++++++++++++++++++++++++++++++++------- libavformat/webvttdec.c | 3 +- 2 files changed, 178 insertions(+), 38 deletions(-) base-commit: e18f87ed9f9f61c980420b315dc8ecb308831bc5 Published-As: https://github.com/ffstaging/FFmpeg/releases/tag/pr-ffstaging-53%2Fsoftworkz%2Fsubmit_hlsvtt-v2 Fetch-It-Via: git fetch https://github.com/ffstaging/FFmpeg pr-ffstaging-53/softworkz/submit_hlsvtt-v2 Pull-Request: https://github.com/ffstaging/FFmpeg/pull/53 Range-diff vs v1: 1: c2e1404a42 ! 1: 3f9ee79232 avformat/hls demuxer: Add WebVTT subtitle support @@ Commit message Signed-off-by: softworkz <softworkz@hotmail.com> ## libavformat/hls.c ## -@@ - #define MPEG_TIME_BASE 90000 - #define MPEG_TIME_BASE_Q (AVRational){1, MPEG_TIME_BASE} - -+static char *vtt_sample = "WEBVTT\n"; -+ - /* - * An apple http stream consists of a playlist with media segment files, - * played sequentially. There may be several playlists with the same @@ libavformat/hls.c: struct playlist { * playlist, if any. */ int n_init_sections; @@ libavformat/hls.c: struct playlist { }; /* -@@ libavformat/hls.c: static struct playlist *new_playlist(HLSContext *c, const char *url, - return NULL; - } - pls->seek_timestamp = AV_NOPTS_VALUE; -+ pls->is_subtitle = 0; - - pls->is_id3_timestamped = -1; - pls->id3_mpegts_timestamp = AV_NOPTS_VALUE; @@ libavformat/hls.c: static struct rendition *new_rendition(HLSContext *c, struct rendition_info *inf return NULL; } @@ libavformat/hls.c: static struct rendition *new_rendition(HLSContext *c, struct rend->playlist = new_playlist(c, info->uri, url_base); - if (rend->playlist) + if (rend->playlist) { - dynarray_add(&rend->playlist->renditions, -- &rend->playlist->n_renditions, rend); -+ &rend->playlist->n_renditions, rend); + if (type == AVMEDIA_TYPE_SUBTITLE) { + rend->playlist->is_subtitle = 1; + rend->playlist->is_id3_timestamped = 0; + } + dynarray_add(&rend->playlist->renditions, + &rend->playlist->n_renditions, rend); + } } @@ libavformat/hls.c: reload: + } + return ret; +} -+ + +static int read_data_continuous(void *opaque, uint8_t *buf, int buf_size) +{ + struct playlist *v = opaque; @@ libavformat/hls.c: reload: + ret = reload_playlist(v, c); + if (ret < 0) + return ret; - ++ + seg = current_segment(v); + + if (!v->input || (c->http_persistent && v->input_read_done)) { @@ libavformat/hls.c: static int hls_read_header(AVFormatContext *s) - ffio_init_context(&pls->pb, pls->read_buffer, INITIAL_BUFFER_SIZE, 0, pls, - read_data, NULL, NULL); + if (pls->is_subtitle) -+ ffio_init_context(&pls->pb, (unsigned char*)av_strdup(vtt_sample), (int)strlen(vtt_sample), 0, pls, -+ NULL, NULL, NULL); ++ ffio_init_context(&pls->pb, (unsigned char*)av_strdup("WEBVTT\n"), (int)strlen("WEBVTT\n"), 0, pls, ++ NULL, NULL, NULL); + else + ffio_init_context(&pls->pb, pls->read_buffer, INITIAL_BUFFER_SIZE, 0, pls, + read_data_continuous, NULL, NULL); 2: aff0dd2be2 = 2: 7550e41042 avformat/webvttdec: Add webvtt extension and MIME type -- ffmpeg-codebot _______________________________________________ ffmpeg-devel mailing list ffmpeg-devel@ffmpeg.org https://ffmpeg.org/mailman/listinfo/ffmpeg-devel To unsubscribe, visit link above, or email ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".
next prev parent reply other threads:[~2025-02-21 15:13 UTC|newest] Thread overview: 9+ messages / expand[flat|nested] mbox.gz Atom feed top 2025-02-19 14:10 [FFmpeg-devel] [PATCH " ffmpegagent 2025-02-19 14:10 ` [FFmpeg-devel] [PATCH 1/2] " softworkz 2025-02-21 9:18 ` Andreas Rheinhardt 2025-02-21 9:23 ` Soft Works 2025-02-21 11:56 ` Soft Works 2025-02-19 14:10 ` [FFmpeg-devel] [PATCH 2/2] avformat/webvttdec: Add webvtt extension and MIME type softworkz 2025-02-21 15:13 ` ffmpegagent [this message] 2025-02-21 15:13 ` [FFmpeg-devel] [PATCH v2 1/2] avformat/hls demuxer: Add WebVTT subtitle support softworkz 2025-02-21 15:13 ` [FFmpeg-devel] [PATCH v2 2/2] avformat/webvttdec: Add webvtt extension and MIME type softworkz
Reply instructions: You may reply publicly to this message via plain-text email using any one of the following methods: * Save the following mbox file, import it into your mail client, and reply-to-all from there: mbox Avoid top-posting and favor interleaved quoting: https://en.wikipedia.org/wiki/Posting_style#Interleaved_style * Reply using the --to, --cc, and --in-reply-to switches of git-send-email(1): git send-email \ --in-reply-to=pull.53.v2.ffstaging.FFmpeg.1740150802.ffmpegagent@gmail.com \ --to=ffmpegagent@gmail.com \ --cc=andreas.rheinhardt@outlook.com \ --cc=ffmpeg-devel@ffmpeg.org \ --cc=softworkz-at-hotmail.com@ffmpeg.org \ --cc=softworkz@hotmail.com \ /path/to/YOUR_REPLY https://kernel.org/pub/software/scm/git/docs/git-send-email.html * If your mail client supports setting the In-Reply-To header via mailto: links, try the mailto: link
Git Inbox Mirror of the ffmpeg-devel mailing list - see https://ffmpeg.org/mailman/listinfo/ffmpeg-devel This inbox may be cloned and mirrored by anyone: git clone --mirror https://master.gitmailbox.com/ffmpegdev/0 ffmpegdev/git/0.git # If you have public-inbox 1.1+ installed, you may # initialize and index your mirror using the following commands: public-inbox-init -V2 ffmpegdev ffmpegdev/ https://master.gitmailbox.com/ffmpegdev \ ffmpegdev@gitmailbox.com public-inbox-index ffmpegdev Example config snippet for mirrors. AGPL code for this site: git clone https://public-inbox.org/public-inbox.git