Menu

How capturing television shows

2009-11-14
2012-10-29
  • Francesco Volonterio

    Hi all,
    I'm new with Directshow and I am facing a big problem.
    i Start by excuse me for my English.
    I want to capture Tv show in a mpg file or asf file or wmv file.
    I use an usb DVB Key as tv receiver.
    I've seen some examples and I have used DVBTTuning as guide line.
    I have setted the channel using ONID,TSID,SID and Frequence..in this way I am
    able to see the various shows.
    Now I want to be able record the show that I am seeing. If I can view a
    preview when the application is capturing, it would be very cool, but If this
    does not occur and the application capture only the shows in a file it is OK.
    This is my code and it works for viewing television shows.
    Channel allowed with ONID,TSID,SID and Frequence are stored in an xml File.

    enter code here
    namespace Television_Application
    {
    public partial class Form1 : Form
    {

    public String ChannelChoosed = "";
    public String XML_PROGRAM_FREQUENCES = Environment.CurrentDirectory +
    @"\ProgramFrequences.xml"; // Path to the XML That contains informations for
    the programs
    public static int FREQUENCE = 0; // Frequence of the program considered
    public static int ONID = 0; // ONID of the program considered
    public static int TSID = 0; // TSID of the program considered
    public static int SID = 0; // SID of the program considered
    private ITuningSelector tuningSelector = null; // set initially the
    tuningSelector
    private BDAGraphBuilder bdaGraphBuilder = null; // set initially the
    bdaGraphBuilder
    String FileName ="C:\"+ DateTime.Now.ToString().Replace(".","").Replace("
    ","").Replace("/","")+".asf";
    Capture cam = null;

    public Form1()
    {
    InitializeComponent();
    buttonRec.Visible = false;
    buttonStop.Visible = false;

    }

    //set the Frequence for the gived Channel ID (for example Rai1)
    public void GetFrequence(String ChannelID)
    {
    int Frq = 0;
    try
    {
    XmlDocument Programs = new XmlDocument();
    Programs.Load(XML_PROGRAM_FREQUENCES);
    Frq = int.Parse(Programs.SelectSingleNode("/Channels/Channel/Frequence").First
    Child.Value.ToString());
    FREQUENCE = Frq;
    }
    catch
    {
    Frq = 0;
    FREQUENCE = Frq;
    }
    }

    //set the ONID for the gived Channel ID (for example Rai1)
    public void GetONID(String ChannelID)
    {
    int OnidToFound = 0;
    try
    {
    XmlDocument Programs = new XmlDocument();
    Programs.Load(XML_PROGRAM_FREQUENCES);
    OnidToFound = int.Parse(Programs.SelectSingleNode("/Channels/Channel/ONID").Fi
    rstChild.Value.ToString());
    ONID = OnidToFound;
    }
    catch
    {
    OnidToFound = 0;
    ONID = OnidToFound;
    }
    }

    //set the TSID for the gived Channel ID (for example Rai1)
    public void GetTSID(String ChannelID)
    {
    int TsidToFound = 0;
    try
    {
    XmlDocument Programs = new XmlDocument();
    Programs.Load(XML_PROGRAM_FREQUENCES);
    TsidToFound = int.Parse(Programs.SelectSingleNode("/Channels/Channel/TSID").Fi
    rstChild.Value.ToString());
    TSID = TsidToFound;
    }
    catch
    {
    TsidToFound = 0;
    TSID = TsidToFound;
    }
    }

    //set the SID for the gived Channel ID (for example Rai1)
    public void GetSID(String ChannelID)
    {
    int sidToFound = 0;
    try
    {
    XmlDocument Programs = new XmlDocument();
    Programs.Load(XML_PROGRAM_FREQUENCES);
    sidToFound = int.Parse(Programs.SelectSingleNode("/Channels/Channel/SID").Firs
    tChild.Value.ToString());
    SID = sidToFound;
    }
    catch
    {
    sidToFound = 0;
    SID = sidToFound;
    }
    }

    // buttonConfirm.click event
    private void ButtonConfirm_Click(object sender, EventArgs e)
    {
    try
    {
    this.bdaGraphBuilder.Dispose();

    }
    catch { }
    // from here the method tries to set the various variables
    ChannelChoosed = textBoxChannelName.Text.ToLower();
    if (!ChannelChoosed.Equals(""))
    {
    try
    {

    GetFrequence(ChannelChoosed);
    GetONID(ChannelChoosed);
    GetSID(ChannelChoosed);
    GetTSID(ChannelChoosed);
    }
    catch
    {
    MessageBox.Show("Invalid Set Operations", "Errors occurred");
    }
    }
    else
    {
    MessageBox.Show("You have to enter a correct value","Please retry");
    }
    // close the set operations
    this.tuningSelector = new DVBTTuning();

    try
    {
    this.bdaGraphBuilder = new BDAGraphBuilder(this);
    this.bdaGraphBuilder.BuildGraph(this.tuningSelector.TuningSpace);
    this.bdaGraphBuilder.SubmitTuneRequest(this.tuningSelector.TuneRequest);
    this.bdaGraphBuilder.RunGraph();
    buttonRec.Visible = true;
    }
    catch
    {
    if (this.tuningSelector.TuneSelect() == true)
    {
    this.bdaGraphBuilder = new BDAGraphBuilder(this);
    this.bdaGraphBuilder.BuildGraph(this.tuningSelector.TuningSpace);
    this.bdaGraphBuilder.SubmitTuneRequest(this.tuningSelector.TuneRequest);
    this.bdaGraphBuilder.RunGraph();
    }

    }

    }

    //on close event
    private void Form1_FormClosed(object sender, FormClosedEventArgs e)
    {
    try
    {
    bdaGraphBuilder.Dispose();
    Application.Exit();
    }
    catch { }
    }

    }
    }

    Now how can I record the channel that I am viewing?
    Thanks in advance
    Francesco

     
  • gbarchiesi

    gbarchiesi - 2009-11-18

    Hi Francesco,
    you have to connect the filtergraph to a file sink filter. Use the
    BDAGraphBuilder a VMR9 filter? If true, the VMR9 has not an output pin and the
    solution is more complicated. In my application I have a VMR9 filter and the
    problem is similar... Sorry for my english, too!!

     

Log in to post a comment.