# ---------------------------------------------------------- # TV ENCODE! -- VERSION 1.4 # # ... a simple script for recording television (or aux in # video) through a video capture (tv) card. # ---------------------------------------------------------- # COPYRIGHT # # TV ENCODE! Copyright (C) 2005,2006,2007,2009 # V. Spinelli, G. Davey # This program comes with ABSOLUTELY NO WARRANTY; # This is free software, released under GNU GPL, # and you are welcome to redistribute it. # # Author: V. Spinelli # Handle: PoweredByDodge # Email: Vince@SpinelliCreations.com # GBDavey@Verizon.net # # CITATION # # tv_encode! is an original work of G. Davey, # expanded upon by V. Spinelli into TV_ENCODE! # # GNU GPL # # This file is part of tv_encode_1.3.r.tar.gz # # TV ENCODE! is free software: you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by # the Free Software Foundation, either version 3 of the License, or # (at your option) any later version. # # TV ENCODE! is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. # # You should have received a copy of the GNU General Public License # along with TV ENCODE!. If not, see . # ---------------------------------------------------------- # NOTE # # This is Linux friendly only; that is to say that while # a Windows version of Mencoder does exist, this script # does not jive with it 'out of the box'. # ---------------------------------------------------------- # INITIAL SETUP # # You must have the following installed and configured prior # to attempting to use this script: # 1- MPlayer (with MEncoder) # ... available from www.mplayerhq.hu # ... rpm versions or compile from source # 2- LAME MP3 Encoder # ... available from lame.sourceforge.net # ... MUST compile from source # 3- VIDEO FOR LINUX (v4l) # ... will need v4l or v4l2 (most devices # now use v4l2). # ... available from linux.bytesex.org/v4l2 # ... note: is built into kernel 2.5.x up # 4- A v4l(2) compatible tv capture card # ... includes multiple interfaces from # PCI to USB to PCI-E, etc. # 5- A minimum of roughly 1.5 GHz CPU in order # to get any sort of worthwhile output. # 6- THE CORRECT PATH! # ... add the parent directory of all # these scripts to your ~/.bash_profile # and to your /etc/crontab Path variable! # ... example in crontab --> # # SHELL=/bin/bash # PATH=/sbin:/bin:/usr/sbin:/usr/bin:/opt/tv_encode # # ... where '/opt/tv_encode' is the location of # tv_encode.sh, options.sh, and # all that good stuff. # ---------------------------------------------------------- # CONFIGURATION # # You MUST edit (using a text editor such as VI, Gedit, # Emacs, or other) 'options.sh' before using this script. # # DO NOT edit any other files without a clear understanding # of their operation -- editing is not reccomended, period. # ---------------------------------------------------------- # EDITING options.sh # # Below are all of the fields that you will find in # the file options.sh, and an explanation of how to # edit them. Also, some explanation of 'why, and what' # is included. ## PATH MENCODER # PATHMENC=/usr/local/bin/ # This is the path that you must use to get to # mencoder. # If you do not know your path, simply go to # a terminal window and start guessing. # Type [abc@123]$ /usr/bin/mencoder # ... if nothing comes up, that's not it. # Then try [abc@123]$ /usr/sbin/mencoder # ... no luck? # Try [abc@123]$ /usr/local/bin/mencoder # # The default for most installations of MPlayer # (which includes MEncoder) should be # /usr/local/bin/ , and that is why it is our # default choice. # # If you still have no luck, pull up the # documentation for both your distribution of # Linux and your distribution of MPlayer/Encoder. ## TEMPORARY OUTPUT FILES # TEMPFILES=/opt/tv_encode/tv_temp/ # This is where you're going to write files as # they are being recorded. ## PERMANENT FINAL LOCATION FOR OUTPUT FILES ## - Could be on a local home server ## - Could be another physical drive on the same machine ## - Must NOT be the same as TEMPFILES # PERMFILES=/opt/tv_encode/tv_out/ # This is where you want your files to end up once # they are finished recording. ## PRIORITY # NICEVAL=-5 # When recording, it is important that MEncoder be # given priority above other applications. For example, # say we are recording, and then during recording your # antivirus software decides it is time for a system scan. # If MEncoder does not have priority, the antivirus program # will use up most of your CPU power, and MEncoder will # likely not be able to record your television show. # On slower computers, it surely will not be able to. # # Reccomended nice value is ' -5 ' to ' -10 ' # Please note that nice values work in reverse, so if you # want MEncoder to be 5 points more important, then you # must enter ' -5 ', not ' 5 '. A value of ' 5 ' (plus 5) # would result in MEncoder being 5 points LESS important! ## TV CARD DRIVER # TVDRIVER=v4l2 # Select ' v4l2 ' or ' v4l ' depending on what matches up # with your tv-tuner. Just about everything is happy with # ' v4l2 ' , and that is why it is our default. See # VIDEO FOR LINUX documentation available at their website # for more information. ## REGION # REGION=NTSC # CHANNELS=us-cable # FPS=29.97 # Choose your region (PAL, NTSC, other), this is the format # of what your television provider broadcasts. # Choose your channel lineup format. It may be us-cable, # us-broadcast, or one of a million other possibilities for # various other countries. See v4l documentation! # FPS = frames per second... dependant on Region, so make # sure they match up. # # This 'default' REGION setup is for NTSC broadcasts in the # UNITED STATES over CABLE. ## VIDEO # WIDTH=640 # #WIDTH=400 # HEIGHT=480 # #HEIGHT=300 # This is the resolution of your image. Ideally, over NTSC, # you would set this to 720 width and 576 height. However, # that'll require a good deal of CPU power to keep up at any # great framerate. # # Provided you maintain a 4 to 3 ratio of width to height, # and both your width and height can be divided by 16 without # a remainder, then you can choose any resolution you like # (assuming your video card can handle it). # # For example, a Philips 7133/4 Chipset tv tuner has a max # width of 700. It can be happily operated at 640 width # and 480 height, providing you with a very very good quality # recording! # # For slower machines, you may want to decrease the image size, # thereby saving you CPU usage. The minimum reccomended (this # will provide 'VCR - magnetic tape' grade recordings or possibly # a little worse) is 400 width by 300 height. # VBITRATE=600 # This is the bitrate of your video, accounting for # frames per minute I believe. # # 600 is the absolute bare minimum for decent video # quality. 1798 would be ideal (60 seconds * 29.97 # frames per second) for NTSC. # This also has a great effect on CPU usage. # # VCODEC=mpeg4 # Codec to record with. Mpeg4 is Divx/Xvid FFDShow # friendly. Snow may also be used, however it # is still experimental and has not proven well in # testing. # BUFFER=160 # Size of recording buffer. Minimum of 64 MB, # but do not use a value larger than 75% of your # system memory (RAM). # BRIGHTNESS=10 # CONTRAST=0 # Often, tv tuners pick up television as # darker than it actually is. So we've # boosted brightness slightly. # VFILTER=lavcdeint,harddup # lavcdeint tells MEncoder to # deinterlace the broadcast # before recording. TV is # broadcast in 480i or 1080i # (low or high definition), # where the 'i' stands for # interlaced. If you record # this material 'as is', then # you will have horizontal # lines like stripes throughout # your recording. Deinterlacing # fixes that problem. # harddup tells MEncoder to # hard drop frames if necessary. # Sometimes, MEncoder will need # to drop a few frames here or # there to keep up with the # recording process. Sans # harddup may result in choppy # video portions. # V4MVYN=no # TRELLYN=no # v4mv and trell... # Both deal with advanced encoding # compensating for motion sensing. # High motion (rapid motion) video # is often best encoded with both # of these options set to 'yes'. # However, these options both use # a good deal of CPU power, so # by default, they are set to 'no'. ## AUDIO # SAMPLEIN=32000 # #SAMPLEIN=44800 # #SAMPLEIN=44100 # Input audio sample rate of your television card. Ideally, # you would sample at 44.1 k (44100), however, some cards # will cause errors with audio / video synchronization over # longer recordings with this value. So, look up the # documentation for your tv tuner card, and find out whether # it works best at 32 k (32000), 44.8 k (44800), or 44.1 k. # Then set SAMPLEIN to that value (must use the xxx00 format, # not the xx.x k format). # ABITRATE=128 # This is the bitrate at which you would like to record the # audio portion of your television programs. This is # constant bitrate MP3 audio that will be part of the output # avi mpeg4 file. 128 is reccomended minimum (good for low # power CPU), and 320 is the max (high horsepower), but other # options include 160, 192, and 256. # AFILTER=lavcresample=44100 # Your audio from 'SAMPLEIN' above, must be resampled at # a rate of 44100 or else it will not encode properly as # an MP3. IT IS NOT RECCOMENDED TO CHANGE THIS SETTING # UNLESS LAME DOCS ADVISE YOU TOO! # PROCESSING # # ---CPU THREADS--- # # ----------- # ---single core cpu 1 # # ----------- # ---single core cpu w/HT 2 # # ----------- # ---dual core cpu 2 to 4 # # ----------- # ---dual core cpu w/HT 4 to 8 # # ----------------- # THREADSQ=1 # #THREADSQ=2 # #THREADSQ=4 # #THREADSQ=8 # # This defines the number of execution threads you want to # issue to the processor(s). If you have a dual core CPU # and have THREADSQ set to 1, then you will only use half # of your processor (one core). Single core CPUs, with or # without HyperThreading (HT) usually work best at 1 THREADQ, # while dual core CPUs perform best at THREADQ = 4. You # may use 8 threads if doing performance high framerate stuff. # ---------------------------------------------------------- # USING TV ENCODE! (finally~) # Ok, so you just spent the last 30 minutes to an hour setting # everything up. Now you're ready to test your recording # abilities. # First, you must know that there are two ways to use # TV ENCODE!. # -- call it for regularly scheduled programs! # -- -- [path] ./tv_encode.sh REGULAR CHANNEL DURATION(minutes) NAME # -- call it for 'just once' or special programs! # -- -- [path] ./tv_encode.sh SPECIAL CHANNEL DURATION(minutes) NAME # ------ RECORDING OFTEN ------ # 1 - inside of your PERMFILES directory, create a # directory for each show you will be recording # on a regular basis. # ex. /opt/tv_encode/tv_out/deal_or_no_deal # /opt/tv_encode/tv_out/stargate_sg1 # /opt/tv_encode/tv_out/oprah # 2 - edit your /etc/crontab file, creating a cron-job # for each show to be recorded regularly. # ex. the following added to /etc/crontab # and obviously remove the single '#' comment # mark in front of each line. ## -- Deal or No Deal -- 10 pm to 11 pm Mon through Fri #00 22 * * 1,2,3,4,5 root /opt/tv_encode/tv_encode.sh REGULAR 4 59.9 deal_or_no_deal ## -- Oprah -- 4 pm to 5 pm Mon through Fri #00 16 * * 1,2,3,4,5 root /opt/tv_encode/tv_encode.sh REGULAR 26 59.9 oprah ## -- Stargate SG1 -- 9 pm to 10 pm Thursday only #00 21 * * 4 root /opt/tv_encode/tv_encode.sh REGULAR 35 59.9 stargate_sg1 # 2a - the result will be that you will have the following # files created over a week's time... # ex. /opt/tv/out/deal_or_no_deal/deal_or_no_deal_on_Monday_Jan_1_2007.avi # /opt/tv/out/deal_or_no_deal/deal_or_no_deal_on_Tuesday_Jan_2_2007.avi # /opt/tv/out/deal_or_no_deal/deal_or_no_deal_on_Wednesday_Jan_3_2007.avi # /opt/tv/out/deal_or_no_deal/deal_or_no_deal_on_Thursday_Jan_4_2007.avi # /opt/tv/out/deal_or_no_deal/deal_or_no_deal_on_Friday_Jan_5_2007.avi # /opt/tv/out/oprah/oprah_on_Monday_Jan_1_2007.avi # /opt/tv/out/oprah/oprah_on_Tuesday_Jan_2_2007.avi # /opt/tv/out/oprah/oprah_on_Wednesday_Jan_3_2007.avi # /opt/tv/out/oprah/oprah_on_Thursday_Jan_4_2007.avi # /opt/tv/out/oprah/oprah_on_Friday_Jan_5_2007.avi # /opt/tv/out/stargate_sg1/stargate_sg1_on_Thursday_Jan_4_2007.avi # ------ ONE TIME RECORDING AND SPECIALS ------ # 1 - the call is... # /opt/tv_encode/tv_encode.sh SPECIAL [channel] [record time] [name of show] # ... for a record time of 30 minutes, I reccomend # using a value of 29.9, this will cut 6 seconds off # the end of the show, but it will allow the system to # recover and finish up before starting to record another # show (if you have shows recording back to back). # ... for an hour, 59.9 --- you get the idea. # ... make sure your 'one time' recordings do not overlap # with your regularly scheduled recordings in /etc/crontab. # You can't record two things at the same time! (unless you # have two tv capture cards and enough CPU power to do it). # 2 - to start recording immediately, use: # /opt/tv_encode/tv_encode.sh SPECIAL [channel] [record time] [name of show] # ex. /opt/tv/scripts/tv_encode_t1a.sh 46 59.9 colbert_report # 2a - the result will be as follows: # ex. /opt/tv/out/colbert_report_on_Thursday_Jan_11_2007.avi # 3 - use the 'at' command in Linux to record ONCE at a scheduled time: # ex. [abc@123]$ at MMDDhhmm /opt/tv_encode/tv_encode.sh SPECIAL 32 29.9 law_and_order # DOES NOT WORK -- NEEDS FIX or WORKAROUND! # ... the 'at' command will not allow you to pass options # to the script that you are scheduling. # Therefore, it ignores 32, 29.9, and law_and_order, which makes our # attempt to record useless. # FURTHER DOCUMENTATION OF HOW TO PROPERLY USE THE 'at' COMMAND # FOR THIS PURPOSE IS REQUIRED! # ----------------------------------------------------------