From patchwork Fri Apr 24 07:45:54 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Elio Blanca X-Patchwork-Id: 19208 Return-Path: X-Original-To: patchwork@ffaux-bg.ffmpeg.org Delivered-To: patchwork@ffaux-bg.ffmpeg.org Received: from ffbox0-bg.mplayerhq.hu (ffbox0-bg.ffmpeg.org [79.124.17.100]) by ffaux.localdomain (Postfix) with ESMTP id D85E0448D53 for ; Fri, 24 Apr 2020 10:46:09 +0300 (EEST) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id A080A68C08B; Fri, 24 Apr 2020 10:46:09 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from libero.it (smtp-35.italiaonline.it [213.209.10.35]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 024E768C081 for ; Fri, 24 Apr 2020 10:46:02 +0300 (EEST) Received: from debbieb1 ([5.171.255.145]) by smtp-35.iol.local with ESMTPA id Rt29jtepUMAUpRt2AjChT7; Fri, 24 Apr 2020 09:46:02 +0200 x-libjamoibt: 1601 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=libero.it; s=s2014; t=1587714362; bh=2ytjKvYIjKYUFoieSfGivN5C0j4Ogz7UlOpcMWcMK+0=; h=From; b=XKL9Yx+LK2vZna3sC9ze2/V0tPXo2uI16NbbLcYz7t7ZG29wNCb+7p3yEID3Tvu6V B7VjsS4YYi5gWfq5y3hnYpqfEU2uMC5SIUgYzLPUknRtsLfUT5/bhanxmn8A0ffZaV FUNi2E4Bz6paf92A6wnBYepzzvVVahT5+itTgtrimtyfXJbF9kDcH453obYOrLbVXy kpHpOm6i7SG9MYdG9bMd8HDi3ismzMeM4pVg0KdB61df/vKt9s75zCMCw4QaUpPEYS hKwPgWRzi0u7dfZzWjEE74StTd2YRExEjqdZVAHiIG0UYvN4RLX/aOukWx8dG/APFT KwGId0MVC9KDA== X-CNFS-Analysis: v=2.3 cv=B/fHL9lM c=1 sm=1 tr=0 a=jAorlCo+K8LhJ7rdskxxSw==:117 a=jAorlCo+K8LhJ7rdskxxSw==:17 a=kj9zAlcOel0A:10 a=ZYi0oID12D1AK0D8AuQA:9 a=CjuIK1q_8ugA:10 Date: Fri, 24 Apr 2020 09:45:54 +0200 From: Elio Blanca To: ffmpeg-devel@ffmpeg.org Message-ID: <20200424094554.6359123b@debbieb1> X-Mailer: Claws Mail 3.17.3 (GTK+ 2.24.32; x86_64-pc-linux-gnu) MIME-Version: 1.0 X-CMAE-Envelope: MS4wfFy9trcFmF0KCG0PdfC29SC5rRzRM5kqsis8PGFoMlI3YR80JxUM+lnnqbPP3E1iXzRhJYqqRXxQECxCtm9qrAVKU7Foct2+Ah75Mko7z3JWW3UnTVeB kldw1QSBykrhzUlKfdEIvpHRY1MUT00HAzIEN9alU4+sOqsmSARF04pm Subject: [FFmpeg-devel] [PATCH] libavcodec/qsvenc.c fixed handling of closed gop flag 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" Hello, this is my very first message to this list, so first of all: thank you for your huge work! Now, to the issue: I made this patch for libavcodec/qsvenc.c in order to honor the GopOptFlag flag for hevc_qsv encodings (maybe others will be affected though). In statement 513 (the third fix) a wrong value was assigned in case of not-closed-gop. Zero is not an allowed value, as the enum mfx.GopOptFlag refers to uses only 1 and 2. What the encoding engine will do when feeded with a non-valid value is unpredictable. Then, in statements 148 and 150 I changed those 'if' replacing '&' with '==' because of the enum, which is different from a bitmask. Apart from those, it sound to me quite suspicious having to set -flags 0 in my command line in order NOT to get closed gops, as the default is a closed gop (I see weird having this as default). Further, I usually avoid using a signed 'int' for a flag field, which needs to be handled with bitmasks, so into libavcodec/avcodec.h I would change those 'int flags;' and 'int flags2;' using unsigned instead; unless, of course, there are solid reasons to have them defined this way. Elio diff --git a/libavcodec/qsvenc.c b/libavcodec/qsvenc.c index 9bf8574e30..d363dae633 100644 --- a/libavcodec/qsvenc.c +++ b/libavcodec/qsvenc.c @@ -145,9 +145,9 @@ static void dump_video_param(AVCodecContext *avctx, QSVEncContext *q, av_log(avctx, AV_LOG_VERBOSE, "GopPicSize: %"PRIu16"; GopRefDist: %"PRIu16"; GopOptFlag: ", info->GopPicSize, info->GopRefDist); - if (info->GopOptFlag & MFX_GOP_CLOSED) + if (info->GopOptFlag == MFX_GOP_CLOSED) av_log(avctx, AV_LOG_VERBOSE, "closed "); - if (info->GopOptFlag & MFX_GOP_STRICT) + if (info->GopOptFlag == MFX_GOP_STRICT) av_log(avctx, AV_LOG_VERBOSE, "strict "); av_log(avctx, AV_LOG_VERBOSE, "; IdrInterval: %"PRIu16"\n", info->IdrInterval); @@ -510,7 +510,7 @@ static int init_video_param(AVCodecContext *avctx, QSVEncContext *q) q->param.mfx.GopPicSize = FFMAX(0, avctx->gop_size); q->param.mfx.GopRefDist = FFMAX(-1, avctx->max_b_frames) + 1; q->param.mfx.GopOptFlag = avctx->flags & AV_CODEC_FLAG_CLOSED_GOP ? - MFX_GOP_CLOSED : 0; + MFX_GOP_CLOSED : MFX_GOP_STRICT; q->param.mfx.IdrInterval = q->idr_interval; q->param.mfx.NumSlice = avctx->slices; q->param.mfx.NumRefFrame = FFMAX(0, avctx->refs);