From patchwork Sun Jul 17 13:32:56 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: facefunk X-Patchwork-Id: 36811 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a05:6a21:1649:b0:8b:613a:194d with SMTP id no9csp566406pzb; Sun, 17 Jul 2022 06:33:50 -0700 (PDT) X-Google-Smtp-Source: AGRyM1u3rFaiTzW8sRp/5ze8pGsCCR1UP+THHTgKT341iNq6OSCIUQZi91mnDrlrUpufPAmQx5Qh X-Received: by 2002:aa7:cd0a:0:b0:43a:8ffd:d8de with SMTP id b10-20020aa7cd0a000000b0043a8ffdd8demr31077587edw.5.1658064830271; Sun, 17 Jul 2022 06:33:50 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1658064830; cv=none; d=google.com; s=arc-20160816; b=uxXSWmpQa42khlfMiKsI+ZlShxfePhMb71HX4uEjp5FKPfEEEEP5ltf03iAvnNLmx0 H4DeCeRsXl6YPQSho242WltyuBxY5+TrdpooaYfD6YjEwlcyA166QqmHEOZ6hO2wA6oL 3MM3OXeqhdvOuvUkLcEe7zPbkDSiJb/Uo5UpKCZiQSHNc/qF1KcOpmDHc+xRbbRf90VR o8r+VmYjw5eo/BHd1ZbfSwA/M14YsUTOUdE/J2t//eidBFwgiiVgQ8XyxlLqtPqo4mPn 4e+GFcKu8rHOL1mwZWljb2jK82SkbKpvkLb0qv4hVR7l6OqXAIngJZlmnbMX5OwDeY7k MkqQ== 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=QDagYJh9XgFY2mJtUo873QkY3qfHjj0c+/+Gz0GqBRM=; b=K87QRAwxLfTqW2qrNwTvfydkj5kK4vBGxAbhJf/DQrD7kDmSWUaY8bWfuD+Ecd8SCM n0zSWfTVSoIOX9w1ieQTjQ2vpbQ3gpTGj/YpU7UjkGjxXkkrlsfa4Su/wyPqfaR0wj5M g1uDogSQQubSLp+FWzO+c5rYYP3wexNwsHe1UAbJD81Y8ktx6LzYCVTyjydwDbAFvvcn 72hm78VMTjZ0EZzxgnafNsn4jc7qEqU8hBt9U/u8jgka5XRTiBbRDtRC3zqaCFv9I1Ea 9lxCMwCkVbbGrOGVQELvZXD/LEI6HsJ5HV6NCmZvSlfdf4aLRY03UlRaIDTWBrijHu1U TMOg== 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 h20-20020a50cdd4000000b004356df259b4si11793134edj.361.2022.07.17.06.33.27; Sun, 17 Jul 2022 06:33:50 -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 6CE9D68B8A0; Sun, 17 Jul 2022 16:33:10 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-wm1-f48.google.com (mail-wm1-f48.google.com [209.85.128.48]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 796F368B901 for ; Sun, 17 Jul 2022 16:33:03 +0300 (EEST) Received: by mail-wm1-f48.google.com with SMTP id p26-20020a1c545a000000b003a2fb7c1274so3466830wmi.1 for ; Sun, 17 Jul 2022 06:33:03 -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=eq2Hb7XLGVETMUkiCvue+7WbelK+kVQd0q69FQ3jjZk=; b=kXhT3DxRmTNnPP0i5++DpYswp2+kNh6KVMfEivfbPpbdgkHsAWTjsA/WvQlj2rIIVG 6a3vZARY4h9QeiZ24rSS5n68ZS7juaYiuyaL9Gz2XPHAyPm7QOob/3gH6zXo7No32lFS pcDaTGjgFual1AOrnne5OKnNHqrjE4tjUlbSbHSxnmPqDmW/wOwO2A4IItP33ihhsWbu ZOdiq3dDRW7a2IzKMy5MaYJzhzG+Fem3qOpsaFXg4hG2ZkqTwb4jcsRUPEwPuxuXNdKJ 79Ce+P0U1JZInrjxTkpx//6jBB1X4XHOuEBOUSjtGh1XmxH9xci96FGtoZWHx23JKeho QksQ== X-Gm-Message-State: AJIora8PpTco5UzNcPJeVVhFsfxC34Z0hKWpIPyPF30aBADyPmSCZHVP lcUwFSO27CHnSBneDsQqU1z4wo5AazJ4rg== X-Received: by 2002:a05:600c:b4d:b0:3a2:e5cd:932e with SMTP id k13-20020a05600c0b4d00b003a2e5cd932emr22101820wmr.98.1658064782638; Sun, 17 Jul 2022 06:33:02 -0700 (PDT) Received: from localhost.localdomain ([84.71.185.98]) by smtp.gmail.com with ESMTPSA id p15-20020a5d68cf000000b0021d20461bbbsm8296001wrw.88.2022.07.17.06.33.02 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 17 Jul 2022 06:33:02 -0700 (PDT) From: facefunk To: ffmpeg-devel@ffmpeg.org Date: Sun, 17 Jul 2022 14:32:56 +0100 Message-Id: <20220717133256.35929-3-facefunk@fcfnk.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20220717133256.35929-1-facefunk@fcfnk.com> References: <20220717133256.35929-1-facefunk@fcfnk.com> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH 2/2] Copy AVStream disposition to AVCodecContext and use to set DISPLAY_FLAG_ALL_SAMPLES_FORCED in movtextenc.c. 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: hpSt3LvMl+w8 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 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->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