Differences between revisions 4 and 5
Revision 4 as of 2006-02-07 17:44:00
Size: 10664
Editor: Kurgan
Comment:
Revision 5 as of 2009-04-12 17:33:25
Size: 10664
Editor: localhost
Comment: converted to 1.6 markup
No differences found!

Registrare la TV su Linux

Questi sono appunti dedicati alla registrazione della TV (e alla visualizzazione di quanto registrato) usando Linux e una scheda di acquisizione TV. Al momento sto usando una Hauppage WinTV Express, una scheda molto economica basata sul chip BT878.

Kernel

Il kernel usato e` un 2.6.12. Occorre compilare il modulo "bttv" (aka bt848) che supporta anche il bt878. Al momento non sono riuscito a usare (ammesso che ci sia dentro, perche` ho dei dubbi) l'encoder dell'audio della scheda TV, per cui ho collegato la sua uscita audio all'ingresso della sound blaster e poi registro da quella. Per registrare dal line in della SB occorre settare appropriatamente aumix (c'e` il pacchetto debian di aumix). Anche per vedere la TV in diretta (e quindi ascoltare il line in) occorre settare aumix.

Per vedere la TV

Per vedere e basta la TV (su X e un monitor, non su una TV) uso l'applicazione "tvtime" della quale c'e` il pacchetto Debian. Fra le varie, mi e` sembrata la piu` semplice e funzionale per il mio scopo, che e` guardare il TG in una finestra, senza telecomando o altro.

Per registrare un programma TV

Sto facendo prove con mencoder (programma di codifica che e` parte del pacchetto di mplayer). Dal momento che in Debian Sarge mplayer e mencoder non ci sono, uso i pacchetti non ufficiali che si trovano qui:

# video e audio
deb ftp://ftp.nerim.net/debian-marillat/ sarge main

Mencoder consente di registrare da command line, il che va benissimo per metterlo in cron e registrare i propri programmi mentre si e` fuori (ah, l'ssh!). Al momento sto provando a trovare un compromesso fra qualita` e occupazione di disco.

Questo funziona per registrare dalla TV, pero` non sceglie il canale, quindi registra sull'ultimo canale sul quale era stata sintonizzata la scheda TV. (una riga sola, l'ho spezzata con un backslash)

mencoder tv:// -tv driver=v4l2:width=768:height=576:device=/dev/video0:buffersize=256:fps=25 -ovc lavc \
-lavcopts vcodec=mpeg4:vbitrate=1460:keyint=300 -oac mp3lame  -vop pp=0x20000  -o test2.avi

Poi ci sono comandi piu` esoterici, che sto ancora studiando. Riporto da un altro sito:

How to watch tv with mplayer
First: why would you watch tv with mplayer instead of Xawtv? Well, for me Xawtv doesn't scale to the full screen when I select: full screen. Zapping (another tv app) does it better, but still, the tv quality is not too nice. In comes mplayer, which allows to do on-the-fly de-interlacing and 3D denoising (meaning: it reduces noise in both spacial directions and on the temporal axis). The command that works best for me is:

mplayer -tv on:driver=v4l:device=/dev/v4l/video1: input=0:channel=27:width=768:height=576:fps=25 -vop lavcdeint,denoise3d=4:3:6

Be sure to put all that on one line (note that I have inserted extra spaces to avoid the lines getting too long; after none of the ":" should there be a space)! Oh, in this case, the tv-tuner is set to channel 27; for watching the signal on the composite video input of the tv-card (video recorder for instance), use:
mplayer -tv on:driver=v4l:device=/dev/v4l/video1:input=1:width=768:height=576:fps=25 -vop lavcdeint,denoise3d=4:3:6
Also, to have audio you have to make sure the mixer control for the input channel of your audio card that you connected the tv-card-audio output with, is set to 70% of maximum volume or so.

