Click here to Skip to main content
15,885,546 members
Articles / Multimedia / DirectX

ProcAmp for DirectShow.Net

Rate me:
Please Sign up or sign in to vote.
1.92/5 (6 votes)
14 Feb 2008CPOL1 min read 35.9K   30   3
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.

VB
'********************************** 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..

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


Written By
Netherlands Netherlands
Jarno Burger
i am videojockey for festivals.
i am getting fed up with the vj programs at the moment , so i am trying to go and write my own one.

if you wanna read some more stuff about directshow.net , then you can read some chunks of info on my blog , with some extra handy links to more articles and forums.

http://jarnoburger.blogspot.com/

Comments and Discussions

 
QuestionProcamp - Could you please send the source code? Pin
Roms15-Feb-08 18:00
Roms15-Feb-08 18:00 
AnswerRe: Procamp - Could you please send the source code? Pin
Jarno Burger19-Feb-08 23:26
Jarno Burger19-Feb-08 23:26 
GeneralRe: Procamp - Could you please send the source code? Pin
Noctris15-Jul-08 11:10
Noctris15-Jul-08 11:10 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.