Tips for Multithreaded h264 Video Decoding on Windows

Vitreous

°
Former Staff
Sep 13, 2009
2,033
591
This post is here to support my 1080p@60fps h264 posts, but may also be of general interest.

Intro
Your video decoder needs to be set up effectively to smoothly playback HD and/or 60fps h264 content. In particular you need to take advantage of multiple CPU cores where possible. However, depending on how (and when) you set up your players & codecs you may not be using your multithreading possibilities, massively reducing your playback potential. This post describes how to check/correct your setup in this regard. This method is for Windows only (XP, Vista or Win 7). It assumes your system has a multi-core processor (2+ cores).

---

Some systems are perfectly capable of playing high-bitrate videos but struggle because of a sub-optimal player/codec setup. Typical problems are using old versions of players/codecs, or installing too many conflicting players/codec packs hence creating a tangle of decoding steps. I can't go into all the potential problems here, but will focus on getting h264 rips decoding efficiently with an up to date software installation.

These steps are in no way guaranteed to work, but should at least identify where the bottleneck in your system is when decoding h264 video.

Required Software
Get the latest software (it's important - updating often brings speed-ups):
- By far the easiest solution is to download and install the latest version of the K-Lite codec pack Get the Mega pack and choose the default settings. The current version of this installs multithreading support for h264 out of the box. It also checks your current setup. See the note below about DXVA though.
- For a more manual setup, download and install the latest Media Player Classic - Home Cinema, the FFDShow decoders and Haali's Media Splitter
- Uninstalling any other codec packs/players might help untangle an over-installed system. However, be wary if you rely on them for more unusual video types or web-cam output etc.
- You may get the option of enabling DXVA support - this allows your graphics card (GPU) to do the decoding rather than your CPU. Whilst this might work well on some machines, DXVA can have driver or synchronisation problems on others. For this reason I suggest you try DXVA only if CPU decoding is ineffective. I am not going to cover DXVA setup in this guide other than mention that it is an option in the K-Lite installation / configuration.

Notes:
- The CCCP codec pack is similar to the K-Lite pack, but unfortunately it's not up to date
- I am only going to discuss the use of Media Player Classic - Home Cinema (MPC-HC) as a player
- You can eliminate tearing (horizontal "ripping" effect in video playback) in MPC-HC as well improve some display issues: right click in the video area and look in the "Render Settings" sub-menu. Choosing "Reset>>Reset to optimal..." usually sets good baseline settings for your system. You can experiment with the "VSync" menu to eliminate tearing. Be careful in this menu though.


Check Efficiency of your Video Decoding
- Close down all major programs except your standard background tasks
- Run task manager [in XP press press Ctrl, Alt & Delete all together, in Vista/Win7 press Ctrl, Shift and Esc all together]
- Click the "Performance" tab. Look at the "CPU Usage History" graphs, there is one for each processor in your systems (x2 if you have HyperThreading)
- Play a high resolution/fps h264 video (MeguIV videos are h264). You can test other players with these steps, but the fix below is just for MPC-HC/FFDShow/K-Lite

Ideally you should see similar activity on all the graphs - the video decoding distributed across all the processors. However, there are several potential problem scenarios:
- If nearly all the activity is on one processor graph then your system is not working at peak performance and you need to enable multithreading (see below)
- If any one of the processor graphs maxes out then the video will drop frames or stutter. Clearly this is more likely if all the activity is on one processor
- If all your processors are maxing out, then your CPU is not powerful enough to play the video. DXVA might help in this case (GPU video decoding), although it requires a decent graphics processor. Try installing/configuring the K-Lite codec pack and checking the DXVA settings
- If the processors are working but not maxing out and you are still getting video stutter, then your graphics card (or on-board graphics) could be the weak point, particularly with high resolution videos - you need to upgrade. A less likely possiblity is a slow hard drive (try putting the vid on a different drive if you have more than one).
- If there is very little activity on any graph then you may already be using DXVA (the GPU is doing the decoding). If you are getting stutter or desynchronization then your GPU is not up to the task. Install / configure the K-Lite codec pack and switch off DXVA. The other possibility in this scenario is that you have a powerful machine and it just isn't breaking a sweat ;)


Enable Multithreaded Decoding
If all the activity was on one processor graph and the other processors were idle then you should follow these steps:
- Run MPC-HC
- In the menus choose "View >> Options..."
- Select "Output" on the left. Now look at the "DirectShow Video" panel:
ㅤㅤ- On Windows XP ensure you have one of "VMR7 (Renderless)", "VMR9 (Renderless)" or "Overlay" selected. You can switch between these settings later if you are still having trouble (e.g. Overylay may be faster than VMRx). You may also want to tweak the VMR7/9 settings panel at this time.
ㅤㅤ- On Windows Vista or Windows 7 ensure "EVR Custom Pres." is selected. If it doesn't work or improve things, then try again with "VMR7 (Renderless)"
ㅤㅤ- Some systems may get a small boost by checking "YUV Mixing" on this tab, for some it might not help or work
- Now select "Internal Filters" on the left
ㅤㅤ- In the left-hand list headed "Source Filters" uncheck "Matroska". This will allow Haali's media splitter to handle MKV files instead of MPC's internal splitter
ㅤㅤ- In the right-hand list headed "Transform Filters", uncheck "H264/AVC (DXVA)" and "H264/AVC (FFmpeg)" if they are there. This will allow FFDShow to decode h264 video instead of MPC-HC.
- Press OK on this Options dialog and close MPC-HC

- Now in the Windows/Start menu (All Programs) run "FFDShow >> Video decoder configuration". This program is in the K-Lite start menu folder if you're using K-Lite.
- At the top of the list at the left, select "Codecs" if it isn't already selected
- In the pane on the right find the entry "H.264/AVC" under "Format", it's probably the first one.
- Drop down the list under the "Decoder" column for this entry and ensure it is on "ffmpeg-mt". It may already be on this setting
ㅤㅤ- [Note: if you ever find a vid that doesn't play, then find and enable it's Decoder in this list]
- Optional steps for slower machines, this may help, or it may spoil the output:
ㅤㅤ- Scroll to the bottom of the list on the left and select "Queue and misc"
ㅤㅤ- Check "Queue ouput samples" and "Use queue only in:" (and optionally "Enable queue in VMR9-YV12")
ㅤㅤ- Add the text "mpc-hc.exe;" to the "Use queue only in:" text box - each entry in this list should be seperated by a semicolon, check it's OK
- Press OK on this configuration dialog

Now test the video again and check your task manager processor graphs. If you're still seeing all the work on one processor then you may have "codec tangle". You could try uninstalling all players/codecs then just installing K-Lite.
If you do get multithreading but don't get the speed, you could try one of the other options that I suggested in the various steps (e.g. "Overlay" on XP, or "YUV Mixing")

Hope that helps someone...
Vit
 

joeman76

Active Member
Feb 15, 2009
212
14
I have AMD Phenom II X4 965 3.40ghz
6.00 GB RAM
64 bit OS
Windows 7 Ultimate


I saw decent activity from the first and last graphs, and just a little activity from the two middle graphs. Is this ok?:puzzled:
 

Vitreous

°
Former Staff
Sep 13, 2009
2,033
591
I saw decent activity from the first and last graphs, and just a little activity from the two middle graphs. Is this ok?
That might happen if your computer isn't breaking a sweat, but if it's struggling to play the vid then that's far from ideal. I believe there are some h264 decoders that use 2 processors (threads) and no more. Clearly it's better if the decoding uses all the available processors. Did you upgrade to the latest K-Lite? I should note that I haven't tested any AMD processors.
 

astrayred

Member
Mar 19, 2008
158
16
I would suggest using the Divx H.264 decoder. It's free, supposedly more efficient than ffdshow's H.264 decoder (as alleged on various forums, and I get positive results on my rig), and you can configure MPC to use it.
 

Vitreous

°
Former Staff
Sep 13, 2009
2,033
591
I would suggest using the Divx H.264 decoder. It's free, supposedly more efficient than ffdshow's H.264 decoder
Well the DivX h264 decoder does seem to be about 8% faster that ffdshow...but...

I have an instinctive distrust of DivX and this codec pack just confirms it. It phones home every time you play a video, even when you set auto-updates to "Never". A suspiciously long license agreement with opaque privacy terms as well as attempts to install random other stuff with the initial install just makes the whole thing an instant uninstall for me...
 

astrayred

Member
Mar 19, 2008
158
16
Well the DivX h264 decoder does seem to be about 8% faster that ffdshow...but...

I have an instinctive distrust of DivX and this codec pack just confirms it. It phones home every time you play a video, even when you set auto-updates to "Never". A suspiciously long license agreement with opaque privacy terms as well as attempts to install random other stuff with the initial install just makes the whole thing an instant uninstall for me...

I didn't know that it phones home. Thanks for letting me know. Time to do something about it.

Interestingly enough, I could have swore one revision of the K-Lite Codec Pack actually bundled the Divx decoder and used it as the H.264 decoder by default. It's gone now, most probably due to legal action from Divx.
 

guy

(;Θ_Θ)ゝ”
Feb 11, 2007
2,079
43
Gotta throw in another word for DXVA:

Using CyberLink/PowerDVD8 H.264/AVC DXVA decoder within MPC (EVR, fullscreen). With it, I am actually able to playback 1080p 24fps and 30fps material on my netbook (Atom Z550 2.0ghz, Intel GMA950) with no frame drops. Doesn't work quite as well when windowed, but on a netbook, 1080p material fills up the screen anyway.

Doesn't play nicely with 60fps material though. But considering netbooks' limited specs to begin with, being able to handle any 720p/1080p material without dedicated decoder cards is pretty nice.
 

isityours

People don't dance no mo'
Sep 27, 2008
2,886
4,135
not sure if it is particularly applicable here but DPC latency checker is a simple tool that can help with identifying which, if any, software is throwing back latency issues (which may affect playback). i have found it useful when troubleshooting.

its not necessary to install and is very small so i attached a copy below.

website