Current version

v1.10.4 (stable)

Navigation

Main page
Archived news
Downloads
Documentation
   Capture
   Compiling
   Processing
   Crashes
Features
Filters
Plugin SDK
Knowledge base
Donate
Contact info
Forum
 
Other projects
   Altirra

Search

Archives

01 Dec - 31 Dec 2013
01 Oct - 31 Oct 2013
01 Aug - 31 Aug 2013
01 May - 31 May 2013
01 Mar - 31 Mar 2013
01 Feb - 29 Feb 2013
01 Dec - 31 Dec 2012
01 Nov - 30 Nov 2012
01 Oct - 31 Oct 2012
01 Sep - 30 Sep 2012
01 Aug - 31 Aug 2012
01 June - 30 June 2012
01 May - 31 May 2012
01 Apr - 30 Apr 2012
01 Dec - 31 Dec 2011
01 Nov - 30 Nov 2011
01 Oct - 31 Oct 2011
01 Sep - 30 Sep 2011
01 Aug - 31 Aug 2011
01 Jul - 31 Jul 2011
01 June - 30 June 2011
01 May - 31 May 2011
01 Apr - 30 Apr 2011
01 Mar - 31 Mar 2011
01 Feb - 29 Feb 2011
01 Jan - 31 Jan 2011
01 Dec - 31 Dec 2010
01 Nov - 30 Nov 2010
01 Oct - 31 Oct 2010
01 Sep - 30 Sep 2010
01 Aug - 31 Aug 2010
01 Jul - 31 Jul 2010
01 June - 30 June 2010
01 May - 31 May 2010
01 Apr - 30 Apr 2010
01 Mar - 31 Mar 2010
01 Feb - 29 Feb 2010
01 Jan - 31 Jan 2010
01 Dec - 31 Dec 2009
01 Nov - 30 Nov 2009
01 Oct - 31 Oct 2009
01 Sep - 30 Sep 2009
01 Aug - 31 Aug 2009
01 Jul - 31 Jul 2009
01 June - 30 June 2009
01 May - 31 May 2009
01 Apr - 30 Apr 2009
01 Mar - 31 Mar 2009
01 Feb - 29 Feb 2009
01 Jan - 31 Jan 2009
01 Dec - 31 Dec 2008
01 Nov - 30 Nov 2008
01 Oct - 31 Oct 2008
01 Sep - 30 Sep 2008
01 Aug - 31 Aug 2008
01 Jul - 31 Jul 2008
01 June - 30 June 2008
01 May - 31 May 2008
01 Apr - 30 Apr 2008
01 Mar - 31 Mar 2008
01 Feb - 29 Feb 2008
01 Jan - 31 Jan 2008
01 Dec - 31 Dec 2007
01 Nov - 30 Nov 2007
01 Oct - 31 Oct 2007
01 Sep - 30 Sep 2007
01 Aug - 31 Aug 2007
01 Jul - 31 Jul 2007
01 June - 30 June 2007
01 May - 31 May 2007
01 Apr - 30 Apr 2007
01 Mar - 31 Mar 2007
01 Feb - 29 Feb 2007
01 Jan - 31 Jan 2007
01 Dec - 31 Dec 2006
01 Nov - 30 Nov 2006
01 Oct - 31 Oct 2006
01 Sep - 30 Sep 2006
01 Aug - 31 Aug 2006
01 Jul - 31 Jul 2006
01 June - 30 June 2006
01 May - 31 May 2006
01 Apr - 30 Apr 2006
01 Mar - 31 Mar 2006
01 Feb - 29 Feb 2006
01 Jan - 31 Jan 2006
01 Dec - 31 Dec 2005
01 Nov - 30 Nov 2005
01 Oct - 31 Oct 2005
01 Sep - 30 Sep 2005
01 Aug - 31 Aug 2005
01 Jul - 31 Jul 2005
01 June - 30 June 2005
01 May - 31 May 2005
01 Apr - 30 Apr 2005
01 Mar - 31 Mar 2005
01 Feb - 29 Feb 2005
01 Jan - 31 Jan 2005
01 Dec - 31 Dec 2004
01 Nov - 30 Nov 2004
01 Oct - 31 Oct 2004
01 Sep - 30 Sep 2004
01 Aug - 31 Aug 2004

Stuff

Powered by Pivot  
XML: RSS feed 
XML: Atom feed 

§ One video codec to break everything

How does one video codec break every other video codec in the system?

Simple, really.

The way that video codecs work in Windows is that each one is queried in turn and asked if it supports the compressed video format. If a codec says "yes," then that codec is used to decode the video. Otherwise, Windows proceeds to the next video codec down the line, until it either finds one that can handle the format or runs out of video codecs. The details are different between Video for Windows and DirectShow, but the general idea is the same. This provides a great deal of flexibility, because a video codec can decode more than one format. Some MPEG-4 video codecs, for instance, can helpfully also decode uncompressed YCbCr formats that are difficult to find dedicated codecs for, like YV12.

