IkMijn pagina voor
prettig werken op de PC
www.pcpret.nl
Homepage Stuur bericht Gastenboek Website Blog Eindhoven

Software development, Amcap for capturing TV and video in Windows

Amcap specific topics: Amcap related topics: Introduction

The chapter Software development, FM radio and TV tuners in Windows was the start. The basics about how tv tuning, FM radio and teletext are explained in more detail there. About Amcap a lot can be told, so this will become my chapter about Amcap. Because the Amcap program is from the Windows SDK a specific chapter on Amcap. Amcap was for me the first program that could display the video that was connected to my first VIVO videocard (MSI MX460). Because I did use an external TV tuner, there was no real need to have a easy way in selecting TV broadcast stations. Amcap uses the Vfw-like interface TV tuner interface for the selection of TV broadcast stations. That method I can not call user friendly. Esspecially because it is more or less guess what to fill in.

During the years not much seems to be changed. Interesting was the way the program specific settings were stored. In the past, this was in Win.ini (under specific personal names). Later it information was stored in a file. What was interesting for me was the storage of Pal video information. In older versions the default choice was NTSC and stayed NTSC when the program was restarted ... On internet several compiled Amcap versions can be found. Most of them seems looks very simple to the original version (C++ sample). Without exception, Amcap was very unstable on my MCE 2005 system, but worked great on normal Windows XP. The newest and best Amcap version one I found was Noël's version). What I really liked in Noë's Amcap version is that it saves the right video settings, so any time the Amcap program is restarted you get the video input and video mode (PAL) you selected the last time. Unhapply Noë's Amcap version can not handle sound of TV-cards without specific audio device driver. This is the major reason for me to improve the Microsoft version of Amcap. The main advantage of Amcap is that this program does not need '.Net'.

