From patchwork Sun Sep 12 20:20:09 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Martin Reboredo X-Patchwork-Id: 30200 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a05:6602:2a4a:0:0:0:0 with SMTP id k10csp3423527iov; Sun, 12 Sep 2021 13:21:01 -0700 (PDT) X-Google-Smtp-Source: ABdhPJy7ywrBlADbO5IpKopzSuZYyDWff5qc+NzEYyC3PShc+jophtBhSynlZlbynB+UcQc3q6Lk X-Received: by 2002:a17:907:8693:: with SMTP id qa19mr8852480ejc.497.1631478061804; Sun, 12 Sep 2021 13:21:01 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1631478061; cv=none; d=google.com; s=arc-20160816; b=0I1W550j828wu0hNeCJcQBHhxjwSASZ4tCfYppbqIS3hI61YdFJ2lEUOAXTY7d0a7e Vz2IN1jUIfXVHNCe7/Nsj52I5is6XpMORr2jCGLyYw1O6J+h7uCp76+hvP7GTzxtIdVI N/0NnTa4fl/MiNOdALOxB3xyPsUgxki/a70J3kjw6qgK67lWU+QUU3rXY30hAYkAQ74u EV0dBhlhobi0/8ZHRV9J7cdtT4JVAPqJWsMGIV3TJd7EDdnPGnjClOQuUbRasFk/9ynv HtKbfDcDLt/NVD6A64JUIQ1z2FFLP1fYDYZ9qWIsbWNvMed0C4sF2yCW4VN0BJjO2sHX DehA== 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=nTWNAIYMyMms6WSvgjziUP3X8UVkFm8kOp1YcXeIIAk=; b=J2uNIn3PgIGAKCLMAyCr1GEO5sRompReMtd4ZgkhSVZwBSKiPPGIICVXj3Ots2vtz0 bpZWUqBNw52mbUpYqmswfIpe9L2Nr9OWrok2rD9B1UEM+oyXb1/CE35iKR0DePnjWsv3 7L8H8oco9AX8IqT4WP1WfPKeRGwKswpm+anOnABCFXVIXewJr7OvproaQJukiGtSHYY8 3rp3ForucDsTYWOAcm47tXanZAWsATCG5ysDFClQ4THLQnevdaqyABNbCTNSSS6VYswb Pm+5ujQ+qDZ0gcdzEBytkGflwGueqiTO90ehhbkjPf+PYqnq+ZEAEIaulBy6EyWxgDUc moYg== ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (body hash did not verify) header.i=@gmail.com header.s=20210112 header.b=NS2GMuei; 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 rn4si5943337ejb.248.2021.09.12.13.21.01; Sun, 12 Sep 2021 13:21:01 -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=NS2GMuei; 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 3607768A628; Sun, 12 Sep 2021 23:20:37 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-oi1-f180.google.com (mail-oi1-f180.google.com [209.85.167.180]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 84A9E68A628 for ; Sun, 12 Sep 2021 23:20:29 +0300 (EEST) Received: by mail-oi1-f180.google.com with SMTP id h133so11387319oib.7 for ; Sun, 12 Sep 2021 13:20:29 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=from:to:subject:date:message-id:in-reply-to:references:mime-version :content-transfer-encoding; bh=p/zR5k45Z1cljUs7P1pz8EIpvlAIyMdBfZ1asn8Y3wA=; b=NS2GMueiVmkf+9TCR5tdU5+/jvj5rgPneooCLF5mXvv9cwiBkPykCxTYyHxHZ3lvhd aJk8/Mj/V3dOmDmYHmmo+TUMid0rQusmSKB0jTA5pb3MsNou+xwK2JS/cfEDjBtlxf6+ +DoK+Aulqs8kCzSQCf+Qei++9xxbtwJQ630WBDjP+X/9L4b4YoEntEvc0hfwq1QdX3o5 +BNiKITPVlbZq/NHDYmTt1M7jZAkmW2dY6n2O0qwdy5BhdGxTj8V7y4Q2cX0iPqUGmOr vxlRvApCe/ZoqWkbLcftblYNNm1d3M9cEvVbiyl0a0Mr/fIwrKpLSBWqTyyFdwtgE5L7 zb8A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=p/zR5k45Z1cljUs7P1pz8EIpvlAIyMdBfZ1asn8Y3wA=; b=GUyGJ4QjNvKABi9Hy2KklctZoKZG0VqXG8VkrnYTMuvYzsw6IIsS04hFiMqVrASqWG 9/IVPV2JNgjyRRCP1SThEtG8KE4EQreP2VO/dHOcxeKYRCjB8aAtyL0BlwY3reK4vfxS F/3xm6BnVFcEBGtmMAeAGv4NEtkPtgukVPT4bYADYa18hnkjQRdDZLrMSlemUEmjkCEu 9C5poE2VDoX1AM9eKFbYMuKDqkLrg+aB2yy3vjc3slAOD/36779okMs9AVoXpnAfaHVu ISU1ySl5FpkDo0YWSAltHi7wkSoUHJL2pxQSTQp5/cuEW1aCWSZMP0WMM3vQcoQd/8pA 66oQ== X-Gm-Message-State: AOAM532sSyphDHFbsYHJo2Y6JkfXsOhA2I2jEPpYLfOOLLgQiDjdyIhH hmJLYvkEGnq2whKiY+stYbNAiCvbKec= X-Received: by 2002:aca:1216:: with SMTP id 22mr5433205ois.35.1631478028104; Sun, 12 Sep 2021 13:20:28 -0700 (PDT) Received: from localhost.localdomain (static.220.238.itcsa.net. [190.15.220.238]) by smtp.gmail.com with ESMTPSA id m24sm1206111oie.50.2021.09.12.13.20.27 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 12 Sep 2021 13:20:27 -0700 (PDT) From: Martin Reboredo To: ffmpeg-devel@ffmpeg.org Date: Sun, 12 Sep 2021 17:20:09 -0300 Message-Id: <20210912202010.1542872-4-yakoyoku@gmail.com> X-Mailer: git-send-email 2.32.0 In-Reply-To: <20210912202010.1542872-1-yakoyoku@gmail.com> References: <20210912202010.1542872-1-yakoyoku@gmail.com> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH v3 3/4] avformat/webpenc: better detection of anim chunks 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: QmYwi5x6a5v9 Receiving RIFF chunks as `av_packet`s from `webpdec.c` in `webpenc.c` it wasn't doing proper animated frame detection/enumeration. Check for `ANIM`/`ANMF` chunks to see if the package is an animated WebP packet and for the `ANMF`/`ALPH`/`VP8 `/`VP8L` chunks if it's an actual frame. Signed-off-by: Martin Reboredo --- libavformat/webpenc.c | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/libavformat/webpenc.c b/libavformat/webpenc.c index 9599fe7b85..50bee91910 100644 --- a/libavformat/webpenc.c +++ b/libavformat/webpenc.c @@ -55,13 +55,18 @@ static int is_animated_webp_packet(AVPacket *pkt) { int skip = 0; unsigned flags = 0; + int fourcc = AV_RL32(pkt->data); if (pkt->size < 4) return AVERROR_INVALIDDATA; - if (AV_RL32(pkt->data) == AV_RL32("RIFF")) + if (fourcc == AV_RL32("RIFF")) skip = 12; + else if (fourcc == AV_RL32("ANIM")) + return 1; + else if (fourcc == AV_RL32("ANMF")) + return 1; // Safe to do this as a valid WebP bitstream is >=30 bytes. - if (pkt->size < skip + 4) + if (pkt->size < skip + 4 && pkt->size != 12) return AVERROR_INVALIDDATA; if (AV_RL32(pkt->data + skip) == AV_RL32("VP8X")) { flags |= pkt->data[skip + 4 + 4]; @@ -143,6 +148,7 @@ static int flush(AVFormatContext *s, int trailer, int64_t pts) static int webp_write_packet(AVFormatContext *s, AVPacket *pkt) { WebpContext *w = s->priv_data; + int fourcc = AV_RL32(pkt->data); int ret; if (!pkt->size) @@ -161,7 +167,9 @@ static int webp_write_packet(AVFormatContext *s, AVPacket *pkt) return ret; av_packet_ref(&w->last_pkt, pkt); } - ++w->frame_count; + if (fourcc == AV_RL32("ANMF") || fourcc == AV_RL32("ALPH") || + fourcc == AV_RL32("VP8 ") || fourcc == AV_RL32("VP8L")) + ++w->frame_count; return 0; }