From patchwork Sat Oct 7 00:14:42 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Michael Niedermayer X-Patchwork-Id: 44186 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a05:6a20:4e24:b0:15d:8365:d4b8 with SMTP id gk36csp152481pzb; Fri, 6 Oct 2023 17:14:59 -0700 (PDT) X-Google-Smtp-Source: AGHT+IHi6yhYZj+d0WdOxJuehqh6ZFiS4dC6em/5SlSrivYSGmTMvRNuhTLj52PbJKnF8k5JD2Pw X-Received: by 2002:a17:906:e:b0:9b2:7492:70a0 with SMTP id 14-20020a170906000e00b009b2749270a0mr8042312eja.27.1696637699514; Fri, 06 Oct 2023 17:14:59 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1696637699; cv=none; d=google.com; s=arc-20160816; b=xbj6jfbyZoVUFGf0JkDZSmpFtwEsrc0wklRQIZPe/L9G9MVKrRhsrWrv5MMN8qj6NS 1/11qE9xuudYhW6QErlKSYToi0pzNGc8HMir+fWlQVQmY0aKyHXX199zwq5PYR7xafuE ClcZY1Yzevqrg0fVlxYTscjYXEVLqJUmKrMI/Jit4gPX4Uwd5TUY8TRbAHbhlUMfXdt+ /2UvD7JNVAa26sEzwHtlp3jUZdT7bwTn3tFUoZHSWji8j3lEFf53YdrDEpQ6I61k82Ij uI8qC417kAWLGQMSgn8dmg8YLqd1Q9AMxLFSMHkkQBa/4gnhF5N7N9d/C0XLiWxKuphM 5Zrw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:content-transfer-encoding:mime-version:reply-to :list-subscribe:list-help:list-post:list-archive:list-unsubscribe :list-id:precedence:subject:message-id:date:to:from:delivered-to; bh=G52AzIfEWhGvaIf74RbIsgcGGFK/b9PJYv+FPNnNxSw=; fh=e5zN9xSzcxLA6bGo3lF+CqTbY/oLwzApV03EO/RBfgQ=; b=GRP330up9zmVRkwjdo6OH2Vs99oQs7aC11ndwnhwia11pXTocmKEtF/hGiHvC4TurB FIRaEekGPAFYA3RKgH+UIdYBDGQDtq6eeCbrFpB114ViRsEGB002MvGNFoUK2t2b4QUu 8vsuE5jpW63yoGbpT7C/0/bnjum9x7SFru+nYvX5B9+DAfkn3yMMI2VJv4eco/bcTI18 Z+EtxiMcldIVC2c9fu//DdzfpOzHMSHNt9cLvvP1bLAmqh4eW9vrdhhp8J3KzuKXT0cd IG/AnS3sh9/IOC4Wi1jhMqAzaZdcc7UWXv4V46BtfhiNdvDg4fOLOo0V/PzyrGBqmj+P rmfQ== ARC-Authentication-Results: i=1; mx.google.com; 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 Return-Path: Received: from ffbox0-bg.mplayerhq.hu (ffbox0-bg.ffmpeg.org. [79.124.17.100]) by mx.google.com with ESMTP id gf17-20020a170906e21100b0099364d9f0e0si2022695ejb.540.2023.10.06.17.14.58; Fri, 06 Oct 2023 17:14:59 -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; 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 Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 4CA7568CAA7; Sat, 7 Oct 2023 03:14:54 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from relay4-d.mail.gandi.net (relay4-d.mail.gandi.net [217.70.183.196]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 35BBC68C94F for ; Sat, 7 Oct 2023 03:14:46 +0300 (EEST) Received: by mail.gandi.net (Postfix) with ESMTPSA id B5E73E0002 for ; Sat, 7 Oct 2023 00:14:45 +0000 (UTC) From: Michael Niedermayer To: FFmpeg development discussions and patches Date: Sat, 7 Oct 2023 02:14:42 +0200 Message-Id: <20231007001444.31861-1-michael@niedermayer.cc> X-Mailer: git-send-email 2.17.1 X-GND-Sasl: michael@niedermayer.cc Subject: [FFmpeg-devel] [PATCH 1/3] avcodec/ffv1enc: Slice combination is unsupported 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 MIME-Version: 1.0 Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" X-TUID: wzLRR73CTApr We always write minimal slices, the size calculation is wrong in some corner cases but as its always 1x1 (minus1) we can for now just hard-code it This helps with ticket 5548 Signed-off-by: Michael Niedermayer --- libavcodec/ffv1enc.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/libavcodec/ffv1enc.c b/libavcodec/ffv1enc.c index 2778c63012e..4d0ddc167ae 100644 --- a/libavcodec/ffv1enc.c +++ b/libavcodec/ffv1enc.c @@ -914,8 +914,8 @@ static void encode_slice_header(FFV1Context *f, FFV1Context *fs) put_symbol(c, state, (fs->slice_x +1)*f->num_h_slices / f->width , 0); put_symbol(c, state, (fs->slice_y +1)*f->num_v_slices / f->height , 0); - put_symbol(c, state, (fs->slice_width +1)*f->num_h_slices / f->width -1, 0); - put_symbol(c, state, (fs->slice_height+1)*f->num_v_slices / f->height-1, 0); + put_symbol(c, state, 0, 0); + put_symbol(c, state, 0, 0); for (j=0; jplane_count; j++) { put_symbol(c, state, f->plane[j].quant_table_index, 0); av_assert0(f->plane[j].quant_table_index == f->context_model); From patchwork Sat Oct 7 00:14:43 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Michael Niedermayer X-Patchwork-Id: 44187 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a05:6a20:4e24:b0:15d:8365:d4b8 with SMTP id gk36csp152542pzb; Fri, 6 Oct 2023 17:15:09 -0700 (PDT) X-Google-Smtp-Source: AGHT+IEB6MMOTSbmOGKM/SDv6x7A/3AH0QyQEoXUouYh3i+bGDt5bb6EUGC77nUSZR/1nSOJhLb7 X-Received: by 2002:a17:906:31c5:b0:9ae:6a51:87c3 with SMTP id f5-20020a17090631c500b009ae6a5187c3mr8923533ejf.9.1696637708916; Fri, 06 Oct 2023 17:15:08 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1696637708; cv=none; d=google.com; s=arc-20160816; b=KauS5VKXxCA+lfFBv6Hb6XdR+Cr+IRwqnCZ9hcs4716LZkuY56jxcEjfTWR/29CyXb WmSPeI5pKEvkX9IC/pumBUbB+ftFpF20vjDF5gcCS2blTaH7uM1ehJrxzM2PFaWAKSz7 ymYKCLpjjWPV9b6LbtYEZOy17P/QMwM/p0d/l4LMi7XhlCDgvrZgif+CJ4p3a5M+zU8S x02UBmpKVJMG3tdaTPq7He1th1LQ4M/Tl1hmhQXW2RL5DkKU2/qy3dSOWSehlLlcaD8x Y/S/98eqPIdoeudogEoWm/7Okfxd/Q9oBkN0VyA9W2A/0BU28XFK2erI45Z+R9OWwZFt 2ICw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:content-transfer-encoding:mime-version:reply-to :list-subscribe:list-help:list-post:list-archive:list-unsubscribe :list-id:precedence:subject:references:in-reply-to:message-id:date :to:from:delivered-to; bh=+QOKSEZXpBmn61oXFkYi1KtoG8adXYXAuAEnTEGpUMM=; fh=e5zN9xSzcxLA6bGo3lF+CqTbY/oLwzApV03EO/RBfgQ=; b=pOsNxs6pz+junONnjJu+PMrddDSNq0XJWgKZrmAsco/Sbo8cNGyXA4TdQnqIguLJM6 MFBRncJ8M7c/Xxcl6XmomEwkOpeeU1wfUpKuqetuUB9nkoIVflZSeCXW9WQzOVJdiatG 71IyVVaQbPo/dVvKnmzLyfA7JqMYwL63YxQwrgyUeq5+uHqQdtMvFZEq+LSPm6djm6yi s29hPvKyVSqWN+XDhPIJCEnllbJaqU4/mhaFr8ao9g2f6HQ3tjqfRDcYrY0CVw2D3cpy /kckB2HhONCtkU2pph4HfwX45pTXNLlC6ORU/8MOfuhaYxlvmRdkw7Zl8nOTNIp5cssR D4bQ== ARC-Authentication-Results: i=1; mx.google.com; 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 Return-Path: Received: from ffbox0-bg.mplayerhq.hu (ffbox0-bg.ffmpeg.org. [79.124.17.100]) by mx.google.com with ESMTP id qq16-20020a17090720d000b0099bcec1f1bbsi2000887ejb.182.2023.10.06.17.15.08; Fri, 06 Oct 2023 17:15:08 -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; 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 Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 7CD9568CAEF; Sat, 7 Oct 2023 03:14:55 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from relay2-d.mail.gandi.net (relay2-d.mail.gandi.net [217.70.183.194]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id A791A68C94F for ; Sat, 7 Oct 2023 03:14:47 +0300 (EEST) Received: by mail.gandi.net (Postfix) with ESMTPSA id C77B940002 for ; Sat, 7 Oct 2023 00:14:46 +0000 (UTC) From: Michael Niedermayer To: FFmpeg development discussions and patches Date: Sat, 7 Oct 2023 02:14:43 +0200 Message-Id: <20231007001444.31861-2-michael@niedermayer.cc> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20231007001444.31861-1-michael@niedermayer.cc> References: <20231007001444.31861-1-michael@niedermayer.cc> X-GND-Sasl: michael@niedermayer.cc Subject: [FFmpeg-devel] [PATCH 2/3] avcodec/ffv1: Store and reuse sx/sy 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 MIME-Version: 1.0 Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" X-TUID: Utcca+1PetcC Signed-off-by: Michael Niedermayer --- libavcodec/ffv1.c | 2 ++ libavcodec/ffv1.h | 1 + libavcodec/ffv1enc.c | 4 ++-- 3 files changed, 5 insertions(+), 2 deletions(-) diff --git a/libavcodec/ffv1.c b/libavcodec/ffv1.c index b6204740edb..f44fead350b 100644 --- a/libavcodec/ffv1.c +++ b/libavcodec/ffv1.c @@ -129,6 +129,8 @@ av_cold int ff_ffv1_init_slice_contexts(FFV1Context *f) fs->slice_height = sye - sys; fs->slice_x = sxs; fs->slice_y = sys; + fs->sx = sx; + fs->sy = sy; fs->sample_buffer = av_malloc_array((fs->width + 6), 3 * MAX_PLANES * sizeof(*fs->sample_buffer)); diff --git a/libavcodec/ffv1.h b/libavcodec/ffv1.h index 04869da5c9a..14e40936065 100644 --- a/libavcodec/ffv1.h +++ b/libavcodec/ffv1.h @@ -129,6 +129,7 @@ typedef struct FFV1Context { int slice_height; int slice_x; int slice_y; + int sx, sy; int slice_reset_contexts; int slice_coding_mode; int slice_rct_by_coef; diff --git a/libavcodec/ffv1enc.c b/libavcodec/ffv1enc.c index 4d0ddc167ae..11be7fe32ea 100644 --- a/libavcodec/ffv1enc.c +++ b/libavcodec/ffv1enc.c @@ -912,8 +912,8 @@ static void encode_slice_header(FFV1Context *f, FFV1Context *fs) int j; memset(state, 128, sizeof(state)); - put_symbol(c, state, (fs->slice_x +1)*f->num_h_slices / f->width , 0); - put_symbol(c, state, (fs->slice_y +1)*f->num_v_slices / f->height , 0); + put_symbol(c, state, fs->sx, 0); + put_symbol(c, state, fs->sy, 0); put_symbol(c, state, 0, 0); put_symbol(c, state, 0, 0); for (j=0; jplane_count; j++) { From patchwork Sat Oct 7 00:14:44 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Michael Niedermayer X-Patchwork-Id: 44188 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a05:6a20:4e24:b0:15d:8365:d4b8 with SMTP id gk36csp152603pzb; Fri, 6 Oct 2023 17:15:17 -0700 (PDT) X-Google-Smtp-Source: AGHT+IExdRjxXeC120AUZUd0bFJ/FnPjCH3Itm2wr3pdkF/iYpEBKQV7yqb3vKUt8e+IrexUlLZf X-Received: by 2002:a17:906:10da:b0:9a9:e393:8bcd with SMTP id v26-20020a17090610da00b009a9e3938bcdmr8013054ejv.5.1696637717099; Fri, 06 Oct 2023 17:15:17 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1696637717; cv=none; d=google.com; s=arc-20160816; b=eWnGxsI6RzP56vX9Yul8c+9hAxYZEGsp6bH2Cwslba34Wivj9I3dkc8yI0JTN1utdV pKWRqk5uraPQ4Y+45fs8kdJ3IjctLKA/zncLLITu189bHtlTfna3m/cWJYkrCJRzqtNK 2oB9yOqL0Avcd8MPTwcWkBeQZU+EcKrKKPJ0glQ8VeINC7EleX2pE/8Y60b0sr7B7wIx TYV56QQTqi/rkO9A8RGpxW3BAOKth1R/Bh2wniNdqkEKofdOcsA2o00yoqJ/164jqqng xcHDu2mMnfeY5Vj06ljLhOWM7aL25vJAnSarlzScm9YrPyDFhiGediaKmO1YZR9n2ung 9AJQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:content-transfer-encoding:mime-version:reply-to :list-subscribe:list-help:list-post:list-archive:list-unsubscribe :list-id:precedence:subject:references:in-reply-to:message-id:date :to:from:delivered-to; bh=8QuXUO+VJWpGxmjnaBQkRkNqPyUjluMWDvEa6XduEW0=; fh=e5zN9xSzcxLA6bGo3lF+CqTbY/oLwzApV03EO/RBfgQ=; b=CWFPHbtteB/d4jMXYRapCMr9tfuc0nF+RRtpLr/sgtvTP1GQbjM6tbFG4Dct+XC5Fu b9WfzHsQoxN80hALRZl616BMobi/edSwyF8UaX7w9UbH2U03b3VVqAWFW0MKPjEu60jr vsvk5ojTkA2DHYl7z5y2yGJex8cp61rISl6imwM4CmsFsjA+xqlDWTrDAYAMySQDVQYl ijXnAs81WAaVA2aas1AH1JibM54yRpp3DvgcaSHOM5PJPnqpk3P2hDg20hqeO6Pt7Ebs dFAOnTbB7OgAP6WWgv9hLWSnV3ObEuL5KqTK8kkue3R0L51sD7EGvl9yZtEYWYi9Z6PR uumw== ARC-Authentication-Results: i=1; mx.google.com; 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 Return-Path: Received: from ffbox0-bg.mplayerhq.hu (ffbox0-bg.ffmpeg.org. [79.124.17.100]) by mx.google.com with ESMTP id v13-20020aa7d64d000000b005363122e777si2023570edr.148.2023.10.06.17.15.16; Fri, 06 Oct 2023 17:15:17 -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; 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 Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 0125F68CB97; Sat, 7 Oct 2023 03:14:57 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from relay7-d.mail.gandi.net (relay7-d.mail.gandi.net [217.70.183.200]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 21C6868CAA5 for ; Sat, 7 Oct 2023 03:14:49 +0300 (EEST) Received: by mail.gandi.net (Postfix) with ESMTPSA id 3271020002 for ; Sat, 7 Oct 2023 00:14:47 +0000 (UTC) From: Michael Niedermayer To: FFmpeg development discussions and patches Date: Sat, 7 Oct 2023 02:14:44 +0200 Message-Id: <20231007001444.31861-3-michael@niedermayer.cc> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20231007001444.31861-1-michael@niedermayer.cc> References: <20231007001444.31861-1-michael@niedermayer.cc> X-GND-Sasl: michael@niedermayer.cc Subject: [FFmpeg-devel] [PATCH 3/3] [RFC] avcodec/ffv1: Better rounding for slice positions 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 MIME-Version: 1.0 Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" X-TUID: 1bR7Z4tEfv2H This fixes green lines in some odd dimensions with some slice configurations like Ticket 5548 This also changes the encoder and whats encoded, and would require an update to the specification. This change attempts to limit the change to configurations that have missing lines currently. Testing is welcome and needed Signed-off-by: Michael Niedermayer --- libavcodec/ffv1.c | 38 ++++++++++++++++++++++++++++++++++---- libavcodec/ffv1.h | 2 ++ libavcodec/ffv1dec.c | 8 ++++---- libavcodec/ffv1enc.c | 7 ++++--- 4 files changed, 44 insertions(+), 11 deletions(-) diff --git a/libavcodec/ffv1.c b/libavcodec/ffv1.c index f44fead350b..e780c910aee 100644 --- a/libavcodec/ffv1.c +++ b/libavcodec/ffv1.c @@ -103,6 +103,36 @@ av_cold int ff_ffv1_init_slices_state(FFV1Context *f) return 0; } +int ff_need_new_slices(int width, int num_h_slices, int chroma_shift) { + int mpw = 1<version > 4) { + old = 0; + } else if (f->version == 3 && f->micro_version > 4 || + f->version == 4 && f->micro_version > 2 + ) { + // If the old system will not encode all pixels we will choose the new + old = !ff_need_new_slices(width, num_h_slices, chroma_shift); + } + + if (old) + return width * sx / num_h_slices; + + sx = (awidth * (int64_t)sx + (num_h_slices * mpw / 2)) / (num_h_slices * mpw) * mpw; + if (sx == awidth) + sx = width; + return sx; +} + av_cold int ff_ffv1_init_slice_contexts(FFV1Context *f) { int i, max_slice_count = f->num_h_slices * f->num_v_slices; @@ -112,10 +142,10 @@ av_cold int ff_ffv1_init_slice_contexts(FFV1Context *f) for (i = 0; i < max_slice_count;) { int sx = i % f->num_h_slices; int sy = i / f->num_h_slices; - int sxs = f->avctx->width * sx / f->num_h_slices; - int sxe = f->avctx->width * (sx + 1) / f->num_h_slices; - int sys = f->avctx->height * sy / f->num_v_slices; - int sye = f->avctx->height * (sy + 1) / f->num_v_slices; + int sxs = ff_slice_coord(f, f->avctx->width , sx , f->num_h_slices, f->chroma_h_shift); + int sxe = ff_slice_coord(f, f->avctx->width , sx + 1, f->num_h_slices, f->chroma_h_shift); + int sys = ff_slice_coord(f, f->avctx->height, sy , f->num_v_slices, f->chroma_v_shift); + int sye = ff_slice_coord(f, f->avctx->height, sy + 1, f->num_v_slices, f->chroma_v_shift); FFV1Context *fs = av_mallocz(sizeof(*fs)); if (!fs) diff --git a/libavcodec/ffv1.h b/libavcodec/ffv1.h index 14e40936065..3f658a26522 100644 --- a/libavcodec/ffv1.h +++ b/libavcodec/ffv1.h @@ -143,6 +143,8 @@ int ff_ffv1_init_slice_contexts(FFV1Context *f); int ff_ffv1_allocate_initial_states(FFV1Context *f); void ff_ffv1_clear_slice_state(const FFV1Context *f, FFV1Context *fs); int ff_ffv1_close(AVCodecContext *avctx); +int ff_need_new_slices(int width, int num_h_slices, int chroma_shift); +int ff_slice_coord(const FFV1Context *f, int width, int sx, int num_h_slices, int chroma_shift); static av_always_inline int fold(int diff, int bits) { diff --git a/libavcodec/ffv1dec.c b/libavcodec/ffv1dec.c index a376a4c8170..0486938eb2b 100644 --- a/libavcodec/ffv1dec.c +++ b/libavcodec/ffv1dec.c @@ -184,10 +184,10 @@ static int decode_slice_header(const FFV1Context *f, FFV1Context *fs) if (sx > f->num_h_slices - sw || sy > f->num_v_slices - sh) return AVERROR_INVALIDDATA; - fs->slice_x = sx * (int64_t)f->width / f->num_h_slices; - fs->slice_y = sy * (int64_t)f->height / f->num_v_slices; - fs->slice_width = (sx + sw) * (int64_t)f->width / f->num_h_slices - fs->slice_x; - fs->slice_height = (sy + sh) * (int64_t)f->height / f->num_v_slices - fs->slice_y; + fs->slice_x = ff_slice_coord(f, f->width , sx , f->num_h_slices, f->chroma_h_shift); + fs->slice_y = ff_slice_coord(f, f->height, sy , f->num_v_slices, f->chroma_v_shift); + fs->slice_width = ff_slice_coord(f, f->width , sx + sw, f->num_h_slices, f->chroma_h_shift) - fs->slice_x; + fs->slice_height = ff_slice_coord(f, f->height, sy + sh, f->num_v_slices, f->chroma_v_shift) - fs->slice_y; av_assert0((unsigned)fs->slice_width <= f->width && (unsigned)fs->slice_height <= f->height); diff --git a/libavcodec/ffv1enc.c b/libavcodec/ffv1enc.c index 11be7fe32ea..e04695efa93 100644 --- a/libavcodec/ffv1enc.c +++ b/libavcodec/ffv1enc.c @@ -397,7 +397,8 @@ static int write_extradata(FFV1Context *f) int i, j, k; uint8_t state2[32][CONTEXT_SIZE]; unsigned v; - + int need_new_slices = ff_need_new_slices(f->avctx->width , f->num_h_slices, f->chroma_h_shift) + ||ff_need_new_slices(f->avctx->height, f->num_v_slices, f->chroma_v_shift); memset(state2, 128, sizeof(state2)); memset(state, 128, sizeof(state)); @@ -412,9 +413,9 @@ static int write_extradata(FFV1Context *f) put_symbol(c, state, f->version, 0); if (f->version > 2) { if (f->version == 3) { - f->micro_version = 4; + f->micro_version = 4 + need_new_slices; } else if (f->version == 4) - f->micro_version = 2; + f->micro_version = 2 + need_new_slices; put_symbol(c, state, f->micro_version, 0); }