[FFmpeg-devel] [PATCH] drawtext: ignore last newline
I created this issue on the bugtracker: https://trac.ffmpeg.org/ticket/7948 Here is now a patch for it. drawtext should ignore the very last newline character in text files, because many editor add automatically a newline at the end. But when the filter draws a box behind the text, the box become to big. What do you think about this solution? From 9a4fa45a74c95d1a56a29dafe6c5c727d83c143c Mon Sep 17 00:00:00 2001 From: jonathan Date: Mon, 10 Jun 2019 17:44:03 +0200 Subject: [PATCH] ignore last newline --- libavfilter/vf_drawtext.c | 6 -- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/libavfilter/vf_drawtext.c b/libavfilter/vf_drawtext.c index 01cd7fa122..e8c33596e9 100644 --- a/libavfilter/vf_drawtext.c +++ b/libavfilter/vf_drawtext.c @@ -1380,8 +1380,10 @@ static int draw_text(AVFilterContext *ctx, AVFrame *frame, for (i = 0, p = text; *p; i++) { GET_UTF8(code, *p++, continue;); -/* skip the \n in the sequence \r\n */ -if (prev_code == '\r' && code == '\n') +/* skip the \n in the sequence \r\n and ignore last empty line */ +if ((prev_code == '\r' && code == '\n') || +(code == '\n' && i == len - 1) || +(code == '\r' && i == len - 2)) continue; prev_code = code; -- 2.21.0 ___ ffmpeg-devel mailing list ffmpeg-devel@ffmpeg.org https://ffmpeg.org/mailman/listinfo/ffmpeg-devel To unsubscribe, visit link above, or email ffmpeg-devel-requ...@ffmpeg.org with subject "unsubscribe".
Re: [FFmpeg-devel] [PATCH] drawtext: ignore last newline
Am 10.06.2019 um 19:14 schrieb Gyan: On 10-06-2019 09:24 PM, Jonathan Baecker wrote: I created this issue on the bugtracker: https://trac.ffmpeg.org/ticket/7948 Here is now a patch for it. drawtext should ignore the very last newline character in text files, because many editor add automatically a newline at the end. Some users may want to deliberately expand the box, so this should not be forced. Then you have the box double so high then it should and most of the free space under the text, but if you want this - a blank space would be enough. Anyway what would be your suggestion? It don't have to be like this, I only though it is more intuitive. What do you think about this solution? - /* skip the \n in the sequence \r\n */ - if (prev_code == '\r' && code == '\n') + /* skip the \n in the sequence \r\n and ignore last empty line */ + if ((prev_code == '\r' && code == '\n') || + (code == '\n' && i == len - 1) || + (code == '\r' && i == len - 2)) I believe this will keep the last line on Mac-style text files. Ok thanks for the hint, tomorrow I can test it on macOS and change it. Gyan ___ ffmpeg-devel mailing list ffmpeg-devel@ffmpeg.org https://ffmpeg.org/mailman/listinfo/ffmpeg-devel To unsubscribe, visit link above, or email ffmpeg-devel-requ...@ffmpeg.org with subject "unsubscribe". ___ ffmpeg-devel mailing list ffmpeg-devel@ffmpeg.org https://ffmpeg.org/mailman/listinfo/ffmpeg-devel To unsubscribe, visit link above, or email ffmpeg-devel-requ...@ffmpeg.org with subject "unsubscribe".
[FFmpeg-devel] [Patch v2] drawtext: ignore last newline
This is a new version from my last patch. As Gyan suggested it is now optional to skip/trim the last line break. From 8d31aab97ceaaec4947e1628e2ff1391dd77d4b2 Mon Sep 17 00:00:00 2001 From: Jonathan Baecker Date: Tue, 11 Jun 2019 14:33:50 +0200 Subject: [PATCH] trim last empty line --- libavfilter/vf_drawtext.c | 16 +++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/libavfilter/vf_drawtext.c b/libavfilter/vf_drawtext.c index 01cd7fa12..22ec870ed 100644 --- a/libavfilter/vf_drawtext.c +++ b/libavfilter/vf_drawtext.c @@ -139,7 +139,7 @@ typedef struct DrawTextContext { int exp_mode; ///< expansion mode to use for the text int reinit; ///< tells if the filter is being reinited #if CONFIG_LIBFONTCONFIG -uint8_t *font; ///< font to be used +uint8_t *font; ///< font to be used #endif uint8_t *fontfile; ///< font to be used uint8_t *text; ///< text to be drawn @@ -162,6 +162,7 @@ typedef struct DrawTextContext { unsigned int default_fontsize; ///< default font size to use int line_spacing; ///< lines spacing in pixels +int trim_end; ///< skip last empty line - true/false short int draw_box; ///< draw box around text - true or false int boxborderw; ///< box border width int use_kerning;///< font kerning is used - true/false @@ -211,6 +212,7 @@ static const AVOption drawtext_options[]= { {"boxcolor","set box color",OFFSET(boxcolor.rgba), AV_OPT_TYPE_COLOR, {.str="white"}, CHAR_MIN, CHAR_MAX, FLAGS}, {"bordercolor", "set border color", OFFSET(bordercolor.rgba), AV_OPT_TYPE_COLOR, {.str="black"}, CHAR_MIN, CHAR_MAX, FLAGS}, {"shadowcolor", "set shadow color", OFFSET(shadowcolor.rgba), AV_OPT_TYPE_COLOR, {.str="black"}, CHAR_MIN, CHAR_MAX, FLAGS}, +{"trim_end","trim last empty line", OFFSET(trim_end), AV_OPT_TYPE_BOOL, {.i64=0}, 0,1 , FLAGS}, {"box", "set box", OFFSET(draw_box), AV_OPT_TYPE_BOOL, {.i64=0}, 0,1 , FLAGS}, {"boxborderw", "set box border width", OFFSET(boxborderw), AV_OPT_TYPE_INT,{.i64=0}, INT_MIN, INT_MAX , FLAGS}, {"line_spacing", "set line spacing in pixels", OFFSET(line_spacing), AV_OPT_TYPE_INT,{.i64=0}, INT_MIN, INT_MAX,FLAGS}, @@ -1377,6 +1379,18 @@ static int draw_text(AVFilterContext *ctx, AVFrame *frame, /* compute and save position for each glyph */ glyph = NULL; + +if (s->trim_end) { +/* skip last newline character */ +char * last = text + len - 1; +char * second_last = text + len - 2; + +if (*second_last == '\r' && *last == '\n') +*second_last = 0; +else if (*last == '\r' || *last == '\n') +*last = 0; +} + for (i = 0, p = text; *p; i++) { GET_UTF8(code, *p++, continue;); -- 2.21.0 ___ ffmpeg-devel mailing list ffmpeg-devel@ffmpeg.org https://ffmpeg.org/mailman/listinfo/ffmpeg-devel To unsubscribe, visit link above, or email ffmpeg-devel-requ...@ffmpeg.org with subject "unsubscribe".
[FFmpeg-devel] [PATCH v2] libavfilter/vf_blackdetect.c
Hello! I wanted to apologize for the mess! Last Monday I already sended this patch, but the first was not correct, and on top the email format was not right to. So I hope now everything is ok. Here is again the description: This patch unify vf_blackdetect with af_silencedetect. Now the logging prints *black_start* and *black_end* in separate lines. This is the same behavior like af_silencedetect and it is also more useful for monitoring stream. It works in that way, that when the black duration passes the duration limit the log massage is: *black_start: 7.56 *and when the last black frame comes, the massage: *black_end: 25 | black_duration: 17.44 *pop up. I did compiling tests on MacOS/Windows and Ubuntu, all works fine. I also make a fate test, it runs to, but I was not able to run this command: tests/fate.sh fate-suite/ It always says something with path not fund... Is it really necessary to run a fate test, even with a little change like this? Regards Jonathan From b6b6e4ab885f9b35a6696492286e504a4b3d6d92 Mon Sep 17 00:00:00 2001 From: Jonathan Date: Mon, 4 Dec 2017 16:05:48 +0100 Subject: [PATCH] unify blackdetect with af_silencedetect. Is more useful for monitoring streams. --- libavfilter/vf_blackdetect.c | 22 +++--- 1 file changed, 15 insertions(+), 7 deletions(-) diff --git a/libavfilter/vf_blackdetect.c b/libavfilter/vf_blackdetect.c index 06ef9988d..92ea39b33 100644 --- a/libavfilter/vf_blackdetect.c +++ b/libavfilter/vf_blackdetect.c @@ -38,6 +38,7 @@ typedef struct BlackDetectContext { int64_t black_end; ///< pts end time of the last black picture int64_t last_picref_pts; ///< pts of the last input picture int black_started; +int black_match; double picture_black_ratio_th; double pixel_black_th; @@ -107,15 +108,20 @@ static int config_input(AVFilterLink *inlink) return 0; } -static void check_black_end(AVFilterContext *ctx) +static void check_black(AVFilterContext *ctx) { BlackDetectContext *blackdetect = ctx->priv; AVFilterLink *inlink = ctx->inputs[0]; -if ((blackdetect->black_end - blackdetect->black_start) >= blackdetect->black_min_duration) { +if ((blackdetect->last_picref_pts - blackdetect->black_start) >= blackdetect->black_min_duration && blackdetect->black_match == 0) { av_log(blackdetect, AV_LOG_INFO, - "black_start:%s black_end:%s black_duration:%s\n", - av_ts2timestr(blackdetect->black_start, &inlink->time_base), + "black_start: %s \n", + av_ts2timestr(blackdetect->black_start, &inlink->time_base)); +blackdetect->black_match = 1; +} +if ((blackdetect->black_end - blackdetect->black_start) >= blackdetect->black_min_duration && blackdetect->black_started == 1) { +av_log(blackdetect, AV_LOG_INFO, + "black_end: %s | black_duration: %s \n", av_ts2timestr(blackdetect->black_end, &inlink->time_base), av_ts2timestr(blackdetect->black_end - blackdetect->black_start, &inlink->time_base)); } @@ -131,7 +137,7 @@ static int request_frame(AVFilterLink *outlink) if (ret == AVERROR_EOF && blackdetect->black_started) { // FIXME: black_end should be set to last_picref_pts + last_picref_duration blackdetect->black_end = blackdetect->last_picref_pts; -check_black_end(ctx); +check_black(ctx); } return ret; } @@ -163,15 +169,17 @@ static int filter_frame(AVFilterLink *inlink, AVFrame *picref) if (!blackdetect->black_started) { /* black starts here */ blackdetect->black_started = 1; +blackdetect->black_match = 0; blackdetect->black_start = picref->pts; av_dict_set(&picref->metadata, "lavfi.black_start", av_ts2timestr(blackdetect->black_start, &inlink->time_base), 0); } +check_black(ctx); } else if (blackdetect->black_started) { /* black ends here */ -blackdetect->black_started = 0; blackdetect->black_end = picref->pts; -check_black_end(ctx); +check_black(ctx); +blackdetect->black_started = 0; av_dict_set(&picref->metadata, "lavfi.black_end", av_ts2timestr(blackdetect->black_end, &inlink->time_base), 0); } -- 2.15.1 ___ ffmpeg-devel mailing list ffmpeg-devel@ffmpeg.org http://ffmpeg.org/mailman/listinfo/ffmpeg-devel
Re: [FFmpeg-devel] [PATCH v2] libavfilter/vf_blackdetect.c
Am 10.12.2017 um 13:48 schrieb Carl Eugen Hoyos: 2017-12-09 19:28 GMT+01:00 Jonathan Baecker : -static void check_black_end(AVFilterContext *ctx) +static void check_black(AVFilterContext *ctx) Why do you rename this function? I rename them because before the function only got called, if the last black frame passes. Now the function get called already when the first black frame comes. So for me are more generic name is more logic. But if you want I can change them back! Please remove the superfluous brackets in the "if()" you change. I did not touch them, but yes I will remove them! Thanks for command! ___ ffmpeg-devel mailing list ffmpeg-devel@ffmpeg.org http://ffmpeg.org/mailman/listinfo/ffmpeg-devel
[FFmpeg-devel] [PATCH v3] libavfilter/vf_blackdetect.c
Here the cleanup version from the patch. From b6b6e4ab885f9b35a6696492286e504a4b3d6d92 Mon Sep 17 00:00:00 2001 From: Jonathan Date: Mon, 4 Dec 2017 16:05:48 +0100 Subject: [PATCH] unify blackdetect with af_silencedetect. Is more useful for monitoring streams. --- libavfilter/vf_blackdetect.c | 22 +++--- 1 file changed, 15 insertions(+), 7 deletions(-) diff --git a/libavfilter/vf_blackdetect.c b/libavfilter/vf_blackdetect.c index 06ef9988d..92ea39b33 100644 --- a/libavfilter/vf_blackdetect.c +++ b/libavfilter/vf_blackdetect.c @@ -38,6 +38,7 @@ typedef struct BlackDetectContext { int64_t black_end; ///< pts end time of the last black picture int64_t last_picref_pts; ///< pts of the last input picture int black_started; +int black_match; double picture_black_ratio_th; double pixel_black_th; @@ -107,15 +108,20 @@ static int config_input(AVFilterLink *inlink) return 0; } -static void check_black_end(AVFilterContext *ctx) +static void check_black(AVFilterContext *ctx) { BlackDetectContext *blackdetect = ctx->priv; AVFilterLink *inlink = ctx->inputs[0]; -if ((blackdetect->black_end - blackdetect->black_start) >= blackdetect->black_min_duration) { +if (blackdetect->last_picref_pts - blackdetect->black_start >= blackdetect->black_min_duration && blackdetect->black_match == 0) { av_log(blackdetect, AV_LOG_INFO, - "black_start:%s black_end:%s black_duration:%s\n", - av_ts2timestr(blackdetect->black_start, &inlink->time_base), + "black_start:%s\n", + av_ts2timestr(blackdetect->black_start, &inlink->time_base)); +blackdetect->black_match = 1; +} +if (blackdetect->black_end - blackdetect->black_start >= blackdetect->black_min_duration && blackdetect->black_started == 1) { +av_log(blackdetect, AV_LOG_INFO, + "black_end:%s | black_duration:%s\n", av_ts2timestr(blackdetect->black_end, &inlink->time_base), av_ts2timestr(blackdetect->black_end - blackdetect->black_start, &inlink->time_base)); } @@ -131,7 +137,7 @@ static int request_frame(AVFilterLink *outlink) if (ret == AVERROR_EOF && blackdetect->black_started) { // FIXME: black_end should be set to last_picref_pts + last_picref_duration blackdetect->black_end = blackdetect->last_picref_pts; -check_black_end(ctx); +check_black(ctx); } return ret; } @@ -163,15 +169,17 @@ static int filter_frame(AVFilterLink *inlink, AVFrame *picref) if (!blackdetect->black_started) { /* black starts here */ blackdetect->black_started = 1; +blackdetect->black_match = 0; blackdetect->black_start = picref->pts; av_dict_set(&picref->metadata, "lavfi.black_start", av_ts2timestr(blackdetect->black_start, &inlink->time_base), 0); } +check_black(ctx); } else if (blackdetect->black_started) { /* black ends here */ -blackdetect->black_started = 0; blackdetect->black_end = picref->pts; -check_black_end(ctx); +check_black(ctx); +blackdetect->black_started = 0; av_dict_set(&picref->metadata, "lavfi.black_end", av_ts2timestr(blackdetect->black_end, &inlink->time_base), 0); } -- 2.15.1 ___ ffmpeg-devel mailing list ffmpeg-devel@ffmpeg.org http://ffmpeg.org/mailman/listinfo/ffmpeg-devel
Re: [FFmpeg-devel] [PATCH v3] libavfilter/vf_blackdetect.c
Hello, after my last update, I got not any response. Is there still something wrong with the patch? Regards Jonathan ___ ffmpeg-devel mailing list ffmpeg-devel@ffmpeg.org http://ffmpeg.org/mailman/listinfo/ffmpeg-devel
Re: [FFmpeg-devel] [PATCH] libavformat/hlsplaylist: add subtitle_varname for naming subtitle streams
Am 04.10.24 um 12:09 schrieb Steven Liu: Jonathan Baecker 于2024年9月29日周日 05:56写道: If 'sname:*' is set in the var_stream_map variable, use it as the NAME attribute for subtitles. This improves the naming of subtitle streams in HTML players, providing clearer and more descriptive labels for users. --- doc/muxers.texi | 5 +++-- libavformat/hlsenc.c | 7 ++- libavformat/hlsplaylist.c | 9 +++-- libavformat/hlsplaylist.h | 2 +- 4 files changed, 17 insertions(+), 6 deletions(-) diff --git a/doc/muxers.texi b/doc/muxers.texi index ce93ba1488..04b7f20b7e 100644 --- a/doc/muxers.texi +++ b/doc/muxers.texi @@ -2436,13 +2436,14 @@ ffmpeg -re -i in.ts -b:a:0 32k -b:a:1 64k -b:v:0 1000k \ @item Create a single variant stream. Add the @code{#EXT-X-MEDIA} tag with @code{TYPE=SUBTITLES} in the master playlist with webvtt subtitle group name -'subtitle'. Make sure the input file has one text subtitle stream at least. +'subtitle' and optional subtitle name, e.g. 'English'. Make sure the input +file has one text subtitle stream at least. @example ffmpeg -y -i input_with_subtitle.mkv \ -b:v:0 5250k -c:v h264 -pix_fmt yuv420p -profile:v main -level 4.1 \ -b:a:0 256k \ -c:s webvtt -c:a mp2 -ar 48000 -ac 2 -map 0:v -map 0:a:0 -map 0:s:0 \ - -f hls -var_stream_map "v:0,a:0,s:0,sgroup:subtitle" \ + -f hls -var_stream_map "v:0,a:0,s:0,sgroup:subtitle,sname:English" \ -master_pl_name master.m3u8 -t 300 -hls_time 10 -hls_init_time 4 -hls_list_size \ 10 -master_pl_publish_rate 10 -hls_flags \ delete_segments+discont_start+split_by_time ./tmp/video.m3u8 diff --git a/libavformat/hlsenc.c b/libavformat/hlsenc.c index 1e932b7b0e..7b2145f5bf 100644 --- a/libavformat/hlsenc.c +++ b/libavformat/hlsenc.c @@ -189,6 +189,7 @@ typedef struct VariantStream { const char *sgroup; /* subtitle group name */ const char *ccgroup; /* closed caption group name */ const char *varname; /* variant name */ +const char *subtitle_varname; /* subtitle variant name */ } VariantStream; typedef struct ClosedCaptionsStream { @@ -1533,7 +1534,8 @@ static int create_master_playlist(AVFormatContext *s, break; } -ff_hls_write_subtitle_rendition(hls->m3u8_out, sgroup, vtt_m3u8_rel_name, vs->language, i, hls->has_default_key ? vs->is_default : 1); +ff_hls_write_subtitle_rendition(hls->m3u8_out, sgroup, vtt_m3u8_rel_name, vs->language, +vs->subtitle_varname, i, hls->has_default_key ? vs->is_default : 1); } if (!hls->has_default_key || !hls->has_video_m3u8) { @@ -2107,6 +2109,9 @@ static int parse_variant_stream_mapstring(AVFormatContext *s) } else if (av_strstart(keyval, "name:", &val)) { vs->varname = val; continue; +} else if (av_strstart(keyval, "sname:", &val)) { +vs->subtitle_varname = val; +continue; } else if (av_strstart(keyval, "agroup:", &val)) { vs->agroup = val; continue; diff --git a/libavformat/hlsplaylist.c b/libavformat/hlsplaylist.c index f8a6977702..17b93a5ef1 100644 --- a/libavformat/hlsplaylist.c +++ b/libavformat/hlsplaylist.c @@ -57,13 +57,18 @@ void ff_hls_write_audio_rendition(AVIOContext *out, const char *agroup, void ff_hls_write_subtitle_rendition(AVIOContext *out, const char *sgroup, const char *filename, const char *language, - int name_id, int is_default) + const char *sname, int name_id, int is_default) { if (!out || !filename) return; avio_printf(out, "#EXT-X-MEDIA:TYPE=SUBTITLES,GROUP-ID=\"%s\"", sgroup); -avio_printf(out, ",NAME=\"subtitle_%d\",DEFAULT=%s,", name_id, is_default ? "YES" : "NO"); +if (sname) { +avio_printf(out, ",NAME=\"%s\",", sname); +} else { +avio_printf(out, ",NAME=\"subtitle_%d\",", name_id); +} +avio_printf(out, "DEFAULT=%s,", is_default ? "YES" : "NO"); if (language) { avio_printf(out, "LANGUAGE=\"%s\",", language); } diff --git a/libavformat/hlsplaylist.h b/libavformat/hlsplaylist.h index d7aa44d8dc..ec44e5a0ae 100644 --- a/libavformat/hlsplaylist.h +++ b/libavformat/hlsplaylist.h @@ -41,7 +41,7 @@ void ff_hls_write_audio_rendition(AVIOContext *out, const char *agroup, int name_id, int is_default, int nb_channels); void ff_hls_write_subtitle_rendition(AVIOContext *out, const char *sgroup, const char *filename,
Re: [FFmpeg-devel] [PATCH v3] avformat/hlsenc: Respect `omit_endlist` flag in subtitle playlists
Am 04.10.24 um 12:06 schrieb Steven Liu: Jonathan Baecker 于2024年10月1日周二 07:56写道: This modification applies Steven's suggestion. Original description was: Ensure that when the `-hls_flags omit_endlist` option is set, the `#EXT-X-ENDLIST` tag is also omitted from the `stream_vtt.m3u8` subtitle playlist. This maintains consistency with the behavior in other playlists when `omit_endlist` is specified. --- libavformat/hlsenc.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libavformat/hlsenc.c b/libavformat/hlsenc.c index 571d6b2752..c258fc812d 100644 --- a/libavformat/hlsenc.c +++ b/libavformat/hlsenc.c @@ -1676,7 +1676,7 @@ static int hls_window(AVFormatContext *s, int last, VariantStream *vs) } } -if (last) +if (last && !(hls->flags & HLS_OMIT_ENDLIST)) ff_hls_write_end_list(hls->sub_m3u8_out); } -- 2.46.2 ___ ffmpeg-devel mailing list ffmpeg-devel@ffmpeg.org https://ffmpeg.org/mailman/listinfo/ffmpeg-devel To unsubscribe, visit link above, or email ffmpeg-devel-requ...@ffmpeg.org with subject "unsubscribe". lgtm Thanks Steven This one to, please. Thank you! ___ ffmpeg-devel mailing list ffmpeg-devel@ffmpeg.org https://ffmpeg.org/mailman/listinfo/ffmpeg-devel To unsubscribe, visit link above, or email ffmpeg-devel-requ...@ffmpeg.org with subject "unsubscribe".
Re: [FFmpeg-devel] [PATCH v3] avformat/hlsenc: Respect `append_list` flag in subtitle
Am 04.10.24 um 12:06 schrieb Steven Liu: Jonathan Baecker 于2024年10月1日周二 03:51写道: Apply Stevens suggestion. Original description: Ensure that when the `-hls_flags append_list` option is set, that *.vtt files in stream_vtt.m3u8 are correctly updated. This fixes https://trac.ffmpeg.org/ticket/11208 --- libavformat/hlsenc.c | 30 ++ 1 file changed, 30 insertions(+) diff --git a/libavformat/hlsenc.c b/libavformat/hlsenc.c index 571d6b2752..8d4322796d 100644 --- a/libavformat/hlsenc.c +++ b/libavformat/hlsenc.c @@ -1202,6 +1202,22 @@ static int hls_append_segment(struct AVFormatContext *s, HLSContext *hls, return 0; } +static int extract_segment_number(const char *filename) { +const char *dot = strrchr(filename, '.'); +const char *num_start = dot - 1; + +while (num_start > filename && *num_start >= '0' && *num_start <= '9') { +num_start--; +} + +num_start++; + +if (num_start == dot) +return -1; + +return atoi(num_start); +} + static int parse_playlist(AVFormatContext *s, const char *url, VariantStream *vs) { HLSContext *hls = s->priv_data; @@ -1295,6 +1311,20 @@ static int parse_playlist(AVFormatContext *s, const char *url, VariantStream *vs goto fail; } ff_format_set_url(vs->avf, new_file); + +if (vs->has_subtitle) { +int vtt_index = extract_segment_number(line); +const char *vtt_basename = av_basename(vs->vtt_basename); +int len = strlen(vtt_basename) + 11; +char *vtt_file = av_mallocz(len); +if (!vtt_file) { +ret = AVERROR(ENOMEM); +goto fail; +} +snprintf(vtt_file, len, vtt_basename, vtt_index); +ff_format_set_url(vs->vtt_avf, vtt_file); +} + is_segment = 0; new_start_pos = avio_tell(vs->avf->pb); vs->size = new_start_pos - vs->start_pos; -- 2.46.2 ___ ffmpeg-devel mailing list ffmpeg-devel@ffmpeg.org https://ffmpeg.org/mailman/listinfo/ffmpeg-devel To unsubscribe, visit link above, or email ffmpeg-devel-requ...@ffmpeg.org with subject "unsubscribe". LGTM Will apply after 48 hours if no more comments. Thanks Steven And the last one :-). Thanks Steven and have a good week! ___ ffmpeg-devel mailing list ffmpeg-devel@ffmpeg.org https://ffmpeg.org/mailman/listinfo/ffmpeg-devel To unsubscribe, visit link above, or email ffmpeg-devel-requ...@ffmpeg.org with subject "unsubscribe".
[FFmpeg-devel] [PATCH] avformat/hlsenc: Fix missing EXT-X-DISCONTINUITY tag in subtitle streams
The EXT-X-DISCONTINUITY tag was not being added to subtitle streams, causing synchronization issues. This patch ensures that the tag is applied consistently across video and subtitle streams. --- libavformat/hlsenc.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libavformat/hlsenc.c b/libavformat/hlsenc.c index 1e932b7..571d6b2 100644 --- a/libavformat/hlsenc.c +++ b/libavformat/hlsenc.c @@ -1668,7 +1668,7 @@ static int hls_window(AVFormatContext *s, int last, VariantStream *vs) ff_hls_write_playlist_header(hls->sub_m3u8_out, hls->version, hls->allowcache, target_duration, sequence, PLAYLIST_TYPE_NONE, 0); for (en = vs->segments; en; en = en->next) { -ret = ff_hls_write_file_entry(hls->sub_m3u8_out, 0, byterange_mode, +ret = ff_hls_write_file_entry(hls->sub_m3u8_out, en->discont, byterange_mode, en->duration, 0, en->size, en->pos, hls->baseurl, en->sub_filename, NULL, 0, 0, 0); if (ret < 0) { -- 2.46.1 ___ ffmpeg-devel mailing list ffmpeg-devel@ffmpeg.org https://ffmpeg.org/mailman/listinfo/ffmpeg-devel To unsubscribe, visit link above, or email ffmpeg-devel-requ...@ffmpeg.org with subject "unsubscribe".
[FFmpeg-devel] [PATCH] avformat/hlsplaylist: set stream name according to var_stream_map varname
From: jb-alvarado If name:* is set in var_stream_map variable, take that as NAME= variable. This helps gives better stream names in html players. --- libavformat/hlsenc.c | 2 +- libavformat/hlsplaylist.c | 9 +++-- libavformat/hlsplaylist.h | 2 +- 3 files changed, 9 insertions(+), 4 deletions(-) diff --git a/libavformat/hlsenc.c b/libavformat/hlsenc.c index 1e932b7..8e01721 100644 --- a/libavformat/hlsenc.c +++ b/libavformat/hlsenc.c @@ -1533,7 +1533,7 @@ static int create_master_playlist(AVFormatContext *s, break; } -ff_hls_write_subtitle_rendition(hls->m3u8_out, sgroup, vtt_m3u8_rel_name, vs->language, i, hls->has_default_key ? vs->is_default : 1); +ff_hls_write_subtitle_rendition(hls->m3u8_out, sgroup, vtt_m3u8_rel_name, vs->language, vs->varname, i, hls->has_default_key ? vs->is_default : 1); } if (!hls->has_default_key || !hls->has_video_m3u8) { diff --git a/libavformat/hlsplaylist.c b/libavformat/hlsplaylist.c index f8a6977..2eedc32 100644 --- a/libavformat/hlsplaylist.c +++ b/libavformat/hlsplaylist.c @@ -57,13 +57,18 @@ void ff_hls_write_audio_rendition(AVIOContext *out, const char *agroup, void ff_hls_write_subtitle_rendition(AVIOContext *out, const char *sgroup, const char *filename, const char *language, - int name_id, int is_default) + const char *varname, int name_id, int is_default) { if (!out || !filename) return; avio_printf(out, "#EXT-X-MEDIA:TYPE=SUBTITLES,GROUP-ID=\"%s\"", sgroup); -avio_printf(out, ",NAME=\"subtitle_%d\",DEFAULT=%s,", name_id, is_default ? "YES" : "NO"); +if (varname) { +avio_printf(out, ",NAME=\"%s\",", varname); +} else { +avio_printf(out, ",NAME=\"subtitle_%d\",", name_id); +} +avio_printf(out, "DEFAULT=%s,", is_default ? "YES" : "NO"); if (language) { avio_printf(out, "LANGUAGE=\"%s\",", language); } diff --git a/libavformat/hlsplaylist.h b/libavformat/hlsplaylist.h index d7aa44d..f181182 100644 --- a/libavformat/hlsplaylist.h +++ b/libavformat/hlsplaylist.h @@ -41,7 +41,7 @@ void ff_hls_write_audio_rendition(AVIOContext *out, const char *agroup, int name_id, int is_default, int nb_channels); void ff_hls_write_subtitle_rendition(AVIOContext *out, const char *sgroup, const char *filename, const char *language, - int name_id, int is_default); + const char *varname, int name_id, int is_default); void ff_hls_write_stream_info(AVStream *st, AVIOContext *out, int bandwidth, int avg_bandwidth, const char *filename, const char *agroup, -- 2.46.1 ___ ffmpeg-devel mailing list ffmpeg-devel@ffmpeg.org https://ffmpeg.org/mailman/listinfo/ffmpeg-devel To unsubscribe, visit link above, or email ffmpeg-devel-requ...@ffmpeg.org with subject "unsubscribe".
[FFmpeg-devel] [PATCH] Respect `append_list` flag in subtitle playlists
Ensure that when the `-hls_flags append_list` option is set, that *.vtt files in stream_vtt.m3u8 are correctly updated. This fixes https://trac.ffmpeg.org/ticket/11208 This is a bit of an ugly fix, let me know what you think. --- libavformat/hlsenc.c | 37 + 1 file changed, 37 insertions(+) diff --git a/libavformat/hlsenc.c b/libavformat/hlsenc.c index 1e932b7..e93af4c 100644 --- a/libavformat/hlsenc.c +++ b/libavformat/hlsenc.c @@ -1202,6 +1202,22 @@ static int hls_append_segment(struct AVFormatContext *s, HLSContext *hls, return 0; } +static int extract_number(const char *filename) { +const char *dot = strrchr(filename, '.'); +const char *num_start = dot - 1; + +while (num_start > filename && *num_start >= '0' && *num_start <= '9') { +num_start--; +} + +num_start++; + +if (num_start == dot) +return -1; + +return atoi(num_start); +} + static int parse_playlist(AVFormatContext *s, const char *url, VariantStream *vs) { HLSContext *hls = s->priv_data; @@ -1294,6 +1310,27 @@ static int parse_playlist(AVFormatContext *s, const char *url, VariantStream *vs ret = AVERROR(ENOMEM); goto fail; } +if (vs->has_subtitle) { +int vtt_index = extract_number(line); +char *vtt_file = av_asprintf(av_basename(vs->vtt_basename), vtt_index); +char *new_vtt; + +if (!vtt_file) { +ret = AVERROR(ENOMEM); +goto fail; +} + +new_vtt = av_strdup(vtt_file); +av_free(vtt_file); + +if (!new_vtt) { +ret = AVERROR(ENOMEM); +goto fail; +} + +ff_format_set_url(vs->vtt_avf, new_vtt); +} + ff_format_set_url(vs->avf, new_file); is_segment = 0; new_start_pos = avio_tell(vs->avf->pb); -- 2.46.1 ___ ffmpeg-devel mailing list ffmpeg-devel@ffmpeg.org https://ffmpeg.org/mailman/listinfo/ffmpeg-devel To unsubscribe, visit link above, or email ffmpeg-devel-requ...@ffmpeg.org with subject "unsubscribe".
[FFmpeg-devel] [PATCH] Respect `omit_endlist` flag in subtitle playlists
Ensure that when the `-hls_flags omit_endlist` option is set, the `#EXT-X-ENDLIST` tag is also omitted from the `stream_vtt.m3u8` subtitle playlist. This maintains consistency with the behavior in other playlists when `omit_endlist` is specified. --- libavformat/hlsenc.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libavformat/hlsenc.c b/libavformat/hlsenc.c index 1e932b7..528ba0f 100644 --- a/libavformat/hlsenc.c +++ b/libavformat/hlsenc.c @@ -1676,7 +1676,7 @@ static int hls_window(AVFormatContext *s, int last, VariantStream *vs) } } -if (last) +if (last && (hls->flags & HLS_OMIT_ENDLIST)==0) ff_hls_write_end_list(hls->sub_m3u8_out); } -- 2.46.1 ___ ffmpeg-devel mailing list ffmpeg-devel@ffmpeg.org https://ffmpeg.org/mailman/listinfo/ffmpeg-devel To unsubscribe, visit link above, or email ffmpeg-devel-requ...@ffmpeg.org with subject "unsubscribe".
[FFmpeg-devel] [PATCH v2] avformat/hlsenc: Respect `omit_endlist` flag in subtitle playlists
Ensure that when the `-hls_flags omit_endlist` option is set, the `#EXT-X-ENDLIST` tag is also omitted from the `stream_vtt.m3u8` subtitle playlist. This maintains consistency with the behavior in other playlists when `omit_endlist` is specified. --- libavformat/hlsenc.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libavformat/hlsenc.c b/libavformat/hlsenc.c index 1e932b7..528ba0f 100644 --- a/libavformat/hlsenc.c +++ b/libavformat/hlsenc.c @@ -1676,7 +1676,7 @@ static int hls_window(AVFormatContext *s, int last, VariantStream *vs) } } -if (last) +if (last && (hls->flags & HLS_OMIT_ENDLIST)==0) ff_hls_write_end_list(hls->sub_m3u8_out); } -- 2.46.1 ___ ffmpeg-devel mailing list ffmpeg-devel@ffmpeg.org https://ffmpeg.org/mailman/listinfo/ffmpeg-devel To unsubscribe, visit link above, or email ffmpeg-devel-requ...@ffmpeg.org with subject "unsubscribe".
[FFmpeg-devel] [PATCH v2] avformat/hlsenc: Respect `append_list` flag in subtitle playlists
Ensure that when the `-hls_flags append_list` option is set, that *.vtt files in stream_vtt.m3u8 are correctly updated. This fixes https://trac.ffmpeg.org/ticket/11208 Is a bit of an ugly fix, let me know what you think. --- libavformat/hlsenc.c | 37 + 1 file changed, 37 insertions(+) diff --git a/libavformat/hlsenc.c b/libavformat/hlsenc.c index 1e932b7..e93af4c 100644 --- a/libavformat/hlsenc.c +++ b/libavformat/hlsenc.c @@ -1202,6 +1202,22 @@ static int hls_append_segment(struct AVFormatContext *s, HLSContext *hls, return 0; } +static int extract_number(const char *filename) { +const char *dot = strrchr(filename, '.'); +const char *num_start = dot - 1; + +while (num_start > filename && *num_start >= '0' && *num_start <= '9') { +num_start--; +} + +num_start++; + +if (num_start == dot) +return -1; + +return atoi(num_start); +} + static int parse_playlist(AVFormatContext *s, const char *url, VariantStream *vs) { HLSContext *hls = s->priv_data; @@ -1294,6 +1310,27 @@ static int parse_playlist(AVFormatContext *s, const char *url, VariantStream *vs ret = AVERROR(ENOMEM); goto fail; } +if (vs->has_subtitle) { +int vtt_index = extract_number(line); +char *vtt_file = av_asprintf(av_basename(vs->vtt_basename), vtt_index); +char *new_vtt; + +if (!vtt_file) { +ret = AVERROR(ENOMEM); +goto fail; +} + +new_vtt = av_strdup(vtt_file); +av_free(vtt_file); + +if (!new_vtt) { +ret = AVERROR(ENOMEM); +goto fail; +} + +ff_format_set_url(vs->vtt_avf, new_vtt); +} + ff_format_set_url(vs->avf, new_file); is_segment = 0; new_start_pos = avio_tell(vs->avf->pb); -- 2.46.1 ___ ffmpeg-devel mailing list ffmpeg-devel@ffmpeg.org https://ffmpeg.org/mailman/listinfo/ffmpeg-devel To unsubscribe, visit link above, or email ffmpeg-devel-requ...@ffmpeg.org with subject "unsubscribe".
[FFmpeg-devel] [PATCH] libavformat/hlsplaylist: add subtitle_varname for naming subtitle streams
If 'sname:*' is set in the var_stream_map variable, use it as the NAME attribute for subtitles. This improves the naming of subtitle streams in HTML players, providing clearer and more descriptive labels for users. --- doc/muxers.texi | 5 +++-- libavformat/hlsenc.c | 7 ++- libavformat/hlsplaylist.c | 9 +++-- libavformat/hlsplaylist.h | 2 +- 4 files changed, 17 insertions(+), 6 deletions(-) diff --git a/doc/muxers.texi b/doc/muxers.texi index ce93ba1488..04b7f20b7e 100644 --- a/doc/muxers.texi +++ b/doc/muxers.texi @@ -2436,13 +2436,14 @@ ffmpeg -re -i in.ts -b:a:0 32k -b:a:1 64k -b:v:0 1000k \ @item Create a single variant stream. Add the @code{#EXT-X-MEDIA} tag with @code{TYPE=SUBTITLES} in the master playlist with webvtt subtitle group name -'subtitle'. Make sure the input file has one text subtitle stream at least. +'subtitle' and optional subtitle name, e.g. 'English'. Make sure the input +file has one text subtitle stream at least. @example ffmpeg -y -i input_with_subtitle.mkv \ -b:v:0 5250k -c:v h264 -pix_fmt yuv420p -profile:v main -level 4.1 \ -b:a:0 256k \ -c:s webvtt -c:a mp2 -ar 48000 -ac 2 -map 0:v -map 0:a:0 -map 0:s:0 \ - -f hls -var_stream_map "v:0,a:0,s:0,sgroup:subtitle" \ + -f hls -var_stream_map "v:0,a:0,s:0,sgroup:subtitle,sname:English" \ -master_pl_name master.m3u8 -t 300 -hls_time 10 -hls_init_time 4 -hls_list_size \ 10 -master_pl_publish_rate 10 -hls_flags \ delete_segments+discont_start+split_by_time ./tmp/video.m3u8 diff --git a/libavformat/hlsenc.c b/libavformat/hlsenc.c index 1e932b7b0e..7b2145f5bf 100644 --- a/libavformat/hlsenc.c +++ b/libavformat/hlsenc.c @@ -189,6 +189,7 @@ typedef struct VariantStream { const char *sgroup; /* subtitle group name */ const char *ccgroup; /* closed caption group name */ const char *varname; /* variant name */ +const char *subtitle_varname; /* subtitle variant name */ } VariantStream; typedef struct ClosedCaptionsStream { @@ -1533,7 +1534,8 @@ static int create_master_playlist(AVFormatContext *s, break; } -ff_hls_write_subtitle_rendition(hls->m3u8_out, sgroup, vtt_m3u8_rel_name, vs->language, i, hls->has_default_key ? vs->is_default : 1); +ff_hls_write_subtitle_rendition(hls->m3u8_out, sgroup, vtt_m3u8_rel_name, vs->language, +vs->subtitle_varname, i, hls->has_default_key ? vs->is_default : 1); } if (!hls->has_default_key || !hls->has_video_m3u8) { @@ -2107,6 +2109,9 @@ static int parse_variant_stream_mapstring(AVFormatContext *s) } else if (av_strstart(keyval, "name:", &val)) { vs->varname = val; continue; +} else if (av_strstart(keyval, "sname:", &val)) { +vs->subtitle_varname = val; +continue; } else if (av_strstart(keyval, "agroup:", &val)) { vs->agroup = val; continue; diff --git a/libavformat/hlsplaylist.c b/libavformat/hlsplaylist.c index f8a6977702..17b93a5ef1 100644 --- a/libavformat/hlsplaylist.c +++ b/libavformat/hlsplaylist.c @@ -57,13 +57,18 @@ void ff_hls_write_audio_rendition(AVIOContext *out, const char *agroup, void ff_hls_write_subtitle_rendition(AVIOContext *out, const char *sgroup, const char *filename, const char *language, - int name_id, int is_default) + const char *sname, int name_id, int is_default) { if (!out || !filename) return; avio_printf(out, "#EXT-X-MEDIA:TYPE=SUBTITLES,GROUP-ID=\"%s\"", sgroup); -avio_printf(out, ",NAME=\"subtitle_%d\",DEFAULT=%s,", name_id, is_default ? "YES" : "NO"); +if (sname) { +avio_printf(out, ",NAME=\"%s\",", sname); +} else { +avio_printf(out, ",NAME=\"subtitle_%d\",", name_id); +} +avio_printf(out, "DEFAULT=%s,", is_default ? "YES" : "NO"); if (language) { avio_printf(out, "LANGUAGE=\"%s\",", language); } diff --git a/libavformat/hlsplaylist.h b/libavformat/hlsplaylist.h index d7aa44d8dc..ec44e5a0ae 100644 --- a/libavformat/hlsplaylist.h +++ b/libavformat/hlsplaylist.h @@ -41,7 +41,7 @@ void ff_hls_write_audio_rendition(AVIOContext *out, const char *agroup, int name_id, int is_default, int nb_channels); void ff_hls_write_subtitle_rendition(AVIOContext *out, const char *sgroup, const char *filename, const char *language, - int name_id, int is_default); + const char *sname, int name_id, int is_default); void ff_hls_write_stream_info(AVStream *st, AVIOContext *out, int bandwidth, int avg_bandwidth, const char *filename, const char *agroup, -- 2.46.1 _
[FFmpeg-devel] [PATCH v3] avformat/hlsenc: Respect `omit_endlist` flag in subtitle playlists
This modification applies Steven's suggestion. Original description was: Ensure that when the `-hls_flags omit_endlist` option is set, the `#EXT-X-ENDLIST` tag is also omitted from the `stream_vtt.m3u8` subtitle playlist. This maintains consistency with the behavior in other playlists when `omit_endlist` is specified. --- libavformat/hlsenc.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libavformat/hlsenc.c b/libavformat/hlsenc.c index 571d6b2752..c258fc812d 100644 --- a/libavformat/hlsenc.c +++ b/libavformat/hlsenc.c @@ -1676,7 +1676,7 @@ static int hls_window(AVFormatContext *s, int last, VariantStream *vs) } } -if (last) +if (last && !(hls->flags & HLS_OMIT_ENDLIST)) ff_hls_write_end_list(hls->sub_m3u8_out); } -- 2.46.2 ___ ffmpeg-devel mailing list ffmpeg-devel@ffmpeg.org https://ffmpeg.org/mailman/listinfo/ffmpeg-devel To unsubscribe, visit link above, or email ffmpeg-devel-requ...@ffmpeg.org with subject "unsubscribe".
[FFmpeg-devel] [PATCH v3] avformat/hlsenc: Respect `append_list` flag in subtitle
Apply Stevens suggestion. Original description: Ensure that when the `-hls_flags append_list` option is set, that *.vtt files in stream_vtt.m3u8 are correctly updated. This fixes https://trac.ffmpeg.org/ticket/11208 --- libavformat/hlsenc.c | 30 ++ 1 file changed, 30 insertions(+) diff --git a/libavformat/hlsenc.c b/libavformat/hlsenc.c index 571d6b2752..8d4322796d 100644 --- a/libavformat/hlsenc.c +++ b/libavformat/hlsenc.c @@ -1202,6 +1202,22 @@ static int hls_append_segment(struct AVFormatContext *s, HLSContext *hls, return 0; } +static int extract_segment_number(const char *filename) { +const char *dot = strrchr(filename, '.'); +const char *num_start = dot - 1; + +while (num_start > filename && *num_start >= '0' && *num_start <= '9') { +num_start--; +} + +num_start++; + +if (num_start == dot) +return -1; + +return atoi(num_start); +} + static int parse_playlist(AVFormatContext *s, const char *url, VariantStream *vs) { HLSContext *hls = s->priv_data; @@ -1295,6 +1311,20 @@ static int parse_playlist(AVFormatContext *s, const char *url, VariantStream *vs goto fail; } ff_format_set_url(vs->avf, new_file); + +if (vs->has_subtitle) { +int vtt_index = extract_segment_number(line); +const char *vtt_basename = av_basename(vs->vtt_basename); +int len = strlen(vtt_basename) + 11; +char *vtt_file = av_mallocz(len); +if (!vtt_file) { +ret = AVERROR(ENOMEM); +goto fail; +} +snprintf(vtt_file, len, vtt_basename, vtt_index); +ff_format_set_url(vs->vtt_avf, vtt_file); +} + is_segment = 0; new_start_pos = avio_tell(vs->avf->pb); vs->size = new_start_pos - vs->start_pos; -- 2.46.2 ___ ffmpeg-devel mailing list ffmpeg-devel@ffmpeg.org https://ffmpeg.org/mailman/listinfo/ffmpeg-devel To unsubscribe, visit link above, or email ffmpeg-devel-requ...@ffmpeg.org with subject "unsubscribe".