Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[ffmpeg-vaapi][VP8 encode] floating point exception #578

Closed
eero-t opened this issue Mar 29, 2019 · 5 comments · Fixed by #622
Closed

[ffmpeg-vaapi][VP8 encode] floating point exception #578

eero-t opened this issue Mar 29, 2019 · 5 comments · Fixed by #622
Assignees
Labels
Encode video encode related P2 Medium priority

Comments

@eero-t
Copy link

eero-t commented Mar 29, 2019

Setup:

  • Tested to happen both on ICL and KBL GT2
  • Git version of drm-tip kernel and all media components

Use-case:

  • ffmpeg -loglevel verbose -hwaccel vaapi -vaapi_device /dev/dri/renderD128 -hwaccel_output_format vaapi -threads 1 -i 1280x720p_29.97_10mb_h264_cabac.264 -c:v vp8_vaapi -y test.webm

Result is floating point exception:

...
Input #0, h264, from 'input/1280x720p_29.97_10mb_h264_cabac.264':
  Duration: N/A, bitrate: N/A
    Stream #0:0: Video: h264 (High), 1 reference frame, yuv420p(tv, bt709, progressive, left), 1280x720 [SAR 1:1 DAR 16:9], 29.97 fps, 29.97 tbr, 1200k tbn, 59.94 tbc
Stream mapping:
  Stream #0:0 -> #0:0 (h264 (native) -> vp8 (vp8_vaapi))
Press [q] to stop, [?] for help
[h264 @ 0x5618e5b2ef40] Reinit context to 1280x720, pix_fmt: vaapi_vld
[graph 0 input from stream 0:0 @ 0x5618e6303b80] w:1280 h:720 pixfmt:vaapi_vld tb:1/1200000 fr:30000/1001 sar:1/1 sws_param:flags=2
[vp8_vaapi @ 0x5618e5b0f480] Input surface format is nv12.
[vp8_vaapi @ 0x5618e5b0f480] Using VAAPI profile VAProfileVP8Version0_3 (14).
[vp8_vaapi @ 0x5618e5b0f480] Using VAAPI entrypoint VAEntrypointEncSlice (6).
[vp8_vaapi @ 0x5618e5b0f480] Using VAAPI render target format YUV420 (0x1).
[vp8_vaapi @ 0x5618e5b0f480] No quality level set; using default (40).
[vp8_vaapi @ 0x5618e5b0f480] RC mode: CQP.
[vp8_vaapi @ 0x5618e5b0f480] RC quality: 40.
[vp8_vaapi @ 0x5618e5b0f480] RC framerate: 30000/1001 (29.97 fps).
[vp8_vaapi @ 0x5618e5b0f480] Using intra and P-frames (supported references: 3 / 0).
[vp8_vaapi @ 0x5618e5b0f480] Driver does not support any packed headers (none wanted).
Output #0, webm, to 'test.webm':
  Metadata:
    encoder         : Lavf58.26.101
    Stream #0:0: Video: vp8 (vp8_vaapi), 1 reference frame, vaapi_vld(left), 1280x720 [SAR 1:1 DAR 16:9], q=-1--1, 29.97 fps, 1k tbn, 29.97 tbc
    Metadata:
      encoder         : Lavc58.47.106 vp8_vaapi
Floating point exception

Same happens also with #409 use-case.

@XinfengZhang XinfengZhang added Encode video encode related P3 Low priority no customer usage, no business requirements, not from communities, just from internal labels Apr 17, 2019
@XinfengZhang XinfengZhang added P2 Medium priority and removed P3 Low priority no customer usage, no business requirements, not from communities, just from internal labels Apr 25, 2019
@wangyan42164
Copy link
Contributor

@eero-t Could you please share this bit stream for reproducing? Thanks

@eero-t
Copy link
Author

eero-t commented May 13, 2019

