From patchwork Mon Jul 18 20:00:52 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: facefunk X-Patchwork-Id: 36825 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a05:6a21:1649:b0:8b:613a:194d with SMTP id no9csp1318255pzb; Mon, 18 Jul 2022 13:01:25 -0700 (PDT) X-Google-Smtp-Source: AGRyM1vp6WI0eBDOi18gmE90ut82OPyaqmfkdF66jMP5P4k+RRYw9/E/fFnXyL+f8x6Dr3GzFqiq X-Received: by 2002:a05:6402:34c3:b0:43a:c323:274f with SMTP id w3-20020a05640234c300b0043ac323274fmr40081524edc.67.1658174484874; Mon, 18 Jul 2022 13:01:24 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1658174484; cv=none; d=google.com; s=arc-20160816; b=QgJsAZCPlJx3WZssH3ISfujJHoMamS9JluTkrrAGrgOQIE19gjK8PcUsbSQi4Y6Ol2 4aQm64JXMxJGGE6nfz/TqPI7m2Z+M0Z47qSl78p9t6cyZJzVyiD2QJcoy/80Nvy9KoWU wRN/gnUztxgNo2NUtMDBcVJ4eAHteSYPWAnAonajKWpJhXc5japxM2nOAPyUAI+Ty0h/ 8UA4onJY19OGplGy/VkwB+b7rjsnWkdF1ID2Xq26DyizfJ1FSbhZka2mL4xoCTvxgqHl x5LOqlIntD9sh3Xj4Gg+AnI7VrEV5DoXAOuhAs/J8qWGhaL0Gx5mxkm3rxCdcdlscQdy mf2Q== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:content-transfer-encoding:cc:reply-to :list-subscribe:list-help:list-post:list-archive:list-unsubscribe :list-id:precedence:subject:mime-version:references:in-reply-to :message-id:date:to:from:delivered-to; bh=BYU76IhixXbjtH6Fvqa4Oc6KjFrqUTqMVeLfdmgQ1hg=; b=E4JagH4g+DyhYQonCfCrfrQ/SKb4GxGUaYujRWpz1OLf/tX2axyD/dQ7KpiHhZkkrv hfH01greW07hITHiXc4Fj16UmMPbIQBM1PvqA2yOLFCLg8CblnbG2454fTPeLqOGHGwD seFcAoNGgbuWiNxBIGc1RS6j07Qx0BhHD03VEIUh40o1a65wN8AQ0GwNnRJmmZkFqGVk wNuTuRlSC/fGIbPPdrWYvUh8ZA17tyNNmi6St6MibQ4C3I4WSYcndnMEiUxLYlNaZB6b kPPWEPKYqHczdbV3nELPzbgJw6gVVCo64zYJyUwOIFPoFU+w5G/E93mu69WqG5dyaA/M A//g== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of ffmpeg-devel-bounces@ffmpeg.org designates 79.124.17.100 as permitted sender) smtp.mailfrom=ffmpeg-devel-bounces@ffmpeg.org Return-Path: Received: from ffbox0-bg.mplayerhq.hu (ffbox0-bg.ffmpeg.org. [79.124.17.100]) by mx.google.com with ESMTP id j17-20020a50ed11000000b0043783a7f05bsi15542373eds.207.2022.07.18.13.01.20; Mon, 18 Jul 2022 13:01:24 -0700 (PDT) Received-SPF: pass (google.com: domain of ffmpeg-devel-bounces@ffmpeg.org designates 79.124.17.100 as permitted sender) client-ip=79.124.17.100; Authentication-Results: mx.google.com; spf=pass (google.com: domain of ffmpeg-devel-bounces@ffmpeg.org designates 79.124.17.100 as permitted sender) smtp.mailfrom=ffmpeg-devel-bounces@ffmpeg.org Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id E934168B9DC; Mon, 18 Jul 2022 23:01:10 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-wr1-f41.google.com (mail-wr1-f41.google.com [209.85.221.41]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 54A0B68B8C9 for ; Mon, 18 Jul 2022 23:01:04 +0300 (EEST) Received: by mail-wr1-f41.google.com with SMTP id d16so18583854wrv.10 for ; Mon, 18 Jul 2022 13:01:04 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=3MT5kfgxc3FnoZxMGAnfhEY4iQseG9ZKejmBhTDlcG0=; b=7lEKXfw1zRFOJtGFXytXeJKkK5uIpWyt9AM6XesdIQ1/J78OMI6nCdcFU0QTlz4lc6 NXHK7FNj8O3R8VoGKVINAT7lK5tha2jWgNIEfSIhyQUrn0yXXoEZxJ8Z5/fRuDDfzUNq ypoU6XdGJ7l4oz/KIJwxpV+cwzqKwOBBKYEN//Gwbq/y5MTpkjQiHfuq0NayvdfttTt2 SxQj334V6zEv4dpCeNt2ep8XX8pErbrMjbG9TKr4q/1nN4JY51l2EqUH7lG66ghoin++ wUeldKeSydJhf88WwdqEEejAixS3NuJEYfZbcSeCcY8sT8zwtpHSFOyOeA+MQWRarg5l Gi8w== X-Gm-Message-State: AJIora9d6s7oTXxfyJuODIDQxCgLk+pk9IKr3varh5C7gPsfDtcaQnb8 nDPmaCOQUBGLyY7PHcGGxjvuz/h+Yh4X7g== X-Received: by 2002:adf:f78b:0:b0:21d:6fef:f4e1 with SMTP id q11-20020adff78b000000b0021d6feff4e1mr23646464wrp.92.1658174463282; Mon, 18 Jul 2022 13:01:03 -0700 (PDT) Received: from localhost.localdomain ([84.71.185.98]) by smtp.gmail.com with ESMTPSA id k21-20020a05600c1c9500b003a3187a2d4csm6893220wms.22.2022.07.18.13.01.02 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 18 Jul 2022 13:01:02 -0700 (PDT) From: facefunk To: ffmpeg-devel@ffmpeg.org Date: Mon, 18 Jul 2022 21:00:52 +0100 Message-Id: <20220718200052.159293-2-facefunk@fcfnk.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20220718200052.159293-1-facefunk@fcfnk.com> References: <20220718160833.12397-2-facefunk@fcfnk.com> <20220718200052.159293-1-facefunk@fcfnk.com> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH v3] libavcodec: Make disposition forced work with mov_text subtitles. X-BeenThere: ffmpeg-devel@ffmpeg.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: FFmpeg development discussions and patches List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Reply-To: FFmpeg development discussions and patches Cc: facefunk Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" X-TUID: M3JHqj8Ptswe 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 0x20000000 + +/** + * 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_FORCED 0x40000000 + +/** + * 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 0xC0000000). + */ +#define DISPLAY_FLAG_ALL_SAMPLES_FORCED 0x80000000 + 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