In the beginning I used Visual Studio 6, later on this became Visual Studio .Net 2003. My favorit compiler however was Turbo Pascal in the past. Nowadays this is Delphi 7 Personal. I still prefer this compiler above Visual Studio. But programming .Net (C#) is very nice and a major improvement above C++ especially if the GUI counts. Delphi is just a little bit more user friendly in programming GUI compared with C#. Amcap was written in C++ and therefore the GUI was not that easy to modify. Compiling Amcap is also a big challenge. I had an older Amcap SDK sample of 2002 and the newest one. After some strugling I could compile both versions with Visual Studio 6 and .Net. Important is that the DirectX SDK and the Windows DDK are available and installed.

In 2005 I discovered DSPack and DShowNet, see Software development, FM radio and TV tuners in Windows for more information on that.

In february 2008 I made an new Amcap as result of a question on Mpeg2 file saving. The main reason to make this new Amcap was not because of Mpeg2 but because I discovered that my Amcap version could not handle audio on my newest Pinnacle TV-card properly.

Ideas

At a certain moment, november 2004, I decided to build a Media Center PC and than the Media Center was not what I thought it would be. But within a year the list of TV tuners grow to:

  • Hauppauge Amity2 or PVR150 TV-card
  • Matrox Marvel G200 videocard with external box with tuner and without tuner.
  • Lenco 878TV (Rev 3.E) TV-card
  • Pinnacle Miromedia PCTV
  • In december 2007, I the following TV tuners can be added to the list:

  • Pinnacle PCTV 330eV USB stick
  • Pinnacle PCTV 310i TV-card
  • It would be nice to have one program that can handle all my TV tuners in very user friendly way. This means: I want to have an easy way to tell the TV card which broadcast station needs to be tuned. Making a list is not difficult but telling it the TV card, that is a hard job. With the standard software there many differences is selecting and finding the TV broadcast stations. And than also the Windows and DirectX versions counts. The Matrox Marvel is the biggest problem for me because Matrox never developed nice working drivers for that videocard. Till today the drivers are unstable. But the TV tuner supports stereo audio and many more functionality so still there is a wish to use it if possible.

    In february 2008 I decided to update my current Amcap version. The update should solve the audio problem with TV-cards having a specific audio device driver (such as the Pinnacle PCTV 310i) and TV-cards having no specific audio device driver, but using the video device driver instead (such as the Pinnacle PCTV 330eV and the Hauppauge PVR150). In addition I want to port the TV broadcast station selection and the Mpeg2 file saving, I made earlier for the Delphi Amcap version, to the C++ Amcap version. The information should be read from a file I am already using for my c# counterpart. For this I need to add TV finetune functionality using the IksPropertySet functionality, so the TV tuning frequency can be used as input instead of the Windows channel number. The Windows channel number could be used instead, but takes some effort to handle correctly. I do not want to make an automatic search yet, there are more important things to do. Furthermore I want to finalize the WST functionality in Amcap so I can use Amcap for additional testing I can not do with the c# counterpart.

    To get an idea my Amcap should do, I had to look at Noël's version. I noticed that that version uses Amcap.ini different, that is a good improvement. There is support for multiple capture devices, and specific settings are stored different. Concern is that at my system there might be 2 till 4 capture devices with some conflicting settings. I think it is better to make a separate initialization file for every capture device. I did not implement that for my version yet. Another difference is the support for TV broadcast selection and auto search of TV broadcast stations. That looks great! Unhappily, it means some extra work for me to implement, it will be a future whish. The TV broadcast station information is stored in Amcap.ini also. I did not want that, I will store the settings in a separate file: AmcapTv.ini To be honest, I wanted to use the same format as its C# counterpart, unhappily that means some extra effort so for now I choose a format that looks more similar to Noël's version. The differences are that I left out the video standard information and use frequency information instead of Windows channel numbers.

    The latets version, 9.11 of Noël, crashes also on my USB TV card, Pinnacle PCTV 330eV. Happily my Amcap version does not crash. For me this means, that testing should be done with great care. Every TV-cards seems to have a weak point for the capture program causing it to fail or to crash.

    Amcap, audio on Hauppauge Amity2 (general)

    In 2005 I discovered that Amcap did not give audible TV audio with the Hauppauge Amity2 (PVR150, MCE version). From the previous investigations I knew already that capturing audio was giving problems. Mainly because this PCI card offers audio and video capture via the PCI bus. The TV card drivers offers special filters to get the audio and video captured. The one for audio, was not taken into account, so that one needs to be added. In BuildPreviewGraph() some code was added that for getting sound on the Hauppauge Amity2 TV card.

    hr = gcap.pBuilder->RenderStream(
    	&PIN_CATEGORY_PREVIEW, &MEDIATYPE_Audio, gcap.pACap, NULL, NULL);
    if(hr != NOERROR)
    {
    	ErrMsg(TEXT("Cannot do special rendering of audio capture stream!"));
    }
    

    Compared with the normal video rendering to the default device the major difference in coding is the choice of the Media type: Audio instead of Interleaved or Video. The result is that there will be audible sound because it is rendered to the default audio device now. In some scenario's, such as with Hauppauge Amity2 with the newest Hauppauge PVR150 Windows XP/MCE software drivers, this code will not work. This because there is no seperate audio device driver anymore. The solution is not that difficult, audio is available via the video device driver:

    hr = gcap.pBuilder->RenderStream(
    	&PIN_CATEGORY_PREVIEW, &MEDIATYPE_Audio, gcap.pVCap, NULL, NULL);
    

    Keep in mind that this specific line of code must be added at more places! Also some related code needs to be modified.

    Amcap, audio on Hauppauge Amity2 and Pinnacle PCTV 310i

    In february 2008, I looked at the Amcap code again trying solve the audio problem I got with the Pinnacle PCTV 310i TV-card. This Pinnacle PCTV TV-card has an audio as well as a video device driver. During testing om my development system, I noticed that the audio did not work properly for the Hauppauge PVR150 TV-card also, well I could get sound, when selecting a TV broadcast station and setting the crossbar. But that was not real user friendly. First I thought it was because of the crossbar, but that was not the problem. Then I noticed that the menu item for the video pin selection was missing, was that a possible cause of the problem? Maybe? What I found out was that Amcap has several checks on the presence of an audio device driver. For specific cases, such as the Hauppauge PVR150 TV-card, there is no audio device driver and in such case Amcap does not initialize audio related data and video pin data! I modified the code to handle such case. Everything okay, well almost: During testing I found a specific scenario were I could get video but no audible sound. In the next section you will find the cause and the solution for it.

    TV tuning, how to do?

    Tuning in Windows is controlled via channel number selection. In TV tuning, how to do? more specific information can be found. In some cases TV card specific modifications will be needed. Esspecially for the Matrox Marvel G200 because two input types (cable and antenna) needs to be used while normally only one (e.g. cable) will do. The Matrox Marvel G200 is a special case, in Windows XP there is buggy driver supporting the IAMTVTuner and IAMTVAudio interface, unfortunately, the best software to use, do not support those interfaces. In such cast the Matrox Marvel G200 register settings will give the easiest solution.

    For TV-cards, supporting the IAMTVTuner interface, there is a much better solution. Use the TV Tuner property page for selecting a TV broadcast station. But okay, the next problem, which channel number between 1 and 368 should be entered ... ? So the next idea was to add frequency finetuning via the IKSPropertySet interface so I knew what tuning information I should enter. In addtion, without TV broadcast station pre selection, the program was still not user friendly enough, at least for me. In february 2008 I added a simple TV broadcast station pre selection and the TV frequency finetuning functionality to Amcap. During testing I discovered that with a clean boot I could select a TV broadcast station with good video, but without audible sound. For some reason some initialization that was done before, was not done now. Well the real difference was: clicking on the TV Tuner property page and fill a Windows channel number that corresponds with a TV broadcast station. The action I called 'not user friendly'. Okay, after setting the TV tuner settings correctly, there was sound. So, some TV tuner settings needs still to be set! The solution is to initialize the TV tuner with specific settings, such as country code, tuningspace, input type, TV format ... Keep in mind that those settings are country dependent, in France or the US different settings are needed then in my country, the Netherlands. In some cases the TV format must be set explicit to get the proper TV tuner frequency range. The IAMAnalogVideoDecoder interface can be used for that.

    Amcap, Mpeg2 file saving

    My idea was to port the Mpeg2 file saving, I made for the Delphi Amcap, into the C++ version. The original Amcap version does not support Mpeg2 file saving right away. In theory Amcap can do this already, using the Mpeg2 mode. The Mpeg2 mode can be selected in the 'Options' menu, it is available only in the 'latest' Amcap versions. This Mpeg2 mode is meant for TV cards providing a Mpeg2 stream but should also work with TV cards having a video and audio capture pin. That specific Mpeg2 mode did not work on my computers. In a rare case I could get preview. Looking to the Amcap code, it was not made to provide preview and capture at the same time. I noticed also that this Mpeg2 mode is not capable to check multiple video capture pins yet. The Hauppauge PVR150 has two video pins, one analog and one for the hardware mpeg encoder. So the current Mpeg2 mode was not usable.

    For the time being I could make a bit simpler implementation for using the filters that I am familiar with. In the mean time I could try to re-design the Mpeg2 mode code doing the proper things that fits in the Amcap concept (preview and capture).

    For Mpeg2 file saving I want to use the same architecture as for Avi file saving. There was one major difference with the current Amcap approach: I want to be able to select filters and changing settings in specific filters. For Avi I added the 'DV Video Encoder' as default video compressor to get readable Avi files. As small extra, Amcap switches the compressor to the proper video standard. For me that is PAL. For Mpeg2 I had to add functionality to select the proper WDM Video Encoder and the software Mpeg encoders. I could do it hard-coded or via the Amcap.ini file, but that is less flexible. But also, it is quite tough to find the filters that are really needed. I already found out that some filters do crash the program so there should be a way to prevend that.

    This architectual software change, means that the original Amcap was changed a lot! First because the approach of pre-selection of the encoder/decompressor may cause a number of conflicts, so all kind of dependencies and conflicts needed to be solved or prevented. Not a real big problem, I did that before in the c# counterpart of this program. Second, more menu information and help functions were needed to get the functionality more user friendly and the program more flexible.

    In future it would be nice to support the Windows Media Format Asf (Wmv and Wma) also. Pinnacle PCTV 330eV WST graph

    Amcap, World Standard Teletext?

    Amcap supports Closed Captioning, this works in US but this is not usable in Europe. So new Teletext needed to be added. The WST architecture looks similar to the CC implementation. Amcap did not implement this functionality correctly yet, this because Amcap gives an extra active movie window when the functionality is made active. An overlay mixer is needed to mix the preview video and the Teletext. Amcap might be able to build the WST graph itself, however that code worked properly only on two of three of my testing computers. The Overlay Mixer and the Smart Tee filter cause problems. It is possible to use no Overlay Mixer and render WST to a separate Active Movie Window It is strange that the code does not work properly on all computers because usually, this functionality works if graphedt is used to add and connect the WST codec filter, the WST decoder and the Overlay Mixer explicit. The figure at the right shows an example of a WST a graph for a TV-card (in this case the Pinnacle PCTV 330eV USB TV-stick).

    Amcap for Delphi

    Maybe it is interesting to know, why this Amcap page was written: well this is because I found this remark on the IKSPropertySet: frequency on tv tuner !?!. Than by looking around I found two sites where a Delphi port of the Amcap C++ sample (SDK 2002 version) could be found: http://www.mechdata.dk/delphi_amcap.zip

    Compiling this delphi_amcap sample seems to be not an easy a beginners job. Here some tips to compile. First get Dspack (version 2.3.4 was used by me) for getting the unit 'Directshow.dcu'. Rename a number of times P_AM_MEDIA_TYPE to PAMMEDIATYPE and similarly for TPIN_INFO to TPININFO. Remove the procedure TMainForm.DeviceChange(). Function might be useful, for the moment it seems to be unused. Finally there was some strugling with gcap.pBuilder.FindPin(). Looking to the code, the third line gave to errors.

      hr := gcap.pBuilder.FindPin(
      	gcap.pVCap, PINDIR_OUTPUT,
      	PIN_CATEGORY_VBI, TGuid(Nil^),
      	FALSE, 0, pPin);
    

    There seems to be a conflict between TGUID and PGUID, on internet I found: PGUID = ^TGUID so had a clue. Changing Tguid(Nil^) in just nil was the first step. The PIN_CATEGORY_VBI was a little strange, a constant that should be used as a pointer? I declared a new variable and give it the PIN_CATEGORY_..., a pointer to a variable that is something that can be coded.

    November 2006, I got a closer look at code of the Amcap Delphi version. I added the audio capture code modification, to get audible sound for modern PCI tv-cards. Also I tried to get the WST (World Standard Teletext) working. The original code did not work, so I assumed that the 'WST Decoder' filter needed to be added first. That was the correct assumption, after adding it, I got Teletext. The use of the 'WST Decoder' property page seems to cause some errors. More investigation is needed on that. This was also an interesting moment to check the IAMWstDecoder interface. The good news is that this interface works! More on this subject can be found here.

    March 2008, this program needs to set the TV format also properly if the PC does not support PAL video as default TV format. If the TV format is not set, the TV finetuning will not work in the expected frequency range. It was strange that the TV format setting, that was change via the TV tuner property page, was not taken into account. I added a function using the IAMAnalogVideoDecoder interface to change the current TV format. Then the TV tuner will work as it should work.

    Note that the Amcap program code (Delphi as well as the Windows C++ version) is not for beginners!

    Amcap version 9.10Amcap (+download)

    In february 2008 my Amcap version seems to become stable enough to be distributed. New features, compared with the original Amcap 2002 version are:

  • Audio for TV-cards having no wired audio connection
  • TV broadcast seletion using TV frequency fine tuning via setup file (amcaptv.ini)
  • Saving country specific data such as country code and TV format
  • Mpeg2 file saving (via WDM hardware encoder) or software encoder (limited usable!)
  • For Avi added 'DV Video Encoder' as default video decompressor with Pal/Ntsc setting
  • Pre selection of Audio and Video compressor (for Avi file saving)
  • For Avi added property page access for video decompressor (if available)
  • For Mpeg2 added property page access for mpeg encoder (if available)
  • IAMStreamConfig interface extened to support audio and video via a program window
  • Preview resolution depends less on the capture resolution
  • Setup file Amcap.ini instead of using Win.ini, more settings and settings renamed, restructured
  • Added WST functionality (tested on Hauppauge PVR150, Pinnacle PCTV 310i)
  • For Mpeg2 file saving I had a good result with the 'Nero Mpeg2 Encoder'. The current implementation is limited usable, because it works either for TV-cards with a hardware Mpeg encoder or with a software encoder that has AV inputs and muxer. The original Amcap Mpeg2 option looks promishing, it checks on pins and media types. Unfortunately, the Amcap Mpeg2 option is unstable, does not work on most of my computers and may crash Amcap for unknown reason. I kept the original functionality in, but there is no garantuee that it will work correctly!

    Known problems:

  • The Pinnacle 310i TV card uses 320x240 video resolution as default.
  • Capture devices with VP pin are not fully supported.
  • World Standard Teletext might not function properly.
  • Changing the audio sampling frequency via the IAMStreamConfig interface fails for the Hauppauge PVR150.
  • Amcap may crash if Vfw property page is used for changing the capture settings.
  • Amcap supports multiple setup files (eg: amcap1.ini, amcap2.ini, ...), start up with 'Amcap 1', 'Amcap 2', ...
  • Important: Upon the first use of Amcap, the proper country code, tuningspace and input type for the TV tuner, needs to be entered. These settings will be stored in the Amcap.ini setup file, so next time, those saved settings will be used.

    There is no garantuee that my current Amcap version works properly on your computer. The program still needs a number of improvements (bug fixing and new features). If a computer has than one video capture card, the settings of the cards usually conflicts with each other. In case of problems, just delete Amcap.ini and start over again! The originally Amcap stored the Amcap specific settings in the Win.ini file in the Windows directory. That file is for general usage but it is Microsoft policy for not using that file anymore. The Microsoft policy is to put device specific settings in the register. That may work, however, I like to have an easy way of checking and changing program specific settings. With a special file it will be also quite easy to modify settings so just a little bit more user friendly then it would be possible via the register. At least that is what I think. In case of multiple Tv/Video capture cards, the multiple configuration file could be used to simplify the use Amcap for (completely) different configurations.

    Download Amcap version 9.10

    Interesting links

    Interesting links, well: The Code Project, here you can find a lot of code examples; Prodigy, DSPack which offers a DirectX interface to Delphi; Microsoft MSDN, here you can find a lot of information of how Windows can control the TV tuner hardware.

    Back to the beginning? Click here.


    Back to the Software Development page,
    the Homepage or the Hobby activities page.


    Contact me? Go back to/look at the Software Development page.
    Date: may 1, 2008