From patchwork Wed Mar 7 15:49:48 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jerome Martinez X-Patchwork-Id: 7848 Delivered-To: ffmpegpatchwork@gmail.com Received: by 10.2.181.170 with SMTP id m39csp5115020jaj; Wed, 7 Mar 2018 07:49:55 -0800 (PST) X-Google-Smtp-Source: AG47ELuMtNxITSypXQio6p+f74gvPP+WvRNzslPoUupchS0RqCD3+0KsKG6oFmJ0W8umbq0dsW6F X-Received: by 10.28.141.131 with SMTP id p125mr14968573wmd.0.1520437795129; Wed, 07 Mar 2018 07:49:55 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1520437795; cv=none; d=google.com; s=arc-20160816; b=DignEOsYLTAMtCv00yuu06CMBJdWoGOJEyrJ2FQCrvjyTwro5c0jxw1XToL0riEB9j BS0ZeOBjMsQd7X5p0ZxzsnHNBnqVsDH9DrdaijgNdlXcn3u9HtLtqQbmLSAVkaYs8B1s wDLxqLFACSYD9ShV2e8hc4wgJ3tYStj013eOjjNUsM36DqfQTwnLlBwnITzSZOq0jcHB z2Fk2lDjuKtMNkr6d+wOaZ7mRgYhYw7YnWjEtoXFW9JMCNKYke6nXl+x/0+/Rg21XOP/ Dr0Z4ltdZfi0pA37gUPMjfmcLJYiw5wE7oyq1vKLH1GVRVI6OBIq8gGpDW8xGr4nfDqH tMmg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:reply-to:list-subscribe:list-help:list-post :list-archive:list-unsubscribe:list-id:precedence:subject :content-language:in-reply-to:mime-version:user-agent:date :message-id:from:references:to:delivered-to :arc-authentication-results; bh=tQi4qCCBEAaH7AqXFWEZWdDDGZ6859CuuC/Ot6M8x4o=; b=ivHDtxW5aMnhgMX62DwIsv0L9kX4aPUJXk8n3PaHoy4som2a1hTa+parWJ+Xbm/exJ UWUV/5wg/LTh0DvRzPrmvDLdmKSynKdUoid+Q1zZr+vlCjp677vCci4NCUMkFyDeMgG6 DQnpCuNZ3wnhE+4Sl37Aq7Tzmu1S3we7D6JBoaj/fsQR/rNSNFkrkoh2tgYVsgYJ7+xs qI+f99UNezRJRfdLug87hkVCGVhMZeh8MgxGgC48bqhRhFCtPxCWVDyXjyZoxMMSIsZ+ T1lUBDmnxB1AnVGZphawez545auY+MITkk4fomNrO7mIUuonB2WAwNPcT+b6xhOlekB4 o4ew== 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 r18si8153431wmd.153.2018.03.07.07.49.54; Wed, 07 Mar 2018 07:49:55 -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; 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 83D2968A501; Wed, 7 Mar 2018 17:49:45 +0200 (EET) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from 17.mo1.mail-out.ovh.net (17.mo1.mail-out.ovh.net [87.98.179.142]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id C025768A4DB for ; Wed, 7 Mar 2018 17:49:38 +0200 (EET) Received: from player778.ha.ovh.net (unknown [10.109.120.6]) by mo1.mail-out.ovh.net (Postfix) with ESMTP id D1014DE959 for ; Wed, 7 Mar 2018 16:49:45 +0100 (CET) Received: from [192.168.2.120] (p5DDB6D89.dip0.t-ipconnect.de [93.219.109.137]) (Authenticated sender: zen-lists@mediaarea.net) by player778.ha.ovh.net (Postfix) with ESMTPSA id 8DE5E18008F for ; Wed, 7 Mar 2018 16:49:45 +0100 (CET) To: ffmpeg-devel@ffmpeg.org References: <4b0efe51-d6c0-9a37-ce34-155387d1a8e8@mediaarea.net> <5d92345d-14c7-d43d-b67b-bd21e24a261e@mediaarea.net> From: Jerome Martinez Message-ID: <8d5bea24-1b19-f33c-7fcb-0f685b2710c3@mediaarea.net> Date: Wed, 7 Mar 2018 16:49:48 +0100 User-Agent: Mozilla/5.0 (Windows NT 10.0; WOW64; rv:52.0) Gecko/20100101 Thunderbird/52.6.0 MIME-Version: 1.0 In-Reply-To: <5d92345d-14c7-d43d-b67b-bd21e24a261e@mediaarea.net> Content-Language: en-GB X-Ovh-Tracer-Id: 727612818908713149 X-VR-SPAMSTATE: OK X-VR-SPAMSCORE: 0 X-VR-SPAMCAUSE: gggruggvucftvghtrhhoucdtuddrgedtfedrkedvgdekudcutefuodetggdotefrodftvfcurfhrohhfihhlvgemucfqggfjpdevjffgvefmvefgnecuuegrihhlohhuthemuceftddtnecu Subject: [FFmpeg-devel] [PATCH 3/7] avcodec/ffv1enc: prevent encoder to create buggy streams with small frame sizes X-BeenThere: ffmpeg-devel@ffmpeg.org X-Mailman-Version: 2.1.20 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" When there is 1 pixel per slice for the first half of slices, the encoder creates buggy slices. Example: ffmpeg -f lavfi -i mandelbrot=s=8x8 -vf format=yuv444p -t 1 -c ffv1 -coder 1 -context 0 -g 1 -level 3 -slices 64 -slicecrc 1 a.mkv ffmpeg -f lavfi -i mandelbrot=s=9x9 -vf format=yuv444p -t 1 -c ffv1 -coder 1 -context 0 -g 1 -level 3 -slices 64 -slicecrc 1 a.mkv ffmpeg -f lavfi -i mandelbrot=s=10x10 -vf format=yuv444p -t 1 -c ffv1 -coder 1 -context 0 -g 1 -level 3 -slices 64 -slicecrc 1 a.mkv ffmpeg -f lavfi -i mandelbrot=s=11x11 -vf format=yuv444p -t 1 -c ffv1 -coder 1 -context 0 -g 1 -level 3 -slices 64 -slicecrc 1 a.mkv ffmpeg -f lavfi -i mandelbrot=s=12x12 -vf format=yuv444p -t 1 -c ffv1 -coder 1 -context 0 -g 1 -level 3 -slices 64 -slicecrc 1 a.mkv then for each file: ffmpeg -i a.mkv [ffv1 @ 000001977d8ee240] bytestream end mismatching by -1 etc This patch is an hotfix for preventing the encoder to create such stream. From 1c78e038a9fb826c70d7b609430a92d5e98ce1de Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=A9r=C3=B4me=20Martinez?= Date: Wed, 7 Mar 2018 10:40:05 +0100 Subject: [PATCH 3/7] avcodec/ffv1enc: prevent encoder to create buggy streams with small frame sizes The first half of slices must have more than 1 pixel else encoder does not correctly handle slice_x and/or slice_y --- libavcodec/ffv1enc.c | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/libavcodec/ffv1enc.c b/libavcodec/ffv1enc.c index ac8b715b74..51aa8c2898 100644 --- a/libavcodec/ffv1enc.c +++ b/libavcodec/ffv1enc.c @@ -864,6 +864,10 @@ FF_ENABLE_DEPRECATION_WARNINGS int plane_count = 1 + 2*s->chroma_planes + s->transparency; int max_h_slices = AV_CEIL_RSHIFT(avctx->width , s->chroma_h_shift); int max_v_slices = AV_CEIL_RSHIFT(avctx->height, s->chroma_v_shift); + while (max_h_slices && ((float)(avctx->width >> (s->chroma_h_shift))) / max_h_slices <= 1.5) // Hotfix: the first half of slices must have more than 1 pixel else encoder does not correctly handle slice_x + max_h_slices--; + while (max_v_slices && ((float)(avctx->height >> (s->chroma_v_shift))) / max_v_slices <= 1.5) // Hotfix: the first half of slices must have more than 1 pixel else encoder does not correctly handle slice_y + max_v_slices--; s->num_v_slices = (avctx->width > 352 || avctx->height > 288 || !avctx->slices) ? 2 : 1; s->num_v_slices = FFMIN(s->num_v_slices, max_v_slices);