<div dir="ltr">Hi,<div><br></div><div>I'm not sure if the email I sent a couple days ago was approved and sent to everyone. If it is the case, note that I have resolved my problem. Information can be found here: <a href="http://stackoverflow.com/questions/34602561/failed-to-execute-0x80070057-when-decoding-video-via-ffmpeg-with-dxva2">http://stackoverflow.com/questions/34602561/failed-to-execute-0x80070057-when-decoding-video-via-ffmpeg-with-dxva2</a></div><div><br></div><div>Thanks,</div><div>Cyril</div></div><div class="gmail_extra"><br><div class="gmail_quote">On Tue, Jan 5, 2016 at 3:16 PM, Cyril Drouet <span dir="ltr"><<a href="mailto:cyril.drouet@gmail.com" target="_blank">cyril.drouet@gmail.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr"><p style="margin:0px 0px 1em;padding:0px;border:0px;font-size:15px;clear:both;color:rgb(34,36,38);font-family:Arial,'Helvetica Neue',Helvetica,sans-serif;line-height:19px">I have successfully implemented a video player using ffmpeg. I am now trying to use hardware decoding but I'm facing a couple issues. I found a post that I followed as a starting point here:<a href="http://comments.gmane.org/gmane.comp.video.ffmpeg.libav.user/13523" rel="nofollow" style="margin:0px;padding:0px;border:0px;text-decoration:none;color:rgb(0,89,153)" target="_blank">http://comments.gmane.org/gmane.comp.video.ffmpeg.libav.user/13523</a></p><p style="margin:0px 0px 1em;padding:0px;border:0px;font-size:15px;clear:both;color:rgb(34,36,38);font-family:Arial,'Helvetica Neue',Helvetica,sans-serif;line-height:19px">I have updated the code that setup the necessary stuff for the decoder. The updated code is available here: <a href="https://drive.google.com/file/d/0B5ufHdoDzA4ieVk5UVpxcDNzRHc/view?usp=sharing" rel="nofollow" style="margin:0px;padding:0px;border:0px;text-decoration:none;color:rgb(0,89,153)" target="_blank">https://drive.google.com/file/d/0B5ufHdoDzA4ieVk5UVpxcDNzRHc/view?usp=sharing</a></p><p style="margin:0px 0px 1em;padding:0px;border:0px;font-size:15px;clear:both;color:rgb(34,36,38);font-family:Arial,'Helvetica Neue',Helvetica,sans-serif;line-height:19px">And this is how I'm using it to initialize the decoder:</p><pre style="margin-top:0px;padding:5px;border:0px;font-size:13px;overflow:auto;width:auto;max-height:600px;background-color:rgb(238,238,238);font-family:Consolas,Menlo,Monaco,'Lucida Console','Liberation Mono','DejaVu Sans Mono','Bitstream Vera Sans Mono','Courier New',monospace,sans-serif;word-wrap:normal;color:rgb(34,36,38)"><code style="margin:0px;padding:0px;border:0px;font-family:Consolas,Menlo,Monaco,'Lucida Console','Liberation Mono','DejaVu Sans Mono','Bitstream Vera Sans Mono','Courier New',monospace,sans-serif;white-space:inherit">// Prepare the decoding context
AVCodec *codec = nullptr;
_codecContext = _avFormatContext->streams[_streamIndex]->codec;
if ((codec = avcodec_find_decoder(_codecContext->codec_id)) == 0)
{
    std::cout << "Unsupported video codec!" << std::endl;
    return false;
}

_codecContext->thread_count = 1;  // Multithreading is apparently not compatible with hardware decoding
InputStream *ist = new InputStream();
ist->hwaccel_id = HWACCEL_AUTO;
ist->hwaccel_device = "dxva2";
ist->dec = codec;
ist->dec_ctx = _codecContext;
_codecContext->coded_width = _width;
_codecContext->coded_height = _height;

_codecContext->opaque = ist;
dxva2_init(_codecContext);

_codecContext->get_buffer2 = ist->hwaccel_get_buffer;
_codecContext->get_format = GetHwFormat;
_codecContext->thread_safe_callbacks = 1;

