[FFmpeg-devel] Should setting disposition forced on a subtitle stream actually force it?
We are not currently able to force mov_text subtitles by setting -disposition:s:0 +forced or equivalent. Should this setting actually result in forced subtitles or is this a misapprehension of the meaning of this setting? Thanks ___ 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] libavcodec: Make disposition forced work with mov_text subtitles.
We are not currently able to force mov_text subtitles by setting -disposition:s:0 +forced or equivalent. By setting the forced flags in movtextenc as specifid in https://developer.apple.com/library/archive/documentation/QuickTime/QTFF/QTFFChap3/qtff3.html subtitles can be forced as expected in VLC and similar players. Copy AVStream disposition to AVCodecContext and use to set DISPLAY_FLAG_ALL_SAMPLES_FORCED in movtextenc.c. Signed-off-by: facefunk --- fftools/ffmpeg_mux_init.c | 5 + libavcodec/avcodec.h | 11 +++ libavcodec/movtextenc.c | 41 ++- 3 files changed, 56 insertions(+), 1 deletion(-) diff --git a/fftools/ffmpeg_mux_init.c b/fftools/ffmpeg_mux_init.c index 0280759b05..86cc304b71 100644 --- a/fftools/ffmpeg_mux_init.c +++ b/fftools/ffmpeg_mux_init.c @@ -1717,6 +1717,11 @@ static int set_dispositions(Muxer *mux, const OptionsContext *o) if (ret < 0) goto finish; + +// For output streams, Set subtitle flags to forced when stream +// disposition is forced. +if(ost->enc_ctx && ost->st->disposition & AV_DISPOSITION_FORCED) +ost->enc_ctx->subtitle_flags |= AV_SUBTITLE_FLAG_FORCED; } } else { // For each media type with more than one stream, find a suitable stream to diff --git a/libavcodec/avcodec.h b/libavcodec/avcodec.h index 0ac581d660..2735a1c847 100644 --- a/libavcodec/avcodec.h +++ b/libavcodec/avcodec.h @@ -2057,6 +2057,17 @@ typedef struct AVCodecContext { * The decoder can then override during decoding as needed. */ AVChannelLayout ch_layout; + +/** + * Subtitle codecs only. Bit set of AV_SUBTITLE_FLAG_*. + * + * Some subtitle codecs may use this field to determine the subtitle + * display flags to encode. + * + * - encoding: set by user + * - decoding: unused + */ +int subtitle_flags; } AVCodecContext; /** diff --git a/libavcodec/movtextenc.c b/libavcodec/movtextenc.c index 7aa74d7c9d..875e003fc4 100644 --- a/libavcodec/movtextenc.c +++ b/libavcodec/movtextenc.c @@ -50,6 +50,40 @@ #define FONTSIZE_SCALE(s,fs) ((fs) * (s)->font_scale_factor + 0.5) #define av_bprint_append_any(buf, data, size) av_bprint_append_data(buf, ((const char*)data), size) +/** + * https://developer.apple.com/library/archive/documentation/QuickTime/QTFF/QTFFChap3/qtff3.html + * + * Display flags + * A 32-bit integer containing flags that describe how the subtitle text should + * be drawn. + * The following flags are defined: + * + * Vertical placement + * Controls vertical placement of the subtitle text. + * If this flag is set, the subtitle media handler uses the top coordinate of + * the display bounds of the override 'tbox' text box to determine the + * subtitle’s vertical placement as described in Subtitle Track Header Size + * and Placement. Otherwise, the subtitle displays at the bottom of the video. + */ +#define DISPLAY_FLAG_VERTICAL_PLACEMENT_TOP 0x2000 + +/** + * Some samples are forced + * Indicates whether any subtitle samples contain forced atoms. If this flag is + * set, at least one sample contains a forced ('frcd') atom as described in + * Subtitle Sample Data. + */ +#define DISPLAY_FLAG_SOME_SAMPLES_FORCED0x4000 + +/** + * All samples are forced + * If this flag is set, the subtitle media handler treats all samples as forced + * subtitles, regardless of the presence or absence of a 'frcd' atom. + * If this flag is set, the Some Samples Are Forced flag must also be set + * (making 0xC000). + */ +#define DISPLAY_FLAG_ALL_SAMPLES_FORCED 0x8000 + typedef struct { uint16_t style_start; uint16_t style_end; @@ -183,6 +217,7 @@ static int encode_sample_description(AVCodecContext *avctx) int font_names_total_len = 0; MovTextContext *s = avctx->priv_data; uint8_t buf[30], *p = buf; +uint32_t display_flags = 0; // 0x00, 0x00, 0x00, 0x00, // uint32_t displayFlags // 0x01, // int8_t horizontal-justification @@ -241,7 +276,11 @@ static int encode_sample_description(AVCodecContext *avctx) (255 - ((uint32_t)style->back_color >> 24)); } -bytestream_put_be32(&p, 0); // displayFlags +if (avctx->subtitle_flags & AV_SUBTITLE_FLAG_FORCED) +display_flags = DISPLAY_FLAG_SOME_SAMPLES_FORCED | +DISPLAY_FLAG_ALL_SAMPLES_FORCED; + +bytestream_put_be32(&p, display_flags); // displayFlags bytestream_put_be16(&p, 0x01FF); // horizontal/vertical justification (2x int8_t) bytestream_put_be32(&p, back_color); bytestream_put_be64(&p, 0); // BoxRecord - 4xint16_t: top, left, bottom, right -- 2.25.1 ___ ffmpeg-devel mailing list ffmpeg-devel@ffmpeg.org https://
[FFmpeg-devel] (no subject)
Hi FFMDevs, I've managed to get forced mov_text subtitles working in VLC Player. -disposition:s:0 +forced is honored but I'm not 100% sure about my approach. The attached patch represents the best idea I came up with so far as the code is minimal and it doesn't require the user to set any extra parameters, however it does puncture an abstraction boundary ever so slightly by copying stream data to the codec, perhaps this isn't a problem. If there's anybody who could look over my patch and let me know if there's a better way of going about this, that would be greatly appreciated. Love your work! Kind regards, facefunk ___ 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 1/2] Typos.
Signed-off-by: facefunk --- libavcodec/movtextenc.c | 2 +- libavutil/opt.h | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/libavcodec/movtextenc.c b/libavcodec/movtextenc.c index 728338f2cc..40cdaa3a81 100644 --- a/libavcodec/movtextenc.c +++ b/libavcodec/movtextenc.c @@ -693,7 +693,7 @@ static const AVOption options[] = { }; static const AVClass mov_text_encoder_class = { -.class_name = "MOV text enoder", +.class_name = "MOV text encoder", .item_name = av_default_item_name, .option = options, .version= LIBAVUTIL_VERSION_INT, diff --git a/libavutil/opt.h b/libavutil/opt.h index 461b5d3b6b..f250579b29 100644 --- a/libavutil/opt.h +++ b/libavutil/opt.h @@ -175,8 +175,8 @@ * above, put the following into the child_opts array: * @code * { "test_flags", "This is a test option of flags type.", - *offsetof(child_struct, flags_opt), AV_OPT_TYPE_FLAGS, { .i64 = 0 }, INT_MIN, INT_MAX, "test_unit" }, - * { "flag1", "This is a flag with value 16", 0, AV_OPT_TYPE_CONST, { .i64 = 16 }, 0, 0, "test_unit" }, + *offsetof(child_struct, flags_opt), AV_OPT_TYPE_FLAGS, { .i64 = 0 }, .unit = "test_unit" }, + * { "flag1", "This is a flag with value 16", 0, AV_OPT_TYPE_CONST, { .i64 = 16 }, .unit = "test_unit" }, * @endcode * * @section avoptions_use Using AVOptions -- 2.25.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 2/2] Copy AVStream disposition to AVCodecContext and use to set DISPLAY_FLAG_ALL_SAMPLES_FORCED in movtextenc.c.
Signed-off-by: facefunk --- fftools/ffmpeg_opt.c| 5 + libavcodec/avcodec.h| 16 libavcodec/movtextenc.c | 41 - 3 files changed, 61 insertions(+), 1 deletion(-) diff --git a/fftools/ffmpeg_opt.c b/fftools/ffmpeg_opt.c index e08455478f..d8ea1d4bc1 100644 --- a/fftools/ffmpeg_opt.c +++ b/fftools/ffmpeg_opt.c @@ -2244,6 +2244,11 @@ static int set_dispositions(OutputFile *of, AVFormatContext *ctx) if (ret < 0) return ret; + +// For output streams, copy stream disposition to the AVCodecContext +// object. +if(ost->enc_ctx) +ost->enc_ctx->stream_disposition = ost->st->disposition; } } else { // For each media type with more than one stream, find a suitable stream to diff --git a/libavcodec/avcodec.h b/libavcodec/avcodec.h index cb5c25bf63..eb11de0293 100644 --- a/libavcodec/avcodec.h +++ b/libavcodec/avcodec.h @@ -37,6 +37,8 @@ #include "libavutil/pixfmt.h" #include "libavutil/rational.h" +#include "libavformat/avformat.h" + #include "codec.h" #include "codec_desc.h" #include "codec_par.h" @@ -2054,6 +2056,20 @@ typedef struct AVCodecContext { * The decoder can then override during decoding as needed. */ AVChannelLayout ch_layout; + +/** + * Stream disposition - a combination of AV_DISPOSITION_* flags from + * libavformat. + * + * Copied from the relevant AVStream object for codecs that need access to + * the stream disposition parameter, such as movtextenc.c which needs to + * read the AV_DISPOSITION_FORCED flag so it knows when to set forced + * subtitles. + * + * - encoding: Set by set_dispositions in ffmpeg_opt.c. + * - decoding: unused + */ +int stream_disposition; } AVCodecContext; /** diff --git a/libavcodec/movtextenc.c b/libavcodec/movtextenc.c index 40cdaa3a81..6f54e2a64c 100644 --- a/libavcodec/movtextenc.c +++ b/libavcodec/movtextenc.c @@ -50,6 +50,40 @@ #define FONTSIZE_SCALE(s,fs) ((fs) * (s)->font_scale_factor + 0.5) #define av_bprint_append_any(buf, data, size) av_bprint_append_data(buf, ((const char*)data), size) +/** + * https://developer.apple.com/library/archive/documentation/QuickTime/QTFF/QTFFChap3/qtff3.html + * + * Display flags + * A 32-bit integer containing flags that describe how the subtitle text should + * be drawn. + * The following flags are defined: + * + * Vertical placement + * Controls vertical placement of the subtitle text. + * If this flag is set, the subtitle media handler uses the top coordinate of + * the display bounds of the override 'tbox' text box to determine the + * subtitle’s vertical placement as described in Subtitle Track Header Size + * and Placement. Otherwise, the subtitle displays at the bottom of the video. + */ +#define DISPLAY_FLAG_VERTICAL_PLACEMENT_TOP 0x2000 + +/** + * Some samples are forced + * Indicates whether any subtitle samples contain forced atoms. If this flag is + * set, at least one sample contains a forced ('frcd') atom as described in + * Subtitle Sample Data. + */ +#define DISPLAY_FLAG_SOME_SAMPLES_FORCED0x4000 + +/** + * All samples are forced + * If this flag is set, the subtitle media handler treats all samples as forced + * subtitles, regardless of the presence or absence of a 'frcd' atom. + * If this flag is set, the Some Samples Are Forced flag must also be set + * (making 0xC000). + */ +#define DISPLAY_FLAG_ALL_SAMPLES_FORCED 0x8000 + typedef struct { uint16_t style_start; uint16_t style_end; @@ -183,6 +217,7 @@ static int encode_sample_description(AVCodecContext *avctx) int font_names_total_len = 0; MovTextContext *s = avctx->priv_data; uint8_t buf[30], *p = buf; +uint32_t display_flags = 0; // 0x00, 0x00, 0x00, 0x00, // uint32_t displayFlags // 0x01, // int8_t horizontal-justification @@ -241,7 +276,11 @@ static int encode_sample_description(AVCodecContext *avctx) (255 - ((uint32_t)style->back_color >> 24)); } -bytestream_put_be32(&p, 0); // displayFlags +if (avctx->stream_disposition & AV_DISPOSITION_FORCED) +display_flags = DISPLAY_FLAG_SOME_SAMPLES_FORCED | +DISPLAY_FLAG_ALL_SAMPLES_FORCED; + +bytestream_put_be32(&p, display_flags); // displayFlags bytestream_put_be16(&p, 0x01FF); // horizontal/vertical justification (2x int8_t) bytestream_put_be32(&p, back_color); bytestream_put_be64(&p, 0); // BoxRecord - 4xint16_t: top, left, bottom, right -- 2.25.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] Make disposition forced work with mov_text subtitles.
We are not currently able to force mov_text subtitles by setting -disposition:s:0 +forced or equivalent. By setting the forced flags in movtextenc as specifid in https://developer.apple.com/library/archive/documentation/QuickTime/QTFF/QTFFChap3/qtff3.html subtitles can be forced as expected in VLC and similar players. ___ 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 1/3] libavcodec: Make disposition forced work with mov_text subtitles.
We are not currently able to force mov_text subtitles by setting -disposition:s:0 +forced or equivalent. By setting the forced flags in movtextenc as specifid in https://developer.apple.com/library/archive/documentation/QuickTime/QTFF/QTFFChap3/qtff3.html subtitles can be forced as expected in VLC and similar players. Copy AVStream disposition to AVCodecContext and use to set DISPLAY_FLAG_ALL_SAMPLES_FORCED in movtextenc.c. Signed-off-by: facefunk --- fftools/ffmpeg_opt.c| 5 + libavcodec/avcodec.h| 16 libavcodec/movtextenc.c | 41 - 3 files changed, 61 insertions(+), 1 deletion(-) diff --git a/fftools/ffmpeg_opt.c b/fftools/ffmpeg_opt.c index e08455478f..d8ea1d4bc1 100644 --- a/fftools/ffmpeg_opt.c +++ b/fftools/ffmpeg_opt.c @@ -2244,6 +2244,11 @@ static int set_dispositions(OutputFile *of, AVFormatContext *ctx) if (ret < 0) return ret; + +// For output streams, copy stream disposition to the AVCodecContext +// object. +if(ost->enc_ctx) +ost->enc_ctx->stream_disposition = ost->st->disposition; } } else { // For each media type with more than one stream, find a suitable stream to diff --git a/libavcodec/avcodec.h b/libavcodec/avcodec.h index cb5c25bf63..eb11de0293 100644 --- a/libavcodec/avcodec.h +++ b/libavcodec/avcodec.h @@ -37,6 +37,8 @@ #include "libavutil/pixfmt.h" #include "libavutil/rational.h" +#include "libavformat/avformat.h" + #include "codec.h" #include "codec_desc.h" #include "codec_par.h" @@ -2054,6 +2056,20 @@ typedef struct AVCodecContext { * The decoder can then override during decoding as needed. */ AVChannelLayout ch_layout; + +/** + * Stream disposition - a combination of AV_DISPOSITION_* flags from + * libavformat. + * + * Copied from the relevant AVStream object for codecs that need access to + * the stream disposition parameter, such as movtextenc.c which needs to + * read the AV_DISPOSITION_FORCED flag so it knows when to set forced + * subtitles. + * + * - encoding: Set by set_dispositions in ffmpeg_opt.c. + * - decoding: unused + */ +int stream_disposition; } AVCodecContext; /** diff --git a/libavcodec/movtextenc.c b/libavcodec/movtextenc.c index 728338f2cc..d2550585e8 100644 --- a/libavcodec/movtextenc.c +++ b/libavcodec/movtextenc.c @@ -50,6 +50,40 @@ #define FONTSIZE_SCALE(s,fs) ((fs) * (s)->font_scale_factor + 0.5) #define av_bprint_append_any(buf, data, size) av_bprint_append_data(buf, ((const char*)data), size) +/** + * https://developer.apple.com/library/archive/documentation/QuickTime/QTFF/QTFFChap3/qtff3.html + * + * Display flags + * A 32-bit integer containing flags that describe how the subtitle text should + * be drawn. + * The following flags are defined: + * + * Vertical placement + * Controls vertical placement of the subtitle text. + * If this flag is set, the subtitle media handler uses the top coordinate of + * the display bounds of the override 'tbox' text box to determine the + * subtitle’s vertical placement as described in Subtitle Track Header Size + * and Placement. Otherwise, the subtitle displays at the bottom of the video. + */ +#define DISPLAY_FLAG_VERTICAL_PLACEMENT_TOP 0x2000 + +/** + * Some samples are forced + * Indicates whether any subtitle samples contain forced atoms. If this flag is + * set, at least one sample contains a forced ('frcd') atom as described in + * Subtitle Sample Data. + */ +#define DISPLAY_FLAG_SOME_SAMPLES_FORCED0x4000 + +/** + * All samples are forced + * If this flag is set, the subtitle media handler treats all samples as forced + * subtitles, regardless of the presence or absence of a 'frcd' atom. + * If this flag is set, the Some Samples Are Forced flag must also be set + * (making 0xC000). + */ +#define DISPLAY_FLAG_ALL_SAMPLES_FORCED 0x8000 + typedef struct { uint16_t style_start; uint16_t style_end; @@ -183,6 +217,7 @@ static int encode_sample_description(AVCodecContext *avctx) int font_names_total_len = 0; MovTextContext *s = avctx->priv_data; uint8_t buf[30], *p = buf; +uint32_t display_flags = 0; // 0x00, 0x00, 0x00, 0x00, // uint32_t displayFlags // 0x01, // int8_t horizontal-justification @@ -241,7 +276,11 @@ static int encode_sample_description(AVCodecContext *avctx) (255 - ((uint32_t)style->back_color >> 24)); } -bytestream_put_be32(&p, 0); // displayFlags +if (avctx->stream_disposition & AV_DISPOSITION_FORCED) +display_flags = DISPLAY_FLAG_SOME_SAMPLES_FORCED | +DISPLAY_FLAG_ALL_SAMPLES_FORCED; + +bytestream_put_be32(&p, display_flags); // di
[FFmpeg-devel] [PATCH 2/3] libavcodec: Correct typo in mov_text encoder class name.
Signed-off-by: facefunk --- libavcodec/movtextenc.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libavcodec/movtextenc.c b/libavcodec/movtextenc.c index d2550585e8..6f54e2a64c 100644 --- a/libavcodec/movtextenc.c +++ b/libavcodec/movtextenc.c @@ -732,7 +732,7 @@ static const AVOption options[] = { }; static const AVClass mov_text_encoder_class = { -.class_name = "MOV text enoder", +.class_name = "MOV text encoder", .item_name = av_default_item_name, .option = options, .version= LIBAVUTIL_VERSION_INT, -- 2.25.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 3/3] libavutil: Correct number of parameters in flag type options documentation.
Signed-off-by: facefunk --- libavutil/opt.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/libavutil/opt.h b/libavutil/opt.h index 461b5d3b6b..f250579b29 100644 --- a/libavutil/opt.h +++ b/libavutil/opt.h @@ -175,8 +175,8 @@ * above, put the following into the child_opts array: * @code * { "test_flags", "This is a test option of flags type.", - *offsetof(child_struct, flags_opt), AV_OPT_TYPE_FLAGS, { .i64 = 0 }, INT_MIN, INT_MAX, "test_unit" }, - * { "flag1", "This is a flag with value 16", 0, AV_OPT_TYPE_CONST, { .i64 = 16 }, 0, 0, "test_unit" }, + *offsetof(child_struct, flags_opt), AV_OPT_TYPE_FLAGS, { .i64 = 0 }, .unit = "test_unit" }, + * { "flag1", "This is a flag with value 16", 0, AV_OPT_TYPE_CONST, { .i64 = 16 }, .unit = "test_unit" }, * @endcode * * @section avoptions_use Using AVOptions -- 2.25.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".
Re: [FFmpeg-devel] Make disposition forced work with mov_text subtitles.
Thanks for the advice. I did --reroll-count=2 but it doesn't seem to have worked. On Mon, 18 Jul 2022 at 18:48, Leo Izen wrote: > On 7/18/22 12:08, facefunk wrote: > > We are not currently able to force mov_text subtitles by setting > -disposition:s:0 +forced or equivalent. By setting the forced flags in > movtextenc as specifid in > https://developer.apple.com/library/archive/documentation/QuickTime/QTFF/QTFFChap3/qtff3.html > subtitles can be forced as expected in VLC and similar players. > > > > ___ > > 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". > In the future, add -v2 to your git-format-patch or git-send-email > command, to make it say [PATCH v2]. This makes it easier to keep track > of what's changed. > > - Leo Izen (thebombzen) > ___ > 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] Make disposition forced work with mov_text subtitles.
Okay, great! Thanks for reviewing. I've addressed your points as well as a few tweaks in the spirit of preserving the abstraction boundary. Would the attached patch revision be acceptable? ___ 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] libavcodec: Make disposition forced work with mov_text subtitles.
We are not currently able to force mov_text subtitles by setting -disposition:s:0 +forced or equivalent. By setting the forced flags in movtextenc as specifid in https://developer.apple.com/library/archive/documentation/QuickTime/QTFF/QTFFChap3/qtff3.html subtitles can be forced as expected in VLC and similar players. Copy AVStream disposition to AVCodecContext and use to set DISPLAY_FLAG_ALL_SAMPLES_FORCED in movtextenc.c. Signed-off-by: facefunk --- fftools/ffmpeg_opt.c| 5 + libavcodec/avcodec.h| 11 +++ libavcodec/movtextenc.c | 41 - 3 files changed, 56 insertions(+), 1 deletion(-) diff --git a/fftools/ffmpeg_opt.c b/fftools/ffmpeg_opt.c index e08455478f..a7fa809859 100644 --- a/fftools/ffmpeg_opt.c +++ b/fftools/ffmpeg_opt.c @@ -2244,6 +2244,11 @@ static int set_dispositions(OutputFile *of, AVFormatContext *ctx) if (ret < 0) return ret; + +// For output streams, Set subtitle flags to forced when stream +// disposition is forced. +if(ost->enc_ctx && ost->st->disposition & AV_DISPOSITION_FORCED) +ost->enc_ctx->subtitle_flags |= AV_SUBTITLE_FLAG_FORCED; } } else { // For each media type with more than one stream, find a suitable stream to diff --git a/libavcodec/avcodec.h b/libavcodec/avcodec.h index cb5c25bf63..182f452557 100644 --- a/libavcodec/avcodec.h +++ b/libavcodec/avcodec.h @@ -2054,6 +2054,17 @@ typedef struct AVCodecContext { * The decoder can then override during decoding as needed. */ AVChannelLayout ch_layout; + +/** + * Subtitle codecs only. Bit set of AV_SUBTITLE_FLAG_*. + * + * Some subtitle codecs may use this field to determine the subtitle + * display flags to encode. + * + * - encoding: set by user + * - decoding: unused + */ +int subtitle_flags; } AVCodecContext; /** diff --git a/libavcodec/movtextenc.c b/libavcodec/movtextenc.c index 728338f2cc..bb6021f6d1 100644 --- a/libavcodec/movtextenc.c +++ b/libavcodec/movtextenc.c @@ -50,6 +50,40 @@ #define FONTSIZE_SCALE(s,fs) ((fs) * (s)->font_scale_factor + 0.5) #define av_bprint_append_any(buf, data, size) av_bprint_append_data(buf, ((const char*)data), size) +/** + * https://developer.apple.com/library/archive/documentation/QuickTime/QTFF/QTFFChap3/qtff3.html + * + * Display flags + * A 32-bit integer containing flags that describe how the subtitle text should + * be drawn. + * The following flags are defined: + * + * Vertical placement + * Controls vertical placement of the subtitle text. + * If this flag is set, the subtitle media handler uses the top coordinate of + * the display bounds of the override 'tbox' text box to determine the + * subtitle’s vertical placement as described in Subtitle Track Header Size + * and Placement. Otherwise, the subtitle displays at the bottom of the video. + */ +#define DISPLAY_FLAG_VERTICAL_PLACEMENT_TOP 0x2000 + +/** + * Some samples are forced + * Indicates whether any subtitle samples contain forced atoms. If this flag is + * set, at least one sample contains a forced ('frcd') atom as described in + * Subtitle Sample Data. + */ +#define DISPLAY_FLAG_SOME_SAMPLES_FORCED0x4000 + +/** + * All samples are forced + * If this flag is set, the subtitle media handler treats all samples as forced + * subtitles, regardless of the presence or absence of a 'frcd' atom. + * If this flag is set, the Some Samples Are Forced flag must also be set + * (making 0xC000). + */ +#define DISPLAY_FLAG_ALL_SAMPLES_FORCED 0x8000 + typedef struct { uint16_t style_start; uint16_t style_end; @@ -183,6 +217,7 @@ static int encode_sample_description(AVCodecContext *avctx) int font_names_total_len = 0; MovTextContext *s = avctx->priv_data; uint8_t buf[30], *p = buf; +uint32_t display_flags = 0; // 0x00, 0x00, 0x00, 0x00, // uint32_t displayFlags // 0x01, // int8_t horizontal-justification @@ -241,7 +276,11 @@ static int encode_sample_description(AVCodecContext *avctx) (255 - ((uint32_t)style->back_color >> 24)); } -bytestream_put_be32(&p, 0); // displayFlags +if (avctx->subtitle_flags & AV_SUBTITLE_FLAG_FORCED) +display_flags = DISPLAY_FLAG_SOME_SAMPLES_FORCED | +DISPLAY_FLAG_ALL_SAMPLES_FORCED; + +bytestream_put_be32(&p, display_flags); // displayFlags bytestream_put_be16(&p, 0x01FF); // horizontal/vertical justification (2x int8_t) bytestream_put_be32(&p, back_color); bytestream_put_be64(&p, 0); // BoxRecord - 4xint16_t: top, left, bottom, right -- 2.25.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".
Re: [FFmpeg-devel] Make disposition forced work with mov_text subtitles.
I see what I did wrong. -v or --reroll-count are arguments to git format-patch so obviously aren't applied by git send-email when providing a preformatted patch, which I did. My mistake. On Mon, 18 Jul 2022 at 18:48, Leo Izen wrote: > On 7/18/22 12:08, facefunk wrote: > > We are not currently able to force mov_text subtitles by setting > -disposition:s:0 +forced or equivalent. By setting the forced flags in > movtextenc as specifid in > https://developer.apple.com/library/archive/documentation/QuickTime/QTFF/QTFFChap3/qtff3.html > subtitles can be forced as expected in VLC and similar players. > > > > ___ > > 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". > In the future, add -v2 to your git-format-patch or git-send-email > command, to make it say [PATCH v2]. This makes it easier to keep track > of what's changed. > > - Leo Izen (thebombzen) > ___ > 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] libavformat/movenc: Is packets being more than INT_MAX apart always an error?
It's commonly the case with forced subtitle tracks that samples are more than INT_MAX microseconds (35m47.48s) apart. This being the case, packet duration will be deemed out of range by check_pkt and the packet dts set to an incorrect value, even if pkt->duration is actually valid. I had begun working out how to inject extra packets to satisfy this check but I thought I would ask. Is this check necessary for mov_text packets? ___ 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] libavformat/movenc: Is packets being more than INT_MAX apart always an error?
Wow! Thanks! That really works. I had no idea we could just play with timescale like that. On Wed, 20 Jul 2022 at 13:41, "zhilizhao(赵志立)" wrote: > > > > On Jul 20, 2022, at 8:18 PM, facefunk wrote: > > > > It's commonly the case with forced subtitle tracks that samples are more > > than INT_MAX microseconds (35m47.48s) apart. This being the case, packet > > duration will be deemed out of range by check_pkt and the packet dts set > to > > an incorrect value, even if pkt->duration is actually valid. > > > > I had begun working out how to inject extra packets to satisfy this check > > but I thought I would ask. Is this check necessary for mov_text packets? > > I think so, it’s still limited by the 32bits sample_delta in stts. > > On the other hand, I have an idea that a timescale like 100 can be used in > that case, which is 2^31/100/3600 = 5965 hours. > > > ___ > > 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 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".