[Libav-user] HW Accelerator in Windows: DXVA2 with new API
Hector Alonso
hector.alonso.aparicio at gmail.com
Tue Aug 26 10:58:45 CEST 2014
Hi,
I've modified my initialization code: supressed flags, and enabled
thread_safe_callbacks, but the result is the same, lots of "Missing
reference picture, default is __" error messages and avcodec_decode_video2
returns -1094995529 "Invalid data found when processing input" half the
time.
The video is showing very very poorly with tons of compression artifacts.
I've read the extradata comment in ffmpeg code and it seems that is not
really used with H264 codec. I've run my ffmpeg-not-HWaccel decoder and the
extradata is not used at all indeed.
This is the new initialization:
#ifdef DXVA2_DECODER_ENABLED
// Create and populate Input Stream structure:
InputStream* ist = new InputStream();
ist->hwaccel_id = HWACCEL_AUTO;
ist->hwaccel_device = "dxva2";
ist->dec = _pCodec;
ist->dec_ctx = _pCodecCtx;
// Set Known width and height
_pCodecCtx->coded_width = 1280;
_pCodecCtx->coded_height = 720;
// Set Input Stream structure as ancillary data into codec
_pCodecCtx->opaque = ist;
// Initialize DXV2 context
dxva2_init(_pCodecCtx);
// Set DXVA2 callbacks to codec context
_pCodecCtx->get_buffer2 = ist->hwaccel_get_buffer;
_pCodecCtx->get_format = get_format;
_pCodecCtx->thread_safe_callbacks = 1;
#endif
Remember: dxva2_init is a call to the analogue method from ffmpeg_dxva.c
file modified by me into a .h and a .cpp attached in a previous mail (I
don't know if that's a common practice in this mail list or you do it in
another way).
Regarding the next step (using the DX surface directly as an OpenGL
texture), it can be done
using: WGLEW_NV_DX_interop, wglDXOpenDeviceNV,
wglDXSetResourceShareHandleNV, wglDXRegisterObjectNV,
make current, lock, etc.
Look at WiDiSample code -> RenderOpenGL.cpp bind texture (Intel Media SDK
video decoder example), and this page:
http://halogenica.net/sharing-resources-between-directx-and-opengl/
...but for now I'm more worried about getting the DXVA2 to work properly
with FFMPEG.
What am I missing?
2014-08-25 17:53 GMT+02:00 wm4 <nfxjfg at googlemail.com>:
> On Mon, 25 Aug 2014 15:23:20 +0200
> Hector Alonso <hector.alonso.aparicio at gmail.com> wrote:
>
> > Hi,
> > I've rebuilt ffmpeg using these instructions
> > https://trac.ffmpeg.org/wiki/CompilationGuide/MSVC from the Visual
> Studio
> > Console, installing MinGW directly from the link with the flags
> --enable-dxva2
> > and --enable-hwaccel=h264_dxva2 and is almost working but I get a lot
> > of errors:
> > -1094995529 "Invalid data found when processing input"
> > from avcodec_decode_video2 a lot of artifacts and a very poor and
> > inconsistent image quality.
> > This is my dxva initialization code:
> >
> > _pCodecCtx->flags|= CODEC_CAP_DR1;
> > _pCodecCtx->flags|= CODEC_CAP_HWACCEL;
> >
> > InputStream *ist = new InputStream ();
> > ist->hwaccel_id = HWACCEL_AUTO;
> > ist->hwaccel_device = "dxva2";
> > ist->dec = _pCodec;
> > ist->dec_ctx = _pCodecCtx;
> > _pCodecCtx->coded_width = 1280;
> > _pCodecCtx->coded_height = 720;
> > _pCodecCtx->opaque = ist;
> > dxva2_init(_pCodecCtx);
> > _pCodecCtx->opaque = ist;
> > _pCodecCtx->get_buffer2 = ist->hwaccel_get_buffer;
> > _pCodecCtx->get_format = get_format;
> > _pCodecCtx->thread_safe_callbacks = 0;
> >
> > before calling
> >
> > if (avcodec_open2(_pCodecCtx , _pCodec, 0) < 0) ...
> >
> > Where get_format is:
> >
> > static enum AVPixelFormat get_format(AVCodecContext *s, const enum
> > 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;
> > }
> >
> > Find attached my modified ffmpeg_dxva2.cpp and ffmpeg_dxva2.h files from
> > the original ffmpeg_dxva2.c and the InputStream declaration from ffmpeg.h
> >
> > For getting the decoded frame I call: dxva2_retrieve_data_call, and then
> I
> > convert it to YUV420p (I make the final conversion via pixel shader with
> > OpenGL texture).
> >
> > Also, with my old CPU decoder I had 3-6% CPU usage and 5-10% GPU usage
> (as
> > I said, I'm converting and painting with OpenGL) and now with the "GPU
> > Accelerated" one I have 5-13% CPU and 6-12% GPU.
>
> PS: nevcairiel mentioned:
> http://developer.download.nvidia.com/opengl/specs/WGL_NV_DX_interop.txt
>
> Unfortunately, it's marked as experimental, and other drivers probably
> don't provide it.
>
> > Any thoughts?
> >
> > Thank you!
> >
> _______________________________________________
> Libav-user mailing list
> Libav-user at ffmpeg.org
> http://ffmpeg.org/mailman/listinfo/libav-user
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://ffmpeg.org/pipermail/libav-user/attachments/20140826/a9f1fdf9/attachment.html>
More information about the Libav-user
mailing list