From patchwork Wed Mar 7 15:50:33 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jerome Martinez X-Patchwork-Id: 7850 Delivered-To: ffmpegpatchwork@gmail.com Received: by 10.2.181.170 with SMTP id m39csp5115969jaj; Wed, 7 Mar 2018 07:50:38 -0800 (PST) X-Google-Smtp-Source: AG47ELsMoYfyVr0DXtk103YSyvLkIXPfiMmUlS5QmQVZoLddL/2iDpNfSTlKv77bnTwbHCi9zepd X-Received: by 10.223.157.131 with SMTP id p3mr19294428wre.278.1520437838672; Wed, 07 Mar 2018 07:50:38 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1520437838; cv=none; d=google.com; s=arc-20160816; b=NEeATpbTvpxjMfLfa9MAX3BmuGa0jbLgy5gIItf2SQYa+GPWuhmugrtxHZsn95Xk3y vAqz+P19JcJ6NQCDWYewZpFEb7Fl20B7hq5YjAk3kBaEUDMdoq2Q9IegEL+ukxUngKv/ vdcOQNYws4YsQESfpiFY3wtfwDyFvt8pSFNSZ8octhA7/YvXf0VjukOyxVZDkWRqxglV 1w1P0UCigf2OZirSLkO562OsQ3UruiAtFEa8beSZp08zV1IPgVpVqU7B9siCl5lCqe8T KXat64QJuQArwXAnnN9tgV1A5LkkMz3acQ1jfEjGmRzLgsxRxp/5B6N+X3wn4RXs17cl nGAg== 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=Os57pxXPS1OPdqu34Uj9diCggv9KJUqdn0NDiS1LhRU=; b=QjkVXaaT345E15ZXgwOYUE3v77d4asj7vcZChm9O9jsxIuvHQrI/X1Frdqo5xNrCmN Ox1MzBkYaby/2jUsnbaiM5dpyz0UdaHmw9VqiUDy/Fgm+o53k2dGc46QdihlDTRbvm1c TXWWSZvnlXawyWG0T9eke66n2t4ezGnhFQPonjd/Goj3jnqKIFqkQtYT1Dts9U7GeYjW pLsLNGs4xDzOjHdiBbhI2EndJUua4Nkjfnwj7l25XVgXmzmKyfg06idJ/pX951B5WDbg c1JEDMpjDE5PSvuzHVXDe6nZ6m27Z6EgRfCmsDEc0DoVgTzcCzl5VEMdRmx4mWG5qpae HmsA== 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 b5si13608682wra.32.2018.03.07.07.50.38; Wed, 07 Mar 2018 07:50:38 -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 3B7AF68A538; Wed, 7 Mar 2018 17:50:29 +0200 (EET) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from 3.mo3.mail-out.ovh.net (3.mo3.mail-out.ovh.net [46.105.44.175]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id D3BF568A52B for ; Wed, 7 Mar 2018 17:50:22 +0200 (EET) Received: from player778.ha.ovh.net (unknown [10.109.120.89]) by mo3.mail-out.ovh.net (Postfix) with ESMTP id A654B1A41AD for ; Wed, 7 Mar 2018 16:50:30 +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 5C78D1800C4 for ; Wed, 7 Mar 2018 16:50:30 +0100 (CET) To: ffmpeg-devel@ffmpeg.org References: <4b0efe51-d6c0-9a37-ce34-155387d1a8e8@mediaarea.net> From: Jerome Martinez Message-ID: <1c68f255-3063-26d2-0aee-585c48aeb869@mediaarea.net> Date: Wed, 7 Mar 2018 16:50:33 +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: <4b0efe51-d6c0-9a37-ce34-155387d1a8e8@mediaarea.net> Content-Language: en-GB X-Ovh-Tracer-Id: 740279192690167997 X-VR-SPAMSTATE: OK X-VR-SPAMSCORE: 0 X-VR-SPAMCAUSE: gggruggvucftvghtrhhoucdtuddrgedtfedrkedvgdekfecutefuodetggdotefrodftvfcurfhrohhfihhlvgemucfqggfjpdevjffgvefmvefgnecuuegrihhlohhuthemuceftddtnecu Subject: [FFmpeg-devel] [PATCH 4/7] avcodec/ffv1enc: prevent encoder to create non-lossless streams with some chroma subsamplings 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 all luma samples for a chroma sample are not in the same slice, resulting bitstream is valid but the compression then decompression is not lossless. ffmpeg -y -f lavfi -i mandelbrot=s=1925x1080 -vf format=yuv411p -vframes 1 -c ffv1 -slices 16 a.mkv ffmpeg -y -f lavfi -i mandelbrot=s=1925x1080 -vf format=yuv411p -vframes 1 -f framemd5 source.md5 ffmpeg -y -i a.mkv -vframes 1 -f framemd5 a.mkv.md5 Framemd5 are not same. For e.g. 4:1:1 and 4 horizontal slices (-slices 16), we have 1920-1921-1922-1923-1924 1926-1927-1928 1931-1932 1936 OK 1925 1929-1930 1933-1934-1935 NOK This patch is an hotfix for preventing the encoder to create such stream. Note that it blocks more than needed (e.g, all the listed widths above except multiples of 16 are blocked) as I didn't find the exact pattern that makes the conversion NOK, the hotfix is definitely not nice and I would welcome another proposal. From 954817ec1f78396d04383a1ea19aec7739fdd7fb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=A9r=C3=B4me=20Martinez?= Date: Wed, 7 Mar 2018 10:41:10 +0100 Subject: [PATCH 4/7] avcodec/ffv1enc: prevent encoder to create non-lossless streams with some chroma subsamplings Some combinations having chroma subsampling are not lossless with current code --- libavcodec/ffv1enc.c | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/libavcodec/ffv1enc.c b/libavcodec/ffv1enc.c index 51aa8c2898..16987117d8 100644 --- a/libavcodec/ffv1enc.c +++ b/libavcodec/ffv1enc.c @@ -876,6 +876,10 @@ FF_ENABLE_DEPRECATION_WARNINGS for (s->num_h_slices = s->num_v_slices; s->num_h_slices < 2*s->num_v_slices; s->num_h_slices++) { int maxw = (avctx->width + s->num_h_slices - 1) / s->num_h_slices; int maxh = (avctx->height + s->num_v_slices - 1) / s->num_v_slices; + if (s->chroma_h_shift && (avctx->width % (s->num_h_slices << s->chroma_h_shift))) // Hotfix: some combinations having chroma subsampling are not lossless with current code, e.g. width of 1919 with 422 subsampling and 2 horizontal slices, or width of 1921 with 422 subsampling and 2 horizontal slices + continue; + if (s->chroma_v_shift && (avctx->height % (s->num_v_slices << s->chroma_v_shift))) // Hotfix: some combinations having chroma subsampling are not lossless with current code, e.g. width of 1919 with 422 subsampling and 2 horizontal slices, or width of 1921 with 422 subsampling and 2 horizontal slices + continue; if (s->num_h_slices > max_h_slices || s->num_v_slices > max_v_slices) continue; if (maxw * maxh * (int64_t)(s->bits_per_raw_sample+1) * plane_count > 8<<24)