Click here to Skip to main content
15,399,339 members
Articles / Desktop Programming / MFC
Posted 20 Aug 2004


69 bookmarked

DirectShow - Fine TV Tuning Using IKsPropertySet.

Rate me:
Please Sign up or sign in to vote.
4.88/5 (19 votes)
20 Aug 20043 min read
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

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
editorSean 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
sammyhg8-Sep-09 20:25
Membersammyhg8-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
vckang1-Oct-06 20:20
Membervckang1-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
Memberrazvar27-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 

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.