From patchwork Thu Nov 3 03:19:28 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: rcombs X-Patchwork-Id: 39123 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a05:6a21:999a:b0:a4:2148:650a with SMTP id ve26csp257367pzb; Wed, 2 Nov 2022 20:19:48 -0700 (PDT) X-Google-Smtp-Source: AMsMyM5d178CHvFtKLvsc6o1Dc6kRrMMKFRWaeqZlsyXKSZsDC64FK5EPGgNYMsTyLdTlCHSx3py X-Received: by 2002:a17:907:5ce:b0:730:bae0:deb with SMTP id wg14-20020a17090705ce00b00730bae00debmr27422478ejb.181.1667445587974; Wed, 02 Nov 2022 20:19:47 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1667445587; cv=none; d=google.com; s=arc-20160816; b=WFPebgBbteTrfUS2prYAEzotYHMEnOV3cYpTMUTReDkgRjS4yFT3DInhjsX+s8oVhK l+oHScJ0ZZNG7pLtC830txc7HstJIu6iD8U90kttTvlEDl/neT/dsxrjNy3nQbJvUgQW RJLBc3mEOseDpK2ELBm9QzI+QGY53CCpUlToTLCXd0c14hgwOrLRE1w62NgYGcYJ7o+X 9R0gvlGA4Fbip375tnkci9Cw2DwG2UyNrwBt+ujpXrRSNNlV9T0KXcx1CrLpnMDlgRW4 9WTI0XT9dKEwCB20gvAWjP/0m+fQWB4fWCJ1Ubzyf3qcVsoJ6cbs9SvJrKAgq2UMn1R3 NhrQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:content-transfer-encoding:reply-to:list-subscribe :list-help:list-post:list-archive:list-unsubscribe:list-id :precedence:subject:mime-version:message-id:date:to:from :dkim-signature:delivered-to; bh=j/FMMabjRmFJwjtKzMakjUQV5WKlFyCQ5ZoocOJHCLI=; b=tRPPvdp6t852MVK1I9gYuKIzCJ/Bmeu4SueM/DKTqC0jlkKZdjCzhaGNqipsMk08dt lr5hEuAZVl4jPTdYiMm9lQTz522stm1vZvrI3vC+r9mJv7K3oNEBkWlbXtU+0WxWVKPW 8YNNQeb9kcRxGCap2zh+nOTLMjlxpMEB59ljYxlqQ6CnsH8W7XVWmwT5Pxr9EtGc8l+p J39twDocUrSojHXHixRdfmOGrod6n1HoPZ+5QFmyaSXecCZ/fQBeW8670TwaUOLdcJei lyh399yH4/UZySPg3jYX6uDs4h5WUN9SNoHpKzY+U0AyheMi/DPjDA2kFQzi5hwtelt2 EfOw== ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (body hash did not verify) header.i=@rcombs.me header.s=google header.b=epyAE5EP; 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; dmarc=fail (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=rcombs.me Return-Path: Received: from ffbox0-bg.mplayerhq.hu (ffbox0-bg.ffmpeg.org. [79.124.17.100]) by mx.google.com with ESMTP id dz19-20020a0564021d5300b0045c13366de4si19513716edb.572.2022.11.02.20.19.47; Wed, 02 Nov 2022 20:19:47 -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; dkim=neutral (body hash did not verify) header.i=@rcombs.me header.s=google header.b=epyAE5EP; 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; dmarc=fail (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=rcombs.me Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 4BEED68BEDA; Thu, 3 Nov 2022 05:19:44 +0200 (EET) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-io1-f51.google.com (mail-io1-f51.google.com [209.85.166.51]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 17CB768BE25 for ; Thu, 3 Nov 2022 05:19:38 +0200 (EET) Received: by mail-io1-f51.google.com with SMTP id r81so402245iod.2 for ; Wed, 02 Nov 2022 20:19:37 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=rcombs.me; s=google; h=content-transfer-encoding:mime-version:message-id:date:subject:to :from:from:to:cc:subject:date:message-id:reply-to; bh=Kxul5S9yhp3LFtBgG+Z8NzPs/oDpHE2O2KaCbCyTD1I=; b=epyAE5EPI5eWWRAbi6Ft04h+rFFK2/QhKTuFMxWyZFAc9quxhJgp8ME831YTssJhPl 7RgXWfynO8WjfxC9uAX7rvfwPM65qLmbbdbG/qkl0bA61gQ4E8fw9DfcyKnsa4UKKp5H GytM7nrbm8ZPXceOB2AbIuaHSBxBoNpO1uWX2RvU/PyxZRmjt/M9cm+V6cl2+rAzP5Rz hBjJ3DGzw0rMgHc5174XLd7Z25nzYTFrlnve2rcDvlXnXaAFGNQwdXm5Hfm8iUx2nIaZ OvYRt+eMDilE6yU1RsGsjPX7hvoDEQa1WhjRwbPm/PvpmYQsoz3Mw5yRc/I1+cpv929i 6Z7Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:message-id:date:subject:to :from:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=Kxul5S9yhp3LFtBgG+Z8NzPs/oDpHE2O2KaCbCyTD1I=; b=tKzE0GRFCpRJosmV0h3dUoMSoHrZ3E61ZoJ3MRXyaCOWZHg4apIODlpQGz+77iIFF8 McG9DdjQJym5BKhjZe31ol7JFdrhL0IlGHVi5xRFNtk9yBCQtCq9Gsn197d1uywM3k1f 0rZ43I+4b4R0OY+NkGzQ20ODY/55OVh20E2rX8jRc/jvN2qSh5eWBk7w9R5f9Z8hAsNX /gYWfuKhG6G/hCXq0yZzXff89C8IhL/GurKDm2O+RRmeopY5zAOjJ9oxG4c9v2eoYW// IVwBqzxEayh6zmYPRjBHVz21esVwrtQDAihFOxL4Ermvs79juPXUgid8nmoncpNYN5pk E8gg== X-Gm-Message-State: ACrzQf1Z2dQzBOcrZo00qTh71Lu4SXRS2Fid6ebwBLTrwKskkD4G1KLI zHAui2Tudm4eSSPrV5vqDjeq5YvLRewk X-Received: by 2002:a05:6602:164b:b0:6cf:bc3f:fcd5 with SMTP id y11-20020a056602164b00b006cfbc3ffcd5mr14179076iow.119.1667445576026; Wed, 02 Nov 2022 20:19:36 -0700 (PDT) Received: from rcombs-mbp.localdomain ([2601:243:2000:5ac:68b3:5bec:e69c:d6c6]) by smtp.gmail.com with ESMTPSA id g9-20020a025b09000000b00363dfbb145asm5335692jab.30.2022.11.02.20.19.34 for (version=TLS1_3 cipher=TLS_CHACHA20_POLY1305_SHA256 bits=256/256); Wed, 02 Nov 2022 20:19:35 -0700 (PDT) From: rcombs To: ffmpeg-devel@ffmpeg.org Date: Wed, 2 Nov 2022 22:19:28 -0500 Message-Id: <20221103031928.3205-1-rcombs@rcombs.me> X-Mailer: git-send-email 2.38.1 MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH] lavc/libaribb24: add default_profile option 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 Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" X-TUID: 0dxef+A0zjg3 This allows decoding of streams that don't have a profile tagged (e.g. ones that were remuxed improperly). --- libavcodec/libaribb24.c | 33 +++++++++++++++++++++++++++------ 1 file changed, 27 insertions(+), 6 deletions(-) diff --git a/libavcodec/libaribb24.c b/libavcodec/libaribb24.c index f40517e22e..8ccf3c4b5d 100644 --- a/libavcodec/libaribb24.c +++ b/libavcodec/libaribb24.c @@ -40,10 +40,18 @@ typedef struct Libaribb24Context { char *aribb24_base_path; unsigned int aribb24_skip_ruby; + + int default_profile; } Libaribb24Context; -static unsigned int get_profile_font_size(int profile) +static unsigned int get_profile_font_size(AVCodecContext *avctx) { + Libaribb24Context *b24 = avctx->priv_data; + int profile = avctx->profile; + + if (profile == FF_PROFILE_UNKNOWN) + profile = b24->default_profile; + switch (profile) { case FF_PROFILE_ARIB_PROFILE_A: return 36; @@ -61,26 +69,31 @@ static void libaribb24_log(void *p, const char *msg) static int libaribb24_generate_ass_header(AVCodecContext *avctx) { + Libaribb24Context *b24 = avctx->priv_data; unsigned int plane_width = 0; unsigned int plane_height = 0; unsigned int font_size = 0; + int profile = avctx->profile; - switch (avctx->profile) { + if (profile == FF_PROFILE_UNKNOWN) + profile = b24->default_profile; + + switch (profile) { case FF_PROFILE_ARIB_PROFILE_A: plane_width = 960; plane_height = 540; - font_size = get_profile_font_size(avctx->profile); break; case FF_PROFILE_ARIB_PROFILE_C: plane_width = 320; plane_height = 180; - font_size = get_profile_font_size(avctx->profile); break; default: av_log(avctx, AV_LOG_ERROR, "Unknown or unsupported profile set!\n"); return AVERROR(EINVAL); } + font_size = get_profile_font_size(avctx); + avctx->subtitle_header = av_asprintf( "[Script Info]\r\n" "; Script generated by FFmpeg/Lavc%s\r\n" @@ -135,6 +148,7 @@ static int libaribb24_init(AVCodecContext *avctx) Libaribb24Context *b24 = avctx->priv_data; void(* arib_dec_init)(arib_decoder_t* decoder) = NULL; int ret_code = AVERROR_EXTERNAL; + int profile = avctx->profile; if (!(b24->lib_instance = arib_instance_new(avctx))) { av_log(avctx, AV_LOG_ERROR, "Failed to initialize libaribb24!\n"); @@ -158,7 +172,10 @@ static int libaribb24_init(AVCodecContext *avctx) goto init_fail; } - switch (avctx->profile) { + if (profile == FF_PROFILE_UNKNOWN) + profile = b24->default_profile; + + switch (profile) { case FF_PROFILE_ARIB_PROFILE_A: arib_dec_init = arib_initialize_decoder_a_profile; break; @@ -209,7 +226,7 @@ static int libaribb24_handle_regions(AVCodecContext *avctx, AVSubtitle *sub) { Libaribb24Context *b24 = avctx->priv_data; const arib_buf_region_t *region = arib_decoder_get_regions(b24->decoder); - unsigned int profile_font_size = get_profile_font_size(avctx->profile); + unsigned int profile_font_size = get_profile_font_size(avctx); AVBPrint buf = { 0 }; int ret = 0; @@ -371,6 +388,10 @@ static const AVOption options[] = { OFFSET(aribb24_base_path), AV_OPT_TYPE_STRING, { .str = NULL }, 0, 0, SD }, { "aribb24-skip-ruby-text", "skip ruby text blocks during decoding", OFFSET(aribb24_skip_ruby), AV_OPT_TYPE_BOOL, { .i64 = 1 }, 0, 1, SD }, + { "default_profile", "default profile to use if not specified in the stream parameters", + OFFSET(default_profile), AV_OPT_TYPE_INT, { .i64 = FF_PROFILE_UNKNOWN }, FF_PROFILE_UNKNOWN, FF_PROFILE_ARIB_PROFILE_C, SD, "profile" }, + {"a", "Profile A", 0, AV_OPT_TYPE_CONST, {.i64 = FF_PROFILE_ARIB_PROFILE_A}, INT_MIN, INT_MAX, SD, "profile"}, + {"c", "Profile C", 0, AV_OPT_TYPE_CONST, {.i64 = FF_PROFILE_ARIB_PROFILE_C}, INT_MIN, INT_MAX, SD, "profile"}, { NULL } };