From patchwork Tue Jul 9 01:55:19 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: James Almer X-Patchwork-Id: 50429 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a05:612c:fad:b0:482:c625:d099 with SMTP id kf13csp98154vqb; Mon, 8 Jul 2024 18:57:05 -0700 (PDT) X-Forwarded-Encrypted: i=2; AJvYcCW8CfBJQODzPQXaBVGr5kvcFLUrftV47ccpC/tyTT28iv1dOyK7XRqfaeSjmk1Bm2zqxlO7ShTfLURiWYDNKxsvTR5MV+yWzm1NUg== X-Google-Smtp-Source: AGHT+IHFAdn5V/3RIas28lymoy4//SZySIhawonfJgnN7bLACYS28S8YO2/nrzOv2flHDKYwlmht X-Received: by 2002:a05:6402:2690:b0:57c:bec1:ff4b with SMTP id 4fb4d7f45d1cf-594dcd76de4mr594634a12.10.1720490225255; Mon, 08 Jul 2024 18:57:05 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1720490225; cv=none; d=google.com; s=arc-20160816; b=JYzssIWzaS9C+UHvyHLjEhFc44AhT2Wri/tfMCuMJF5ygVYth5IjrRUmZxScry5y4J 42zsNrqGzfIdloi1GCJ+GIxzmMXUFtx0zxVvX1Y8UK3KKJ53G6V37C+VwqfJQ6mB6zzT IyfCanSu/c4g7oOJPnz1U5s2kfGtFbBr+CxoUMmI1pmZcCuc+lmrpXsqsFLBI+TXX670 iBj/Y1mDRWo+sfRd8HMe/lTqx38tHfLcamfrA7XeUHcUXsAEOzVrBVxGGU/z3G4sUaPI kgr3flvDGj9Y1Y58Kpp21KfObZFQRk+mSZtQkKkQ2V7gYgbixTxVgthurQV/EKHlKnkq HuxQ== 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=Y73sFCfHdTZBY6dj1kjncYXQARw0sXs+5ZI/ZGwzvtc=; fh=YOA8vD9MJZuwZ71F/05pj6KdCjf6jQRmzLS+CATXUQk=; b=cznfUBI8aBlYSDydu1r2PbjbWKlFWCeFpq+5kTrCPjrnzUo0DYnpLMB0oItm4WHFv5 7YJh4ftinjxHL+i+xTDvL3hwvt1B09YJi2nRB21rpxFe1P109qZGuQiHa0WTdI+07XEi WOEVOmjAPGlWPqiTO8A8pTgbVZ55TDbSXoQuefce8dd9pWoq6dE3AQQ53NFNaF8qPk9i RbMHobCtLkDdqMoM3gc/LHXKF+JVnU2s3HmpSfvI1bqFYHlEtlPDA/N1Um4sE0fxZ2Wb tJ8RP13V0DRljA8ITFtJMSwP9EM/bEVwWETfWRdY6JAZdYQn/n+us/2xuF/uneTVTWbd ZRXQ==; dara=google.com ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (body hash did not verify) header.i=@gmail.com header.s=20230601 header.b=CfTVk9vn; 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 4fb4d7f45d1cf-594bde5f2f4si424135a12.389.2024.07.08.18.57.04; Mon, 08 Jul 2024 18:57:05 -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=20230601 header.b=CfTVk9vn; 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 9720868DA4C; Tue, 9 Jul 2024 04:57:01 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-pl1-f174.google.com (mail-pl1-f174.google.com [209.85.214.174]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id B2E0B68D90D for ; Tue, 9 Jul 2024 04:56:54 +0300 (EEST) Received: by mail-pl1-f174.google.com with SMTP id d9443c01a7336-1faad2f1967so38257875ad.0 for ; Mon, 08 Jul 2024 18:56:54 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1720490212; x=1721095012; darn=ffmpeg.org; h=content-transfer-encoding:mime-version:message-id:date:subject:to :from:from:to:cc:subject:date:message-id:reply-to; bh=7nKPuqY6L3OTCXe5Ngt4HbUXC8B0IWFr5l+PvGqU7No=; b=CfTVk9vnHRJOl71jf3p4dj0TImMDPcA7AW9A7i8yoSAEz6jGsv2nI7TeBjbmwsKgWH YNku0zmHYsp11kFolmBrMXL7rUrAAp7lKl8pyeZApF/eBaQ/+sWLW468JRT6dUN50Syf q8xSYSTHkh9zxyOYL81S4Paw7AInRJ25yhZ8csH0yfP3F8JBsueFP8MVF1yXYjANXLsx lrpnDgZJTovF98o07mEnVaffDRm1xPCQpsxxFLLchs/XPIKGWNjMMDJVvsqSBexCHcA3 AIvR2gQO401Hxu98xjF/WsQf1azsDuucNbWddS/WEusG6wHsV0ArmMXjdK19aAviKVaC jT5Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1720490212; x=1721095012; 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=7nKPuqY6L3OTCXe5Ngt4HbUXC8B0IWFr5l+PvGqU7No=; b=dbH+MGRwtrMZXQeGEcTvXGaAP38gmtxW+qhGBIGZJ0S9kRYZ94DkIhL2O2eudvFjkq +HLh2cT2K+c8RqzG728CUGofWK+X+p2vFbtndqmczuiLgC4iOZwKrLH2Qy89ydi7JY5O URIoPf2Tx0Q4FDc7wXixNtmnHslXZApeMiZnDKJcqxoe1EO8qfzB8Oo6KFo9kvSJQ7CG GMKK+VLhliWvYpjFtlayVeL9BJe701inBttiK0/o0/Ckk42ahlDixqidiQRgtrPec2Tf bA4nzubP4Wrd6oUBwnDzuA5SwumKo/+FrYZekDgEe/y6QvfNOJE+ktZBYw/mNAnXLOuv 9ENA== X-Gm-Message-State: AOJu0YxAhxkAJiB6EIL7nC1LauJFr5mFcbraSAQZEEDE06A3+68pLt7g zpxnVAqgTasFNj3NyYO22Pgc21VHizHlDt6b6OVobFe9QfXPbUhXdlak7Q== X-Received: by 2002:a17:902:d488:b0:1f9:a69d:4e05 with SMTP id d9443c01a7336-1fbb7fe5a5amr12293605ad.19.1720490211531; Mon, 08 Jul 2024 18:56:51 -0700 (PDT) Received: from localhost.localdomain ([190.194.167.233]) by smtp.gmail.com with ESMTPSA id d9443c01a7336-1fbb6a2f055sm5022935ad.110.2024.07.08.18.56.50 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 08 Jul 2024 18:56:51 -0700 (PDT) From: James Almer To: ffmpeg-devel@ffmpeg.org Date: Mon, 8 Jul 2024 22:55:19 -0300 Message-ID: <20240709015521.10083-1-jamrial@gmail.com> X-Mailer: git-send-email 2.45.2 MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH 1/2] avformat/mov: export cropping values from clap boxes 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: GODP6zvaLKHN Addresses part of ticket #7437. Signed-off-by: James Almer --- libavformat/mov.c | 78 +++++++++++++++++++++++++ tests/ref/fate/aic | 32 +++++----- tests/ref/fate/prores-transparency | 4 +- tests/ref/fate/prores-transparency_skip | 4 +- 4 files changed, 98 insertions(+), 20 deletions(-) diff --git a/libavformat/mov.c b/libavformat/mov.c index d862434d25..0e290617ed 100644 --- a/libavformat/mov.c +++ b/libavformat/mov.c @@ -1208,6 +1208,83 @@ static int mov_read_wfex(MOVContext *c, AVIOContext *pb, MOVAtom atom) return ret; } +static int mov_read_clap(MOVContext *c, AVIOContext *pb, MOVAtom atom) +{ + AVStream *st; + AVPacketSideData *sd; + AVRational aperture_width, aperture_height, horiz_off, vert_off; + AVRational pc_x, pc_y; + int top, bottom, left, right; + + if (c->fc->nb_streams < 1) + return 0; + st = c->fc->streams[c->fc->nb_streams-1]; + + aperture_width.num = avio_rb32(pb); + aperture_width.den = avio_rb32(pb); + aperture_height.num = avio_rb32(pb); + aperture_height.den = avio_rb32(pb); + + horiz_off.num = avio_rb32(pb); + horiz_off.den = avio_rb32(pb); + vert_off.num = avio_rb32(pb); + vert_off.den = avio_rb32(pb); + + if (aperture_width.num < 0 || aperture_width.den < 0 || + aperture_height.num < 0 || aperture_height.den < 0 || + horiz_off.den < 0 || vert_off.den < 0 || + av_q2d(aperture_width) > st->codecpar->width || + av_q2d(aperture_height) > st->codecpar->height) + return AVERROR_INVALIDDATA; + + av_log(c->fc, AV_LOG_TRACE, "clap: apertureWidth %d/%d, apertureHeight %d/%d " + "horizOff %d/%d vertOff %d/%d\n", + aperture_width.num, aperture_width.den, aperture_height.num, aperture_height.den, + horiz_off.num, horiz_off.den, vert_off.num, vert_off.den); + + pc_x = av_mul_q((AVRational) { st->codecpar->width - 1, 1 }, (AVRational) { 1, 2 }); + pc_x = av_add_q(pc_x, horiz_off); + pc_y = av_mul_q((AVRational) { st->codecpar->height - 1, 1 }, (AVRational) { 1, 2 }); + pc_y = av_add_q(pc_y, vert_off); + + aperture_width = av_sub_q(aperture_width, (AVRational) { 1, 1 }); + aperture_width = av_mul_q(aperture_width, (AVRational) { 1, 2 }); + aperture_height = av_sub_q(aperture_height, (AVRational) { 1, 1 }); + aperture_height = av_mul_q(aperture_height, (AVRational) { 1, 2 }); + + left = av_q2d(av_sub_q(pc_x, aperture_width)); + right = av_q2d(av_add_q(pc_x, aperture_width)); + top = av_q2d(av_sub_q(pc_y, aperture_height)); + bottom = av_q2d(av_add_q(pc_y, aperture_height)); + + if (top < 0 || bottom < 0 || + left < 0 || right < 0 || + bottom > (st->codecpar->height - 1) || + right > (st->codecpar->width - 1)) + return AVERROR_INVALIDDATA; + + bottom = st->codecpar->height - 1 - bottom; + right = st->codecpar->width - 1 - right; + + if ((left + right) >= st->codecpar->width || + (top + bottom) >= st->codecpar->height) + return AVERROR_INVALIDDATA; + + sd = av_packet_side_data_new(&st->codecpar->coded_side_data, + &st->codecpar->nb_coded_side_data, + AV_PKT_DATA_FRAME_CROPPING, + sizeof(uint32_t) * 4, 0); + if (!sd) + return AVERROR(ENOMEM); + + AV_WL32(sd->data, top); + AV_WL32(sd->data + 4, bottom); + AV_WL32(sd->data + 8, left); + AV_WL32(sd->data + 12, right); + + return 0; +} + /* This atom overrides any previously set aspect ratio */ static int mov_read_pasp(MOVContext *c, AVIOContext *pb, MOVAtom atom) { @@ -8922,6 +8999,7 @@ static const MOVParseTableEntry mov_default_parse_table[] = { { MKTAG('a','l','a','c'), mov_read_alac }, /* alac specific atom */ { MKTAG('a','v','c','C'), mov_read_glbl }, { MKTAG('p','a','s','p'), mov_read_pasp }, +{ MKTAG('c','l','a','p'), mov_read_clap }, { MKTAG('s','i','d','x'), mov_read_sidx }, { MKTAG('s','t','b','l'), mov_read_default }, { MKTAG('s','t','c','o'), mov_read_stco }, diff --git a/tests/ref/fate/aic b/tests/ref/fate/aic index 244ea25967..30197129f7 100644 --- a/tests/ref/fate/aic +++ b/tests/ref/fate/aic @@ -1,20 +1,20 @@ #tb 0: 100/2997 #media_type 0: video #codec_id 0: rawvideo -#dimensions 0: 1440x1080 +#dimensions 0: 1416x1062 #sar 0: 4/3 -0, 0, 0, 1, 2332800, 0xc22b8485 -0, 1, 1, 1, 2332800, 0xc22b8485 -0, 2, 2, 1, 2332800, 0xe0c21bd8 -0, 3, 3, 1, 2332800, 0x3e1a8fa0 -0, 4, 4, 1, 2332800, 0xbcb3f235 -0, 5, 5, 1, 2332800, 0x1a7cabd6 -0, 6, 6, 1, 2332800, 0xc0136ba8 -0, 7, 7, 1, 2332800, 0x295e59a6 -0, 8, 8, 1, 2332800, 0xf9c09288 -0, 9, 9, 1, 2332800, 0x0518cc8f -0, 10, 10, 1, 2332800, 0x9ad3068e -0, 11, 11, 1, 2332800, 0x5a8b7af1 -0, 12, 12, 1, 2332800, 0x7b35a8fa -0, 13, 13, 1, 2332800, 0xbe5801eb -0, 14, 14, 1, 2332800, 0x31ca019f +0, 0, 0, 1, 2255688, 0x48f3973d +0, 1, 1, 1, 2255688, 0x48f3973d +0, 2, 2, 1, 2255688, 0x8c9f3c83 +0, 3, 3, 1, 2255688, 0xb89c02e3 +0, 4, 4, 1, 2255688, 0x185b1a84 +0, 5, 5, 1, 2255688, 0x82167715 +0, 6, 6, 1, 2255688, 0xe675971e +0, 7, 7, 1, 2255688, 0x623759db +0, 8, 8, 1, 2255688, 0x910274ad +0, 9, 9, 1, 2255688, 0x0eafce15 +0, 10, 10, 1, 2255688, 0x4457b006 +0, 11, 11, 1, 2255688, 0x48f70e0b +0, 12, 12, 1, 2255688, 0xfd269c3d +0, 13, 13, 1, 2255688, 0x4c6258ad +0, 14, 14, 1, 2255688, 0xb131c4af diff --git a/tests/ref/fate/prores-transparency b/tests/ref/fate/prores-transparency index 246e0b26aa..a4452e7333 100644 --- a/tests/ref/fate/prores-transparency +++ b/tests/ref/fate/prores-transparency @@ -1,13 +1,13 @@ #tb 0: 1/25 #media_type 0: video #codec_id 0: rawvideo -#dimensions 0: 1920x1080 +#dimensions 0: 1888x1062 #sar 0: 1/1 #tb 1: 1/48000 #media_type 1: audio #codec_id 1: pcm_s16le #sample_rate 1: 48000 #channel_layout_name 1: stereo -0, 0, 0, 1, 16588800, 0xcfb3d806 +0, 0, 0, 1, 16040448, 0x74480f47 1, 0, 0, 1024, 4096, 0x00000000 1, 1024, 1024, 896, 3584, 0x00000000 diff --git a/tests/ref/fate/prores-transparency_skip b/tests/ref/fate/prores-transparency_skip index 3f5fa0a13f..3e99a3de94 100644 --- a/tests/ref/fate/prores-transparency_skip +++ b/tests/ref/fate/prores-transparency_skip @@ -1,13 +1,13 @@ #tb 0: 1/25 #media_type 0: video #codec_id 0: rawvideo -#dimensions 0: 1920x1080 +#dimensions 0: 1888x1062 #sar 0: 1/1 #tb 1: 1/48000 #media_type 1: audio #codec_id 1: pcm_s16le #sample_rate 1: 48000 #channel_layout_name 1: stereo -0, 0, 0, 1, 12441600, 0x74f53304 +0, 0, 0, 1, 12030336, 0x088e6a36 1, 0, 0, 1024, 4096, 0x00000000 1, 1024, 1024, 896, 3584, 0x00000000 From patchwork Tue Jul 9 01:55:20 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: James Almer X-Patchwork-Id: 50430 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a05:612c:fad:b0:482:c625:d099 with SMTP id kf13csp98194vqb; Mon, 8 Jul 2024 18:57:14 -0700 (PDT) X-Forwarded-Encrypted: i=2; AJvYcCXcN3I0eztgind0dkac52N/IDJjydcq8TH+RUqtImjg6HwoObOwLL16LJkrKu5tgioSseRY3JIj3LMe0T+cBdTQHTzTMwOrOSODbg== X-Google-Smtp-Source: AGHT+IE4m7QJqckT91Gyin9q8isI/C5yZcHdzmccJiAdnCN1V7xMZrft5+zEOYXe+vij0VJTcaa4 X-Received: by 2002:a17:907:e92:b0:a6f:586b:6c1 with SMTP id a640c23a62f3a-a780b88459emr90235366b.56.1720490234719; Mon, 08 Jul 2024 18:57:14 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1720490234; cv=none; d=google.com; s=arc-20160816; b=cWAy2VVTKamf/20FnLvsWZV6e/XlLicTlVy9U7uEWBbkgggRj0yY9sFxmlOJ+bhbe9 XksS/jNBX2RJo9F6OeDjuY9ppmCZXMiMlJicKuoVwsatg/7YKunclI43HOsp95cYRt4k eXkPM1hMETAgAX4fWYidBdzwq9RM6DsU6obrnObQBFjqUtUvg8U1ulI9o95YPyz31+02 anIfVan0yDMEfuekxTh8MphNj8DvD4rpjih61rRMC2TymKAuob3hwwBkbQq0yKyvp8QR cSO5MuucCr8iyWqjC7uj8tLRcmDfRc1IdeqSdhTUzHtmHx/cL1SBFq0VwBioKRCzVy+M OeNg== 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:references:in-reply-to:message-id :date:to:from:dkim-signature:delivered-to; bh=TieeA4tkTNrDlFN2nl5NVnuFKpFPd1xdPesd0OhJerc=; fh=YOA8vD9MJZuwZ71F/05pj6KdCjf6jQRmzLS+CATXUQk=; b=sKwnZe49CW7qKdGxmNg1k95fQO5FLcHMr0PU5HA4D/USMVPZDoMNzm8BQVcjnkHE48 msimhvembpDqUWAJ/BACCqQ6kINHyuhFh9V/KDKTBAFwI1Gej3TIEGI5UATUU4bmRN6x hl+lHhfvfU81AufPlgTpsbcf8QiUB3HlraS8W7leUwoNeHodezepD5RWep0sXiUsEW7m XjMpBZihzRfWMtg3RvYoJE4svaegsjbR2tYTcnLgat9DNxwT5EEuI3/msw1gwMBG28zT CmbBmH37FTVqql+7G5vjtjskCsTTo/atoGsQyMwNo5s9cJby6dvalMonF9fBhp9Zve87 cEog==; dara=google.com ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (body hash did not verify) header.i=@gmail.com header.s=20230601 header.b=OeZ4GHTP; 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 a640c23a62f3a-a780a9c84b1si50308466b.100.2024.07.08.18.57.14; Mon, 08 Jul 2024 18:57:14 -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=20230601 header.b=OeZ4GHTP; 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 0EF3E68DA65; Tue, 9 Jul 2024 04:57:05 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-pl1-f179.google.com (mail-pl1-f179.google.com [209.85.214.179]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 5AAB168DA4C for ; Tue, 9 Jul 2024 04:56:56 +0300 (EEST) Received: by mail-pl1-f179.google.com with SMTP id d9443c01a7336-1fb3cf78fbdso22949095ad.1 for ; Mon, 08 Jul 2024 18:56:56 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1720490213; x=1721095013; darn=ffmpeg.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:from:to:cc:subject:date:message-id :reply-to; bh=hSZpLBoeNPfeddiqEpImZf7tpNLmfrP4bGVhDKvGPLY=; b=OeZ4GHTPk9qlhexqZRlbRjFyan0qviwmrNhcxZKK1dktym0DBBjETKfzG1Pti1MGXH 2n49ZLayG5GCN9tQ2cVl2LnzhVkb1jR5jqSD8lCQO/dT5C3EKSXmBkBCylU8zdBLbkT5 x4a6k0nybSaAwa+5If9cmOX6gs3QbuHFYt7gotNz9FU5q/qBMZhGHHeG/YfksM29oc9w Kw8uFyIV+5E3H7cfRZ0jMMUi+CCY0wM0gtusYHjjdXOPeLLhY6FfKr6uEZRDYu2dSWkZ N9DuVjPdlvv9GpZPR5PLm0Z35AytTX4XGDSMjCQlzGV+x9hSfTKW7wIuPZ7uZCL0XXNg zsdQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1720490213; x=1721095013; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=hSZpLBoeNPfeddiqEpImZf7tpNLmfrP4bGVhDKvGPLY=; b=fqnn/NsxCRz+FF141KJFwM7MeidF5UKLmlV3+uyVCGvmjqzlQrywiKPm1gJBmzPyIY P03hD0gKZxYDcPM2mUlJKSNF4dBmWPMI//KzQijbo0XjeTV3G/mGNWR+H2/swYt6yqml VHTFCUtAiZhhEmyHOvS+SarYwQzIA0KYwpPG0nYiN/XxRX+2nmRETlLWnxgiE3bLadss XnpCauP44w652mfBFKBS2LrLo1l8yqCyMxy5xsmYwOTG73Zxfvx9woFv8DGscIjdA88Q py4ajlPteSOj8qqm/sYeK02tdFl5xO6Bz0ynHVxN6Bq4vYx6sTX1P7LIDey+KbgpLZBE WAoA== X-Gm-Message-State: AOJu0Yw3C3TXAL3hHiHNi6z/6ZfXnMVbelIXfCmNMBP3RwLzsH7tAy2+ TfkXTnE8D/BogTnmsZBdCmYj8L3JCFyrX3sG62OfGd7CSzxfhKNiVnKrXQ== X-Received: by 2002:a17:903:2448:b0:1fb:1faa:96b7 with SMTP id d9443c01a7336-1fbb6cd18d4mr10785275ad.9.1720490213387; Mon, 08 Jul 2024 18:56:53 -0700 (PDT) Received: from localhost.localdomain ([190.194.167.233]) by smtp.gmail.com with ESMTPSA id d9443c01a7336-1fbb6a2f055sm5022935ad.110.2024.07.08.18.56.51 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 08 Jul 2024 18:56:52 -0700 (PDT) From: James Almer To: ffmpeg-devel@ffmpeg.org Date: Mon, 8 Jul 2024 22:55:20 -0300 Message-ID: <20240709015521.10083-2-jamrial@gmail.com> X-Mailer: git-send-email 2.45.2 In-Reply-To: <20240709015521.10083-1-jamrial@gmail.com> References: <20240709015521.10083-1-jamrial@gmail.com> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH 2/2] avformat/movenc: support writing cropping values 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: VbVMskgtehA7 Finishes implementing ticket #7437. Signed-off-by: James Almer --- libavformat/movenc.c | 56 +++++++++++++++++++++++++++---------- tests/ref/fate/copy-trac236 | 16 +++++------ 2 files changed, 50 insertions(+), 22 deletions(-) diff --git a/libavformat/movenc.c b/libavformat/movenc.c index b5c02d2198..2bea55e33d 100644 --- a/libavformat/movenc.c +++ b/libavformat/movenc.c @@ -2351,18 +2351,31 @@ static int mov_write_dvcc_dvvc_tag(AVFormatContext *s, AVIOContext *pb, AVDOVIDe return 32; /* 8 + 24 */ } -static int mov_write_clap_tag(AVIOContext *pb, MOVTrack *track) -{ +static int mov_write_clap_tag(AVIOContext *pb, MOVTrack *track, + uint32_t top, uint32_t bottom, + uint32_t left, uint32_t right) +{ + uint32_t cropped_width = track->par->width - left - right; + uint32_t cropped_height = track->height - top - bottom; + AVRational horizOff = + av_sub_q((AVRational) { track->par->width - cropped_width, 2 }, + (AVRational) { left, 1 }); + AVRational vertOff = + av_sub_q((AVRational) { track->height - cropped_height, 2 }, + (AVRational) { top, 1 }); + avio_wb32(pb, 40); ffio_wfourcc(pb, "clap"); - avio_wb32(pb, track->par->width); /* apertureWidth_N */ - avio_wb32(pb, 1); /* apertureWidth_D (= 1) */ - avio_wb32(pb, track->height); /* apertureHeight_N */ - avio_wb32(pb, 1); /* apertureHeight_D (= 1) */ - avio_wb32(pb, 0); /* horizOff_N (= 0) */ - avio_wb32(pb, 1); /* horizOff_D (= 1) */ - avio_wb32(pb, 0); /* vertOff_N (= 0) */ - avio_wb32(pb, 1); /* vertOff_D (= 1) */ + avio_wb32(pb, cropped_width); /* apertureWidthN */ + avio_wb32(pb, 1); /* apertureWidthD */ + avio_wb32(pb, cropped_height); /* apertureHeightN */ + avio_wb32(pb, 1); /* apertureHeightD */ + + avio_wb32(pb, -horizOff.num); + avio_wb32(pb, horizOff.den); + avio_wb32(pb, -vertOff.num); + avio_wb32(pb, vertOff.den); + return 40; } @@ -2590,6 +2603,7 @@ static int mov_write_video_tag(AVFormatContext *s, AVIOContext *pb, MOVMuxContex { int ret = AVERROR_BUG; int64_t pos = avio_tell(pb); + const AVPacketSideData *sd; char compressor_name[32] = { 0 }; int avid = 0; @@ -2763,7 +2777,6 @@ static int mov_write_video_tag(AVFormatContext *s, AVIOContext *pb, MOVMuxContex if (track->mode == MODE_MOV || (track->mode == MODE_MP4 && mov->fc->strict_std_compliance <= FF_COMPLIANCE_UNOFFICIAL)) { - const AVPacketSideData *sd; const AVStereo3D *stereo3d = NULL; const AVSphericalMapping *spherical_mapping = NULL; @@ -2800,9 +2813,24 @@ static int mov_write_video_tag(AVFormatContext *s, AVIOContext *pb, MOVMuxContex mov_write_pasp_tag(pb, track); } - if (uncompressed_ycbcr){ - mov_write_clap_tag(pb, track); - } + sd = av_packet_side_data_get(track->st->codecpar->coded_side_data, + track->st->codecpar->nb_coded_side_data, + AV_PKT_DATA_FRAME_CROPPING); + if (sd && sd->size >= sizeof(uint32_t) * 4) { + uint64_t top = AV_RL32(sd->data + 0); + uint64_t bottom = AV_RL32(sd->data + 4); + uint64_t left = AV_RL32(sd->data + 8); + uint64_t right = AV_RL32(sd->data + 12); + + if ((left + right) >= track->par->width || + (top + bottom) >= track->height) { + av_log(s, AV_LOG_ERROR, "Invalid cropping dimensions in stream side data\n"); + return AVERROR(EINVAL); + } + if (top || bottom || left || right) + mov_write_clap_tag(pb, track, top, bottom, left, right); + } else if (uncompressed_ycbcr) + mov_write_clap_tag(pb, track, 0, 0, 0, 0); if (mov->encryption_scheme != MOV_ENC_NONE) { ff_mov_cenc_write_sinf_tag(track, pb, mov->encryption_kid); diff --git a/tests/ref/fate/copy-trac236 b/tests/ref/fate/copy-trac236 index 5a9e08ad0c..c89649e953 100644 --- a/tests/ref/fate/copy-trac236 +++ b/tests/ref/fate/copy-trac236 @@ -1,24 +1,24 @@ -34b0ad38518b0eb8464aff04e6d0e143 *tests/data/fate/copy-trac236.mov -630878 tests/data/fate/copy-trac236.mov +ca4068319c6586de757c1f6a592b31e5 *tests/data/fate/copy-trac236.mov +630918 tests/data/fate/copy-trac236.mov #tb 0: 100/2997 #media_type 0: video #codec_id 0: rawvideo -#dimensions 0: 720x480 +#dimensions 0: 704x480 #sar 0: 10/11 #tb 1: 1/48000 #media_type 1: audio #codec_id 1: pcm_s16le #sample_rate 1: 48000 #channel_layout_name 1: stereo -0, 0, 0, 1, 518400, 0x81ab2140 +0, 0, 0, 1, 506880, 0xc4d654e3 1, 0, 0, 1024, 4096, 0x67dc99a3 1, 1024, 1024, 1024, 4096, 0xf115a681 -0, 1, 1, 1, 518400, 0x81ab2140 +0, 1, 1, 1, 506880, 0xc4d654e3 1, 2048, 2048, 1024, 4096, 0xf455b597 1, 3072, 3072, 1024, 4096, 0x67dc99a3 -0, 2, 2, 1, 518400, 0x81ab2140 +0, 2, 2, 1, 506880, 0xc4d654e3 1, 4096, 4096, 1024, 4096, 0xf115a681 -0, 3, 3, 1, 518400, 0x81ab2140 +0, 3, 3, 1, 506880, 0xc4d654e3 1, 5120, 5120, 1024, 4096, 0xf455b597 1, 6144, 6144, 759, 3036, 0xa291a36d -0, 4, 4, 1, 518400, 0x81ab2140 +0, 4, 4, 1, 506880, 0xc4d654e3