It also adds a bit of fragility, in that occasionally a video codec's decompression query routine acts as follows:

Q: Do you support video format....
A: Yes!
Q: Uh, I didn't tell you the video format. You really support this?
A: Yes!

The errant video codec then proceeds to capture every video format that comes its way, and happily barfs whenever it gets any format other than the one it was supposed to handle. Since the shell media extension in Windows XP uses video codecs to try to get basic information and thumbnails for videos, Windows Explorer can now crash if you hover over the wrong videos. And guess what... the common File-Open dialog is based on an Explorer view, so it too can crash in any program.

As a result, one bad video codec can cause every other video codec in the system to fail to function. So far, I have encountered three video codecs that do this. It's even more fun when you realize that querying a codec involves loading it, so a codec that crashes on load due to Data Execution Prevention (DEP) crashes, anti-debugger checks, etc. can cause even more... fun.

For those of you who are considering or have worked on plugin APIs, this has some implications for API design. Querying every codec provides maximum flexibility to the video codecs, but also increases the fragility of the system -- if anyone goofs up, the whole thing breaks. Now, none of the three video codecs I've found so far were actually trying to decode multiple formats, but did so unintentionally. By having plugins provide some basic information that the API host can use to pre-filter queries, the system becomes more reliable, as it is much easier to make a single routine in the host reliable than a series of checks in all third-party plugins. It's also faster since you're not loading a ton of DLLs every time.

Those of you who read Raymond Chen's The Old New Thing blog may recognize the above problem as a variant on his "sure, we do that" story. Happily, the workaround is similar. What VirtualDub does is that it eschews use of the VFW ICLocate() function and instead manually enumerates and opens the video codecs, so it can directly control the query process. It then calls ICDecompressQuery() with a bogus compressed format and sees if the video codec bites. If the video codec takes the bogus format, then VirtualDub only uses that video codec if the compressed format is one that the codec says it can compress to; otherwise, it bypasses the codec and keeps going. You'll know if this happens because VirtualDub will display a warning on opening a video file with the name of the video codec that has the bug.

Comments

Comments posted:


hehe sounds like loads of fun

Would this perhaps be the problem where an occasional divx installation causes explorer to barf when you try to view the properties of a divx avi? I've had a few installations do that and it seems the only solution they had was to disable the explorer function querying that data. Something to keep in mind I guess.

Is there any way for non-programmers (like myself) to manually set the order in which codecs are queried? Sometimes there may be a codec that you'd rather use other than the one that first answers yes. I recall having to dump a codec years ago for this reason. Can't recall which one it was either.

SonOfAdam - 03 01 07 - 02:39


"So far, I have encountered three video codecs that do this."
Can you tell us which ones are they?

SonOfAdam, why do you think the DivX codec is on top of the list while the XviD is usually at the bottom?

PCto - 03 01 07 - 03:30


Because like all the others listed, it's alphabetical.

SonOfAdam - 03 01 07 - 06:14


It's alphabetical in VirtualDub because I manually enumerate the codecs and sort the list. If you use an app that just uses AVISaveOptions() or ICCompressorChoose(), you'll get them in the enumerated order.

If you are using Windows 95/98/ME, then the search order for video codecs is the order in which they are listed in SYSTEM.INI. If you are using Windows NT/2000/XP/Vista then you're probably out of luck, because I think it's the Registry enumeration order and I'm not sure how to change that.

The ugly thing is, when you add a video codec, it usually ends up at the end, so you're unlikely to discover this problem when testing your own codec unless you specifically know about it.

Phaeron - 03 01 07 - 23:36


SonOfAdam, I ment in WinXP. DivX is installed as first decoder and XviD is usuali one of the wast ones if not the wast one. in other words DivX is forcing it's way on the other codecs and if there is a bug in it ...

PCto - 04 01 07 - 02:59


Theres an app called Direct Show Filter Manager that lets you change the priority of every dshow filter in your registry, though ive had a few filters that ignore the registry setting and just load themselves all the time...

Matariel - 04 01 07 - 05:10


In Win9x, there was a nice little setting that allowed one to re-work ACM codecs priority directly in the Control Panel; it looks like it's gone...

Mitch 74 - 10 01 07 - 05:54


Thats why I disabled video preview en the folders!

Alejandro Lapeyre (link) - 16 01 07 - 01:51


hi, my first post here ;)

you could use GSpot - there's in List Codec and Other Filters are option to change the merit value of a filter/codec

thats helped me many times with some nasty dshow filters...

hINDUs - 09 06 07 - 08:37

Comment form


Please keep comments on-topic for this entry. If you have unrelated comments about VirtualDub, the forum is a better place to post them.
Name:  
Remember personal info?

Email (Optional):
Your email address is only revealed to the blog owner and is not shown to the public.
URL (Optional):
Comment: /

An authentication dialog may appear when you click Post Comment. Simply type in "post" as the user and "now" as the password. I have had to do this to stop automated comment spam.



Small print: All html tags except <b> and <i> will be removed from your comment. You can make links by just typing the url or mail-address.