Unexpected Windows Media Encoder shutdown / crash while encoding

I found an interesting problem when dynamically changing the input format of the WM Encoder while encoding. In other words if you are capturing from a single digital capture card and the card can change the input resolution dynamically then WM Encoder may behave strangely, shutdown or crash.

The problem appears to be that the underlying graph is shutting down because the input resolution has changed. When the input resolution changes the graph manager shuts down the graph and starts dynamically reconnecting the filters’ pins. In this case the graph is shutting down cleanly but the ASF multiplexer (mux) thread (external to the graph) is not getting notified that the graph is shutting down. Because of this the mux thread is still processing sample data that is no longer viable since the graph has stopped. Because of this we may get strange behavior, unexpected application shutdown or a crash.

This is probably a timing issue and does not happen every time the display is changed. I don’t’ think that the WM Encoder was designed for this scenario but it should handle this situation gracefully. Unfortunately it does not. Additional research is required to verify how the encoder is expected to handle dynamic format changes during encoding.

Changing the resolution of the input video signal during encoding is permitted (and won’t crash the Encoder) as long as the change is accompanied by a "source switch" from the WM Encoder. The change in resolution of the input signal MUST be triggered by the “source switch”. You can't change the input resolution independent of a source switch. To allow a source switch to change the resolution you must use two different sources. In this case there should be two different video capture devices. You can then switch between the capture devices using the Encoder's “source switch”.