From patchwork Tue Dec 20 15:37:09 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dmitrii Ovchinnikov X-Patchwork-Id: 39735 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a05:6a20:bc95:b0:ad:ade2:bfd2 with SMTP id fx21csp5059089pzb; Tue, 20 Dec 2022 07:37:30 -0800 (PST) X-Google-Smtp-Source: AA0mqf5W7U4cdl+8pNDiU3M0Uciz1YA2An2Tor4F+6Ib6FeNxo4ZSxFnstUjDlg1h6mlEVy8QdLl X-Received: by 2002:a17:906:81d3:b0:7c1:515:a0ec with SMTP id e19-20020a17090681d300b007c10515a0ecmr31393110ejx.63.1671550650418; Tue, 20 Dec 2022 07:37:30 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1671550650; cv=none; d=google.com; s=arc-20160816; b=LZv62C5DTnIP9XpQX+YVdwJk7Xwd1Jqfqaydq0Mlz2e6vyFf1PQuvYu7ikzRg0PnyP 9bE6TnHCLVbru8lUqzDy9bddxyuSuj4VBeCgjZW6vr1JBuzSwxs1KLtm5AMv3lFcQsfM SDgIZuE8Bciv2SoDg0b6/htKgCgjd/i3hZ6ItEazmsPggrhhiPI3ZqDHKA/j+Wt5G+LZ UTvWgRQkrQJsctjL58HeFba3VyWSr1WRE5EHEeEx2BtGrGMtABIbvToOqNk2LVGW67F3 9AUk3V7PF+OuTEP6GN6Uq1DWCFmZfsbif+lrl86WV7sCSNGRuGFtj3OhS+sSLqCuEymW 3dYA== 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:message-id:date:to:from :dkim-signature:delivered-to; bh=OdKCDWAdHijcC6/ENmFXZvfNX/rpozVX7kVfpv7H8sg=; b=mKlo2yZ0qZmQzWSNY3/WaMlcbpCexz/HDetHZHyCBNcJYeuD7DJrMhX9i5Tisp9MCe PvgdO6k1OzlKXas1PYx2hsvZoCREirDt4IMGfZpHlMSeo9TkpL9D+7U0K1gML+S9A+5w JI8LqZcLa4y6tKRjX9qjNM6gHheOYKzsIp/PHwYgujxwfGhLwbT7sNAbgHzNt4RUBn7R I+p3wMi60GjSLRQHte+AvYDXtlNuV0OxJLWxr3tPnExJty6H087mfGXSy3QkY8L6Wqck CR9p4sSOU7f5iTypVuEyqzPE/fEIvNon2fF5Ci50k4xIM1ZCujBUBy00bttMLdCky979 0mig== ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (body hash did not verify) header.i=@gmail.com header.s=20210112 header.b=UlnU3yaN; 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=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from ffbox0-bg.mplayerhq.hu (ffbox0-bg.ffmpeg.org. [79.124.17.100]) by mx.google.com with ESMTP id du15-20020a17090772cf00b008173e855731si7048366ejc.624.2022.12.20.07.37.29; Tue, 20 Dec 2022 07:37:30 -0800 (PST) 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=@gmail.com header.s=20210112 header.b=UlnU3yaN; 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=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id B435768B9CA; Tue, 20 Dec 2022 17:37:26 +0200 (EET) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-wr1-f51.google.com (mail-wr1-f51.google.com [209.85.221.51]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 2E88668B1F1 for ; Tue, 20 Dec 2022 17:37:20 +0200 (EET) Received: by mail-wr1-f51.google.com with SMTP id y16so12130942wrm.2 for ; Tue, 20 Dec 2022 07:37:20 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:from:to:cc:subject:date:message-id:reply-to; bh=vm0FT5EN5QkxYkTK2NySaKVLbde+JZdPpigd+ndmP0s=; b=UlnU3yaNGWmR5pc4s2ztvIR8qKSwOCupQ32+tE9ypPUJ/2WOwWoh5E4c59hGoC/yvZ NiRdQjBlw/Y1rIkCJoMbVVcmj4H14IyCJ0/UptSkFwj2qwi7zXtgl6d5HPAOTsJa9UvT 1j+cSiyE9hl9Qgwn+3BpRuGli0f2BFwdLlizW/VYdvLq+hHwAl3xaiO1BPeDRl4h5OwW 6fDnAAgCnK3jVG1q2VInx1Q4dNV23GiIQurH6l0aB0qPNWV7rMA0aJjQi8OflW5bQZBV OWvGIGTSv6ziiI+UIbulveGgH8YNsyuqB1KCs6LjpC6BEGGfcHVEdjhVGvjPrKmmXo4c g30Q== 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:cc :to:from:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=vm0FT5EN5QkxYkTK2NySaKVLbde+JZdPpigd+ndmP0s=; b=wEDmrR0gBdE/uRTgWnhrOlBJkxh9S1g3cqmJAs9YHB1Oa/iKyYEyOvUNS+nvk7ceM6 ehtF7yZcVZ4t3060l9xLRUucItIuZYLtgzvh5wOPuzaj/sxHClYulkXWy94ekUR2hU6Z +gvjE5319U4YxwbY++DIUF7tW4iZIC1j/FRQSKBnel9Kd0wbJc7oajiDLBA/59mX3D8v tYHrxtQT6t9ZHk1HzYhSM8vUvjk5+Hmo4V8bKiEeqCl2BSzNLEvuSJD5mOBRzV1sOnN9 LJ/yHPRYzJekVg2uWo+qf5sdeKyQS8GiJSIH1THceNVJZObXVcdRnby/x6KTPfzP9Qdy AYDA== X-Gm-Message-State: ANoB5pl8Hg8MkvDBWLM4P5p0YkOITBwuyWkI57iZinEJTzNtFllCjDF0 2t62pjO+q0PbEfVZ7BJ3ZgM4xHvQnGk= X-Received: by 2002:a05:6000:10cf:b0:242:5ba8:d025 with SMTP id b15-20020a05600010cf00b002425ba8d025mr29542381wrx.39.1671550639076; Tue, 20 Dec 2022 07:37:19 -0800 (PST) Received: from dovchinn.amd.com (109-93-70-158.dynamic.isp.telekom.rs. [109.93.70.158]) by smtp.gmail.com with ESMTPSA id y1-20020adfd081000000b002421a8f4fa6sm13167716wrh.92.2022.12.20.07.37.18 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 20 Dec 2022 07:37:18 -0800 (PST) From: Dmitrii Ovchinnikov X-Google-Original-From: Dmitrii Ovchinnikov To: ffmpeg-devel@ffmpeg.org Date: Tue, 20 Dec 2022 16:37:09 +0100 Message-Id: <20221220153711.1831-1-Dmitriy.Ovchinnikov@amd.com> X-Mailer: git-send-email 2.38.1.windows.1 MIME-Version: 1.0 Subject: [FFmpeg-devel] [crop support for matroska demuxer, V4 1/3] libavcodec: Add crop related fields to structure AVCodecContext and AVCodecParameters. 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: Dmitrii Ovchinnikov Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" X-TUID: Hg4r6rdlIDxT From: Dmitrii Ovchinnikov --- libavcodec/avcodec.h | 35 +++++++++++++++++++++++++++++++++++ libavcodec/codec_par.h | 8 ++++++++ libavcodec/options_table.h | 4 ++++ 3 files changed, 47 insertions(+) diff --git a/libavcodec/avcodec.h b/libavcodec/avcodec.h index 3edd8e2636..57b340c24d 100644 --- a/libavcodec/avcodec.h +++ b/libavcodec/avcodec.h @@ -380,6 +380,19 @@ typedef struct RcOverride{ */ #define AV_GET_ENCODE_BUFFER_FLAG_REF (1 << 0) +/** +* Video decoding only. Certain container support cropping, meaning that +* only a sub-rectangle of the decoded frame is intended for display. +* Certain codec supports cropping as well.This option controls how +* cropping is handled by libavcodec when container cropping and +* codec cropping exist. +*/ +enum CONTAINER_CROPPING_POLICY_TYPE { + FF_CONTAINER_CROPPING_IGNORE = 0, + FF_CONTAINER_CROPPING_ADDITION, + FF_CONTAINER_CROPPING_OVERWRITE +}; + struct AVCodecInternal; /** @@ -2057,6 +2070,28 @@ typedef struct AVCodecContext { * The decoder can then override during decoding as needed. */ AVChannelLayout ch_layout; + + /* When set to 1 (the default), libavcodec will apply container cropping + * to codec cropping additionally. + * + * When set to 2, libavcodec will use container cropping to overwrite + * codec cropping (the final cropping uses container cropping parameters) + * + * When set to 0, libavcodec will ignore container cropping parameters + * (the final cropping uses codec cropping parameters) + * + * This field works with "apply_cropping". Only if apply_cropping is 1, this + * field works + */ + enum CONTAINER_CROPPING_POLICY_TYPE container_apply_cropping; + + /** + * The cropping parameters from container. + */ + int container_crop_top; + int container_crop_left; + int container_crop_bottom; + int container_crop_right; } AVCodecContext; /** diff --git a/libavcodec/codec_par.h b/libavcodec/codec_par.h index f51d27c590..cc0695689c 100644 --- a/libavcodec/codec_par.h +++ b/libavcodec/codec_par.h @@ -211,6 +211,14 @@ typedef struct AVCodecParameters { * Audio only. The channel layout and number of channels. */ AVChannelLayout ch_layout; + + /** + * The cropping parameters from container. + */ + int container_crop_top; + int container_crop_left; + int container_crop_bottom; + int container_crop_right; } AVCodecParameters; /** diff --git a/libavcodec/options_table.h b/libavcodec/options_table.h index cd02f5096f..fd1ef21f90 100644 --- a/libavcodec/options_table.h +++ b/libavcodec/options_table.h @@ -401,6 +401,10 @@ static const AVOption avcodec_options[] = { {"allow_profile_mismatch", "attempt to decode anyway if HW accelerated decoder's supported profiles do not exactly match the stream", 0, AV_OPT_TYPE_CONST, {.i64 = AV_HWACCEL_FLAG_ALLOW_PROFILE_MISMATCH }, INT_MIN, INT_MAX, V | D, "hwaccel_flags"}, {"extra_hw_frames", "Number of extra hardware frames to allocate for the user", OFFSET(extra_hw_frames), AV_OPT_TYPE_INT, { .i64 = -1 }, -1, INT_MAX, V|D }, {"discard_damaged_percentage", "Percentage of damaged samples to discard a frame", OFFSET(discard_damaged_percentage), AV_OPT_TYPE_INT, {.i64 = 95 }, 0, 100, V|D }, +{ "container_apply_cropping", "ploicy using container cropping parameters", OFFSET(container_apply_cropping), AV_OPT_TYPE_INT64, {.i64 = FF_CONTAINER_CROPPING_ADDITION }, 0, 2, V | D, "container_apply_cropping" }, +{ "ignore", "ignore container cropping", 0, AV_OPT_TYPE_CONST, {.i64 = FF_CONTAINER_CROPPING_IGNORE }, 0, 0, V | D, "container_apply_cropping" }, +{ "addition", "apply container cropping additionally to elementary stream cropping", 0, AV_OPT_TYPE_CONST, {.i64 = FF_CONTAINER_CROPPING_ADDITION }, 0, 0, V | D, "container_apply_cropping" }, +{ "overwrite", "use container cropping to overwrite elementary stream cropping", 0, AV_OPT_TYPE_CONST, {.i64 = FF_CONTAINER_CROPPING_OVERWRITE }, 0, 0, V | D, "container_apply_cropping" }, {NULL}, };