<div dir="ltr"><span style="font-family:arial,sans-serif;font-size:13px">Hi,</span><div style="font-family:arial,sans-serif;font-size:13px">I'm developing a H264 decoder in Windows and I want to use the hardware acceleration capabilities: DXVA2</div>
<div style="font-family:arial,sans-serif;font-size:13px">I've already built FFMPEG from git (lastest version: N-65404-gd34ec64; libavcodec 55.73.101 ...) using Mingw64 for 32bits this way:</div><div style="font-family:arial,sans-serif;font-size:13px">
<div><pre style="white-space:pre-wrap;border:none!important;margin-top:0px!important;margin-bottom:0px!important;width:auto!important;clear:none!important;overflow:visible!important;line-height:16px!important;padding:0px 4px!important;border-top-left-radius:0px!important;border-top-right-radius:0px!important;border-bottom-right-radius:0px!important;border-bottom-left-radius:0px!important;background-image:initial!important;background-color:rgb(249,249,249);background-repeat:initial!important">
<font face="arial, helvetica, sans-serif" color="#000000"><br></font></pre><pre style="white-space:pre-wrap;border:none!important;margin-top:0px!important;margin-bottom:0px!important;width:auto!important;clear:none!important;overflow:visible!important;line-height:16px!important;padding:0px 4px!important;border-top-left-radius:0px!important;border-top-right-radius:0px!important;border-bottom-right-radius:0px!important;border-bottom-left-radius:0px!important;background-image:initial!important;background-color:rgb(249,249,249);background-repeat:initial!important">
<font face="arial, helvetica, sans-serif" color="#000000">echo 'export PATH=.:/local/bin:/bin:/mingw64/bin' > .profile
source .profile</font></pre><pre style="white-space:pre-wrap;border:none!important;margin-top:0px!important;margin-bottom:0px!important;width:auto!important;clear:none!important;overflow:visible!important;line-height:16px!important;padding:0px 4px!important;border-top-left-radius:0px!important;border-top-right-radius:0px!important;border-bottom-right-radius:0px!important;border-bottom-left-radius:0px!important;background-image:initial!important;background-color:rgb(249,249,249);background-repeat:initial!important">
<font face="arial, helvetica, sans-serif" color="#000000"><br></font></pre></div><div><font face="arial, helvetica, sans-serif" color="#000000"><span style="line-height:16px;white-space:pre-wrap;background-color:rgb(249,249,249)">git config</span><span style="line-height:16px;white-space:pre-wrap;background-color:rgb(249,249,249)"> </span><span style="line-height:16px;white-space:pre-wrap;background-color:rgb(249,249,249)">--global</span><span style="line-height:16px;white-space:pre-wrap;background-color:rgb(249,249,249)"> core.autocrlf </span><span style="line-height:16px;white-space:pre-wrap;background-color:rgb(249,249,249)">false</span><br>
</font></div><div><font face="arial, helvetica, sans-serif" color="#000000"><span style="line-height:16px;white-space:pre-wrap;background-color:rgb(249,249,249)"> 
</span><span style="line-height:16px;white-space:pre-wrap;background-color:rgb(249,249,249)">git clone</span><span style="line-height:16px;white-space:pre-wrap;background-color:rgb(249,249,249)"> git:</span><span style="line-height:16px;white-space:pre-wrap;background-color:rgb(249,249,249)">//</span><span style="line-height:16px;white-space:pre-wrap;background-color:rgb(249,249,249)"><a href="http://git.videolan.org/" target="_blank">git.videolan.org</a></span><span style="line-height:16px;white-space:pre-wrap;background-color:rgb(249,249,249)">/</span><span style="line-height:16px;white-space:pre-wrap;background-color:rgb(249,249,249)">x264.git x264
</span><span style="line-height:16px;white-space:pre-wrap;background-color:rgb(249,249,249)">cd</span><span style="line-height:16px;white-space:pre-wrap;background-color:rgb(249,249,249)"> x264
.</span><span style="line-height:16px;white-space:pre-wrap;background-color:rgb(249,249,249)">/</span><span style="line-height:16px;white-space:pre-wrap;background-color:rgb(249,249,249)">configure </span><span style="line-height:16px;white-space:pre-wrap;background-color:rgb(249,249,249)">--host</span><span style="line-height:16px;white-space:pre-wrap;background-color:rgb(249,249,249)">=x86_64-w64-mingw32 </span><span style="line-height:16px;white-space:pre-wrap;background-color:rgb(249,249,249)">--enable-static</span><span style="line-height:16px;white-space:pre-wrap;background-color:rgb(249,249,249)"> </span><span style="line-height:16px;white-space:pre-wrap;background-color:rgb(249,249,249)">--enable-shared</span><span style="line-height:16px;white-space:pre-wrap;background-color:rgb(249,249,249)"> </span><span style="line-height:16px;white-space:pre-wrap;background-color:rgb(249,249,249)">&&</span><span style="line-height:16px;white-space:pre-wrap;background-color:rgb(249,249,249)"> </span><span style="line-height:16px;white-space:pre-wrap;background-color:rgb(249,249,249)">make</span><span style="line-height:16px;white-space:pre-wrap;background-color:rgb(249,249,249)"> </span><span style="line-height:16px;white-space:pre-wrap;background-color:rgb(249,249,249)">&&</span><span style="line-height:16px;white-space:pre-wrap;background-color:rgb(249,249,249)"> </span><span style="line-height:16px;white-space:pre-wrap;background-color:rgb(249,249,249)">make</span><span style="line-height:16px;white-space:pre-wrap;background-color:rgb(249,249,249)"> </span><span style="line-height:16px;white-space:pre-wrap;background-color:rgb(249,249,249)">install</span><span style="line-height:16px;white-space:pre-wrap;background-color:rgb(249,249,249)">
</span><span style="line-height:16px;white-space:pre-wrap;background-color:rgb(249,249,249)">cd</span><span style="line-height:16px;white-space:pre-wrap;background-color:rgb(249,249,249)"> ..
 