None of the input video's I've tested, works. Here's one example: https://media.xiph.org/video/derf/webm/FourPeople_1280x720_60.webm

Backtrace with media driver & FFmpeg git versions from yesterday:

Thread 1 "ffmpeg" received signal SIGFPE, Arithmetic exception.
(gdb) bt
#0  0x00007fffedb7121a in CodechalEncodeVp8::SetPictureStructs (this=this@entry=0x555557bd9760)
    at media-driver/media_driver/agnostic/common/codec/hal/codechal_encode_vp8.cpp:1279
#1  0x00007fffedb714a9 in CodechalEncodeVp8::InitializePicture (this=0x555557bd9760, params=...)
    at media-driver/media_driver/agnostic/common/codec/hal/codechal_encode_vp8.cpp:1119
#2  0x00007fffedb29cde in CodechalEncoderState::ExecuteEnc (this=0x555557bd9760, 
    encodeParams=0x7fffffffc610)
    at media-driver/media_driver/agnostic/common/codec/hal/codechal_encoder_base.cpp:4263
#3  0x00007fffedd81f04 in DdiEncodeVp8::EncodeInCodecHal (this=0x555557bbf4c0, 
    numSlices=<optimized out>)
    at media-driver/media_driver/linux/common/codec/ddi/media_ddi_encode_vp8.cpp:651
#4  0x00007fffedd740bc in DdiEncodeBase::EndPicture (this=0x555557bbf4c0, ctx=<optimized out>, 
    context=<optimized out>)
    at media-driver/media_driver/linux/common/codec/ddi/media_ddi_encode_base.cpp:77
#5  0x00007fffedd770d8 in DdiEncode_EndPicture (ctx=ctx@entry=0x55555736fad0, 
    context=context@entry=536870912)
    at media-driver/media_driver/linux/common/codec/ddi/media_libva_encoder.cpp:584
#6  0x00007fffedd98feb in DdiMedia_EndPicture (ctx=0x55555736fad0, context=536870912)
    at media-driver/media_driver/linux/common/ddi/media_libva.cpp:3243
#7  0x00007ffff6259f20 in vaEndPicture (dpy=0x55555736f960, context=536870912)
(gdb) info locals
currRefIdx = 1 '\001'
numRef = <optimized out>
brcPrecision = <optimized out>
averageQp = 40

When looking at the relevant code in header and codechal_encode_vp8.cpp:

// picture coding type
#define I_TYPE          1
#define P_TYPE          2
#define B_TYPE          3
#define NUM_PIC_TYPES   3
...
    if (m_pictureCodingType == I_TYPE)
    {
        m_averageKeyFrameQp   = averageQp;
        m_pFramePositionInGop = 0;
    }
    else
    {
        m_averagePFrameQp     = averageQp;
        m_pFramePositionInGop = (m_storeData - 1) % m_vp8SeqParams->GopPicSize;
    }

And the values for the relevant variables at exception:

(gdb) print m_pictureCodingType
$1 = 2
(gdb) print m_averagePFrameQp
$2 = 40
(gdb) print m_storeData
$3 = 2
(gdb) print m_vp8SeqParams->GopPicSize
$4 = 0

There's an obvious division by zero.

(And code exception handling for some reason converts that to a "floating point" exception?)

wangyan42164 added a commit to wangyan42164/media-driver that referenced this issue May 14, 2019
1. Initialize BRC variales for avoiding wrong DSH allocation.
2. Set the right CQP enum number (RATECONTROL_CQP = 3).
3. Avoid division by zero in CQP mode.
Fixes intel#578.

Signed-off-by: Yan Wang <yan.wang@linux.intel.com>
@wangyan-intel
Copy link

wangyan-intel commented May 14, 2019

@eero-t I submitted the #622 to fix it. It works fine on my platform. Could you please try it? Thanks.

