Freevo

- Index
- AnalogTvConfig

# AnalogTvConfig

Site Index:

1. Intro
2. Btaudio
3. TV Line In
   1. Description
   2. OSS instructions
   3. ALSA
4. IVTV setup
5. Multi tv card info
6. Use frequencies in mencoder instead of channels

## Intro

There are three different types of Freevo Recording. Tv Line In, Btaudio and ivtv. The first two depend on using the bttv module for your tv card. The third is for use only with the ivtv module for the wintv PVR type cards.

## Btaudio

This process uses the sound from btaudio kernel module and the pictures from your bttv module. This is the preffered freevo setup for recording and the default settings in VCR_CMD reflect this.

This setup is problematic though since the majority of cards do not support btaudio and some cards only thought to work in certain configurations. Btaudio setup is its own topic and help can be found in the FAQ.

Once you have that setup you can change the default VCR_CMD's adevice to point to it.

This is also the best setup for doing timeshifting, thus it is recommended to really try hard to get this setup to work for you.

## TV Line In

### Description

This process using the line out sound from your tv card into the line in of your sound card for the sound and bttv for your pictures. This is a common bttv setup.

It has a couple inherit problems. First you will hear the program in the background when you are recording. And Second, You cannot run any apps that use the soundcard while recording (which pretty rules out everything except images and maybe running some scripts in commands plugin).

Another problem is that depending on your sound system you have to do different things to setup the recording.

VIA USERS: Note that if you have a VIA-based on-board sound card, you should uninstall the current drivers in your system and install the appropriate drivers found at http://www.viaarena.com . Then increase your IGain setting on your audio mixer to something greater than zero (ie: # aumix -l 0 -l R -i 35).

### OSS instructions

Typically you need to use something like the following to mute and unmute the audio:

    # to unmute the audio
    aumix -l 80 -l R

    # to mute the audio
    aumix -l 0

Unfortunately some Sound Blaster cards also need another variable tweaked when used with OSS. The soundblasters cards need and extra parameter (IGAIN) added to the aumix calls. for example:

    # to unmute the audio
    aumix -l 80 -l R -i 1

    # to mute the audio
    aumix -l 0 -i 0

Another variable that needs to change in the VCR_CMD is the adevice to /dev/dsp. You can do this by changing your VCR_CMD to a script setup similar to one here. (One good thing about controlling recording from a script is that it makes it easy to experiment from the command line.)

This can be done by using VCR_PRE_REC = 'command opts' and VCR_POST_REC = 'commands opts'

