diff mbox series

[FFmpeg-devel] libavcodec/qsvenc.c: Set height and width alignment when encoding with mjpeg_qsv

Message ID 20200121130643.4520116-1-jon.cook@cubicmotion.com
State New
Headers show
Series [FFmpeg-devel] libavcodec/qsvenc.c: Set height and width alignment when encoding with mjpeg_qsv
Related show

Checks

Context Check Description
andriy/ffmpeg-patchwork pending
andriy/ffmpeg-patchwork success Applied patch
andriy/ffmpeg-patchwork success Configure finished
andriy/ffmpeg-patchwork success Make finished
andriy/ffmpeg-patchwork success Make fate finished

Commit Message

Jon Cook Jan. 21, 2020, 1:06 p.m. UTC
From: JonCookCubic <jon.cook@cubicmotion.com>

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 <jon.cook@cubicmotion.com>
---
 libavcodec/qsvenc.c | 6 ++++++
 1 file changed, 6 insertions(+)
diff mbox series

Patch

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;
 }