Click here to Skip to main content
13,148,211 members (53,149 online)
Click here to Skip to main content
Add your own
alternative version


69 bookmarked
Posted 20 Aug 2004

DirectShow - Fine TV Tuning Using IKsPropertySet.

, 20 Aug 2004
Rate this:
Please Sign up or sign in to vote.
How to fine tune a TV channel in DirectShow / How to set custom video frequencies of TV tuner devices?


If you are developing a TV tuner application for your tuner device using Direct Show, then you will definitely look for some function which can perform fine TV tuning (i.e., you want to set video frequency manually to get the precise video signal on a specific TV channel), but unfortunately, there in no such function in standard DirectShow TV tuning interfaces IAMTuner and IAMTVTuner.

The DirectShow TV tuning architecture is based on pre-defined frequency tables, and the TV Tuner filter ( has an internal list of frequency tables. Each frequency table contains a list of frequencies, and corresponds to the broadcast or cable frequencies for a given country/region. So, when you use the IAMTuner interface, it gets the channel frequency values from the internal frequency tables according to the selected country/ region and tunes the TV channels.

Because the IAMTuner interface will not allow you to modify the frequency values for a specific channel manually, you can't fine tune a channel while previewing. However, there is an AutoTune function available in IAMTVTuner interface which can help you to fine tune a channel, but this will also give you no control for manual fine tuning on the fly or to set custom video frequencies.

But the following code will describe you the complete details of fine tuning on the fly using IKsPropertySet. I am writing this article only to help those who really want to get some clue on fine TV tuning because I know how difficult it is to get help on this topic. Even, you will not find a single function in the whole DirectShow documentation which can help you on this.

While writing this code, I assumed that the reader has good knowledge of DirectShow video capturing and know the details of DirectShow graph building techniques, filers, and TV tuner graphs. I hope the DirectShow guys will be happy after reading this article.

This is my first article on Code Project, so some of you may find it difficult to read ;).

// It is assumed that you have constructed the complete TV tuner Graph 
// of your Device.And will use this function to set custom frequencies 
// or to fine tune a tuned TV channel.Please also make sure to set the 
// appropriate Video standard and contry code before calling this function.

#define INSTANCEDATA_OF_PROPERTY_SIZE(x) (sizeof((x)) - sizeof(KSPROPERTY))

