Making an MP4 renderer.

Topics: User Forum
Nov 10, 2006 at 3:08 PM
Hi There,

Thanks for all your hard work on this, it's a real help having these libraries. However, I am trying to add support for the MP4/3gp filter at . It looks like it should be as easy as modifying the existing AVI/WMV renderers but i'm finding it a bit tricky.

I've made a MPEGFileRenderer.cs with the following:

// Create the file writer
IBaseFilter multiplexer = StandardFilters.RenderMPEGDestination(Cleanup, graphBuilder, Graph, outputFile);

Based on the AVI renderer, and added in the new standard filter:

public static IBaseFilter RenderMPEGDestination(DisposalCleanup dc, ICaptureGraphBuilder2 graphBuilder, IGraphBuilder graph,
string outputFile)
if (dc == null) throw new ArgumentNullException("dc");
if (graphBuilder == null) throw new ArgumentNullException("graphBuilder");
if (string.IsNullOrEmpty(outputFile)) throw new ArgumentNullException("outputFile");

int hr = 0;
// mpeg objects (from directencode)
IBaseFilter m_pMPEGWriter;
IStandardMpegEncoder m_pIMPEGEncoder;
StandardMpegEncoderProfile m_pIMPEGEncoderProfile;
DirectEncodeNET.SystemsOutputFormat m_systemsFormat;
DirectEncodeNET.Constraint m_constraint;

Guid guid = new Guid("CFD87339-C61F-46ca-B6A1-F87D6B96243E");
Type comtype = Type.GetTypeFromCLSID(guid);
m_pMPEGWriter = (IBaseFilter)Activator.CreateInstance(comtype);

mpIMPEGEncoder = (IStandardMpegEncoder)mpMPEGWriter;

// make the mpeg encoder select one of the pre-defined
// profile objects that it stores internally. For audio
// you will need to create your own profile.
msystemsFormat = DirectEncodeNET.SystemsOutputFormat.SYSTEMSFORMATMP4;
mconstraint = DirectEncodeNET.Constraint.CONSTRAINTNONE;

mpIMPEGEncoder.SelectFormat(msystemsFormat, m_constraint);
mpIMPEGEncoder.GetSelectedProfile(out mpIMPEGEncoderProfile);

IBaseFilter fileWriter = (IBaseFilter)new FileWriter();
IFileSinkFilter fs = (IFileSinkFilter)fileWriter;
hr = fs.SetFileName(outputFile, null);

hr = graph.AddFilter(fileWriter, "File Writer Filter");

hr = graph.AddFilter(m_pMPEGWriter, "Standard MPEG Encoder");

// Create the file write

return fileWriter;

However, when I run it, i get an error on line 319 of AbstractRenderer

There is a sample of the MPEG filter in use at

Hope you can point me in the right direction?

Thanks, Mike
Nov 23, 2006 at 10:15 PM
Sorry about the huge delay in responding to this, I've been very slack in monitoring the forums - If you can supply the source code for your renderer so far, I'll attempt to get it working properly (and add it the contrib project).

I'll turn this into a work item as well, so you can track it's progress.
Jan 13, 2007 at 3:20 AM
This discussion has been copied to Work Item 7270. You may wish to continue further discussion there.
Jan 19, 2012 at 5:06 AM
bittercoder wrote:
This discussion has been copied to Work Item 7270. You may wish to continue further discussion there.


I wonder how to see the work item for the project? I am looking for the same thing and see if this thread has been dead. Thanks in advance.