Jeff Griffin

Transcode to MP4

Posted on May 10, 2011

A few weeks ago, I talked about playing with WPF and DirectShow with WPF MediaKit.  I wanted to finish a video transcoder project I had laying around for some time.  Originally, it was a very simple WinForms app that guides the process of building a graph in DirectShow to extract the audio and video streams from some video file source, send them through some other compressor (or not), and place them in an MP4 container.  The goal was to allow my wife to convert the files from her camera, so she could post them on YouTube (She didn't want to use GraphEdit, imagine that).  At the time, HandBrake didn't exist, or wasn't available on Windows and there were plenty of paid options, but I figured I could mock up a solution at a similar cost.  That was true, until I moved it to WPF and added a video preview, but whatever, it was fun.  This is the result:

Transcode to MP4 - Version 1.0.0.0
Source

Required:

Haali Media Splitter: Actually, only the MP4 Multiplexer is required, but the splitter is a handy file source, supporting many formats.

.NET 4.0 Client Profile

Recomended:

FFDShow Tryouts: This adds a ton of functionality and customization, through the filter settings dialogs. See Issues and Solutions below.

MONOGRAM AAC Encoder: This is my own build of this filter.  I found this and a number of other GPL and LGPL based DirectShow filters at RadScorpion's blog.  I wanted to use this filter, but it doesn't register as an Audio Compressor in DirectShow, which this Transcoder requires.  If you would like the source for my changes, please don't hesitate to ask.

There are a number of other filter options you can experiment with, and of course your mileage may vary.  Also, this program will attempt to allow you to make any decision you want about what codecs you would like to use.  That doesn't mean that the MP4 Multiplexer or your video player of choice will appreciate the decision you made, and this program does not protect you from this.

Options:

The Show Preview option can be found in the render options menu.  Some filters don't work so nicely with the Pin Tee Filter, which is used to show a video preview during the encoding process.  Turning off the Show Preview option lets this program build a graph without including the Pin Tee and Video Renderer.  Media Center filters will require the Show Preview setting to be off.

The Use Clock option is the same as the one found in GraphEdit.  It will generally allow the graph to progress at or below the speed of playback.  You should always try leaving this option off for the sake of speed, but some filters don't appreciate being rushed.

Clicking on the gear icon next to the selected decoder filter will pop the filter's configuration dialog (if it has one).  These are implemented by the filter's vendor.

Issues and Solutions:

I found out while testing this with the filters Media Center uses with WTV and DVR-MS files that some files aren't so happy working outside the bounds of their original intent.  I did have success transcoding these formats, however, by turning off the Show Preview option.

In testing with FFDShow Tryouts, files with MPEG audio streams tended to halt or crash the program.  This was corrected by going into the FFDShow Audio Decoder Configuration in the start menu, and under Codecs, I switched the MP1,MP2 decoder from libmad to libavcodec.

Why not just use HandBrake now?

By all means, you should if it suits your needs.  HandBrake offers tons of options, is relatively user friendly and doesn't require all this mucking about with DirectShow filters.  If it were out when I wrote the first pass of this, I would have had no motivation to write it.  However this is an extremely open-ended tool, so if you need to transcode something that handbrake doesn't support, but for which there are DirectShow filters available, you can use this as an alternative to GraphEdit.  Media Center files are a good example of this.

Please leave me a feedback if you are experiencing issues using this tool, you have feature requests, or other questions.