How to record tv with mencoder
This was quite tough, since I couldn't manage to get the audio as well. After a lot of messing around I found that selecting the audio input for recording in kmix and alsamixergui was not good enough (beats me why), but aumix does the job. It even does the job on the command line (but you are free to use the GUI and play with the buttons and sliders), so you can just do:
aumix -l R -l 75
Which sets the record channel to the line input of the audio card, and the record volume to 75. Then you should be able to record, which I do with:

mencoder -tv on:driver=v4l:device=/dev/v4l/video1: channel=27:width=768:h eight=576: fps=25 -vop lavcdeint,denoise3d=4:3:6 -oac mp3lame -lameopts abr=:preset=128 -ovc lavc -lavcopts vcodec=mpeg4:vbitrate=1500 -info name=test:artist=channel-27: genre=trash:subject=snippet:copyright=aRTee: srcform=teevee:comment='just testing' -frames 500 -o videocap.avi

See man mencoder for the right syntax and options (note that I have inserted extra spaces to avoid the lines getting too long; after none of the ":" should there be a space); the -frames 500 equals 20 seconds (25 frames per second) which I just put there for testing. With this bitrate you get 1 hour of video into 770MB or so. Play with the settings to get the right balance; the command I use is just here as an example and startingpoint. Also, this pushes my system to 92 - 98% load, quite high for an Athlon 2400+ (2GHz) CPU.... 

Per rivedere la roba registrata

Su Windows funziona bene Videolan Player (www.videolan.org).