</span><span style="line-height:16px;white-space:pre-wrap;background-color:rgb(249,249,249)">git clone</span><span style="line-height:16px;white-space:pre-wrap;background-color:rgb(249,249,249)"> git:</span><span style="line-height:16px;white-space:pre-wrap;background-color:rgb(249,249,249)">//</span><span style="line-height:16px;white-space:pre-wrap;background-color:rgb(249,249,249)"><a href="http://github.com/" target="_blank">github.com</a></span><span style="line-height:16px;white-space:pre-wrap;background-color:rgb(249,249,249)">/</span><span style="line-height:16px;white-space:pre-wrap;background-color:rgb(249,249,249)">mstorsjo</span><span style="line-height:16px;white-space:pre-wrap;background-color:rgb(249,249,249)">/</span><span style="line-height:16px;white-space:pre-wrap;background-color:rgb(249,249,249)">fdk-aac.git fdk-aac
</span><span style="line-height:16px;white-space:pre-wrap;background-color:rgb(249,249,249)">cd</span><span style="line-height:16px;white-space:pre-wrap;background-color:rgb(249,249,249)"> fdk-aac
.</span><span style="line-height:16px;white-space:pre-wrap;background-color:rgb(249,249,249)">/</span><span style="line-height:16px;white-space:pre-wrap;background-color:rgb(249,249,249)">autogen.sh
.</span><span style="line-height:16px;white-space:pre-wrap;background-color:rgb(249,249,249)">/</span><span style="line-height:16px;white-space:pre-wrap;background-color:rgb(249,249,249)">configure </span><span style="line-height:16px;white-space:pre-wrap;background-color:rgb(249,249,249)">--host</span><span style="line-height:16px;white-space:pre-wrap;background-color:rgb(249,249,249)">=x86_64-w64-mingw32 </span><span style="line-height:16px;white-space:pre-wrap;background-color:rgb(249,249,249)">--enable-static</span><span style="line-height:16px;white-space:pre-wrap;background-color:rgb(249,249,249)"> </span><span style="line-height:16px;white-space:pre-wrap;background-color:rgb(249,249,249)">--enable-shared</span><span style="line-height:16px;white-space:pre-wrap;background-color:rgb(249,249,249)"> </span><span style="line-height:16px;white-space:pre-wrap;background-color:rgb(249,249,249)">&&</span><span style="line-height:16px;white-space:pre-wrap;background-color:rgb(249,249,249)"> </span><span style="line-height:16px;white-space:pre-wrap;background-color:rgb(249,249,249)">make</span><span style="line-height:16px;white-space:pre-wrap;background-color:rgb(249,249,249)"> </span><span style="line-height:16px;white-space:pre-wrap;background-color:rgb(249,249,249)">&&</span><span style="line-height:16px;white-space:pre-wrap;background-color:rgb(249,249,249)"> </span><span style="line-height:16px;white-space:pre-wrap;background-color:rgb(249,249,249)">make</span><span style="line-height:16px;white-space:pre-wrap;background-color:rgb(249,249,249)"> </span><span style="line-height:16px;white-space:pre-wrap;background-color:rgb(249,249,249)">install</span><span style="line-height:16px;white-space:pre-wrap;background-color:rgb(249,249,249)">
</span><span style="line-height:16px;white-space:pre-wrap;background-color:rgb(249,249,249)">cd</span><span style="line-height:16px;white-space:pre-wrap;background-color:rgb(249,249,249)"> ..</span></font></div></div><div style="font-family:arial,sans-serif;font-size:13px">
<span style="color:rgb(0,0,0);font-family:monospace;font-size:12px;line-height:16px;white-space:pre-wrap;background-color:rgb(249,249,249)"><br></span></div><div style="font-family:arial,sans-serif;font-size:13px"><div><font color="#000000" face="arial, helvetica, sans-serif"><span style="line-height:16px;white-space:pre-wrap;background-color:rgb(249,249,249)">git clone</span><span style="line-height:16px;white-space:pre-wrap;background-color:rgb(249,249,249)"> git:</span><span style="line-height:16px;white-space:pre-wrap;background-color:rgb(249,249,249)">//</span><span style="line-height:16px;white-space:pre-wrap;background-color:rgb(249,249,249)"><a href="http://source.ffmpeg.org/" target="_blank">source.ffmpeg.org</a></span><span style="line-height:16px;white-space:pre-wrap;background-color:rgb(249,249,249)">/</span><span style="line-height:16px;white-space:pre-wrap;background-color:rgb(249,249,249)">ffmpeg.git </span><span style="line-height:16px;white-space:pre-wrap;background-color:rgb(249,249,249)">ffmpeg</span><span style="line-height:16px;white-space:pre-wrap;background-color:rgb(249,249,249)">
</span><span style="line-height:16px;white-space:pre-wrap;background-color:rgb(249,249,249)">cd</span><span style="line-height:16px;white-space:pre-wrap;background-color:rgb(249,249,249)"> </span><span style="line-height:16px;white-space:pre-wrap;background-color:rgb(249,249,249)">ffmpeg</span></font></div>
<div><span style="color:rgb(0,0,0);font-family:arial,helvetica,sans-serif">./configure --enable-gpl --enable-nonfree --enable-libx264 --enable-libfdk_aac --enable-memalign-hack --enable-runtime-cpudetect --enable-dxva2 --enable-decoder?h264_dxva2 --disable-hwaccels --enable-hwaccel=h264_dxva2 --enable-static --enable-shared --extra-cflags=-I/local/</span><span style="color:rgb(0,0,0);font-family:arial,helvetica,sans-serif">include --extra-ldflags='-L/local/lib -static' && make && make install</span><br>
</div></div><div style="font-family:arial,sans-serif;font-size:13px"><span style="color:rgb(0,0,0);font-family:arial,helvetica,sans-serif"><br></span></div><div style="font-family:arial,sans-serif;font-size:13px"><span style="color:rgb(0,0,0);font-family:arial,helvetica,sans-serif">I've adapted the newest version of ffmpeg_dxva2.c to C++ (with a header file including InputStream, </span><font color="#000000" face="arial, helvetica, sans-serif">HWAccelID and dxva2_init</font><span style="color:rgb(0,0,0);font-family:arial,helvetica,sans-serif"> declarations), now it builds with VisualStudio 2012 and everything is running correctly with my current decoder (not HW accelerated).</span></div>
<div style="font-family:arial,sans-serif;font-size:13px"><span style="color:rgb(0,0,0);font-family:arial,helvetica,sans-serif"><br></span></div><div style="font-family:arial,sans-serif;font-size:13px"><span style="color:rgb(0,0,0);font-family:arial,helvetica,sans-serif">I found an old post of this list (</span><font color="#000000" face="arial, helvetica, sans-serif"><a href="https://lists.ffmpeg.org/pipermail/ffmpeg-user/2012-May/006600.html" target="_blank">https://lists.ffmpeg.org/pipermail/ffmpeg-user/2012-May/006600.html</a></font><span style="color:rgb(0,0,0);font-family:arial,helvetica,sans-serif">) describing the steps for running it, but now te API has changed...</span></div>
<div style="font-family:arial,sans-serif;font-size:13px"><span style="color:rgb(0,0,0);font-family:arial,helvetica,sans-serif">I've also studied the VLC method, but it is also working with the older API (get_buffer instead of get_buffer2, and so).</span></div>
<div style="font-family:arial,sans-serif;font-size:13px"><font color="#000000" face="arial, helvetica, sans-serif">In the newest ffmpeg.c they actually use the hwaccel including DXVA2, but in quite a complicated way... could you please give an example or a piece of advice  on how to do it? </font></div>
<div style="font-family:arial,sans-serif;font-size:13px"><font color="#000000" face="arial, helvetica, sans-serif"><br></font></div><div style="font-family:arial,sans-serif;font-size:13px"><font color="#000000" face="arial, helvetica, sans-serif">1.- Create a InputStream instance, populate it and address it to AVCodecContext->opaque. Which are the needed attributes? It requires width and height of the input before opening it!</font></div>
<div style="font-family:arial,sans-serif;font-size:13px"><font color="#000000" face="arial, helvetica, sans-serif"><br></font></div><div style="font-family:arial,sans-serif;font-size:13px"><font color="#000000" face="arial, helvetica, sans-serif">2.- call dxva_init() with the decoder AVCodecContext allocated using avcodec_alloc_context3 from CODEC_ID_H264 codec before calling avcodec_open2 ?</font></div>
<div style="font-family:arial,sans-serif;font-size:13px"><font color="#000000" face="arial, helvetica, sans-serif"><br></font></div><div style="font-family:arial,sans-serif;font-size:13px"><font color="#000000" face="arial, helvetica, sans-serif">3.- Call dxva2_retrieve_data() with the decoder </font><span style="color:rgb(0,0,0);font-family:arial,helvetica,sans-serif">AVCodecContext</span><span style="color:rgb(0,0,0);font-family:arial,helvetica,sans-serif">  and a </span><font color="#000000" face="arial, helvetica, sans-serif">AV_PIX_FMT_NV12 frame when avcodec_decode_video2 returns a complete frame (got_output</font><span style="color:rgb(0,0,0);font-family:arial,helvetica,sans-serif">) ?</span></div>
<div style="font-family:arial,sans-serif;font-size:13px"><font color="#000000" face="arial, helvetica, sans-serif"><br></font></div><div style="font-family:arial,sans-serif;font-size:13px"><font color="#000000" face="arial, helvetica, sans-serif">4.- Copy (convert) the resulting frame to a YUV420P OpenGL texture, apply a pixelformat conversion shader and show it! <- This step is working fine (I did it for a separated decoder using </font><span style="color:rgb(0,0,0);font-family:arial,helvetica,sans-serif">Intel Media SDK</span><span style="color:rgb(0,0,0);font-family:arial,helvetica,sans-serif"> </span><span style="color:rgb(0,0,0);font-family:arial,helvetica,sans-serif">last week).</span></div>
<div style="font-family:arial,sans-serif;font-size:13px"><span style="color:rgb(0,0,0);font-family:arial,helvetica,sans-serif"><br></span></div><div style="font-family:arial,sans-serif;font-size:13px"><span style="color:rgb(0,0,0);font-family:arial,helvetica,sans-serif">(Future step. - use directly the DX surface using OpenGL extensions.)</span></div>
<div style="font-family:arial,sans-serif;font-size:13px"><font color="#000000" face="arial, helvetica, sans-serif"><br></font></div><div style="font-family:arial,sans-serif;font-size:13px"><font color="#000000" face="arial, helvetica, sans-serif">Now I'm stuck in the first and second steps, when </font><span style="color:rgb(0,0,0);font-family:arial,helvetica,sans-serif">avcodec_decode_video2</span><span style="color:rgb(0,0,0);font-family:arial,helvetica,sans-serif">  is called it crashes. I've debugged step by step the dxva initialization and the DX surfaces are being created correctly. What am I missing?</span></div>
<div style="font-family:arial,sans-serif;font-size:13px"><span style="color:rgb(0,0,0);font-family:arial,helvetica,sans-serif"><br></span></div><div style="font-family:arial,sans-serif;font-size:13px"><span style="color:rgb(0,0,0);font-family:arial,helvetica,sans-serif">Thanks!</span></div>
</div>