From patchwork Tue Jan 21 13:06:43 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jon Cook X-Patchwork-Id: 17455 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 5CD9944B87B for ; Tue, 21 Jan 2020 15:06:55 +0200 (EET) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 3581F68B11F; Tue, 21 Jan 2020 15:06:55 +0200 (EET) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-wr1-f68.google.com (mail-wr1-f68.google.com [209.85.221.68]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id C3DB668A9F3 for ; Tue, 21 Jan 2020 15:06:48 +0200 (EET) Received: by mail-wr1-f68.google.com with SMTP id c9so3099581wrw.8 for ; Tue, 21 Jan 2020 05:06:48 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=cubicmotion.com; s=google; h=from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=1jpFfQcuwNLS8qRk2Omc4SETXObdfCp0SDonexWQOoY=; b=iCY/6VVQlQq8db7VnUvof4ETwnFNyqrHITkkkNeqILMrJyql/UKgYZ55gW9rAUZrFI 9B/Shvri3cf5hXdJFZX3TPmRf8zG8Rj8NlumM6Lo9byTGRray6ea3bNiqVNgK0tN3QnZ rnKPv6tYIGDGqxkNU29+SoVrpcsK9vbyn0mA8mx/OHQfJgXiWMDE6V6mjvBt74rBvng2 x2xdcDoxiwj2qe1Oki6AB/or5/PJflZYA9XHfXC0xcHzEpKXk4TJdsmRwIo2QeuHpKng cHFRlk5rW15nqYbf/n7BQ7p204a1nN88vHisVy0oCPLJ2qRtjY4OqiSNCUwUdbkBNFWl KhMg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=1jpFfQcuwNLS8qRk2Omc4SETXObdfCp0SDonexWQOoY=; b=G0tSFszWRXZLcvwXxNc08ceovzQXKcbyWhOsWT0rVBy8JOBkUYhO0ypfw5qua6D9X2 /2ZmmtkT7bo21RIhb3uVuXPn8fakscBa5jSMP7RgwSC7/L+hXx++k6a5j8g0qczKawAq 3ejW/gAfunN0uvM3+wRqtHSOc3O0WAF1Cc+gKhAL5Bc/+7M6YT10XuhFTCRn/HSgcz7G JQnmJgAepoKnG5d02Mo1gi62U31LU5glg3OOOmBmY2C6MBaqLqzzig+MDSGI6Nr1HqNm qtPYX7iQnOsPiqjxGmzYU/TrvkHyw+ZKb+mn6Lsf3vqIA6U287+WMLDjuTjmLycSQ46B XqRA== X-Gm-Message-State: APjAAAUnNbZrJSJN/9LNdF7lyWUJSVnxlT0kVm9ky2yY/AzB+Upl2Zqy CN6UOHdRN/indCmfbTHE+i5baLoLYqjgjg== X-Google-Smtp-Source: APXvYqwn9FDW5htdtUWvT90Y0J4aRsE8J6tM/RBROeOZnMHFePra6W2cjTDeUQ955Vk9rjuO51BG3A== X-Received: by 2002:adf:d183:: with SMTP id v3mr5348870wrc.180.1579612007796; Tue, 21 Jan 2020 05:06:47 -0800 (PST) Received: from Development-A22.cubicmotion.net ([81.92.211.68]) by smtp.gmail.com with ESMTPSA id l6sm3975829wmf.21.2020.01.21.05.06.46 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 21 Jan 2020 05:06:46 -0800 (PST) From: Jon Cook To: ffmpeg-devel@ffmpeg.org Date: Tue, 21 Jan 2020 13:06:43 +0000 Message-Id: <20200121130643.4520116-1-jon.cook@cubicmotion.com> X-Mailer: git-send-email 2.20.1.windows.1 MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH] libavcodec/qsvenc.c: Set height and width alignment when encoding with mjpeg_qsv 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 Cc: JonCookCubic Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" From: JonCookCubic Currently width_align and height_align are zero when encoding with mjpeg_qsv which causes "Error submitting the frame for encoding". This patch sets the alignments. There is a little bit more about the problem here http://ffmpeg.org/pipermail/ffmpeg-user/2019-November/046143.html The following command line shows the problem (output is without the patch applied). Input video is not important, any video will do. $ ./ffmpeg.exe -loglevel debug -y -i C:/Users/jcook/Desktop/sample.avi -c:v mjpeg_qsv output.mp4 ffmpeg version N-95883-ga2fbdc6898 Copyright (c) 2000-2019 the FFmpeg developers built with Microsoft (R) C/C++ Optimizing Compiler Version 19.16.27031.1 for x64 configuration: --toolchain=msvc --target-os=win64 --arch=x86_64 --prefix=/ffmpeg --enable-shared --disable-static --enable-yasm --enable-asm --enable-libmfx --enable-nonfree libavutil 56. 36.101 / 56. 36.101 libavcodec 58. 62.100 / 58. 62.100 libavformat 58. 35.100 / 58. 35.100 libavdevice 58. 9.101 / 58. 9.101 libavfilter 7. 67.100 / 7. 67.100 libswscale 5. 6.100 / 5. 6.100 libswresample 3. 6.100 / 3. 6.100 Splitting the commandline. Reading option '-loglevel' ... matched as option 'loglevel' (set logging level) with argument 'debug'. Reading option '-y' ... matched as option 'y' (overwrite output files) with argument '1'. Reading option '-i' ... matched as input url with argument 'C:/Users/jcook/Desktop/sample.avi'. Reading option '-c:v' ... matched as option 'c' (codec name) with argument 'mjpeg_qsv'. Reading option 'output.mp4' ... matched as output url. Finished splitting the commandline. Parsing a group of options: global . Applying option loglevel (set logging level) with argument debug. Applying option y (overwrite output files) with argument 1. Successfully parsed a group of options. Parsing a group of options: input url C:/Users/jcook/Desktop/sample.avi. Successfully parsed a group of options. Opening an input file: C:/Users/jcook/Desktop/sample.avi. [NULL @ 000001E0699F8540] Opening 'C:/Users/jcook/Desktop/sample.avi' for reading [file @ 000001E0699D8280] Setting default whitelist 'file,crypto' [avi @ 000001E0699F8540] Format avi probed with size=2048 and score=100 [avi @ 000001E0699D86C0] use odml:1 st:1 removing common factor 36 from timebase [avi @ 000001E0699F8540] Before avformat_find_stream_info() pos: 4108 bytes read:142280 seeks:5 nb_streams:2 [mpeg4 @ 000001E069A0AE00] Format yuv420p chosen by get_format(). [avi @ 000001E0699F8540] All info found [avi @ 000001E0699F8540] After avformat_find_stream_info() pos: 16409 bytes read:142280 seeks:5 frames:21 Input #0, avi, from 'C:/Users/jcook/Desktop/sample.avi': Metadata: encoder : MEncoder SVN-r33148-4.0.1 Duration: 00:00:05.56, start: 0.000000, bitrate: 540 kb/s Stream #0:0, 1, 1/25: Video: mpeg4 (Simple Profile), 1 reference frame (XVID / 0x44495658), yuv420p(left), 320x240 [SAR 1:1 DAR 4:3], 0/1, 425 kb/s, 25 fps, 25 tbr, 25 tbn, 25 tbc Stream #0:1, 20, 32/1225: Audio: mp3 (U[0][0][0] / 0x0055), 44100 Hz, stereo, fltp, 100 kb/s Successfully opened the file. Parsing a group of options: output url output.mp4. Applying option c:v (codec name) with argument mjpeg_qsv. Successfully parsed a group of options. Opening an output file: output.mp4. [file @ 000001E06B51B9C0] Setting default whitelist 'file,crypto' Successfully opened the file. detected 12 logical cores Stream mapping: Stream #0:0 -> #0:0 (mpeg4 (native) -> mjpeg (mjpeg_qsv)) Stream #0:1 -> #0:1 (mp3 (mp3float) -> aac (native)) Press [q] to stop, [?] for help cur_dts is invalid st:0 (0) [init:0 i_done:0 finish:0] (this is harmless if it occurs once at the start per stream) [graph_1_in_0_1 @ 000001E069A12A40] Setting 'time_base' to value '1/44100' [graph_1_in_0_1 @ 000001E069A12A40] Setting 'sample_rate' to value '44100' [graph_1_in_0_1 @ 000001E069A12A40] Setting 'sample_fmt' to value 'fltp' [graph_1_in_0_1 @ 000001E069A12A40] Setting 'channel_layout' to value '0x3' [graph_1_in_0_1 @ 000001E069A12A40] tb:1/44100 samplefmt:fltp samplerate:44100 chlayout:0x3 [format_out_0_1 @ 000001E069A2F800] Setting 'sample_fmts' to value 'fltp' [format_out_0_1 @ 000001E069A2F800] Setting 'sample_rates' to value '96000|88200|64000|48000|44100|32000|24000|22050|16000|12000|11025|8000|7350' [AVFilterGraph @ 000001E069AA7100] query_formats: 4 queried, 9 merged, 0 already done, 0 delayed cur_dts is invalid st:0 (0) [init:0 i_done:0 finish:0] (this is harmless if it occurs once at the start per stream) Last message repeated 20 times [mpeg4 @ 000001E069A2EE00] Format yuv420p chosen by get_format(). cur_dts is invalid st:0 (0) [init:0 i_done:0 finish:0] (this is harmless if it occurs once at the start per stream) Last message repeated 28 times [graph 0 input from stream 0:0 @ 000001E069A31640] Setting 'video_size' to value '320x240' [graph 0 input from stream 0:0 @ 000001E069A31640] Setting 'pix_fmt' to value '0' [graph 0 input from stream 0:0 @ 000001E069A31640] Setting 'time_base' to value '1/25' [graph 0 input from stream 0:0 @ 000001E069A31640] Setting 'pixel_aspect' to value '1/1' [graph 0 input from stream 0:0 @ 000001E069A31640] Setting 'sws_param' to value 'flags=2' [graph 0 input from stream 0:0 @ 000001E069A31640] Setting 'frame_rate' to value '25/1' [graph 0 input from stream 0:0 @ 000001E069A31640] w:320 h:240 pixfmt:yuv420p tb:1/25 fr:25/1 sar:1/1 sws_param:flags=2 [format @ 000001E06BBCED80] Setting 'pix_fmts' to value 'nv12|qsv' [auto_scaler_0 @ 000001E06BBCEE80] Setting 'flags' to value 'bicubic' [auto_scaler_0 @ 000001E06BBCEE80] w:iw h:ih flags:'bicubic' interl:0 [format @ 000001E06BBCED80] auto-inserting filter 'auto_scaler_0' between the filter 'Parsed_null_0' and the filter 'format' [AVFilterGraph @ 000001E069AA7F80] query_formats: 4 queried, 2 merged, 1 already done, 0 delayed [auto_scaler_0 @ 000001E06BBCEE80] w:320 h:240 fmt:yuv420p sar:1/1 -> w:320 h:240 fmt:nv12 sar:1/1 flags:0x4 [mjpeg_qsv @ 000001E069A01B80] Initialized an internal MFX session using hardware accelerated implementation Output #0, mp4, to 'output.mp4': Metadata: encoder : Lavf58.35.100 Stream #0:0, 0, 1/12800: Video: mjpeg (mjpeg_qsv), 1 reference frame (mp4v / 0x7634706D), nv12(left), 320x240 [SAR 1:1 DAR 4:3], 0/1, q=2-31, 200 kb/s, 25 fps, 12800 tbn, 25 tbc Metadata: encoder : Lavc58.62.100 mjpeg_qsv Stream #0:1, 0, 1/44100: Audio: aac (LC) (mp4a / 0x6134706D), 44100 Hz, stereo, fltp, delay 1024, 128 kb/s Metadata: encoder : Lavc58.62.100 aac Clipping frame in rate conversion by 0.000008 [mjpeg_qsv @ 000001E069A01B80] Error submitting the frame for encoding. Video encoding failed [AVIOContext @ 000001E06B51BA80] Statistics: 0 seeks, 1 writeouts [aac @ 000001E069A3A6C0] Qavg: 709.099 [aac @ 000001E069A3A6C0] 2 frames left in the queue on closing [AVIOContext @ 000001E0699D1440] Statistics: 175048 bytes read, 5 seeks Conversion failed! Signed-off-by: JonCookCubic --- libavcodec/qsvenc.c | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/libavcodec/qsvenc.c b/libavcodec/qsvenc.c index 9e416500e9..40904af388 100644 --- a/libavcodec/qsvenc.c +++ b/libavcodec/qsvenc.c @@ -470,6 +470,12 @@ static int init_video_param_jpeg(AVCodecContext *avctx, QSVEncContext *q) q->param.mfx.Quality = av_clip(avctx->global_quality, 1, 100); q->param.mfx.RestartInterval = 0; + q->width_align = 16; + q->height_align = 16; + + q->param.mfx.FrameInfo.Width = FFALIGN(avctx->width, q->width_align); + q->param.mfx.FrameInfo.Height = FFALIGN(avctx->height, q->height_align); + return 0; }