Su Linux funziona bene mplayer (chei l'avrebbe mai detto?)

Per rivedere sul Kiss dp1500

Occorre registrare rispettando i vincoli imposti dal Kiss, a tal riguardo cito una mail del supporto tecnico:

All the divX certified (www.divx.com) and all the Xvid are supported. The only limitations are:
- The resolution: 720X576 (PAL) or 720X480 (NTSC). Except for DivX3.11: 352X288
- The bit rate: around 3MB/s (DivX-4, DivX-5 and Xvid) and 1,2MB/s (DivX-3,11 LM and DivX-3,11 FM). 
The only unsupported option in the video is the QPEL (in this case the player specify it). The QPEL (= Quarter Pixel) is one of the three options in divX Pro. The two others (GMC and B-vop) are fully supported. The C.P.U. of the player is not powerful enough to decode it, but anyway a TV screen cannot handle it.
DivX6 the new DivX version is now released. It is supported in all our players, as it is actually DivX 5.2.:
- Multiple sub: it works fine like on the previous divX:
- movie.avi
- movie.sub
- movie.srt
Use SUBPIC to switch from one file to another.
- Only feature not supported: DivX6 Menus: not supported (pack bit stream) – It is one .avi file containing the menu: WON’T be supported.

The only soundtrack formats supported are mp3 (CBR and VBR), ac3 and pcm. The Windows Media Audio (WMA, also called DivX Audio or Audio DivX) and Ogg Vorbis, that are only supported as stand-alone formats, are not supported because of a hardware limitation.
BivX (DivX with two audio tracks) can be played by the players, the AUDIO button on the remote is to switch between the two soundtracks.

Regarding MPEG files:
The mpeg1and mpeg2 files are supported in .mpg, .mpeg and .vob containers.
Max resolution: 720X576 (PAL) or 720X480 (NTSC).8
Max bit rate: 1,5 MB/s.
Please note that FF/RW is not supported on these files.

Dalle mie prove, risulta che:

  • E` fondamentale usare un filtro per deinterlacciare, altrimenti il panning fa pieta` e si vedono le immagini sdoppiate mente si muovono (negli esempi di seguito il filtro viene sempre usato, e` il pezzo di comando che dice "-vop pp=0x20000")
  • Il codec che funziona meglio con il Kiss sembra essere mpeg4, con il vincolo che occorre forzare il fourCC a "divx". Questo codec funziona bene e consuma poca CPU per cui posso encodare in realtime su un P4 2600 usando circa il 30% di CPU. Qui uso un bitrate di 2500KB/sec, ma di fatto si vede bene anche con 1500. Il massimo del Kiss e` 3000.
    • mencoder -quiet -endpos $DURATA:00 -ffourcc "divx" tv:// -tv driver=v4l2:channel=$CANALE:width=720:height=576:device=/dev/video0:buffersize=256:fps=25 
      -ovc lavc -lavcopts vcodec=mpeg4:vbitrate=2500 -vop pp=0x20000 -oac mp3lame -o /ud2/video/$NOME$DATA.avi
  • Funziona anche xvid, ma per avere un risultato decente occorre fare tre passaggi (prima si registra raw, poi due passaggi di codifica xvid, il che non puo` essere fatto in real time e consuma un casino di hard disk e anche di cpu. Riporto i tre comandi in sequenza, ma non lo consiglio.
    • mencoder -quiet -endpos $DURATA:00 tv:// -tv driver=v4l2:channel=$CANALE:width=720:height=576:device=/dev/video0
      :buffersize=256:fps=25 -ovc lavc -lavcopts vcodec=mjpeg  -oac mp3lame   -o /ud2/video/$NOME$DATA.temp.avi
      
      mencoder  -quiet /ud2/video/$NOME$DATA.temp.avi -ovc xvid -xvidencopts pass=1:par=pal43 -oac copy -o /dev/null
      
      mencoder  -quiet /ud2/video/$NOME$DATA.temp.avi -ovc xvid -xvidencopts pass=2:par=pal43:bitrate=3000 -oac copy -o /ud2/video/$NOME$DATA.avi
      
      rm  /ud2/video/$NOME$DATA.temp.avi
  • Funziona anche il DivX 3.11, ma la qualita` e` bassa e non lo consiglio.
  • I files piu` lunghi di 2 GB si leggono, ma hanno problemi nel seek (ovvero, oltre un certo punto il seek non funziona piu`, probabilmente c'e` un problema di overflow del contatore della dimensione del file)

Script per registrare

Questo e` uno scriptino che mi sono fatto per registrare da cron. Registra in formato mpeg4 (fourcc divx) che e` quello piu` riuscito fra quelli che ho trovato.

# Tvrecord, uno scriptino semplice per registrare dalla TV usando mencoder.

# Questo script, lanciato da Cron o in console, registra un dato canale per tot tempo
# e salva un file con un nome composto da un parametro dato in ingresso e data e ora di inizio
# della registrazione.

# I parametri sono:
#  Nome del file
#  canale TV
#  Durata della registrazione in formato HH:MM

NOME=$1
CANALE=$2
DURATA=$3
DATA=`date +%F`

if [[ $# != 3 ]]
then
        echo "Numero errato di parametri";
        echo "Uso: tvrecord <nome file> <canale> <durata>"
else
        echo $NOME, $CANALE, $DURATA, $DATA;
        mencoder -quiet -endpos $DURATA:00 -ffourcc "divx" tv:// -tv \
        driver=v4l2:channel=$CANALE:width=720:height=576:device=/dev/video0:buffersize=256:fps=25 \
        -ovc lavc -lavcopts vcodec=mpeg4:vbitrate=2500 -vop pp=0x20000 -oac mp3lame -o /ud2/video/$NOME$DATA.avi
fi

Stream server per il Kiss

Per usare il Kiss senza quel cesso di PC-Link che gira solo su windows, ho usato "Kissd", che seppure un po` instabile sembra essere il meglio che ci sia per Linux, e in effetti funziona.

Problemi noti

  • Occorre trovare un modo per fare funzionare il seek su files piu` lunghi di 2 GB, oppure un modo per registrare i files "a puntate" in modo da non superare mai i 2 GB.
  • Mentre sto registrando non posso rivedere il file che sto ancora registrando tramite il Kiss, quindi non posso fare "time-shifting" ma devo aspettare di finire la registrazione prima di rivederla.

LinuxDebian/MplayerMencoder (last edited 2009-04-12 17:33:25 by localhost)