HRESULT SetFrequency(long Freq)
    HRESULT hr;
    DWORD dwSupported=0;  

    // Query the IKsPropertySet on your Device TV Tuner Filter.
    // m_pTvtuner is IBaseFilter Pointer of your TV Tuner Filter.   

    CComPtr m_pKSProp;
    hr = m_pTvtuner->QueryInterface(IID_IKsPropertySet, (void**)&m_pKSProp); 
    if (FAILED(hr))
        return E_FAIL;

    ModeCaps.Mode = AMTUNER_MODE_TV; 

    // Check either the Property is supported or not by the Tuner drivers 

    hr = m_pKSProp->QuerySupported(PROPSETID_TUNER, 
        DWORD cbBytes=0;
        return E_FAIL; 


    // Here the real magic starts

    if(Freq>=ModeCaps.MinFrequency && Freq<=ModeCaps.MaxFrequency)
        hr = m_pKSProp->Set(PROPSETID_TUNER,
            return E_FAIL;  
        return E_FAIL;

    return S_OK;

Explanation of Code

The SetFrequency functions set the video frequency of a tuner device, the only parameter Freq is the desired video frequency in Hz. The code is using IKsPropertySet interface to perform the desired operations, IKsPropertySet interface is part of the WDM KS (Win32® Driver Model Kernel Streaming) architecture and allows drivers to provide extended capabilities that can be used without API extensions.

The basic 3 steps performed by this code are..

  1. Check the support of IKsPropertySet on Tuner Drivers.
  2. Check the PROPSETID_TUNER property on Tuner Drivers.
  3. Set the user defined video frequency on tuner in Hz.

Using the Code

The SetFrequency function can be used in several ways, i.e., fine TV tuning, manual TV tuning, new TV channels tuning, and etc.

  1. Fine tuning of a tuned TV channel.
    • Call IAMTuner::put_Channel to set the desired TV channel.
    • Call IAMTVTuner::get_VideoFrequency to get the current video frequency.
    • Call SetFrequency by adding the desired +/- frequency value in the original channel frequency and perform the operation until you find the best video quality on that channel.
  2. Manual TV tuning.
    • Call the SetFrequency with your desired frequency value in Hz.
      HRESULT hr= SetFrequency( 67250000 )


This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here


About the Author

Liaqat Fayyaz
Team Leader V One Multimedia
Singapore Singapore
No Biography provided

You may also be interested in...

Comments and Discussions

SuggestionNo Frequency Change in tuner Pin
Member 76604076-Jun-14 1:22
memberMember 76604076-Jun-14 1:22 
GeneralSet TV Tuner Audio Frequency Pin
Death_Star_LAG28-Jan-11 8:55
memberDeath_Star_LAG28-Jan-11 8:55 
GeneralRe: Set TV Tuner Audio Frequency Pin
Member 76604076-Jun-14 1:25
memberMember 76604076-Jun-14 1:25 
QuyLV2-Mar-09 21:17
memberQuyLV2-Mar-09 21:17 
GeneralPoor TV Quality Pin
ammar7915-Aug-07 8:33
memberammar7915-Aug-07 8:33 
Generala msg from ragavan Pin
Sean Ewington30-Apr-07 5:29
staffSean Ewington30-Apr-07 5:29 
Questionis there any other method to play TV using TV tuner card Pin
Lalit N Dubey21-Mar-07 20:35
memberLalit N Dubey21-Mar-07 20:35 
Generalpoor TV Graphic /picture quality problem Pin
Lalit N Dubey19-Mar-07 21:50
memberLalit N Dubey19-Mar-07 21:50 
GeneralRe: poor TV Graphic /picture quality problem Pin
Liaqat Fayyaz20-Mar-07 0:06
memberLiaqat Fayyaz20-Mar-07 0:06 
GeneralRe: poor TV Graphic /picture quality problem Pin
Lalit N Dubey21-Mar-07 15:15
memberLalit N Dubey21-Mar-07 15:15 
GeneralRe: poor TV Graphic /picture quality problem Pin
ilvesh8-Sep-09 20:25
memberilvesh8-Sep-09 20:25 
QuestionHow can it have sound ? Pin
ngochuy22-Feb-07 22:59
memberngochuy22-Feb-07 22:59 
AnswerRe: How can it have sound ? Pin
Lalit N Dubey19-Mar-07 21:54
memberLalit N Dubey19-Mar-07 21:54 
GeneralTv tuner vc++ 7.0 sample project (setfrequency included) Pin
takyonxxx8-Mar-06 4:12
membertakyonxxx8-Mar-06 4:12 
GeneralRe: Tv tuner vc++ 7.0 sample project (setfrequency included) Pin
kang gu joon1-Oct-06 20:20
memberkang gu joon1-Oct-06 20:20 
GeneralRe: Tv tuner vc++ 7.0 sample project (setfrequency included) Pin
ngochuy22-Feb-07 22:38
memberngochuy22-Feb-07 22:38 
QuestionKSPROPERTY_TUNER_MODE_CAPS_S seems to be error? Pin
jarba7-Mar-06 23:24
memberjarba7-Mar-06 23:24 
QuestionAccess with VB Pin
LameHack8-Nov-05 14:52
memberLameHack8-Nov-05 14:52 
GeneralProblems with fine tuning and SignalPresent Pin
razvar27-Jun-05 1:56
sussrazvar27-Jun-05 1:56 
GeneralRe: Problems with fine tuning and SignalPresent Pin
Liaqat Fayyaz27-Jun-05 2:34
memberLiaqat Fayyaz27-Jun-05 2:34 
GeneralProject Files or C# Alternate Pin
yateee11-Mar-05 19:58
memberyateee11-Mar-05 19:58 
GeneralRe: Project Files or C# Alternate Pin
hamdyali12-Jun-05 5:33
memberhamdyali12-Jun-05 5:33 
GeneralRe: Project Files or C# Alternate Pin
almere10922-Dec-05 1:53
memberalmere10922-Dec-05 1:53 
QuestionRe: Project Files or C# Alternate Pin
troedi9-Jan-07 3:45
membertroedi9-Jan-07 3:45 
AnswerRe: Project Files or C# Alternate Pin
almere1099-Jan-07 8:47
memberalmere1099-Jan-07 8:47 
GeneralRe: Project Files or C# Alternate Pin
troedi9-Jan-07 9:49
membertroedi9-Jan-07 9:49 
GeneralRe: Project Files or C# Alternate Pin
almere1099-Jan-07 11:57
memberalmere1099-Jan-07 11:57 
GeneralRe: Project Files or C# Alternate Pin
troedi12-Jan-07 3:56
membertroedi12-Jan-07 3:56 
GeneralRe: Project Files or C# Alternate Pin
almere10912-Jan-07 5:41
memberalmere10912-Jan-07 5:41 
GeneralRe: Project Files or C# Alternate Pin
almere10915-Jan-07 11:42
memberalmere10915-Jan-07 11:42 
GeneralRe: Project Files or C# Alternate Pin
troedi15-Jan-07 11:51
membertroedi15-Jan-07 11:51 
GeneralRe: Project Files or C# Alternate Pin
almere10915-Jan-07 20:36
memberalmere10915-Jan-07 20:36 
GeneralRe: Project Files or C# Alternate Pin
almere10923-Jan-07 10:56
memberalmere10923-Jan-07 10:56 
GeneralRe: Project Files or C# Alternate Pin
troedi25-Jan-07 23:02
membertroedi25-Jan-07 23:02 
GeneralRe: Project Files or C# Alternate Pin
almere10926-Jan-07 7:19
memberalmere10926-Jan-07 7:19 
GeneralRe: Project Files or C# Alternate Pin
troedi8-Feb-07 20:06
membertroedi8-Feb-07 20:06 
GeneralRe: Project Files or C# Alternate Pin
almere1099-Feb-07 7:58
memberalmere1099-Feb-07 7:58 
QuestionManual (Dirty Edit) of Tuner Filter? Pin
Anon_2004093029-Sep-04 16:00
sussAnon_2004093029-Sep-04 16:00 
AnswerRe: Manual (Dirty Edit) of Tuner Filter? Pin
Rui Godinho Lopes4-Oct-04 9:55
memberRui Godinho Lopes4-Oct-04 9:55 
GeneralRe: Manual (Dirty Edit) of Tuner Filter? Pin
saruman2-May-05 1:20
membersaruman2-May-05 1:20 
General[Message Deleted] Pin
Kyle Halse15-Sep-04 21:16
memberKyle Halse15-Sep-04 21:16 
GeneralRe: GetFrequency... Pin
Liaqat Fayyaz15-Sep-04 21:44
memberLiaqat Fayyaz15-Sep-04 21:44 
GeneralRe: GetFrequency... Pin
takyonxxx10-Mar-06 0:26
membertakyonxxx10-Mar-06 0:26 
QuestionMissing project files? Pin
Anonymous2-Sep-04 7:15
sussAnonymous2-Sep-04 7:15 
AnswerRe: Missing project files? Pin
Liaqat Fayyaz2-Sep-04 19:06
memberLiaqat Fayyaz2-Sep-04 19:06 

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.

Permalink | Advertise | Privacy | Terms of Use | Mobile
Web01 | 2.8.170924.2 | Last Updated 21 Aug 2004
Article Copyright 2004 by Liaqat Fayyaz
Everything else Copyright © CodeProject, 1999-2017
Layout: fixed | fluid