before freevo 1.5.x we could use

    VCR_CMD = ( 'aumix -l 80 -l R; '+
                CONF.mencoder + ' ' +
                blah

This doens't work anymore. An example how it should be confgred now

    VCR_PRE_REC = ('aumix -l 80 -l R; ')
    VCR_CMD = ( CONF.mencoder + ' ' +
                'tv:// ' +                      # New mplayer requires this.
                '-tv driver=v4l:input=0' +      # Input 0 = TV, Input 1 = Comp. V. in
                ':norm=%s' % CONF.tv +
                ':channel=%(channel)s' +        # Filled in by Freevo
                ':chanlist=us-cable' +          # Change
                ':width=%d:height=%d' % (TV_REC_SIZE[0], TV_REC_SIZE[1]) +
                ':outfmt=%s' % TV_REC_OUTFMT +
                ':device=%s' % TV_DEVICE +
                ':adevice=/dev/dsp' +
                ':audiorate=32000' +            # 44100 for better sound
                ':forceaudio:forcechan=1:' +    # Forced mono for bug in my driver
                'buffersize=64' +               # 64 Megabyte capture buffer, change?
                ' -ovc lavc -lavcopts ' +       # Mencoder lavcodec video codec
                'vcodec=mpeg4' +                # lavcodec mpeg-4
                ':vbitrate=1200:' +             # Change lower/higher, bitrate
                'keyint=30 ' +                  # Keyframe every 10 secs, change?
                '-oac mp3lame -lameopts ' +     # Use Lame for MP3 encoding
                'br=128:cbr:mode=3 ' +          # MP3 const. bitrate, 128 kbit/s
                '-ffourcc divx ' +              # Force 'divx' ident, better compat.
                '-endpos %(seconds)s ' +        # only mencoder uses this so do it here.
                '-o %(filename)s.avi ')         # Filled in by Freevo
    VCR_POST_REC = ('aumix -l 0')

### ALSA

To use alsa, the best way is to create to scripts that do the necessary changes for the sound before and after the vcr command. You can use the config variables VCR_PRE_REC and VCR_POST_REC for this. The two scripts, don't forget to make them executable (example : chmod +x /usr/local/freevo/scripts/vcr_pre_rec.sh)

    #!/bin/bash
    # VCR_PRE_REC script to set the line in volume and mute the sound so you don't hear it wehen recording

    AMIXER=/usr/bin/amixer          # path to amixer

    $AMIXER -q sset CD 87% mute
    $AMIXER -q sset Capture 87%
    $AMIXER -q cset numid=30 1      # select capture source, 30 is capture source control, 1 = CD, 3 =aux 4 = line
    $AMIXER -q cset numid=31 1      # set capture source switch to 1 (= on)

    #!/bin/bash
    # VCR_POST_REC script : unmute cd again to hear sound when using watching tv after recording

    AMIXER=/usr/bin/amixer          # path to amixer

    $AMIXER -q sset CD 87% unmute   # unmute cd again to hear sound when using watching tv after recording

The numid used are specific to the my sound card (Epia M onboard sound card), You will most likely need to change these variables. For my soundcard 'ceset numdid=30 1 ' is to select the CD as capture source (0 = mic, 1 = cd,3 = aux 4 = line) and numid=31 is the capture switch. Run "amixer controls" to get the numid's. Run "amixer cset numid=30" to get the capture source items (change numid=30 with yor capture source), Most people will use #4, the "line in". So use 'amixer cset numid=30 4' to select "line in" as capture. amixer cget numid=30 to see the devices you can select for capture (change numid=30 with yor capture source).

The next example shows you how to use these scripts with freevo and a vcr command example.

    VCR_PRE_REC = ('/usr/local/freevo/scripts/vcr_pre_rec.sh')
    VCR_CMD = ( CONF.mencoder + ' ' +
                'tv:// ' +                        # New mplayer requires this.
                '-tv driver=v4l:input=0' +        # Input 0 = TV, Input 1 = Comp. V. in
                ':norm=%s' % CONF.tv +            # TV norm (pal, ntsc, ..) from freevo.conf
                ':channel=%(channel)s' +          # Filled in by Freevo
                ':chanlist=%s' % CONF.chanlist +  # Change
                ':width=%d:height=%d' % (TV_REC_SIZE[0], TV_REC_SIZE[1]) +
                ':outfmt=%s' % TV_REC_OUTFMT +
                ':device=%s' % TV_DEVICE +
                ':adevice=/dev/sound/dsp' +
                ':audiorate=32000' +            # 44100 for better sound
                'buffersize=64' +               # 64 Megabyte capture buffer, change?
                ' -ovc lavc -lavcopts ' +       # Mencoder lavcodec video codec
                'vcodec=mpeg4' +                # lavcodec mpeg-4
                ':vbitrate=1200:' +             # Change lower/higher, bitrate
                'keyint=30 ' +                  # Keyframe every 10 secs, change?
                '-oac mp3lame -lameopts ' +     # Use Lame for MP3 encoding
                'br=128:cbr:mode=3 ' +          # MP3 const. bitrate, 128 kbit/s
                '-ffourcc divx ' +              # Force 'divx' ident, better compat.
                '-endpos %(seconds)s ' +        # Filled in by Freevo
                '-o %(filename)s.avi ')         # Filled in by Freevo
    VCR_POST_REC = ('/usr/local/freevo/scripts/vcr_post_rec.sh')

Example scripts for soundblaster live 5.1

    #!/bin/bash
    # VCR_PRE_REC script to set the line in volume and mute the sound so you don't hear it wehen recording

    AMIXER=/usr/bin/amixer          # path to amixer

    $AMIXER -q sset Line 87% mute
    $AMIXER -q sset Capture 87%
    $AMIXER -q cset numid=63 4      # select capture source, 63 is capture source control, 1 = CD and 4 = line
    $AMIXER -q cset numid=64 1      # set capture source switch to 1 (= on)

    #!/bin/bash
    # VCR_POST_REC script : unmute cd again to hear sound when using watching tv after recording

    AMIXER=/usr/bin/amixer          # path to amixer

    $AMIXER -q sset Line 87% unmute   # unmute cd again to hear sound when using watching tv after recording

See btaudio page for using alsa with snd-bt87x module (the alsa btaudio equivalent)

## IVTV setup

In order to use the ivtv recording plugin have the following in your local_conf.py:

    plugin.remove('tv.generic_record')
    plugin_record = plugin.activate('tv.ivtv_record')

Also for ivtv_record you may set some recording options:

    IVTV_OPTIONS = {
        'input'         : 4,
        'resolution'    : '720x480',
        'aspect'        : 2,
        'audio_bitmask' : 233,
        'bframes'       : 3,
        'bitrate_mode'  : 1,
        'bitrate'       : 4000000,
        'bitrate_peak'  : 4000000,
        'dnr_mode'      : 0,
        'dnr_spatial'   : 0,
        'dnr_temporal'  : 0,
        'dnr_type'      : 0,
        'framerate'     : 0,
        'framespergop'  : 15,
        'gop_closure'   : 1,
        'pulldown'      : 0,
        'stream_type'   : 10,
    }

    # Please see freevo_config.py for details.

You also have to configure the video groups, this wasn't needed before freevo 1.5.0

    VIDEO_GROUPS = [
       VideoGroup(vdev="/dev/video0",
          adev=None,
          input_type='tuner',
          input_num=4,
          tuner_norm=CONF.tv,
          tuner_chanlist=CONF.chanlist,
          desc='Cable',
          group_type="ivtv",
          recordable=True),
       ]

VCR_PRE_REC and VCR_POST_REC can be used with ivtv setup. You don't need the VCR_CMD for ivtv.

## Multi tv card info

- Someone needs to explain the mutlicard stuff..

## Use frequencies in mencoder instead of channels

The channel list is a convention on which frequencies are allowed to be broadcasted in some countries. Cable operators need more channels and have the possibility to use frequencies which are not allowed for Antenna transmission. (Frequencies, used by the military, is such a exemple). So first you need to add the non-standard frequencies to you're local_conf.py file. This is a illustrated example of my TV_CHANNELS settings

    TV_CHANNELS = [
        ( 'bbcworld', 'BBC World', 'bbcworld' ),
        ( 'bbc1', 'BBC1', 'bbc1' ),
        ( 'bbc2', 'BBC2', 'bbc2' ),
        ...

The last parameter of every item in the list will be mapped to a frequency

So this is a part of my FREQUENCY_TABLE The frequencies are in Khz

    FREQUENCY_TABLE = {
         'bbcworld' : 294250,
         'bbc1': 266250,
         'bbc2': 273250,
         ...

Check with you're local cable tv supplier (website?) to find out.

This would work correctly with Tvtime, but not with mencoder. As you see in this example, it will try to pass a channel parameter I have defined in freevo to mencoder

    2004/07/28 22:40 CEST [*RecordServer*] popen
    /usr/bin/mencoder tv:// -tv driver=v4l2:input=0:norm=pal:channel=bbcworld...

A channel setting mencoder doesn't understand.

Basically a tvtuner will tune in with a specific frequency and is not aware of channels. Channel descriptions are different, regarding the standard (pal,secam,ntsc) or the country you're living in. As I described above, Cable operators don't have to follow these conventions, cause they where designed with antenna broadcast in mind.

I've modified the VCR_CMD to use a frequency instead of channels. The mencoder recording program supports the use of freq instead of channels.

    #           ':channel=%(channel)s' +        # Filled in by Freevo
    #           ':freq=%(frequency)s' +        # Filled in by Freevo
               ':freq=%(frequencyMhz)s' +

The frequency in Khz defined in FREQUENCY_TABLE needs to be divided by 1000, since mencoder uses the frequency in Mhz

To be able to introduce the parameter frequencyMhz, wich is identical to default parameter frequency, except it's using Mhz instead of Khz as required by mencoder I modified the file ....freevo/tv/plugins/generic_record.py

These are my modifications

     def Record(self, rec_prog):
            frequency = self.fc.chanSet(str(rec_prog.tunerid), 'record plugin')
           # modif gedeco
            frequencyT = str(frequency)
            frequencyT1 = len(frequencyT)
            frequencyleftpointer = frequencyT1-3
            frequencyA = frequencyT[0:frequencyleftpointer]
            frequencyB = frequencyT[frequencyleftpointer:frequencyT1]
            frequencyMh = frequencyA + '.' + frequencyB
            frequencyMhz = str(frequencyMh)
           # end modif gedeco
            rec_prog.filename = tv_util.getProgFilename(rec_prog)

            cl_options = { 'channel'  : rec_prog.tunerid,
                           # modif gedeco
                           'frequencyMhz' : frequencyMhz,
                           # modif gedeco
                           'frequency' : frequency,

A python programmer will find this probably a kludge --- which it is. I'm not a programmer. So somebody capable of streamlining this, go ahead. But using the frequency would be a much better way to drive mencoder, cause both are depending on different channel lists. Made to confuse.

Thnx to Mick, who put me on the right track

last edited 2005-01-16 21:13:24 by BHeremans
current version: http://freevo.sourceforge.net/cgi-bin/doc/AnalogTvConfig