ProcAmp for DirectShow.Net






1.92/5 (6 votes)
How to use use brightness, contrast, saturation, hue in your DirectShow.Net filtergraph.
Introduction
I am starting out multiple articles that will describe parts of how to use DirectShow.Net. When I have finished with enough examples, I will combine them into a complete video player program written in VB.NET.
This article will explain how to extend your filtergraph to use the ProcAmp control. The ProcAmp is a really cool thing. Let's make your movie all the colors of the rainbow! I am using the DirectShow.Net library. It lets you build DirectShow stuff in VB.NET/C#. Be aware, not all filtergraphs support this trick. The if then
code part tries to catch that..
Using the code
Please create a filtergraph first. I am only giving an example for brightness here, but with some extra lines of code, hue, contrast, and saturation will work the same.
This part of the code is placed behind your .renderstream
function. f_VideoMixing_Renderer
is a VideoMixingRenderer9
object (that is part of my filtergraph).
f_VideoMixerProcampControl
is a control (VMR9ProcAmpControl
) that gives you access to colorizing your video.
f_VideoMixerProcampRange
(VMR9ProcAmpControlRange
) is the object that you put in and get out of your ProcAmp control. You always have to marshal.sizeof
when getting/setting something in your ProcAmp.
'********************************** video procamp *****************************************
'new setup mixer control
Dim f_VideoMixerControl As IVMRMixerControl9 = _
CType(f_VideoMixingRenderer, IVMRMixerControl9)
DsError.ThrowExceptionForHR(hr)
'new setup procamp control
Dim f_VideoMixerProcampControl As VMR9ProcAmpControl
f_VideoMixerProcampControl.dwSize = Marshal.SizeOf(f_VideoMixerProcampControl)
f_VideoMixerProcampControl.dwFlags = 0
hr = f_VideoMixerControl.GetProcAmpControl(0, f_VideoMixerProcampControl)
DsError.ThrowExceptionForHR(hr)
If (f_VideoMixerProcampControl.dwFlags And VMR9ProcAmpControlFlags.Brightness) > 0 Then
Debug.WriteLine("brightness")
End If
If (f_VideoMixerProcampControl.dwFlags And VMR9ProcAmpControlFlags.Contrast) > 0 Then
Debug.WriteLine("constrast")
End If
If (f_VideoMixerProcampControl.dwFlags And VMR9ProcAmpControlFlags.Hue) > 0 Then
Debug.WriteLine("hue")
End If
If (f_VideoMixerProcampControl.dwFlags And VMR9ProcAmpControlFlags.Mask) > 0 Then
Debug.WriteLine("mask")
End If
If (f_VideoMixerProcampControl.dwFlags And VMR9ProcAmpControlFlags.None) > 0 Then
Debug.WriteLine("none")
End If
If (f_VideoMixerProcampControl.dwFlags And VMR9ProcAmpControlFlags.Saturation) > 0 Then
Debug.WriteLine("saturation")
End If
'get procamp control range for brightness
Dim f_VideoMixerProcampRange As VMR9ProcAmpControlRange
f_VideoMixerProcampRange.dwProperty = VMR9ProcAmpControlFlags.Brightness
f_VideoMixerProcampRange.dwSize = Marshal.SizeOf(f_VideoMixerProcampRange)
hr = f_VideoMixerControl.GetProcAmpControlRange(0,f_VideoMixerProcampRange)
DsError.ThrowExceptionForHR(hr)
'set the brightness in ProcAmp , tell that the size has changed
Dim brightpos As Double = 0.1
f_VideoMixerProcampControl.Brightness = _
CSng(f_VideoMixerProcampRange.MinValue + brightpos * _
(f_VideoMixerProcampRange.MaxValue - f_VideoMixerProcampRange.MinValue))
'set the new value in ProcAmp to the videomixercontrol
f_VideoMixerProcampControl.dwSize = Marshal.SizeOf(f_VideoMixerProcampControl)
hr = f_VideoMixerControl.SetProcAmpControl(0, f_VideoMixerProcampControl)
DsError.ThrowExceptionForHR(hr)
Points of Interest
It took me two years to learn VB.NET, half year to learn DirectShow, and half a day to do ProcAmp. You have to go and read about every command I used if you are a newbie to this.
History
This is the first version of this code..