wangyan42164 added a commit to wangyan42164/media-driver that referenced this issue May 14, 2019
1. Initialize BRC variales for avoiding wrong DSH allocation.
2. Set the right CQP enum number (RATECONTROL_CQP = 3).
3. Avoid division by zero in CQP mode.
Fixes intel#578.

Signed-off-by: Yan Wang <yan.wang@linux.intel.com>
@eero-t
Copy link
Author

eero-t commented May 14, 2019

Yes, it gets rid of the exception. However, fix to #409 is also needed, otherwise output file is empty.

(Tested on KBL GT2.)

@zhoub
Copy link

zhoub commented May 20, 2019

Interesting, I have this issue with libva+vaapi driver at i7 8700k.

vainfo: VA-API version: 1.4 (libva 2.4.0)
vainfo: Driver version: Intel iHD driver - 18.4.git_1d28de_2019-02-11
vainfo: Supported profile and entrypoints
      VAProfileNone                   :	VAEntrypointVideoProc
      VAProfileNone                   :	VAEntrypointStats
      VAProfileMPEG2Simple            :	VAEntrypointVLD
      VAProfileMPEG2Simple            :	VAEntrypointEncSlice
      VAProfileMPEG2Main              :	VAEntrypointVLD
      VAProfileMPEG2Main              :	VAEntrypointEncSlice
      VAProfileH264Main               :	VAEntrypointVLD
      VAProfileH264Main               :	VAEntrypointEncSlice
      VAProfileH264Main               :	VAEntrypointFEI
      VAProfileH264Main               :	VAEntrypointEncSliceLP
      VAProfileH264High               :	VAEntrypointVLD
      VAProfileH264High               :	VAEntrypointEncSlice
      VAProfileH264High               :	VAEntrypointFEI
      VAProfileH264High               :	VAEntrypointEncSliceLP
      VAProfileVC1Simple              :	VAEntrypointVLD
      VAProfileVC1Main                :	VAEntrypointVLD
      VAProfileVC1Advanced            :	VAEntrypointVLD
      VAProfileJPEGBaseline           :	VAEntrypointVLD
      VAProfileJPEGBaseline           :	VAEntrypointEncPicture
      VAProfileH264ConstrainedBaseline:	VAEntrypointVLD
      VAProfileH264ConstrainedBaseline:	VAEntrypointEncSlice
      VAProfileH264ConstrainedBaseline:	VAEntrypointFEI
      VAProfileH264ConstrainedBaseline:	VAEntrypointEncSliceLP
      VAProfileVP8Version0_3          :	VAEntrypointVLD
      VAProfileVP8Version0_3          :	VAEntrypointEncSlice
      VAProfileHEVCMain               :	VAEntrypointVLD
      VAProfileHEVCMain               :	VAEntrypointEncSlice
      VAProfileHEVCMain               :	VAEntrypointFEI
      VAProfileHEVCMain10             :	VAEntrypointVLD
      VAProfileHEVCMain10             :	VAEntrypointEncSlice
      VAProfileVP9Profile0            :	VAEntrypointVLD
      VAProfileVP9Profile2            :	VAEntrypointVLD

wangyan42164 added a commit to wangyan42164/media-driver that referenced this issue May 21, 2019
1. Initialize BRC variales for avoiding wrong DSH allocation.
2. Set the right CQP enum number (RATECONTROL_CQP = 3).
3. Avoid division by zero in CQP mode.
Fixes intel#578.

Signed-off-by: Yan Wang <yan.wang@linux.intel.com>
intel-mediadev pushed a commit that referenced this issue May 21, 2019
1. Initialize BRC variales for avoiding wrong DSH allocation.
2. Set the right CQP enum number (RATECONTROL_CQP = 3).
3. Avoid division by zero in CQP mode.
Fixes #578.

Signed-off-by: Yan Wang <yan.wang@linux.intel.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Encode video encode related P2 Medium priority
Projects
None yet
Development

Successfully merging a pull request may close this issue.

6 participants