giovedì 7 gennaio 2010

Recording TV shows with an old Pinnacle PCTV Miro on Ubuntu Karmic 9.10

In my holidays house I have a pc with a "vintage" Pinnacle PCTV Miro capture card. Even though my card is superseded by new models and by DVB-T cards, in my holidays house we'll receive Digital Video Broadcasting - Terrestrial signal in late 2011 and I just go on using my card. Linux gets continously updated, but I notified that my capture card needs a fine tuning on Karmic 9.10 cause autodetecting doesn't work properly.

Why? BTTV uses the PCI Subsystem ID to autodetect the card type.  The output of lspci:
01:07.0 Multimedia video controller: Brooktree Corporation Bt848 Video Capture (rev 12)
Only bt878-based cards can have a subsystem ID (which does not mean that every card really has one).  bt848 cards can't have a Subsystem ID and therefore can't be autodetected: PCTV Miro is a bt848-based card. Ok, I really appreciate the possibility to record my preferred TV Shows with mencoder, so we have to survive holidays with patience. Let's find my vintage PCTV in the list of supported cards:


Good, take a note: Pinnacle PCTV Miro is card 1.
Now, the TV tuner! I tried a lot of tuners and for me the right one is:

 tuner=0 - Temic PAL (4002 FH5)

Take another note: Pinnacle PCTV Miro' s tuner is 0.

My card has not radio support, so another good option is radio=0.
Browsing the internet, I found my card has 35 MHz crystal installed. It means we need the option pll=2.
BTTV capture driver only provided applications with two buffers by default in versions shipped with kernels before 2.4.21. Advanced deinterlacing algorithms require a longer history of past input frames in order to predict motion in the video stream. To give applications more buffers, use this option when loading the bttv driver: gbuffers=4.
Now, the audio and first of all, GPIO pins:
GPIO means General Purpose I/O. Video decoder chips like the SAA713x or the BT8x8 have a number of I/O pins that are not used by the video decoder itself. They have no special purpose, each manufacturer can do with them whatever he wants.
Download BtSpy from here. This small utility can come in handy during the process to find correct GPIO pins. Run it on Windows, follow all directions and save the report. In my case I have something like this:
General information:
 Name:Pinnacle, Miro PCTV
 Chip: Bt848 , Rev: 0x00
 Subsystem: 0x00000000
 Vendor: Gammagraphx, Inc.
 Values to MUTE audio:
  Mute_GPOE  : 0x23000f
  Mute_GPDATA: 0x230002
 Has TV Tuner: Yes
  TV_Mux   : 2
  TV_GPOE  : 0x23000f
  TV_GPDATA: 0x230002
 Number of Composite Ins: 1
  Composite in #1
   Composite1_Mux   : 3
   Composite1_GPOE  : 0x23000f
   Composite1_GPDATA: 0x230000
 Has SVideo: Yes
  SVideo_Mux   : 1
  SVideo_GPOE  : 0x23000f
  SVideo_GPDATA: 0x230000
 Has Radio: No
Ok, I need this option: gpiomask=0x23000f audiomux=0x230002,0x230002,0x230000,0x230000
Almost done! You can try your grabber card in this way: run a terminal and type:

 stefano@SERVER:~$ sudo modprobe -r bttv
 stefano@SERVER:~$ sudo modprobe bttv card=1 tuner=0 radio=0 pll=0  gbuffers=4 gpiomask=0x23000f audiomux=0x230002,0x230002,0x230000,0x230000
 stefano@SERVER:~$ dmesg | grep bttv
[ 7173.661024] bttv: driver version 0.9.18 loaded
[ 7173.661029] bttv: using 4 buffers with 2080k (520 pages) each for capture
[ 7173.661112] bttv: Bt8xx card found (0).
[ 7173.661130] bttv0: Bt848 (rev 18) at 0000:01:07.0, irq: 17, latency: 32, mmio: 0xd8000000
[ 7173.661469] bttv0: using: MIRO PCTV [card=1,insmod option]
[ 7173.661473] bttv0: gpio config override: mask=0x23000f, mux=0x230002,0x230002,0x230000,0x230000
[ 7173.661479] IRQ 17/bttv0: IRQF_DISABLED is not guaranteed on shared IRQs
[ 7173.661515] bttv0: gpio: en=00000000, out=00000000 in=00ff07ff [init]
[ 7173.666902] bttv0: i2c: checking for MSP34xx @ 0x80... not found
[ 7173.667434] bttv0: miro: id=1 tuner=0 radio=no stereo=no
[ 7173.667438] bttv0: tuner type=0
[ 7173.678921] bttv0: audio absent, no audio device found!
[ 7173.687126] bttv0: registered device video0
[ 7173.687154] bttv0: registered device vbi0
[ 7173.687179] bttv0: PLL can sleep, using XTAL (35468950).

Cool! We can load our options at boot time. Type in our terminal:

 stefano@SERVER:~$ sudo gedit /etc/modules

Add the module bttv, then, as superuser, create a new file in /etc/modprobe.d. Call it bttv and add this line:

options bttv card=1 tuner=0 radio=0 pll=0 gbuffers=4 gpiomask=0x23000f audiomux=0x230002,0x230002,0x230000,0x230000

Once the setup is finished, we can capture our preferite TV shows with mencoder:

 stefano@SERVER:~$ mencoder tv:// -v -tv driver=v4l2:width=640:height=480:input=1:device=/dev/video0:immediatemode=0:forceaudio:outfmt=yv12:adevice=/dev/dsp -o outfile.avi -oac mp3lame -lameopts cbr:br=96 -ovc lavc -lavcopts vcodec=mpeg4:vbitrate=1000:autoaspect=1:vhq -vf pp=lb -ffourcc XVID -endpos 00:02:00

This command will record 2 minutes of the video stream on /dev/video0 using XviD codec and a quality similar to the TV shows you can download from EZTV
If your output file hasn't sound, check wheter your line-in is mute. You can use this command:

 stefano@SERVER:~$ v4lctl volume mute off|on

to unmute your grabber card.

That's all!
Best regards.