How to use RotateFilter.dll with c#.

Help
Debo
2014-04-11
2014-10-30
  • Debo

    Debo - 2014-04-11

    I need to rotate the video to a particular angle. My application is in c#. Code snippet are as follows. I have used directshow library and register rotatefilter using regedit. Then updated the directshow library by adding following line in file Uuids.cs

    #region Filter Classes
    
    /// <summary>
    /// CLSID_RotateFilter (Debo)
    /// </summary>
    [ComImport, Guid("66888CFF-359B-414B-BC20-CFD6D811209B")]
    public class RotateFilter
    {
    }
    

    Then in my application used the RotateFilter as shown below.

    IBaseFilter pRotate = new RotateFilter() as IBaseFilter;
    hr = m_FilterGraph.AddFilter(pRotate, "ROTATE_90_DEGREES_CLOCKWISE");
    DsError.ThrowExceptionForHR(hr);
    

    I am not yet successful in rotating the video. Please help me. I guess i am missing something here.

    Debu

     
  • daniel

    daniel - 2014-04-24

    Did you find any solution? I also don't know how to access the parameters via c#.

     
  • daniel

    daniel - 2014-04-24

    I solved the issue:

     IBaseFilter pCSIRVPPRotateFilter = (IBaseFilter)Activator.CreateInstance(Type.GetTypeFromCLSID(CLSID_CSIRVPPRotateFilter));
            ISettingsInterface rot_settings = pCSIRVPPRotateFilter as ISettingsInterface;    
            hr = rot_settings.SetParameter("rotationmode", "5"); // 0 none, 1 90, 2 180, 3 270, 4 upsidedown, 5 mirror, 6 diagonal
    

    [ComImport, System.Security.SuppressUnmanagedCodeSecurity,Guid("388EEF20-40CC-4752-A0FF-66AA5C4AF8FA"),InterfaceType(ComInterfaceType.InterfaceIsIUnknown)]
    public interface ISettingsInterface
    {
    [PreserveSig]
    int GetParameter(
    [MarshalAs(UnmanagedType.LPStr)] String type,
    [MarshalAs(UnmanagedType.I4)] int buffersize,
    [In, Out, MarshalAs(UnmanagedType.LPStr)] String value,
    [In, Out, MarshalAs(UnmanagedType.I4)] ref int length
    );

            [PreserveSig]
            int SetParameter(
                [MarshalAs(UnmanagedType.LPStr)] String type,
                [MarshalAs(UnmanagedType.LPStr)] String value
                );
    
            [PreserveSig]
            int GetParameterSettings(
                [MarshalAs(UnmanagedType.LPStr)] ref String szResult,
                [In] int nSize
                );
        }
    
     
    Last edit: daniel 2014-04-24
  • Debo

    Debo - 2014-05-11

    Thanks Daniel for the inputs. I understood most of the code that you have shared and integrated with my application. But still could not get it working due to the following line.

    IBaseFilter pCSIRVPPRotateFilter = (IBaseFilter)Activator.CreateInstance(Type.GetTypeFromCLSID(CLSID_CSIRVPPRotateFilter));

    What is "CLSID_CSIRVPPRotateFilter" and how do we define this.

    Debu

     
  • Debo

    Debo - 2014-05-12

    Danial, Is this the right way to define "CLSID_CSIRVPPRotateFilter"....

    Guid CLSID_CSIRVPPRotateFilter = new Guid("66888CFF-359B-414B-BC20-CFD6D811209B");

    here "66888CFF-359B-414B-BC20-CFD6D811209B" is the GUID of "CSIR VPP Rotate Filter".

    This does not give me error but it does not function. Where should i put this code in the application.. I mean to ask, what is the process of using the filters.

    Debu

     
  • Debo

    Debo - 2014-05-12

    Finally i ended up with the following code but still i could not rotate the video preview.

    File: Capture.cs....

           // Set the video window within the control specified by hControl
        private void ConfigVideoWindow(Control hControl)
        {
            int hr;
            IBaseFilter pCSIRVPPRotateFilter = new RotateFilter() as IBaseFilter;
            ISettingsInterface rot_settings = pCSIRVPPRotateFilter as ISettingsInterface;
            hr = rot_settings.SetParameter("rotationmode", "2"); // 0 none, 1 90, 2 180, 3 270, 4 upsidedown, 5 mirror, 6 diagonal
            DsError.ThrowExceptionForHR(hr);
    
            // Add the sample grabber to the graph
            hr = m_FilterGraph.AddFilter(pCSIRVPPRotateFilter, "CSIR VPP Rotate Filter");
            DsError.ThrowExceptionForHR(hr);
    
            IVideoWindow ivw = m_FilterGraph as IVideoWindow;
    
            // Set the parent
            hr = ivw.put_Owner(hControl.Handle);
            DsError.ThrowExceptionForHR(hr);
    
            // Turn off captions, etc
            hr = ivw.put_WindowStyle(WindowStyle.Child | WindowStyle.ClipChildren | WindowStyle.ClipSiblings);
            DsError.ThrowExceptionForHR( hr );
    
            // Yes, make it visible
            hr = ivw.put_Visible( OABool.True );
            DsError.ThrowExceptionForHR( hr );
    
            // Move to upper left corner
            Rectangle rc = hControl.ClientRectangle;
    
            hr = ivw.SetWindowPosition(0, 0, rc.Right, rc.Bottom);
            DsError.ThrowExceptionForHR( hr );
    
        }
    

    File: Uuids.cs....

    #region Filter Classes
    
    /// <summary>
    /// CLSID_CSIRVPPRotateFilter (Debo)
    /// </summary>
    [ComImport, Guid("66888CFF-359B-414B-BC20-CFD6D811209B")]
    public class RotateFilter
    {
    }
    

    File: AXExtend.cs....

    [ComImport, System.Security.SuppressUnmanagedCodeSecurity, Guid("388EEF20-40CC-4752-A0FF-66AA5C4AF8FA"), InterfaceType(ComInterfaceType.InterfaceIsIUnknown)]
    public interface ISettingsInterface
    {
        [PreserveSig]
        int GetParameter(
        [MarshalAs(UnmanagedType.LPStr)] String type,
        [MarshalAs(UnmanagedType.I4)] int buffersize,
        [In, Out, MarshalAs(UnmanagedType.LPStr)] String value,
        [In, Out, MarshalAs(UnmanagedType.I4)] ref int length
        );
        [PreserveSig]
        int SetParameter(
            [MarshalAs(UnmanagedType.LPStr)] String type,
            [MarshalAs(UnmanagedType.LPStr)] String value
            );
    
        [PreserveSig]
        int GetParameterSettings(
            [MarshalAs(UnmanagedType.LPStr)] ref String szResult,
            [In] int nSize
            );
    }
    

    No error is produces, but still not working. Please tell me.. am i missing anything here.

    Debo

     
  • Scott

    Scott - 2014-10-30

    Debo,

    I was struggling to get this work as well. The problem for me at least seems to be in instantiating the rotation filter.

    IBaseFilter pCSIRVPPRotateFilter = new RotateFilter() as IBaseFilter;

    the variable was null. The RotateFilter cannot be cast to an IBaseFilter. Turns out i didn't have the filter registered properly. Maybe yours isn't either? Once I made sure it was using the "DirectShow FIlter Manager 0.5" http://www.free-codecs.com/DirectShow_Filter_Manager_download.htm

    I was able to use your code without a problem.

    I used this library:
    http://www.codeproject.com/Articles/421167/Pure-NET-DirectShow-Filters-in-Csharp

    to add the Filter to and voila, I've got rotating video output from my webcam.

    My issue now is, how do I deploy my solution to my tablet(s) which do not have the RotateFilter registered as a COM object? Yes, I could have someone load it on each of them I suppose, but there's gotta be a way to load the Filter without registering the COM object.

     
    Last edit: Scott 2014-10-30

Log in to post a comment.

Get latest updates about Open Source Projects, Conferences and News.

Sign up for the SourceForge newsletter:

JavaScript is required for this form.





No, thanks