From patchwork Tue Jan 3 12:40:55 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mark Thompson X-Patchwork-Id: 2035 Delivered-To: ffmpegpatchwork@gmail.com Received: by 10.103.89.21 with SMTP id n21csp4348609vsb; Tue, 3 Jan 2017 04:41:11 -0800 (PST) X-Received: by 10.194.203.135 with SMTP id kq7mr64599216wjc.26.1483447270940; Tue, 03 Jan 2017 04:41:10 -0800 (PST) Return-Path: Received: from ffbox0-bg.mplayerhq.hu (ffbox0-bg.ffmpeg.org. [79.124.17.100]) by mx.google.com with ESMTP id b203si73309150wmc.136.2017.01.03.04.41.10; Tue, 03 Jan 2017 04:41:10 -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; dkim=neutral (body hash did not verify) header.i=@jkqxz-net.20150623.gappssmtp.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 180AE689D71; Tue, 3 Jan 2017 14:41:03 +0200 (EET) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-wm0-f44.google.com (mail-wm0-f44.google.com [74.125.82.44]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 93D326898E8 for ; Tue, 3 Jan 2017 14:40:55 +0200 (EET) Received: by mail-wm0-f44.google.com with SMTP id a197so383796851wmd.0 for ; Tue, 03 Jan 2017 04:41:00 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=jkqxz-net.20150623.gappssmtp.com; s=20150623; h=subject:references:cc:from:message-id:date:user-agent:mime-version :in-reply-to:content-transfer-encoding; bh=MtomSqxdy3RnvTAwp57CcAap0krCFllY9l1oRDvHw4k=; b=qDyL27TTR8wHy34BhjujRVUqnlrsLRXJxXZW//aVQwv1m+cYNUk9yanUmn24y4GsMm CFzHZG/ta7e9BoGOQFrXKVvysDgdUPB+hNR+Hhq/4P+i2KMyQvrDOLJJq+vsSJRrExVg UmPKyEkvohXSxjUCDQVgP3WaUAv9xHDFwkjcR71AiVh8zcH3yD4fGnycN7TGXzp9aXSp YuGNqGhkJ1TRZIH/LkPA8U/+6/ff4wQUm65NDO7S+C/KrOZvs9KMb8w8r4Fm7gywP3ou C461yXyE4L3+5ZUcJGP5yF6wbHWCEYsAEWeWD9QHw0AaM8b1KxnxrjaKcdRpcjSXzSEX pGdQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:subject:references:cc:from:message-id:date :user-agent:mime-version:in-reply-to:content-transfer-encoding; bh=MtomSqxdy3RnvTAwp57CcAap0krCFllY9l1oRDvHw4k=; b=ZM87sm0VTZDnYZIwAO4CMcNri2j7urh2vXpmnZ8vzKOMAYfP1HR9R9gECFi/zYUlFe AY+V3C7Qx6qhmxvkXkj3ANzyWHzHWVnTzFuhq2p5rr2U74xH7Se5z5x/sm8ljnstcYDE S5KoWfeJOSzopAbHvs3zXRABZPY7yCrq5nPPoHD/CkfsjlAWvdBuE1OtiyviMegj97E7 PGzT7lznnzSroMnjIpWFMIp1ATLOehZX9QvLHH1e4dDPZsR0cW4IoUXoWn1mVA3OzMIo N3Z/JocEFKwJdQw+4Ml4hw1hYdKgRGKlWuqbcCigPpQs+0WWe7ABzHRHIT94JimvUL+/ nggg== X-Gm-Message-State: AIkVDXKWGrMy9XdvSw6Qbayb7pk7cW/HgVCAY+eoTmN54crfxyH2UV0DeZbfBKS/eVAy+Q== X-Received: by 10.28.178.205 with SMTP id b196mr55748701wmf.8.1483447259420; Tue, 03 Jan 2017 04:40:59 -0800 (PST) Received: from [10.0.0.193] ([213.210.30.6]) by smtp.gmail.com with ESMTPSA id x188sm89474941wmx.4.2017.01.03.04.40.58 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 03 Jan 2017 04:40:58 -0800 (PST) References: <2590bfe7-9daf-4316-52e3-2c37f9b2f061@gmail.com> Cc: FFmpeg development discussions and patches From: Mark Thompson Message-ID: Date: Tue, 3 Jan 2017 12:40:55 +0000 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:45.0) Gecko/20100101 Icedove/45.4.0 MIME-Version: 1.0 In-Reply-To: <2590bfe7-9daf-4316-52e3-2c37f9b2f061@gmail.com> Subject: Re: [FFmpeg-devel] [PATCH] libavutil/hwcontext_qsv: Fix bug that the QSV encoded frames'width and height are 32-aligned 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" On 03/01/17 06:35, Huang, Zhengxu wrote: > From 8b1bcc0634f6ce36acfbd2bfdd26690a6323d09c Mon Sep 17 00:00:00 2001 > From: Zhengxu > Date: Fri, 16 Dec 2016 11:10:34 +0800 > Subject: [PATCH] libavutil/hwcontext_qsv: Fix bug that the QSV encoded frames' > width and height are 32-aligned. > > Description: > If an input is of 1280x720, the encoded stream created by command below is of 1280x736: > ffmpeg -hwaccel qsv -c:v h264_qsv -i test.h264 -c:v h264_qsv out.h264 > > Reason: > When creating a AVQSVFramesContext, width and height shouldn't be aligned, or the mfxSurfaces' > cropW and cropH will be wrong. > > Fix: > User should configure AVQSVFramesContext with origin width and height and AVFramesContext will > align the width and height when being initiallized. > > Signed-off-by: ChaoX A Liu > Signed-off-by: Huang, Zhengxu > Signed-off-by: Andrew, Zhang > --- > ffmpeg_qsv.c | 8 ++++---- > libavutil/hwcontext_qsv.c | 8 ++++++-- > 2 files changed, 10 insertions(+), 6 deletions(-) > > diff --git a/ffmpeg_qsv.c b/ffmpeg_qsv.c > index 68ff5bd..aab7375 100644 > --- a/ffmpeg_qsv.c > +++ b/ffmpeg_qsv.c > @@ -76,8 +76,8 @@ int qsv_init(AVCodecContext *s) > frames_ctx = (AVHWFramesContext*)ist->hw_frames_ctx->data; > frames_hwctx = frames_ctx->hwctx; > > - frames_ctx->width = FFALIGN(s->coded_width, 32); > - frames_ctx->height = FFALIGN(s->coded_height, 32); > + frames_ctx->width = s->coded_width; > + frames_ctx->height = s->coded_height; > frames_ctx->format = AV_PIX_FMT_QSV; > frames_ctx->sw_format = s->sw_pix_fmt; > frames_ctx->initial_pool_size = 64; > @@ -152,8 +152,8 @@ int qsv_transcode_init(OutputStream *ost) > encode_frames = (AVHWFramesContext*)encode_frames_ref->data; > qsv_frames = encode_frames->hwctx; > > - encode_frames->width = FFALIGN(ist->resample_width, 32); > - encode_frames->height = FFALIGN(ist->resample_height, 32); > + encode_frames->width = ist->resample_width; > + encode_frames->height = ist->resample_height; > encode_frames->format = AV_PIX_FMT_QSV; > encode_frames->sw_format = AV_PIX_FMT_NV12; > encode_frames->initial_pool_size = 1; > diff --git a/libavutil/hwcontext_qsv.c b/libavutil/hwcontext_qsv.c > index 03244a6..2dc9aca 100644 > --- a/libavutil/hwcontext_qsv.c > +++ b/libavutil/hwcontext_qsv.c > @@ -308,9 +308,13 @@ static int qsv_init_pool(AVHWFramesContext *ctx, uint32_t fourcc) > surf->Info.ChromaFormat = MFX_CHROMAFORMAT_YUV444; > > surf->Info.FourCC = fourcc; > - surf->Info.Width = ctx->width; > + /* > + * WxH being aligned with 32x32 is needed by MSDK. > + * CropW and CropH are the real size of the frame. > + */ > + surf->Info.Width = FFALIGN(ctx->width, 32); > surf->Info.CropW = ctx->width; > - surf->Info.Height = ctx->height; > + surf->Info.Height = FFALIGN(ctx->height, 32); > surf->Info.CropH = ctx->height; > surf->Info.FrameRateExtN = 25; > surf->Info.FrameRateExtD = 1; > -- > 1.8.3.1 > This seems wrong to me - the hwcontext code is only dealing in surfaces, and should not be interested in the actual dimensions of the frame on each surface (that is a per-frame property anyway, since it need not be the same for all frames in a context). Is it possible to instead fix this case by adjusting the cropping parameters after copying the FrameInfo at libavcodec/qsvenc.c:378? Maybe this (not tested at all): Thanks, - Mark diff --git a/libavcodec/qsvenc.c b/libavcodec/qsvenc.c index ac443c1a26..32e2a4ed13 100644 --- a/libavcodec/qsvenc.c +++ b/libavcodec/qsvenc.c @@ -376,6 +376,8 @@ static int init_video_param(AVCodecContext *avctx, QSVEncContext *q) AVHWFramesContext *frames_ctx = (AVHWFramesContext*)avctx->hw_frames_ctx->data; AVQSVFramesContext *frames_hwctx = frames_ctx->hwctx; q->param.mfx.FrameInfo = frames_hwctx->surfaces[0].Info; + q->param.mfx.FrameInfo.CropW = avctx->width; + q->param.mfx.FrameInfo.CropH = avctx->height; } else { q->param.mfx.FrameInfo.FourCC = MFX_FOURCC_NV12; q->param.mfx.FrameInfo.Width = FFALIGN(avctx->width, q->width_align);