Quantcast
Viewing all articles
Browse latest Browse all 45436

Change DirectShow filter properties using code

Hello

I developed an application in C# using DirectShow.NET which can capture video from a source and create video.
I used several DirectShow filters such as ffdshow Deinterlace, Smart Tee, MPEG-2 Video Encoder, AVI Mux, File Writer and etc.
I want to change properties of MPEG-2 Video Encoder. I found this code:
Code:

IVideoEncoder videoEncoder = videoCompressorFilter as IVideoEncoder;
object min, max, step;
videoEncoder.GetParameterRange(PropSetID.ENCAPIPARAM_BitRate, out min, out max, out step);
 
videoEncoder.SetValue(PropSetID.ENCAPIPARAM_BitRate, min);

but this code doesn't work.

After googling more I found this code which opens a filter's property window:
Code:

private void DisplayPropertyPage(IBaseFilter dev)
{
    //Get the ISpecifyPropertyPages for the filter
    ISpecifyPropertyPages pProp = dev as ISpecifyPropertyPages;
    int hr = 0;
 
    if (pProp == null)
    {
        //If the filter doesn't implement ISpecifyPropertyPages, try displaying IAMVfwCompressDialogs instead!
        IAMVfwCompressDialogs compressDialog = dev as IAMVfwCompressDialogs;
        if (compressDialog != null)
        {
 
            hr = compressDialog.ShowDialog(VfwCompressDialogs.Config, IntPtr.Zero);
            DsError.ThrowExceptionForHR(hr);
        }
        else
        {
            MessageBox.Show("Item has no property page", "No Property Page", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
        }
        return;
    }
 
    //Get the name of the filter from the FilterInfo struct
    FilterInfo filterInfo;
    hr = dev.QueryFilterInfo(out filterInfo);
    DsError.ThrowExceptionForHR(hr);
 
    // Get the propertypages from the property bag
    DsCAUUID caGUID;
    hr = pProp.GetPages(out caGUID);
    DsError.ThrowExceptionForHR(hr);
 
    //Create and display the OlePropertyFrame
    object oDevice = (object)dev;
    hr = OleCreatePropertyFrame(this.Handle, 0, 0, filterInfo.achName, 1, ref oDevice, caGUID.cElems, caGUID.pElems, 0, 0, IntPtr.Zero);
    DsError.ThrowExceptionForHR(hr);
 
    Marshal.ReleaseComObject(oDevice);
 
    if (filterInfo.pGraph != null)
    {
        Marshal.ReleaseComObject(filterInfo.pGraph);
    }
 
    // Release COM objects
    Marshal.FreeCoTaskMem(caGUID.pElems);
}

It works but it's settings/properties doesn't save! Every time I should change it's properties. It weird because everytime GraphEdit opens it's property window, properties are correct (they are what I set).
What's wrong? :confused:
How can I change a filter's properties correcly?

Thanks
Regards

Viewing all articles
Browse latest Browse all 45436

Trending Articles