if (avcodec_open2(_codecContext, codec, nullptr) < 0)
{
    std::cout << "Video codec open error" << std::endl;
    return false;
}
</code></pre><p style="margin:0px 0px 1em;padding:0px;border:0px;font-size:15px;clear:both;color:rgb(34,36,38);font-family:Arial,'Helvetica Neue',Helvetica,sans-serif;line-height:19px">And here is the definition of GetHwFormat referenced above:</p><pre style="margin-top:0px;padding:5px;border:0px;font-size:13px;overflow:auto;width:auto;max-height:600px;background-color:rgb(238,238,238);font-family:Consolas,Menlo,Monaco,'Lucida Console','Liberation Mono','DejaVu Sans Mono','Bitstream Vera Sans Mono','Courier New',monospace,sans-serif;word-wrap:normal;color:rgb(34,36,38)"><code style="margin:0px;padding:0px;border:0px;font-family:Consolas,Menlo,Monaco,'Lucida Console','Liberation Mono','DejaVu Sans Mono','Bitstream Vera Sans Mono','Courier New',monospace,sans-serif;white-space:inherit">AVPixelFormat GetHwFormat(AVCodecContext *s, const AVPixelFormat *pix_fmts)
{
    InputStream* ist = (InputStream*)s->opaque;
    ist->active_hwaccel_id = HWACCEL_DXVA2;
    ist->hwaccel_pix_fmt = AV_PIX_FMT_DXVA2_VLD;
    return ist->hwaccel_pix_fmt;
}
</code></pre><p style="margin:0px 0px 1em;padding:0px;border:0px;font-size:15px;clear:both;color:rgb(34,36,38);font-family:Arial,'Helvetica Neue',Helvetica,sans-serif;line-height:19px">When I open an mp4 (encoded in h264) video that is HD resolution or less, everything seems to be working fine. However, as soon as I try higher resolution videos like 3840x2160, I get the following errors repeatedly:</p><pre style="margin-top:0px;padding:5px;border:0px;font-size:13px;overflow:auto;width:auto;max-height:600px;background-color:rgb(238,238,238);font-family:Consolas,Menlo,Monaco,'Lucida Console','Liberation Mono','DejaVu Sans Mono','Bitstream Vera Sans Mono','Courier New',monospace,sans-serif;word-wrap:normal;color:rgb(34,36,38)"><code style="margin:0px;padding:0px;border:0px;font-family:Consolas,Menlo,Monaco,'Lucida Console','Liberation Mono','DejaVu Sans Mono','Bitstream Vera Sans Mono','Courier New',monospace,sans-serif;white-space:inherit">Failed to execute: 0x80070057
Hardware accelerator failed to decode picture
</code></pre><p style="margin:0px 0px 1em;padding:0px;border:0px;font-size:15px;clear:both;color:rgb(34,36,38);font-family:Arial,'Helvetica Neue',Helvetica,sans-serif;line-height:19px">I also start getting the following errors after a few seconds:</p><pre style="margin-top:0px;padding:5px;border:0px;font-size:13px;overflow:auto;width:auto;max-height:600px;background-color:rgb(238,238,238);font-family:Consolas,Menlo,Monaco,'Lucida Console','Liberation Mono','DejaVu Sans Mono','Bitstream Vera Sans Mono','Courier New',monospace,sans-serif;word-wrap:normal;color:rgb(34,36,38)"><code style="margin:0px;padding:0px;border:0px;font-family:Consolas,Menlo,Monaco,'Lucida Console','Liberation Mono','DejaVu Sans Mono','Bitstream Vera Sans Mono','Courier New',monospace,sans-serif;white-space:inherit">co located POCs unavailable
</code></pre><p style="margin:0px 0px 1em;padding:0px;border:0px;font-size:15px;clear:both;color:rgb(34,36,38);font-family:Arial,'Helvetica Neue',Helvetica,sans-serif;line-height:19px">And the video is not displayed properly: I get a lot of artifacts all over the video and it is lagging. I checked the first error in the ffmpeg source code. It seems that IDirectXVideoDecoder_Execute fails because of an invalid parameter. Since this is happening withing ffmpeg, there must be something that I'm missing but I can't figure out what. The only relevant post that I found with this error was because of multithreading but I set the thread_count to 1 before opening the codec.</p><p style="margin:0px 0px 1em;padding:0px;border:0px;font-size:15px;clear:both;color:rgb(34,36,38);font-family:Arial,'Helvetica Neue',Helvetica,sans-serif;line-height:19px">This issue is happening on my main computer which has the following specs:</p><ul style="margin:0px 0px 1em 30px;padding:0px;border:0px;font-size:15px;list-style-position:initial;color:rgb(34,36,38);font-family:Arial,'Helvetica Neue',Helvetica,sans-serif;line-height:19px"><li style="margin:0px 0px 0.5em;padding:0px;border:0px;word-wrap:break-word">i7-4790 CPU @ 3.6GHz</li><li style="margin:0px 0px 0.5em;padding:0px;border:0px;word-wrap:break-word">RAM 16 GB</li><li style="margin:0px 0px 0.5em;padding:0px;border:0px;word-wrap:break-word">Intel HD Graphics 4600</li><li style="margin:0px;padding:0px;border:0px;word-wrap:break-word">Windows 8.1</li></ul><p style="margin:0px 0px 1em;padding:0px;border:0px;font-size:15px;clear:both;color:rgb(34,36,38);font-family:Arial,'Helvetica Neue',Helvetica,sans-serif;line-height:19px">The same issue is not happening on my second computer which has the following specs:</p><ul style="margin:0px 0px 1em 30px;padding:0px;border:0px;font-size:15px;list-style-position:initial;color:rgb(34,36,38);font-family:Arial,'Helvetica Neue',Helvetica,sans-serif;line-height:19px"><li style="margin:0px 0px 0.5em;padding:0px;border:0px;word-wrap:break-word">i7 4510U @ 2GHz</li><li style="margin:0px 0px 0.5em;padding:0px;border:0px;word-wrap:break-word">RAM 8 GB</li><li style="margin:0px 0px 0.5em;padding:0px;border:0px;word-wrap:break-word">NVIDIA GeForce GTX 750Ti</li><li style="margin:0px;padding:0px;border:0px;word-wrap:break-word">Windows 10</li></ul><p style="margin:0px 0px 1em;padding:0px;border:0px;font-size:15px;clear:both;color:rgb(34,36,38);font-family:Arial,'Helvetica Neue',Helvetica,sans-serif;line-height:19px">If I use DXVAChecker on my main computer, it says that my graphics card supports DXVA2 for H264_VLD_*, and I can see that the calls to the Microsoft API are being made (DXVA2_DecodeDeviceCreated, DXVA2_DecodeDeviceBeginFrame, DXVA2_DecodeDeviceGetBuffer, DXVA2_DecodeDeviceExecute, DXVA2_DecodeDeviceEndFrame) while my video is playing.</p><p style="margin:0px 0px 1em;padding:0px;border:0px;font-size:15px;clear:both;color:rgb(34,36,38);font-family:Arial,'Helvetica Neue',Helvetica,sans-serif;line-height:19px"><span style="font-size:13px;line-height:16px">I also tested on a Surface Pro 3 with an i5 4300U @ 1.9GHz (4 CPUs), 8 GB of RAM, Intel HD Graphics 4400, Windows 10, and the video looks good. There are no error messages.CPU usage is 40% less than without hardware decoding like the second computer mentioned above.GPU is only 1% or maybe 2% more (same as for the other 2 computers mentioned above) while testing the same video at 3840x2160</span><br></p><p style="margin:0px 0px 1em;padding:0px;border:0px;font-size:15px;clear:both;color:rgb(34,36,38);font-family:Arial,'Helvetica Neue',Helvetica,sans-serif;line-height:19px">Note that I tried both the Windows release available on the FFmpeg website, and a version that I compiled with --enable-dxva2. I have searched a lot already but I was unable to find what I'm doing wrong.<br></p><p style="margin:0px 0px 1em;padding:0px;border:0px;font-size:15px;clear:both;color:rgb(34,36,38);font-family:Arial,'Helvetica Neue',Helvetica,sans-serif;line-height:19px">Hopefully, someone can help me, or maybe point me to a better example?</p><p style="margin:0px 0px 1em;padding:0px;border:0px;font-size:15px;clear:both;color:rgb(34,36,38);font-family:Arial,'Helvetica Neue',Helvetica,sans-serif;line-height:19px"><br></p><p style="margin:0px 0px 1em;padding:0px;border:0px;font-size:15px;clear:both;color:rgb(34,36,38);font-family:Arial,'Helvetica Neue',Helvetica,sans-serif;line-height:19px">Thanks!</p></div>
</blockquote></div><br></div>