1

I am trying to output H.264 video in a Windows application. I am moderately familiar with FFMPEG and I have been successful at getting it to play H.264 in a SDL window without a problem. Still, I would really benefit from using Hardware Acceleration (probably through DXVA2)

I am reading raw H264 video, no container, no audio ... just raw video (and no B-frames, just I and P). Also, I know that all the systems that will use this applications have Nvidia GPUs supporting at least VP3. Given that set of assumptions I was hoping to cut some corners, make it simple instead of general, just have it working for my particular scenario.

So far I know that I need to set the hardware acceleration in the codec context by filling the hwaccel member through a call to ff_find_hwaccel. My plan is to look at Media Player Classic Home Cinema which does a pretty good job at supporting DXVA2 using FFMPEG when decoding H.264. However, the code is quite large and I am not exactly sure where to look. I can find the place where ff_find_hwaccel is called in h264.c, but I was wondering where else should I be looking at.

More specifically, I would like to know what is the minimum set of steps that I have to code to get DXVA2 through FFMPEG working?

EDIT: I am open to look at VLC or anything else if someone knows where I can find the "important" piece of code that does the trick. I just mentioned MPC-HC because I think it is the easiest to get to compile in Windows.

cloudraven
  • 2,484
  • 1
  • 24
  • 49
  • I was under impression that `MPC-HC`'s `DXVA` support is not `FFmpeg` based. Instead, it would take advantage of DXVA2 support on DirectShow video renderer. `FFmpeg` on the other hand is likely (not sure) to use DXVA API directly bypassing DirectShow/MF layer. – Roman R. Apr 28 '12 at 07:25
  • My impression is that it supports both. The source code has a call to the accelerator interface of ffmpeg in the h264 handling code. Now, my small understanding on this is that ffmpeg does not do all the job. You still have to do something more to get it to work. Would it be easier with DirectShow? does it support raw h264? – cloudraven Apr 28 '12 at 07:43
  • 1
    With DirectShow it is like this: you feed H.264 wrapped into well known format, that is payload data + media type describing H.264, you feed it into standard Windows 7 video decoder and video renderer which is capable of using DXVA wherever it is available. If it find it impossible, it falls back to software decoding. You don't have a lot of flexibility to control this process, however if the requirements are met it happens transparently and without need for you to care. In Vista and earlier there is no standard decoder of this kind, but the one from `MPC-HC` might work out fine. – Roman R. Apr 28 '12 at 08:05
  • So just raw h264 wouldn't work? I get the sps + pps. I am not that familiar with the container formats, but if that ends up being the easiest way I will give it a try. Thanks – cloudraven Apr 28 '12 at 19:57
  • 1
    It is almost raw, but you cannot just throw bytes in and expect them to be converted into picture automatically. The essential thing is to associate a proper media type http://msdn.microsoft.com/en-us/library/windows/desktop/dd757808%28v=vs.85%29.aspx `H.264 Video Types`. Then you will throw portions of the stream (individual H.264 NAL Units) into pipeline and things are going to start rolling. – Roman R. Apr 28 '12 at 21:12
  • Thanks a lot for your help. Would that allow me to pre-process the frames before displaying them? A restriction I have is that I should make some small modifications to the decoded image before showing it. I was taking a look at the tutorials for directshow (http://msdn.microsoft.com/en-us/library/windows/desktop/dd389098(v=vs.85).aspx) and it seems that it decodes and shows in one step which unfortunately doesn't work for me. – cloudraven Apr 29 '12 at 05:42
  • Actually, just writing the decoded frames to memory or to a file may be good enough. As long as the decoding is accelerated by HW (so I dont have a lot of CPU usage). Would Media Foundation be better for this? – cloudraven Apr 29 '12 at 09:17

0 Answers0