From patchwork Fri Oct 7 14:59:40 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dmitrii Ovchinnikov X-Patchwork-Id: 38603 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a05:6a21:789c:b0:9c:c2cd:5584 with SMTP id bf28csp70921pzc; Fri, 7 Oct 2022 08:00:08 -0700 (PDT) X-Google-Smtp-Source: AMsMyM4JXrCtmOynHPMZrHfAR9ytWZCZAokTAAMulQHyXTyy0NcCReOGh9tzSYnk2pcLPcxdEzXP X-Received: by 2002:a17:907:2e19:b0:78d:3e57:474a with SMTP id ig25-20020a1709072e1900b0078d3e57474amr4427536ejc.198.1665154807817; Fri, 07 Oct 2022 08:00:07 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1665154807; cv=none; d=google.com; s=arc-20160816; b=emcrECKsN37lE0/vNR7hF+ysdqOtLcurv7JrxhL8QFjvHBYGHr9ZStMzM6n4lEtLAO 5qCFW0UEy87F87PGFGUTAUC+7W/2lS/l0kWZeqCf/BbkbNyacaMcIwKcohGMdrGQzWqq hX7vKE4JOc2LoXcvP80d5zACQxSuRf6j/R9tDsB91nSCGt9VvfSyfuNryy6GjSHxKl24 UZjOFRbLHPFfK3oGihdpnOdW3DC8/R+EpVBdBIFvTAyuRaS+GKnFz3Cf1cvTkiui3+0v VLGXTFjAvrKUvRbHiqcK2mfqEli5WHN16l/YTBfBvhhxhVp8I6mPDuUc2FvM5U1sj5cI 3mag== 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=eOOU9LPXcvIbSJ/oI/zLGxEPBw1RXTNvun7DX5AE2iY=; b=JDapIadQOK7CR25bKCC8spq/7C/m9k88b8wi0P1KS1nO7Z5P8Xd1+AGz1uXEgzf4Xh +xM0GxpCMOyeAHr71gYtCHZKLiW0bmW7sULB8zOcAAswytA4CeU87S1/MNFCDyKREI/y lNIXksBeFGyWRaKBoHGjP7LHGXctdxbaLwFFJsPd19WlM+sLBU87gx1ogZWikzKYPfkH +/WDBh78wayM+SgN9BrKRqc1zEwGfVAn4m9wg+RbCN14AcYqLU39U0p9f3BQvxnJy4L1 8vuM2Ala+ZU8n/d5LyO13GZhVky83Z/NgSjPwZ6fDCtwncwJPxlaUKxLIIH3y4J+2yc9 AseA== ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (body hash did not verify) header.i=@gmail.com header.s=20210112 header.b="IKE/qRUM"; 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 k22-20020a170906681600b00770d9e664f8si2207354ejr.152.2022.10.07.08.00.06; Fri, 07 Oct 2022 08:00:07 -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=@gmail.com header.s=20210112 header.b="IKE/qRUM"; 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 5143768BB4E; Fri, 7 Oct 2022 18:00:02 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-wr1-f48.google.com (mail-wr1-f48.google.com [209.85.221.48]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id C29E068BAFA for ; Fri, 7 Oct 2022 17:59:55 +0300 (EEST) Received: by mail-wr1-f48.google.com with SMTP id bv10so4123603wrb.4 for ; Fri, 07 Oct 2022 07:59:55 -0700 (PDT) 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=4VZ+FIy9X3PRhSwkvoXa3XJKZkhzhK753KKs64vDtDI=; b=IKE/qRUM0DBT11HhAd/pxDy7lz09wnarTFuSTiTFbnsMEGd+2pOapYMK937JEQ1tAC v+Er4qtS25MGIqi8W1e+n+VnuDTo94ImDOkx4JBBq6BKDszNBzG4Q5nn4U7iB683ckCu GFkMCcZmFj0QxHSF5683k6Nm0a8M+e9/8H5d59uu1gFNnPLg2e2REMYuTeQrZbU8gzVD wkuFJZ1csa3uhfAKyr52ZixrCZddpO9AVyuupJHvTdfEfKFJVPOIkYFYKmJK0PowBHmH VelAqxzIIbqi5OyntIFybGMAw21SA6IKunZxZcxq6CNEYO/Q/rD/Ks/pkFO0c/hMMNLy m24A== 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=4VZ+FIy9X3PRhSwkvoXa3XJKZkhzhK753KKs64vDtDI=; b=k6dv5sgTchmCS8DbU2q9NFvW2LAoBxBGiDyU2R9/CpKyK8j/RqpIQK35zYlBhgitJV +9WHZl2HK+Gg89iKPDwQhMV7ShtDXoWAYeeKKsveoZElLrpG3Kk5LhtyKeeQVYEBY9oi qWQP6KijpzunYeZfYr/77PfvmGOh3KjPJCQva8d3hO96VJMrzCScL6t4TCj2isFL9fdw 5zmVTc1wFEwKaqmNzviBNBIfX3BQ6XionHW/EYNfpM42pN9UDECxGlQ3SzJ9Fbv9MJEq 9EtGXFNY5hlv2QFBoYMcyFa4yrXZoXyabPs8cQYaFi9VWoYlTbcUixkfoNbQKDcQ7Fuo kLPw== X-Gm-Message-State: ACrzQf1BvAdQ7i8s3Ay0YGCXskBl9g8qwg3e4+dpnptBeegurNjeqfcV 4IrQEOVQwOjHjrxRC/dLHbNsFmhm25b/wKaM X-Received: by 2002:a5d:452b:0:b0:22e:3d4a:2ea3 with SMTP id j11-20020a5d452b000000b0022e3d4a2ea3mr3425596wra.309.1665154794577; Fri, 07 Oct 2022 07:59:54 -0700 (PDT) Received: from localhost.localdomain (178-222-23-217.dynamic.isp.telekom.rs. [178.222.23.217]) by smtp.gmail.com with ESMTPSA id o5-20020adfe805000000b00228cd9f6349sm2245302wrm.106.2022.10.07.07.59.53 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 07 Oct 2022 07:59:53 -0700 (PDT) From: OvchinnikovDmitrii To: ffmpeg-devel@ffmpeg.org Date: Fri, 7 Oct 2022 16:59:40 +0200 Message-Id: <20221007145942.880-1-ovchinnikov.dmitrii@gmail.com> X-Mailer: git-send-email 2.30.0.windows.2 MIME-Version: 1.0 Subject: [FFmpeg-devel] [crop support for matroska demuxer, V3 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: OvchinnikovDmitrii Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" X-TUID: p1GzarqXM4Dh --- 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 7365eb5cc0..d28a7cc022 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 7660791a12..12d8ceb521 100644 --- a/libavcodec/codec_par.h +++ b/libavcodec/codec_par.h @@ -210,6 +210,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}, }; From patchwork Fri Oct 7 14:59:41 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dmitrii Ovchinnikov X-Patchwork-Id: 38604 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a05:6a21:789c:b0:9c:c2cd:5584 with SMTP id bf28csp71016pzc; Fri, 7 Oct 2022 08:00:18 -0700 (PDT) X-Google-Smtp-Source: AMsMyM7kuv1toFCN+ZSxENWxgnWH1qUZeYnZvsQeICOTlemV3SddNNY8HA+R6wIWy9DWvJ4lNhkq X-Received: by 2002:a17:906:db02:b0:780:24e:cf9 with SMTP id xj2-20020a170906db0200b00780024e0cf9mr4407001ejb.460.1665154818557; Fri, 07 Oct 2022 08:00:18 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1665154818; cv=none; d=google.com; s=arc-20160816; b=oUr7/F9UHES38egFRrXckl46QAQDGtjP5JNLVG+aJOkXq/wiN3aiTEXKsDoBOFozGU veI2xPymT7CSDrEEn9eLhaXZaLB2V6ttaT+VJZPeulmFJIKLgbZYs9qHNnpwR6a37CKA IYZpOYpDEwbyuiNHNCGVyzNZW36rgIrV0O5yq0IDbJTNOO0m3ZlhzvcK33Wrfvbf9Gkm 4APXTIELFRaz3b7c+DOJ8xcgJoMNQ8y3/5siS20bfdtvSzvsE1Xc66PhLiWrNNX6O68n 5Ma4Tlqb9LFh2BYtZv9xlFOJMj1GAqkzu/e+3G8tsNUe988StVr3cj4FUYgM2AnNiXhG amKA== 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:dkim-signature:delivered-to; bh=i44F9nwveiqm4Zt1eouEB2KTwe/qRL6QJdN1mnOIXhE=; b=L+5yDOgyW517tOUCR50LCDtZbrOGvDYeirWtuCZ6ozXu7HH+fK/LhyxCRgN8uOT2AA aydCVkXKCQYjMg0DLZPXQenHmlS+AgPeHi7Qg21duqGKAMi+yWsZtNdpA4BaLIHphu5M G5WSxDpLkXeVawlb7GivCTwbfHI6O5yZuaI+XEIki28ymsK7MStHHhDlyOYyp8cPX4vy 7/+WCEUcDo5OaC2Hf/I0X7E+qICvGNF5eiyu8f20l/WQATxDdsQtQEBopbn9qqo+cwiZ 50EEGQuGTMy/4qIi0m5MIyPXHItweJu7Fi1O3NAupuEB6kdkCJjkPgdLX/Vv2QqQVsv9 g/xA== ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (body hash did not verify) header.i=@gmail.com header.s=20210112 header.b=qeq5wyaW; 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 ho38-20020a1709070ea600b0078d484e0e79si2737058ejc.481.2022.10.07.08.00.17; Fri, 07 Oct 2022 08:00:18 -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=@gmail.com header.s=20210112 header.b=qeq5wyaW; 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 8A3A368BB7F; Fri, 7 Oct 2022 18:00:03 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-wr1-f45.google.com (mail-wr1-f45.google.com [209.85.221.45]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 8F9B168BB25 for ; Fri, 7 Oct 2022 17:59:56 +0300 (EEST) Received: by mail-wr1-f45.google.com with SMTP id f11so7702754wrm.6 for ; Fri, 07 Oct 2022 07:59:56 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=cp4HKm3i/MEDB8tsBKi+8J/E10PJQxFka0dewqn8HVw=; b=qeq5wyaW8897HZhi+8dMJINngG9ayiDWQS1gRtjsGOyDWjcKR2jjrUco/UZ9UUuM/y 2WdrgyZHxHIOmfWGRQLCbTJeDPT9hjS8N7JnevSKXGF9vaJ2s0JNmtGAIek+wGawXHrT 8ECwHgJDdLV8uNneZuM5RUTrtgcNwZykBfJeoYvq1Va7EO8n5NwMoehX/Wi9V7tRe+ql Z4aFfvnB4VFxP7xi+0CpYq9kWz/DGRcotsgcRp1q5JTSuT6IBX1HkLSNLFEa3zSlnAQ+ wQfDUYhGz/seJIB/betQVNAzKuJlgT2S0uQY8YEOgd9HkiCG1uaMxyZqx9f6FTMov900 fjTQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=cp4HKm3i/MEDB8tsBKi+8J/E10PJQxFka0dewqn8HVw=; b=xnxDoZb+1rofG84/Xlq78bgI0JW0bAiv31Xavo9IIXMoX3dtnX4bFRFAu/vAmBtmOw ZIMTOExYDwL9UIeInoNWLnqMZt808hqww5IxBs6iOQr87UHMESVk6VVTeA9VUL12p9Ab GWuIFyio718tWQhsXzu37bI01xy9Hl0CabhneXOkpb1j5mwsiC6LzGcSJfZTnRxrs0R9 9LxP+Hxp5hyOqAx/V6hU/X8BDOI2sj1E41QQ53xZzZuQjQuPQLzFSEYdakLZNBEUIXZZ U5xAY7CLoV4RklC5tPHqlxcLpd59la0G/NLQlXjLZwS+OvbveoVpW7GsDRy9EigJtWuy p2iA== X-Gm-Message-State: ACrzQf2Lxg0TzJGb6OD8WOQBjYaX0hm0/uaHBMYCgF11aYaNTBSTpQjR 18PdrmOT/KsIDdqi+WS9UDhMRWvGw4n33P4e X-Received: by 2002:a5d:6c62:0:b0:22a:2f59:cb7d with SMTP id r2-20020a5d6c62000000b0022a2f59cb7dmr3554460wrz.405.1665154795546; Fri, 07 Oct 2022 07:59:55 -0700 (PDT) Received: from localhost.localdomain (178-222-23-217.dynamic.isp.telekom.rs. [178.222.23.217]) by smtp.gmail.com with ESMTPSA id o5-20020adfe805000000b00228cd9f6349sm2245302wrm.106.2022.10.07.07.59.54 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 07 Oct 2022 07:59:54 -0700 (PDT) From: OvchinnikovDmitrii To: ffmpeg-devel@ffmpeg.org Date: Fri, 7 Oct 2022 16:59:41 +0200 Message-Id: <20221007145942.880-2-ovchinnikov.dmitrii@gmail.com> X-Mailer: git-send-email 2.30.0.windows.2 In-Reply-To: <20221007145942.880-1-ovchinnikov.dmitrii@gmail.com> References: <20221007145942.880-1-ovchinnikov.dmitrii@gmail.com> MIME-Version: 1.0 Subject: [FFmpeg-devel] [crop support for matroska demuxer, V3 2/3] libavcodec: Public code to support container crop 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: OvchinnikovDmitrii Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" X-TUID: VinP+hBzEa2d Support both simple and receive_frame api The container crop information is applied additional to frame crop information --- libavcodec/codec_par.c | 30 +++++++++++++++++++----------- libavcodec/decode.c | 14 ++++++++++++++ 2 files changed, 33 insertions(+), 11 deletions(-) diff --git a/libavcodec/codec_par.c b/libavcodec/codec_par.c index abda649aa8..9738402434 100644 --- a/libavcodec/codec_par.c +++ b/libavcodec/codec_par.c @@ -115,17 +115,21 @@ int avcodec_parameters_from_context(AVCodecParameters *par, switch (par->codec_type) { case AVMEDIA_TYPE_VIDEO: - par->format = codec->pix_fmt; - par->width = codec->width; - par->height = codec->height; - par->field_order = codec->field_order; - par->color_range = codec->color_range; - par->color_primaries = codec->color_primaries; - par->color_trc = codec->color_trc; - par->color_space = codec->colorspace; - par->chroma_location = codec->chroma_sample_location; - par->sample_aspect_ratio = codec->sample_aspect_ratio; - par->video_delay = codec->has_b_frames; + par->format = codec->pix_fmt; + par->width = codec->width; + par->height = codec->height; + par->container_crop_top = codec->container_crop_top; + par->container_crop_left = codec->container_crop_left; + par->container_crop_bottom = codec->container_crop_bottom; + par->container_crop_right = codec->container_crop_right; + par->field_order = codec->field_order; + par->color_range = codec->color_range; + par->color_primaries = codec->color_primaries; + par->color_trc = codec->color_trc; + par->color_space = codec->colorspace; + par->chroma_location = codec->chroma_sample_location; + par->sample_aspect_ratio = codec->sample_aspect_ratio; + par->video_delay = codec->has_b_frames; break; case AVMEDIA_TYPE_AUDIO: par->format = codec->sample_fmt; @@ -199,6 +203,10 @@ int avcodec_parameters_to_context(AVCodecContext *codec, codec->pix_fmt = par->format; codec->width = par->width; codec->height = par->height; + codec->container_crop_top = par->container_crop_top; + codec->container_crop_left = par->container_crop_left; + codec->container_crop_bottom = par->container_crop_bottom; + codec->container_crop_right = par->container_crop_right; codec->field_order = par->field_order; codec->color_range = par->color_range; codec->color_primaries = par->color_primaries; diff --git a/libavcodec/decode.c b/libavcodec/decode.c index 6be2d3d6ed..412c7cc2f4 100644 --- a/libavcodec/decode.c +++ b/libavcodec/decode.c @@ -693,6 +693,20 @@ static int apply_cropping(AVCodecContext *avctx, AVFrame *frame) if (!avctx->apply_cropping) return 0; + if (avctx->container_apply_cropping == FF_CONTAINER_CROPPING_ADDITION) + { + frame->crop_top += avctx->container_crop_top; + frame->crop_left += avctx->container_crop_left; + frame->crop_bottom += avctx->container_crop_bottom; + frame->crop_right += avctx->container_crop_right; + } + else if (avctx->container_apply_cropping == FF_CONTAINER_CROPPING_OVERWRITE) { + frame->crop_top = avctx->container_crop_top; + frame->crop_left = avctx->container_crop_left; + frame->crop_bottom = avctx->container_crop_bottom; + frame->crop_right = avctx->container_crop_right; + } + return av_frame_apply_cropping(frame, avctx->flags & AV_CODEC_FLAG_UNALIGNED ? AV_FRAME_CROP_UNALIGNED : 0); } From patchwork Fri Oct 7 14:59:42 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dmitrii Ovchinnikov X-Patchwork-Id: 38605 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a05:6a21:789c:b0:9c:c2cd:5584 with SMTP id bf28csp71083pzc; Fri, 7 Oct 2022 08:00:27 -0700 (PDT) X-Google-Smtp-Source: AMsMyM55dW0NevnPFlrAp0tHQhZL6iwVN93URP+BCBOZymOHtvv9uj/6MPcvm9uLHZydou+RPzPN X-Received: by 2002:a17:907:3f85:b0:733:3f0e:2f28 with SMTP id hr5-20020a1709073f8500b007333f0e2f28mr4434553ejc.376.1665154827720; Fri, 07 Oct 2022 08:00:27 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1665154827; cv=none; d=google.com; s=arc-20160816; b=rtYc3L9OYg1Iw0E6KyP8obhSTIaPw+wp0m2sDqXditoW4QG2ySSh6wTvHec+DATwM7 mx82mqDtq5ED1nu1xTUoZBtbNbazKRpecCFDwGm7ZxPXOfJbijEhJ1jUgutPx/Wbs8SA rfwsZIS6/8bMetusXYqI34Bi/233KHMTxyRl6GDBzvMLx1oawVmf3yrxNpwQubIHTz4d iMnTYX0TexSm0CQABt/nJAGSzgYJ4o65NBN5jOHPow8p7ouFu12oqdNuOCt/NAMEIp+W BRAHnD1IHJr2GTQkb9lG+/M0T1sl5xykegL9HfD6Q80kEu3zALZ9y3CVcMpOvxJAs1zJ ZUeQ== 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:dkim-signature:delivered-to; bh=57MIS0ABsmnzJZtXTSbk36JPc03FAXikwD/K2cJqnSY=; b=MJWfrZrWm0hIjBDR4bYHN7o4cyqk0qjAfPAiZzkaOU0lbMAO3ayCqQLIITKOlYMeW8 YkFV6sUX0b1YHYXUGytSdRt0ETBgIpcmlOB8dKvEGEYy/EDRRmliszZJ81HPDBz4qSs6 13vSVO9+gPNKTCZBSmw2y97bA9muex69lJOOAPR3Dgfso7e1NXeHMM3eSaqCPEzNR3pP GAWDFgcCuD5S3MPoSem+ZA+fpxF3LsAUDVxJgWyDf1FpkjEHeKKmMJJ1C55+2cDvE/lM +v5ZQ60M+D1F+28TEverSy6LCUtbmaz+XLsjZR0/iF1NfRtKJKYaBG8WoMB03WFF9lNA GsOw== ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (body hash did not verify) header.i=@gmail.com header.s=20210112 header.b=Jdzcl9nw; 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 nb13-20020a1709071c8d00b00781c9c3b6f5si2829095ejc.474.2022.10.07.08.00.27; Fri, 07 Oct 2022 08:00:27 -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=@gmail.com header.s=20210112 header.b=Jdzcl9nw; 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 B2A3268BB97; Fri, 7 Oct 2022 18:00:04 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-wm1-f43.google.com (mail-wm1-f43.google.com [209.85.128.43]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 7004868BA1B for ; Fri, 7 Oct 2022 17:59:57 +0300 (EEST) Received: by mail-wm1-f43.google.com with SMTP id p26-20020a7bcc9a000000b003c384e59047so785196wma.4 for ; Fri, 07 Oct 2022 07:59:57 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=EMKN36PBkgiECH2gzWDbrsJ24HfA3V9ZKSlVvR2a6Ew=; b=Jdzcl9nwE4P8E6XYhbt6d8OPj1gr3Lo+fjMotBPQVfpDVnlqCN3ONkZ1llBOAz3CDZ TqV5lAMZkgNMSeAAnszt9AYMe4imeJ4P8cT9fX5sEtwQW7z597CHDu/kZO2dIYgOCljx xkehQz0UDxWetF2ITHsJMAL3K+x7WLlW71onU9l63851zPe0UacLLcUHfkOxLEJFN+uG RfzzU1Fn9iDBEMThcvdV9CUGyGydEWY0d9uteOElJCTFU8tth+DkD8/cvxYT4YuK4c/T tmx2t7b992q107ZZ8+/yo+WnQ6ujF8ib4ubsmDT4BpkL6L3TP2NKB7Vke9kjzmQFI2Wn vzbg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=EMKN36PBkgiECH2gzWDbrsJ24HfA3V9ZKSlVvR2a6Ew=; b=Ha7p6ag0qO8/eLt+by6bvEzs0Vtm0upL1dLjIlyqJ8kcbtYkbdaz/mtLVhISfVqo+l r1BNMJv2S+bhQIELGiUO81DeT0enPcXScSAAcw2k3Bkgwp7w7j9SjiMEY9exSq4ocsCq OxVIc5QhawoUSdCwgbyjuJwVB7/kMadOygdGvGLXMU7ButP2M6IpXmJ7ObngqNvd6a2X kkVm0chd3WfEMId9znPWy7Hlk6GmL/cWLHVFuCeHTnks0K/PCy9//WM+ZUFk5MUJhQej 6vPM69XaDJ8L8yU1vwNOdURO1ro3X5/g8tSy3LvhsDQ5deHjCkSbTDqsZwsegQ5IsUnh 0NQA== X-Gm-Message-State: ACrzQf0UOvP3Zuz6svCr7eYZRLbRuCum+LOS405/1kCueAZpNiJGCBPm Pd87j6FBrMZfSPO76t7VeDX5QEc7yMPB1Wpw X-Received: by 2002:a05:600c:3d0c:b0:3b4:c481:c63b with SMTP id bh12-20020a05600c3d0c00b003b4c481c63bmr10204214wmb.147.1665154796439; Fri, 07 Oct 2022 07:59:56 -0700 (PDT) Received: from localhost.localdomain (178-222-23-217.dynamic.isp.telekom.rs. [178.222.23.217]) by smtp.gmail.com with ESMTPSA id o5-20020adfe805000000b00228cd9f6349sm2245302wrm.106.2022.10.07.07.59.55 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 07 Oct 2022 07:59:55 -0700 (PDT) From: OvchinnikovDmitrii To: ffmpeg-devel@ffmpeg.org Date: Fri, 7 Oct 2022 16:59:42 +0200 Message-Id: <20221007145942.880-3-ovchinnikov.dmitrii@gmail.com> X-Mailer: git-send-email 2.30.0.windows.2 In-Reply-To: <20221007145942.880-1-ovchinnikov.dmitrii@gmail.com> References: <20221007145942.880-1-ovchinnikov.dmitrii@gmail.com> MIME-Version: 1.0 Subject: [FFmpeg-devel] [crop support for matroska demuxer, V3 3/3] libavformat\matroskadec.c: crop support for matroska demuxer. 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: OvchinnikovDmitrii Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" X-TUID: t/a4S67LgQiQ In webm specification, it supports cropping information. (https://www.webmproject.org/docs/container/) In ffmpeg, the implementation of webm is a subset of matroska. In matroskadec.c, those cropping related four fields are forced to 0. for the sample file with crop (crop_bottom =8, crop_top=crop_left=crop_right=0.) ffmpeg.exe -i test_with_container_crop.webm -pix_fmt yuv420p -y output.yuv original ffmpeg code - the output.yuv resolution is 1920x1088 changed code - the output.yuv resolution is 1920x1080 Previous discussion :https://patchwork.ffmpeg.org/project/ffmpeg/list/?series=7668 --- libavformat/matroskadec.c | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) diff --git a/libavformat/matroskadec.c b/libavformat/matroskadec.c index d582f566a2..2023fd4977 100644 --- a/libavformat/matroskadec.c +++ b/libavformat/matroskadec.c @@ -210,6 +210,10 @@ typedef struct MatroskaTrackVideo { uint64_t pixel_width; uint64_t pixel_height; EbmlBin color_space; + uint64_t pixel_cropt; + uint64_t pixel_cropl; + uint64_t pixel_cropb; + uint64_t pixel_cropr; uint64_t display_unit; uint64_t interlaced; uint64_t field_order; @@ -517,10 +521,10 @@ static EbmlSyntax matroska_track_video[] = { { MATROSKA_ID_VIDEOALPHAMODE, EBML_UINT, 0, 0, offsetof(MatroskaTrackVideo, alpha_mode), { .u = 0 } }, { MATROSKA_ID_VIDEOCOLOR, EBML_NEST, 0, sizeof(MatroskaTrackVideoColor), offsetof(MatroskaTrackVideo, color), { .n = matroska_track_video_color } }, { MATROSKA_ID_VIDEOPROJECTION, EBML_NEST, 0, 0, offsetof(MatroskaTrackVideo, projection), { .n = matroska_track_video_projection } }, - { MATROSKA_ID_VIDEOPIXELCROPB, EBML_NONE }, - { MATROSKA_ID_VIDEOPIXELCROPT, EBML_NONE }, - { MATROSKA_ID_VIDEOPIXELCROPL, EBML_NONE }, - { MATROSKA_ID_VIDEOPIXELCROPR, EBML_NONE }, + { MATROSKA_ID_VIDEOPIXELCROPT, EBML_UINT, 0, 0, offsetof(MatroskaTrackVideo, pixel_cropt), {.u = 0 } }, + { MATROSKA_ID_VIDEOPIXELCROPL, EBML_UINT, 0, 0, offsetof(MatroskaTrackVideo, pixel_cropl), {.u = 0 } }, + { MATROSKA_ID_VIDEOPIXELCROPB, EBML_UINT, 0, 0, offsetof(MatroskaTrackVideo, pixel_cropb), {.u = 0 } }, + { MATROSKA_ID_VIDEOPIXELCROPR, EBML_UINT, 0, 0, offsetof(MatroskaTrackVideo, pixel_cropr), {.u = 0 } }, { MATROSKA_ID_VIDEODISPLAYUNIT, EBML_UINT, 0, 0, offsetof(MatroskaTrackVideo, display_unit), { .u= MATROSKA_VIDEO_DISPLAYUNIT_PIXELS } }, { MATROSKA_ID_VIDEOFLAGINTERLACED, EBML_UINT, 0, 0, offsetof(MatroskaTrackVideo, interlaced), { .u = MATROSKA_VIDEO_INTERLACE_FLAG_UNDETERMINED } }, { MATROSKA_ID_VIDEOFIELDORDER, EBML_UINT, 0, 0, offsetof(MatroskaTrackVideo, field_order), { .u = MATROSKA_VIDEO_FIELDORDER_UNDETERMINED } }, @@ -2879,6 +2883,11 @@ static int matroska_parse_tracks(AVFormatContext *s) st->codecpar->width = track->video.pixel_width; st->codecpar->height = track->video.pixel_height; + st->codecpar->container_crop_top = track->video.pixel_cropt; + st->codecpar->container_crop_left = track->video.pixel_cropl; + st->codecpar->container_crop_bottom = track->video.pixel_cropb; + st->codecpar->container_crop_right = track->video.pixel_cropr; + if (track->video.interlaced == MATROSKA_VIDEO_INTERLACE_FLAG_INTERLACED) st->codecpar->field_order = mkv_field_order(matroska, track->video.field_order); else if (track->video.interlaced == MATROSKA_VIDEO_INTERLACE_FLAG_PROGRESSIVE)