TV Capture

Summary

  • Television video and audio robust in live tv on clitunno -- tvtime for local viewing, xawtv or motv remote.
  • Recording works for both audio and video, in sync, using the channel script in /usr/local/bin:
    channel  <channel number> <recording time in minutes> <optional title> <optional card>
  • However, the bttv driver seems to deliver significantly better quality than the cx88 driver, so don't use the analog driver for the pcHDTV cards.
  • Note that mencoder supports -ovc nuv for nuppelvideo -- may be worth experimenting with this
  • Use kcron to set up recording jobs.

Issues
  • is it possible to instruct v4l to return timestamps based on CLOCK_MONOTONIC instead of CLOCK_REALTIME, which gettimeofday() uses? It would simplify capturing the video as now one has to disable tools like ntp during longer captures to ensure the a/v sync will be reliable. (I didn't know this and don't quite know what to do about it.)
  • System clock jitter is far from being the only source of A/V de-synchronization. The difference between the nominal and true sampling frequency in whatever sound capture device is used, can be worse.  We have a 24/7 video capture system, on which
    • (1) we use ntp
    • (2) trust the system clock (system, audio and video clocks are somewhat unreliable, so you have to trust one of them)
    • (3) drop or synthesize video or audio frames as needed to keep the 2 encoded fluxes synchronous with the system clock
    • (4) the software is resistant to large skips in the system clock (one test involves resetting the clock back by 1 hour!).

Guides and software

  • Systems
  • pcHDTV
    • DVB with the pcHDTV HD3000 (excellent instructions for Debian sid and kernel 2.6.12 from Sep 05)
    • cx88 video capture chip
      • Documentation/video4linux/README.cx88
    • pcHDTV wiki on LinuxTV (very useful)
    • pcHDTV (review)
      • forum
      • success report (19 Feb 2005)
        • Select Scan for Channels,  choose full scan, select ATSC transport as "Cable" instead of Terrestrial
        • Reception issues (with local discussions)
      • patches added to the dvb portion of the kernel
        • add support for OR51132 frontend (pcHDTV HD-3000), by Gerd Knorr on 13 March 2005
        • DVB support for the pcHDTV HD2000 card submitted by Rusty Scott (late April)
        • This suggests we can use the DVB driver rather than the v4l driver...!
      • patches added to v4l by David George <david@thegeorges.us>
      • pcHDTV-1.6 from vendor
        • README: Drivers under kernel-2.6.x have been tested against kernel 2.6.9 but should work for younger 2.6 kernels.  There appear to be significant changes happening in 2.6.10 to the PCI interface and we are told this driver has troubles compiling in 2.6.10.  We are doing our best to provide support, but we have purposely chosen to stay away from the bleeding edge.
        • Conclusion: 
          • stick with 2.6.9-ac6 and install the driver there (but current setup is working flawlessly), or
          • leave off for now and wait until 2.6.11 or even 12 is out, then wait for driver to be ready
      • Bryan J. Smith's comments -- he says unencoded HDTV is 19.2Mb/s or 2.4MB/s -- that's 8.5GB/hr
        • He advises using the Netcell disk array, but it's not necessary
    • pchdtvPVR by Merrick Johnson <inkling@nop.org>
    • Test the digital part of pcHDTV -- see /usr/share/doc/xine/README.dvb.gz for using xine to watch digital tv (HDTV is a US/Korean version of DVB)

  • Watching TV
    • mplayer
      • mplayer - < /dev/video0
      • mplayer tv:// -tv driver=v4l2
    • xawtv
      • xawtv -remote -noxv (watching remotely -- works without the -remote switch too)
      • xawtv -remote -noxv -c /dev/video0 -C /dev/vbi0
      • motv -remote -noxv -c /dev/video2 -C /dev/vbi2
      • cvs
    • xdtv
      • FAQ with suggestions on testing display modes
      • don't use the tv-fonts in this package -- conflicts with main tv-fonts
    • kdetv (unofficial Debian packages available, but not for amd64; you could build from source)
    • fbtv (frame buffer)
    • motv
    • aatv
    • tvtime
    • zapping (Gnome TV viewer)

  • Recording
  • ffmpeg manual
    • ffmpeg -vd /dev/video0 -r 29.97 -b 2048 -s 720x480 -t 60 video.mpg (poor sync)
    • ffmpeg -vd /dev/video2 -f avi -vcodec h264 -r 29.97 -b 800 -s 640x480 \
      -ad /dev/dsp2 -acodec mp3 -ab 64 -t 10 video.avi (works, drops frames)
      • try -acodec pcm_s16be -ar 8000 for mov files
      • ffmpeg -ad /dev/dsp1 -ac 2 -ar 48000 -target dvd test.mpg
    • if ffplay can play a file, you can convert it to dv using "ffmpeg -i your.avi -vcodec copy new.dv"
  • aspect ratios and frame sizes
  • cat /dev/video0 >dev_video0.mpg (untested, said to work)
  • mencoder
    • from analog tv to mpeg2: $ /usr/bin/mencoder -tv driver=v4l2:input=0:
      width=768:height=576:outfmt=yv12:device=/dev/video0:adevice=/dev/dsp2: audiorate=44100:forceaudio:forcechan=2:buffersize=512 -ovc lavc -lavcopts
      vcodec=mpeg2video:vbitrate=5000 -oac mp3lame -lameopts cbr:br=128:
      mode=0  -o tv--10.11_2313.avi tv://
  • motv
  • record (sound only)
    • krecord -- cvs
  • streamer (good for debugging)
    • streamer -n ntsc -t 0:10 -s 640x480 -r 30 -o stream.avi -f mjpeg -F stereo -c /dev/video1 -C /dev/dsp1
  • transcode v4l2 import module
    • man transcode
  • xmltv (xmltv-gui, xmltv-util) -- program guide
  • xdtv lets you record TV directly to divX5 or libavcodec and lame (see FAQ)
    • feature for setting up cron jobs for recording
    • descrambler: a plugin allows you to watch encrypted channels
  • nvrec (barely maintained)
    • download (old download)
      • run clitunno:/share/software/tarballs/nvrec-20041227/configure to see dependencies
    • building for Debian
    • nuppelrec -v /dev/video0 -ua OSS -d /dev/dsp1 -input Television  -o /var/tmp/test.nuv
    • usefully combines with transcode; see /usr/share/doc/transcode/import_nvrec.txt.gz
    • reputed to be good at keeping video/audio sync
    • not updated for amd64 and wrong dependencies in Debian
      • deb http://www.esat.kuleuven.ac.be/~mleeman/debian unstable/
  • pchdtvPVR
  • VCR -- command-line video capture program, in Debian (not maintained)
  • VDR and KVDR (the KDE GUI) -- PC as video recorder, require DVB
  • home-made bash scripts, currently using mencoder
    • channel script -- see /usr/local/bin/channel and /ssa/TV/scripts/testing/channel.sh
    • channel-timestamp script -- see /usr/local/bin and /ssa/TV/scripts/testing
    • Note that cron's PATH must include /usr/local/bin (see kcron Variables)

  • Scheduling
  • cron is currently used for scheduling
    • frontend kcron is nearly perfect -- but schedules in 5-min intervals
    • add a job: crontab -l > cronjobs; cat newjobs >> cronjobs | crontab cronjobs
  • usermin-cron has a great interface, with 1-minute intervals -- and it's better to do this on the web
    • solutions:
      • in the pilot phase, only you set the schedules -- use kcron and crontab -e
      • for demonstratins, stick with 5-minute intervals and use kcron
      • pay to get kcron to support 1-minute intervals (already bugreported)
      • install usermin and train people to do the scheduling online -- this is the best solution
  • freeguide would probably be an even better choice -- could write to cron or to pycron
  • Playing back
    • mplayer -vo xv *mpg
    • -speed <0.01-100> (Slow down or speed up playback by the factor given)
    • -sstep <sec> (display one frame every <sec> seconds -- slideshows, slowmo)

  • Making clips
  • avidemux
  • ffmpeg -ss 00:01:00.0 -t 00:01:00.0 -i some.mpg -vcodec dvvideo -sameq -async 1 > 1minute.dv
  • kmenc15 (gui for mencoder -- most useful for editing and encoding large high quality AVIs capped from TV. Allows cutting and merging at exact frames, applying filters and preview.)

  • Storage and access
  • imgSeek -- image viewer and manager (in debian)
  • annodex -- annotating and indexing networked media
    • Continuous Media Markup Language (CMML) -- in Debian:
      • cmml-tools
      • libcmml0
      • libfishsound1 -- for reading CMML files
  • kimdaba -- Kde tool for indexing, searching and viewing images by keywords

Commands

  • Configuration
  • insert the kernel modules
    • modprobe bttv i2c_debug=1 card=13 radio=0 tuner=2
    • modprobe btaudio analog=1 dsp1=1 dsp2=2 debug=1 rate=32000
    • modprobe bttv i2c_debug=1 card=11,22 radio=0  tuner=33,44 (for two cards)
  • check and set the audio channels
    • amixer controls
    • amixer scontrols
    • amixer -c 0 cget numid=18
    • amixer -c 0 cset numid=18 100%,100% unmute cap
    • alsactl restore
    • alsactl store
    • dump-mixers (show mixer values)
    • cat /proc/asound/version (check ALSA version used)
    • arecord -d 5 -N -vvv foobar.wav (see man arecord)
      • aplay foobar.wav
  • tune the card from console:
    • tvtime-scanner
    • scantv -c /dev/video2 -C /dev/vbi2 (see available stations)
    • v4lctl -c /dev/video2 list
    • v4lctl setnorm ntsc-m
    • v4lctl setfreqtab us-cable
    • v4lctl setfreqtab us-bcast
    • v4lctl setchannel 3
    • v4lctl volume mute off
    • v4lctl setattr automute on (sets a two-second automute on channel switching)
    • v4lctl volume 100
    • v4lctl audio stereo
    • v4lctl -c /dev/video0 setattr 'chroma agc' on (bttv only)
    • settings for pcHDTV cards:
      • v4lctl -c /dev/video0 hue "100%"   (or "0%" -- same thing)
      • v4lctl -c /dev/video1 bright "50%"
      • v4lctl -c /dev/video2 contrast "45%"
      • v4lctl -c /dev/video0 color "100%"
      • Note that the /dev/video1 card needs only color "50%"
    • V4Lmark (performance benchmark?)
  • test video
    • xawtv -hwscan
  • test overlay mode (capture card controls display -- easy on CPU)
    • -noxv -capture overlay
    • -v4l1 -capture overlay
    • -xvtv -capture overlay
    • -xvtv_overlay on -capture overlay
    • -xvtv_overlay off -capture overlay
  • test grabdisplay mode (application controls display -- required for deinterlacing and other effects)
    • -noxv -capture grabdisplay
    • -v4l1 -capture grabdisplay
    • -xvtv -capture grabdisplay
    • -xvtv_overlay on -capture grabdisplay
    • -xvtv_overlay off -capture grabdisplay

  • Debugging
  • v4l-info
  • id -a (list groups you're a member of)
  • atscpackets /dev/video0 3 (on KnoppMyth -- not in Debian)
  • xawtv -hwscan  and xawtv -xvport xxx (xxx as result of hwscan)
  • aumix -q (see available channels)
    • aumix -h
    • aumix -i 10 (set the input gain)
    • aumix -d /dev/mixer1 -2 R  (set recording to Line2 on the TV card mixer)
    • aumix -d /dev/mixer1 -2 50 (set recording volume to 50% on Line2)
    • kmix
  • black screen on pcHDTV -- rmmod cx8800 cx8802 cx88xx and insert them again

  • Viewing
    • Play the video coming in on the capture device (see the video4linux-list for more hints):
      • cat /dev/video0 | xine -
      • cat /dev/video0 | mplayer -nocache -
      • basically you can pipe it to any application
    • Remote
      • ssh clit xawtv -remote -noxv (try without the -remote switch)
      • remote sound -- see nas under Sound
    • Playback of captured file
      • mplayer -autosync 30 (fixes minor sync problems from mencoder captures)
      • kplayer (under Settings | Configure kplayer | Advanced | Additional commandline arguments:
        • -autosync 30
  • Capture
  • ffmpeg -vd /dev/video0 -r 29.97 -b 2048 -an -s 720x480 -t 10 video.mpg
    • be sure to specify threads=2 in the ffmpeg.cfg file
    • ffmpeg -s 176x144 -i f%d.yuv -o f.avi  (concatenating several files into one)

  • transcode v4l2 import module
    • transcode -x v4l2 -o tvtest.avi -f 29.970 -i /dev/video0 -y ffmpeg -F mpeg4 -p /dev/dsp -b 128
      -g 720x480 -I 1 --print_status 20 -u 128 -c 0-60:00 -H 0 -w 1500 -q 1 -J hqdn3d=pre=1,smartyuv
      • this is tested and works (5 March 2005)
      • Sync is fine -- but you could try this if there's a persistent problem
        • -T 2,15 -- resync when audio differs from video by at least 2 frames and check every 15 frames
      • Try -y xvid or -y xvid,null without audio
      • -J hqdn3d=pre=1 -- High Quality 3D Denoiser
      • -J smartyuv -- Smart YUV Deinterlacer Test Filter Settings
      • Make sure -J values (import filters) are concatenated (give -J once and use commas, as above)
      • duration in frames or hours, minutes, and seconds: -c 0-01:05:00
      • -q 2 -- verbose debug level
    • -x mplayer,mplayer -- use mplayer as import filter
  • mencoder capture commands
    • timelapse
    • use ~./mplayer/mencoder to set configuration defaults
    • mencoder -ovc help
    • Active
      mencoder -tv driver=v4l2:width=640:height=480:norm=ntsc:device=/dev/video$DEV
      -ffourcc DIVX -fps 29.97 -ovc lavc -lavcopts vcodec=mpeg4:vhq -oac mp3lame
      -lameopts cbr:br=128 -endpos $TIM -o $DIR/$FIL.mpg tv:// > /dev/null
    • Ed Gomez' mencoder onepass:
      mencoder -ovc xvid -xvidencopts max_bframes=2:bquant_ratio=150:
      bquant_offset=75:bf_threshold=0:chroma_me:vhq=1:trellis
      -vf crop=704:416,scale=500:270 -sws 9
      #:qpel:quant_type=mpeg:turbo:cartoon:me_quality=1
      -oac mp3lame -lameopts cbr:br=96:q=0:aq=0:mode=1 -o output.avi
    • Ed Gomez' mencoder xvid 2-pass:
      mencoder -ovc xvid -xvidencopts
      max_bframes=1:bquant_ratio=150:bquant_offset=100:bf_threshold=0:
      chroma_me:vhq=4:trellis:qpel:bitrate=700
      -vf crop=704:416,scale=500:270 -sws 9
      #quant_type=mpeg:turbo:cartoon:me_quality=1:packed
      #-rawvideo on:format=I420:w=352:h=288 -fps 30
      -oac mp3lame -lameopts cbr:br=96:q=0:aq=0:mode=1 -o output.avi
    • Guillaume Poirier's two-pass benchmark:
      Filters: -vf crop=688:448:18:60,pp=fd,scale=480:288 (this speeds encoding quite a bit)
      XviD options:  max_bframes=2:me_quality=6:chroma_me:chroma_opt:trellis:\
      closed_gop:hq_ac:vhq=4:bvhq=1:autoaspect:psnr:bitrate=900
      Source: MPEG-2 (PAL DVD)  518,960 secs, 12975 frames
    • mencoder -tv driver=v4l2:width=720:height=480:norm=ntsc-m -ovc xvid
      -xvidencopts bitrate=900 -oac mp3lame -lameopts cbr:br=128 -endpos
      $TIM -o $DIR/$FIL.mpg tv:// > /dev/null
    • mencoder -tv driver=v4l2:width=720:height=480 -ovc lavc -lavcopts vcodec=mpeg4:vbitrate=900
      -oac mp3lame -lameopts cbr:br=64 -o output.avi tv://
    • mencoder -tv  on:driver=v4l:device=/dev/video0:norm=NTSC:width=320:height=240 -oac copy -ovc lavc
      -lavcopts vcodec=mpeg4:vbitrate=800 -vop pp=lb -endpos $2 -o $f.avi 2> /dev/null > /dev/null
    • encoding a tv-captured file to H264 (use threads=1 for single processor):
      mencoder 2*avi -o /dev/null -oac copy -ovc x264 -x264encopts \
          pass=1:bitrate=400:bframes=3:subq=2:threads=2
      mencoder 2*avi -o out.avi -oac copy -ovc x264 -x264encopts \
          pass=2:bitrate=400:bframes=3:subq=6:threads=2:frameref=4:8x8dct
    • encoding to H264 (2 pass, lots of features):
      mencoder -ss 00:00:00.400 -frames 1000 -sws 9 -vf crop=720:416:0:82,
      scale=640:256,harddup source.vob -ovc x264 -x264encopts pass=1:
      qp_constant=22:cabac:deblock:frameref=3:subq=4 -o NUL: -passlogfile "x264_2pass.log"
      mencoder -ss 00:00:00.400 -frames 1000 -sws 9 -vf crop=720:416:0:82,
      scale=640:256,harddup source.vob -ovc x264 -x264encopts pass=2:
      bitrate=650:cabac:deblock:frameref=3:subq=5 -of avi -ffourcc VSSH -o output.avi -passlogfile "x264_2pass.log"
  • mencoder HDTV capture
    • First pass:
      mencoder -vfm ffmpeg <hdtv-1080i-mpeg-ts-file> -tsprog 1 -vop hqdn3d=4:3:3,
      scale=1024:576,harddup,softskip,filmdint=crop=1908:1078:4:0 -oac copy -ovc lavc -lavcopts vcodec=mpeg4:psnr:mbd=2:v4mv:aspect=16/9:vmax_b_frames=1:trell:cbp:
      cmp=2:precmp=2:subcmp=2:vb_qoffset=0.5:vpass=1:vdpart:vpsize=1000:
      vqcomp=0.75:lmin=4:lmax=4 -force-avi-aspect 16/9 -sws 1 -fps 29.97 -ofps 23.976
    • Second pass:
      mencoder -vfm ffmpeg <hdtv-1080i-mpeg-ts-file> -tsprog 1 -vop hqdn3d=4:3:3,
      scale=1024:576,harddup,softskip,filmdint=crop=1908:1078:4:0 -oac copy -ovc lavc -lavcopts vcodec=mpeg4:psnr:mbd=2:v4mv:aspect=16/9:vmax_b_frames=1:trell:cbp:cmp=2:
      precmp=2:subcmp=2:vb_qoffset=0.5:vpass=3:vqcomp=0.75:vbitrate=1000:
      vdpart:vpsize=1000 -force-avi-aspect 16/9 -sws 1 -fps 29.97 -ofps 23.976
  • ntsc-cc -c  >> file.txt
  • record -h (xawtv-tools' recorder)
  • motv (capture from gui)
  • test sound from TV card
    • sox your_file.wav -t ossdsp -w -s /dev/dsp
  • test sound capture (none of the sox commands are currently working)
    • sox -c 1 -u -r 32000 -t ossdsp /dev/dsp1 test.wav
  • read audio data from btaudio (dsp2), send to es1730 (dsp,dsp1):
    • sox -w -r 32000 -t ossdsp /dev/dsp2 -t ossdsp /dev/dsp
  • read audio data from the saa7134 card and pipe it to /dev/dsp?
    • sox -c 2 -s -w -r 32000 -t ossdsp /dev/dsp1 -t ossdsp /dev/dsp
  • read audio data from btaudio, send to esound daemon (which might be running on another host):
    • sox -c 2 -w -r 32000 -t ossdsp /dev/dsp2 -t sw - | esdcat -r 32000
    • sox -c 1 -w -r 32000 -t ossdsp /dev/dsp2 -t sw - | esdcat -m -r 32000
  • streamer -n ntsc -q -t $2 -s 320x240 -r 20 -o $f.avi -f jpeg -j 86 -F stereo 2>> tmp/TV_rec.err
    • streamer -h for commands
    • streamer -d -o test.avi for debug

  • Convertions
  • extract stills (how can you extract only reference frames -- and name them by timestamp?)
    • ffmpeg -i video.mpg png/test-%04d.png  (convert an mpeg movie to png images)
    • ffmpeg -i video.mpg -r 1 -f image test-%04d.png (extract every 30th frame)
    • ffmpeg -an -y -t 0:0:0.001 -ss 0:0:4.000 -i  video.mpg -s 320x240 -f image -img jpeg image%d.jpg (over a time interval)
      • display 'vid:*.png' (show a screenfull of stills)
  • turn a png files into an animated gif
    • convert -delay 5 -loop 0 frame-???.png movie.gif  (works -- creates an animated gif)
  • turn a sequence of images into a movie
    • ls -1 | grep .png > image_list.txt  (create a list of images to convert)
    • transcode -i image_list.txt -x imlist,null -g 720x480 --use_rgb -z -y ffmpeg,null -F mpeg4 -o test1.avi -H 0 -f 29.97
    • convert *.png movie.mpg (requires mpeg2encode)
      • set the quality at 99 or better to avoid frame drops
    • convert *.png video-0%d.jpg (no need to do this)
  • convert captured files to be playable in windows media player:
    • ffmpeg -i original.mpg -acodec adpcm_ms -vcodec mpeg4 new.asf

  • Concatenation
  • concatenate two or more mpeg files
    • mpgtx
    • cat foo.mpg bar.mpg > bah.mpg
    • use zip -0 and rename the file .mpg
    • use tar ditto (better)

Alsa mixer settings

  • Master
  • PCM (for soundcard playback -- not used by TV)
  • Line (the first of the three Line components)
  • Analog Mix (the first of two -- for TV playback)
  • Analog Mix (the second of two -- for TV recording)
  • Audigy Analog Output Jack (unmute)
  • EMU10K1 PCM (both -- for soundcard playback)
  • Front
On Clitunno 2.6.14 and the Audigy2:value card, I had to enable these:
  • Audigy Analog/Digital Output Jack (to hear anything)
  • Line (for TV playback)
  • Front
I still haven't found what I need for tv recording. Test:
  • arecord -d 5 -D hw:1 -f S16_LE -c2 -r32000 test.wav (record from a saa713x tv capture card)

Capture and recording (see Digital Video Archive for main links)

  • channel.sh -- script for recording, use with at jobs (accessible remotely)
  • motv -- records with decent sync
  • xdtv lets you record TV directly to divX5 or libavcodec and lame (see FAQ)
    • feature for setting up cron jobs for recording
    • descrambler: a plugin allows you to watch encrypted channels
  • VCR -- command-line video capture program, in Debian (not maintained)
  • VDR and KVDR (the KDE GUI) -- PC as video recorder, require DVB
  • NVrec (not maintained)

Data sheets

Linux VCR

"VCR is a non-interactive text-console video recorder for video4linux supported capture cards. It can real-time encode video using popular Windows codecs like DivX ;-) etc." Good but no longer maintained.

This is the method I use, but if you plan to start using it, there are a few things to keep in mind.

1. The maintainer is no longer maintaining it. I have been working with the Debian developer who maintains the package on a couple of issues.

2. The program has a 2GB limitation. At 2GB, it just quits recording, not even exiting gracefully. Using the recommended DivX ;-) Low Motion codec (which records at about 875MB/hour), 2GB equates to a hair over 2 hours and 15 minutes. I have recently started using DivX5.0 for the codec and found that I am getting about 450MB/hr, which gives me almost 4 1/2 hours at a stretch.

3. Postprocessing can take a bit more time than the movie itself, but using mencoder, I generally get very good results. Generally speaking, record using vcr, then run mencoder -idx, then use avidemux for commercial removal. After that, I use a 3-pass DivX conversion. Result is not DVD quality, but for television, its very good."

Post-processing

Streaming

Hardware and drivers

Gstreamer

See http://linuxtv.org/v4lwiki/index.php/Gstreamer


Mpeg encoder cards

Lots of mpeg encoder board reviews by Warren Young -- http://tangentsoft.net/video/mpeg/reviews/ -- the the comparative tables. He likes the DViCO FusionMPEG ($380), see http://tangentsoft.net/video/mpeg/reviews/fusion.html -- doesn't seem to be available in the US. He comments, "Like the Hauppauge WinTV PVR, the FusionMPEG is designed for time-shifting live TV, like a TiVo box." However, the audio is poor.

Warren Young writes, "Modern TV tuner cards have at least a 640x480 frame size, but there are a few that have 720x480, which is the actual resolution of the TV signal. Beware: your card's software might offer you a 720x480 mode, but it may well simply be a 640x480 picture stretched out to 720x480. To know if your card truly supports 720x480, capture the same picture at both resolutions, then take the 640x480 version and use a good paint program to scale that image up to 720x480. If you can't tell the difference between the two, your card is probably scaling the picture. You want to use a highly-detailed still picture for this test, like a paused DVD." -- see http://tangentsoft.net/video/tv-tuners.html

I wrote to Warren Young at tangent@cyberport.com on 30 December 2001 asking for advice.

See also compression

Video-in driver

Some nVidia cards have a TV-in feature -- in other words, a frame grabber! The chip uses the SAA7113H driver (cf. installation instructions). You can use lots of programs with it, including ffmpeg, mplayer, and vcr.
RivaTV is a V4L driver for nVidia cards with a video-in feature.

RivaTV can be found at http://rivatv.sourceforge.net/

Questions can be asked on rivatv-help@ or rivatv-devel@lists.sf.net.
The kernel loads this, according to dmesg:
Linux video capture interface: v1.00

Modifications to Knoppmyth installation

At the end of a fresh install, before rebooting:
  • open a console
  • su root
  • mkdir gubbio
  • mount -t ext3 /dev/hda1 gubbio
  • chroot gubbio
  • vi /etc/lilo.conf -- vga=normal
After booting into KnoppMyth for the first time:
  • mkdir /mnt/vm && mount -t ext3 /dev/hdg1 /mnt/vm
  • apt-get update
  • apt-get install nano wajig
  • ln -sf /usr/bin/wajig /usr/bin/just
  • ln -sf /usr/bin/nano /usr/bin/pico
  • ln -sf /usr/bin/atscpackets /usr/bin/signal
  • just force libxv1
  • just install xawtv
  • cd /mnt/vm/knoppmyth/installation
  • cp .bash* /root
  • cp XF* /etc/X11
  • cp fstab /etc
  • cp hosts /etc
  • cp interfaces /etc/network
  • ifup eth0
  • ssh sigillo -t steen
    • su root
    • cd /root/.ssh
    • pico known_hosts
    • cp /root/.ssh/a* gubbio:/root/.ssh
    • scp /etc/ssh/sshd_config gubbio:/etc/ssh
  • just restart ssh
If you need to use dhcp
  • echo "auto eth0" >> /etc/network/interfaces && echo "iface eth0 inet dhcp" >> /etc/network/interfaces && ifup eth0

Installation history

16 April 2006

Speedup with two threads benchmarks

http://www.ee.oulu.fi/~tuukkat/mplayer/tests/x264test4/readme.html
Encoding straight to x264 on a dual-core:
transcode -x v4l2=resync_margin=1:resync_interval=250,v4l2 -M 2 -H 0 \
-i /dev/video$DEV -p /dev/dsp$DEV -y ffmpeg -F h264 -c 00:$TIM \
-g 640x480 -f 29.970,4 -w 800 -Q 5 -u 1024,2 -e 32000,16,2 -b 96 \
-o $DIR/$FIL.h264 --progress_off

# Switches                                                 File-size  CPU    Memory
# -w 500 video bitrate (cf. "bits/pixel .054")
# -b 96 (disables "--lame_preset medium") audio bitrate
# -I 1  De-interlacing through scanline interpolation       none      +3%?
# -Q 3  Quality (1-5, 5 is best)
# -u 128                                                                        7%
# -u 512                                                                       24%
# -u 1024 makes transcode run out of buffers                                   48%
# -H 0  Turn off probing, gets rid of error messages
# --encode_fields t --crop 0,0,0,0
# --progress_off should remove details from the mailed logs
# ALSA import ability is in the works --
# cf. http://www.transcoding.org/cgi-bin/transcode?WorkingOn

This gives good results on a dual-core, but creates garbage on a single CPU (messed-up sound).

26 March 2006 -- sound to ffmpeg on esteve

Files encoded to h264 using mencoder don't stream properly to any platform, although they play fine, also in amd64. Files encoded in ffmpeg, however, stream perfectly. I therefore looked to see if I can record tv using ffmpeg instead of mencoder. The problem is referring to the sound device.

ffmpeg -threads 2 -vd /dev/video$DEV -r 29.97 -b 800 -s 576x432 -vcodec h264 -qmax 51 \
-me epzs -deinterlace -g 300 -async 1 -acodec mp3 -ab 64 -ar 32000 -ad /dev/dsp$DEV \
-t $TIM -f avi -y $DIR/$FIL.avi

works, but there's no sound. On the other hand, I get sound here:

sox -w -r 32000 -t ossdsp /dev/dsp1 -t .wav test.wav

while tv is playing.  How do I tell ffmpeg to access the sound?

I discovered the saa7134-alsa module, inserted with

saa7134-alsa index=1,2,3,4
generates a slew of device nodes, possibly first of the oss kind:
/dev/audio1
/dev/audio2
/dev/audio3
/dev/audio4
/dev/dsp1
/dev/dsp2
/dev/dsp3
/dev/dsp4
/dev/mixer1
/dev/mixer2
/dev/mixer3
/dev/mixer4
These are supposedly the alsa devices:
/dev/snd/controlC1
/dev/snd/controlC2
/dev/snd/controlC3
/dev/snd/controlC4
/dev/snd/pcmC1D0c
/dev/snd/pcmC2D0c
/dev/snd/pcmC3D0c
/dev/snd/pcmC4D0c

Moreover, I discovered that

alsamixergui -c 1

will open the sound device, and you can set recording to line 1 as before. In addition,
aumix -d /dev/dsp1
will similarly open the device and let you set recording to line 1.
sudo alsactl store 1
will save the setting.

Now, note that "sox -w -r 32000 -t ossdsp /dev/dsp1 -t .wav test.wav" is able to get the sound directly off /dev/dsp1, where ffmpeg doesn't hear a thing.

I found the capture devices on the main card:
# amixer controls | grep Capture
numid=26,iface=MIXER,name='Capture Source'
numid=27,iface=MIXER,name='Capture Switch'
numid=28,iface=MIXER,name='Capture Volume'
numid=40,iface=MIXER,name='IEC958 Capture Switch'
Then see what the Capture Source is set to:
# amixer -c 0 cget numid=26
numid=26,iface=MIXER,name='Capture Source'
  ; type=ENUMERATED,access=rw---,values=2,items=8
  ; Item #0 'Mic'
  ; Item #1 'CD'
  ; Item #2 'Video'
  ; Item #3 'Aux'
  ; Item #4 'Line'
  ; Item #5 'Mix'
  ; Item #6 'Mix Mono'
  ; Item #7 'Phone'
  : values=0,0
In contrast, on Chianti it's set to 5,5, so I do:
# amixer -c 0 cset numid=26 5,5
numid=26,iface=MIXER,name='Capture Source'
  ; type=ENUMERATED,access=rw---,values=2,items=8
  ; Item #0 'Mic'
  ; Item #1 'CD'
  ; Item #2 'Video'
  ; Item #3 'Aux'
  ; Item #4 'Line'
  ; Item #5 'Mix'
  ; Item #6 'Mix Mono'
  ; Item #7 'Phone'
  : values=5,5
I also set Capture Volume like Chianti:
# amixer -c 0 cset numid=28 15,15
numid=28,iface=MIXER,name='Capture Volume'
  ; type=INTEGER,access=rw---,values=2,min=0,max=15,step=0
  : values=15,15

That's probably enough -- but no, no luck. I made files on chianti and esteve and compared them:

alsactl store -f chianti-alsa
alsactl store -f esteve-alsa
They were similar, but the settings were all different; I transferred most of chianti's settings to esteve using kompare, but it made no difference. (Nor should it, since mencoder is already working.)

On the positive side, the video that is captured directly to h264 with ffmpeg streams beautifully -- and I can capture at quite high quality without maxing out the CPU. So we're down to getting sound off the card with ffmpeg.

25 March 2006 -- autodetection

The kernel loads the cards on esteve incorrectly, so put this in /etc/modprobe.d/saa7134:

options saa7134 card=2,2,2,2 tuner=43,43,43,43 video_nr=1,2,3,4 vbi_nr=1,2,3,4 \ radio_nr=1,2,3,4 alsa=1,1,1,1
Then put this in /etc/modules:
  saa7134-alsa index=1,2,3,4
Delete the files used only by the 2.4 kernel -- /etc/modules.conf and /etc/modutils.

21 March 2006 -- saa7134 on PCI-X

I discovered to my shock that the LifeView FlyVideo-3000FM cards fit in the PCI-X slot! I borrowed a card from Chianti and tested it on Clitunno. The picture comes through fine, I can record audio, and closed captioning works. Modules  unload and reload fine:

modprobe saa7134 video_nr=2 vbi_nr=2 dsp_nr=2 mixer_nr=2 radio_nr=2 card=2 \
    tuner=43 oss=1

saa7133[0]: registered device video2 [v4l2]
saa7133[0]: registered device vbi2
saa7133[0]: registered device radio2
saa7133[0]: registered device dsp2
saa7133[0]: registered device mixer2

aumix -d /dev/mixer2 -1 R
sox -w -r 32000 -t ossdsp /dev/dsp2 -t .wav test.wav (works!)

zvbi-ntsc-cc -d /dev/vbi2 -cp (works!)
So you can record video, audio, and closed captioning -- you just can't get the sound to the speakers -- this fails:
/etc/init.d/alsa unload

xdtv -c /dev/video2 -C /dev/vbi2 -v 0 -mixer_dev /dev/mixer2 -audio_dev /dev/audio2 -mixer_tvchan line1
This is not the purpose of the test, however -- all you needed to find out is that recording works!

Successful test -- you can remove the card and put it back in Chianti.

12 February 2006 -- testing ffmpeg codecs

Testing ffmpeg on chianti -- get a list of video encoding codecs with "ffmpeg -formats | grep EV", using

ffmpeg -vd /dev/video2 -f avi -vcodec h264  -r 29.97 -b 800 -s 640x480 -ad /dev/dsp2 -acodec mp3 -ab 64  -t 10 video.avi

Codecs tested:

  • ffv1 -- "under development, files encoded with it may not be decodeable with future versions"
  • h264 -- 100% cpu usage, excellent quality, good sound -- but skips frames (you're close)
  • rawvideo -- doens't stop recording, unplayable
  • mpeg4 -- 19% cpu usage, records fine, lots of skips
  • xvid (libxvidcore4 1.1.0-final-0.0) -- records something but doesn't stop, unplayable
  • mpeg1video -- 22 cpu usage, records fine, very blocky, sync problems or no sound
  • msmpeg4 --  22 cpu usage, records fine, plays fine, tcprobe says DIV3
  • msmpeg4v1 -- unplayable
  • msmpeg4v2 -- same as msmpeg4
In brief, the results are that msmpeg4v2 (or msmpeg4) is the only codec that works for real-time grabbing with decent quality.  It also shows ffmpeg works just as well as mencoder. Finally, these results show that the h264 codec produces a brilliant output at great compression, but the CPU isn't fast enough. If Steve's dual-core is fast enough, you could upgrade for $300 and record to h264.

21 November 2005: pcHDTV on trevi

Instructions

I rebuilt the 2.6.14 kernel, as I'd forgotten to include the cx88-dvb driver. On pchdtv.com, I find this:

Start with a fresh boot and try to load the modules in this order:

modprobe cx8800
modprobe cx8802
modprobe cx88-dvb

cx8800 is the analog section and will cause the tuner module to load, which cx88-dvb needs. cx88-dvb won't autoload the tuner because of some depmod issues.

cx8802 has some functions cx88-dvb needs, and is usually autoloaded when you load cx88-dvb, but no harm in manual load.

cx88-dvb is the actual dvb driver.
I swapped in a pcHDTV-3000 card for testing. See normal initialization and full instructions. First, the status after booting with the new device:
cx2388x v4l2 driver version 0.0.5 loaded
ACPI: PCI Interrupt 0000:03:04.0[A] -> GSI 16 (level, low) -> IRQ 21
CORE cx88[0]: subsystem: 7063:3000, board: pcHDTV HD3000 HDTV [card=22,autodetected]
TV tuner 52 at 0x1fe, Radio tuner -1 at 0x1fe
cx88[0]/0: found at 0000:03:04.0, rev: 5, irq: 21, latency: 64, mmio: 0xfc000000
tuner 1-0061: chip found @ 0xc2 (cx88[0])
tuner 1-0061: type set to 52 (Thomson DDT 7610 (ATSC/NTSC))
cx88[0]/0: registered device video0 [v4l2]
cx88[0]/0: registered device vbi0
cx88[0]/0: registered device radio0
cx2388x blackbird driver version 0.0.5 loaded
cx2388x dvb driver version 0.0.5 loaded
ACPI: PCI Interrupt 0000:03:04.2[A] -> GSI 16 (level, low) -> IRQ 21
cx88[0]/2: found at 0000:03:04.2, rev: 5, irq: 21, latency: 64, mmio: 0xfd000000
cx88[0]/2: cx2388x based dvb card
DVB: registering new adapter (cx88[0]).
DVB: registering frontend 0 (Oren OR51132 VSB/QAM Frontend)...
So far so good -- that loaded these modules:
cx88_dvb                8900  0
mt352                   7044  1 cx88_dvb
or51132                 9796  1 cx88_dvb
video_buf_dvb           5380  1 cx88_dvb
dvb_core               82364  1 video_buf_dvb
crc32                   4416  1 dvb_core
lgdt330x                8348  1 cx88_dvb
cx22702                 6276  1 cx88_dvb
dvb_pll                 8836  3 cx88_dvb,or51132,cx22702
cx88_blackbird         14292  0
cx8802                 10372  2 cx88_dvb,cx88_blackbird
firmware_class          9280  2 or51132,cx88_blackbird
tuner                  39464  0
cx8800                 31116  1 cx88_blackbird
cx88xx                 58336  4 cx88_dvb,cx88_blackbird,cx8802,cx8800
i2c_algo_bit            9032  1 cx88xx
video_buf              20036  6 cx88_dvb,video_buf_dvb,cx88_blackbird,cx8802,
                               cx8800,cx88xx
ir_common               8516  1 cx88xx
tveeprom               14992  1 cx88xx
btcx_risc               4616  3 cx8802,cx8800,cx88xx
Wow. That's a lot of stuff. 

Create device nodes:
#!/bin/sh
rm -rf /dev/dvb/adapter*/*
device=0
for card in `seq 0 3`; do
mkdir -p /dev/dvb/adapter$card
device=`echo $card \* 64 | bc`
for dev in video audio sec frontend demux dvr ca net osd; do
mknod /dev/dvb/adapter${card}/${dev}0 c 212 $device
chmod 0660 /dev/dvb/adapter${card}/${dev}0
let device=device+1
done
done
Unload and reload the modules:
  modprobe -rv cx88_blackbird
modprobe -rv cx88-dvb
modprobe -rv cx8800
modprobe -v cx88-dvb
Get the dvb-apps tools from Debian's dvb-utils or from CVS (don't use the dvb_atsc_tools download from pchdtv.com):
cvs -z3 -d ':pserver:anonymous@cvs.linuxtv.org:/cvs/linuxtv' co -P dvb-apps
To build it, comment out this line in util/Makefile:
$(MAKE) -C ttusb_dec_reset $(MAKECMDGOALS)
Made and installed.  Now get the firmware:
# Download the firmware
mkdir -p /usr/lib/hotplug/firmware
cd /usr/lib/hotplug
wget http://pchdtv.com/downloads/firmware.tar.gz
tar zxf firmware.tar.gz
rm -f firmware.tar.gz
That put the firmware in /usr/lib/hotplug/firmware --
rw-r--r-- 1 501 501 12772 Feb 11  2005 dvb-fe-or51132-qam.fw
-rw-r--r-- 1 501 501 17532 Feb 11  2005 dvb-fe-or51132-vsb.fw
-rw-r--r-- 1 501 501  8518 Feb 15  2005 dvb-fe-or51211.fw
How to get it loaded? I installed udev (the fixed 0.76-3 version) and scanned:
atscscan /share/usr/local/share/dvb/scan/atsc/us-NTSC-center-frequencies-8VSB
DVB: registering frontend 0 (Oren OR51132 VSB/QAM Frontend)...
or51132: Waiting for firmware upload(dvb-fe-or51132-vsb.fw)...
or51132: Version: 10001134-19430000 (113-4-194-3)
or51132: Firmware upload complete.
or51132: Waiting for firmware upload(dvb-fe-or51132-qam.fw)...
or51132: Version: 10001334-17430000 (133-4-174-3)
or51132: Firmware upload complete.
Now, use the dtvsignal and channel_scan programs.  Saved channels.conf-qam-correct to ~/.azap/channel.conf and issued
$ azap c88
using '/dev/dvb/adaptusing '/dev/dvb/adapter0/frontend0' and '/dev/dvb/adapter0/demux0'
tuning to 609000000 Hz
video pid 0x0000, audio pid 0x0000
status 00 | signal 3999 | snr f703 | ber 00000000 | unc 00000000 |
status 00 | signal 6ac0 | snr eb9d | ber 00000000 | unc 00000000 |
status 00 | signal 6b84 | snr efc7 | ber 00000000 | unc 00000000 |
status 00 | signal a936 | snr f7b7 | ber 00000000 | unc 00000000 |
No channels are found -- just lots of "status 00" -- and no more luck with atscscan:
$ atscscan /share/usr/local/share/dvb/scan/atsc/us-CA-SF-Bay-Area
scanning /share/usr/local/share/dvb/scan/atsc/us-CA-SF-Bay-Area
using '/dev/dvb/adapter0/frontend0' and '/dev/dvb/adapter0/demux0'
>>> tune to: 503000000:8VSB
WARNING: >>> tuning failed!!!
Still, this is pretty serious progress. Then try OTA (Over-the-Air) reception -- see instructions:
just install libxml-xpath-perl
cd /share/software/cvs/dvb-apps/dvb-apps-1/util/szap/channels-conf/atsc
perl make_atsc_chanconf.pl 90024 > /home/steen/.azap/channels-90024.conf
It found a single station, "KVCR:545000000:8VSB:0:0".  I issued,
$ azap -r KVCR -c channels-90024.conf
and get a signal!
$ azap -r KVCR -c channels-90024.conf
using '/dev/dvb/adapter0/frontend0' and '/dev/dvb/adapter0/demux0'
tuning to 545000000 Hz
video pid 0x0000, audio pid 0x0000
status 00 | signal ae55 | snr cd37 | ber 00000000 | unc 00000000 |
status 1f | signal 19db | snr ab87 | ber 00000000 | unc 00000000 | FE_HAS_LOCK
status 1f | signal 1d2e | snr aaa5 | ber 00000000 | unc 00000000 | FE_HAS_LOCK
status 1f | signal 1333 | snr a3f7 | ber 00000000 | unc 00000000 | FE_HAS_LOCK
status 00 | signal 3999 | snr c09b | ber 00000000 | unc 00000000 |
status 1f | signal 1645 | snr a69b | ber 00000000 | unc 00000000 | FE_HAS_LOCK
status 1f | signal 0a3d | snr cd37 | ber 00000000 | unc 00000000 | FE_HAS_LOCK
status 1f | signal 1ef9 | snr ab29 | ber 00000000 | unc 00000000 | FE_HAS_LOCK
status 1f | signal 0d0e | snr 9b4f | ber 00000000 | unc 00000000 | FE_HAS_LOCK
status 00 | signal 3999 | snr cd37 | ber 00000000 | unc 00000000 |

It goes on. I get lots of status 1f now.  However, if I then run dvbtraffic in another window at the same time, the signal is too weak to be worth anything:
-PID--FREQ-----BANDWIDTH-BANDWIDTH-
0000     1 p/s     0 kb/s     2 kbit
0001     0 p/s     0 kb/s     1 kbit
0002     1 p/s     0 kb/s     2 kbit
The Bandwidth numbers may occasionally go up to 60, but they need to be in the thousands.

See Local HDTV Info and Reception --
Los Angeles, CA
     Los Angeles, CA - OTA
     Los Angeles, CA - Adelphia
     Los Angeles, CA - Charter
     Los Angeles, CA - Comcast
     Los Angeles, CA - DBS
     Orange County, CA - Cox
You need the OTA forum -- you likely simply need a better antenna.

Use mplayer dvb://"channel name" once you have a valid channels.conf  in ~/.mplayer/.
Here are the utilities in dvb-utils:
 av7110_loadkeys - tool to load keyfiles of ir-remotes
 evtest - find out events-keys to generate a keyfile for your remote
 femon  - monitor the singal-strength... of your card
 scan   - scan all transponders and generate a channels.conf
 azap   - scan for ATSC channels?
 czap   - simple zapping tool for the Linux DVB API (DVB-C-Cards)
 szap   - simple zapping tool for the Linux DVB API (DVB-S-Cards)
 tzap   - simple zapping tool for the Linux DVB API (DVB-T-Cards)
You also have the packages
dvbsnoop -- DVB / MPEG stream analyzer
dvbstream -- Broadcast a DVB Transport stream over a LAN
dvbtune -- Simple tuning application for DVB cards
Get the latest Xine from xinehq.de and apply the patch found there called atsc-patch by cd-ing to top level of xine-lib and issue
cat atsc-patch | patch -p1
then make and install the xine-lib and xine-ui and run it with your channels.conf file.

28 October 2005: recording from bttv with 2.6.14 on trevi

For a year I postponed upgrading the kernel on trevi and stuck with 2.6.9-ac6, as I was unable to record from the tv card on 2.6.12, using the Audigy2 Value card.  Unnecessary really -- I wrote detailed instructions for finding the capture channel at http://linuxtv.org/v4lwiki/index.php/TVCapture_98 -- in brief,

  • amixer controls | grep Capture
  • use Analog Mix Capture Volume
  • amixer -c 0 cset numid=19 100%,100% unmute cap

The capture channel had simply been moved from 18 to 19 during an ALSA upgrade.  You don't need the snd_bt87x module.

22 April 2005: btaudio on trevi

It looks like the snd_bt87x module may block the btaudio module's creation of device nodes -- I had to remove it first to get this:

modprobe btaudio analog=1 dsp1=2 dsp2=1 debug=1 rate=32000

ACPI: PCI interrupt 0000:03:04.1[A] -> GSI 16 (level, low) -> IRQ 16
btaudio: Bt878 (rev 17) at 03:04.1, irq: 16, latency: 64, mmio: 0xfb6ff000
btaudio: using card config "default"
btaudio: registered device dsp1 [digital]
btaudio: registered device dsp2 [analog]
btaudio: registered device mixer0
I don't need the digital one, so use this instead:
modprobe btaudio analog=1 digital=0 debug=3
Then I used this to set the channel:
aumix -d /dev/mixer0
Yep! There it is -- Line1, Line2, Line3. Recording set to Line2, which is where it should be. You can also do this:
aumix -d /dev/mixer1 -2 R
You should now have sound on dsp1 -- analog mono. However, you cannot move the volume slider; it's stuck on zero. Then I learn from Michel Bardiaux that you get set it from the commandline:
aumix -d /dev/mixer1 -2 50
That succeeds in setting the recording volume to 50% on Line2!

Try Steve Dibb's line:
mencoder -tv driver=v4l2:device=/dev/video0:fps=30000/1001:chanlist=us-cable:audiorate=32000:
adevice=/dev/dsp1:input=0:amode=1:normid=4 -ffourcc DIVX -ovc lavc -oac mp3lame -lameopts cbr:br=128 -endpos 60 -o test.avi tv://5
Gerd Knorr says about btaudio on bttv,
The analog mode supports mono only.  Both 8 + 16 bit.  Both are _signed_ int, which is uncommon for the 8 bit case.  Sample rate range is 119 kHz to 448 kHz.  Yes, the number of digits is correct.  The driver supports downsampling by powers of two, so you can ask for more usual sample rates like 44 kHz too.
Great instructions. But mencoder just halts when I try to get it to grab from btaudio:
mencoder -tv driver=v4l2:device=/dev/video0:fps=30000/1001:chanlist=us-cable:
audiorate=32000:adevice=/dev/dsp1:input=0:amode=1:normid=4 -ffourcc DIVX
-ovc lavc -oac mp3lame -lameopts cbr:br=128 -endpos 10 -o test.avi tv://5

mencoder -tv driver=v4l2:device=/dev/video0:fps=30000/1001:chanlist=us-cable:
audiorate=448000:adevice=/dev/dsp1:input=0:amode=1:normid=4 -ffourcc DIVX
-ovc lavc -oac mp3lame -lameopts cbr:br=128 -endpos 10 -o test.avi -srate 30000 tv://5
Here's what I get for sound:
Opening audio decoder: [pcm] Uncompressed PCM audio decoder
AUDIO: 32000 Hz, 1 ch, s16le, 512.0 kbit/100.00% (ratio: 64000->64000)
Selected audio codec: [pcm] afm:pcm (Uncompressed PCM)
Note it's not stereo. And it just sits there.
# dump-mixers
/dev/mixer0 = Audigy2 (SigmaTel STAC9750/51)
  vol        ( 0) :  mono          100
  bass       ( 1) :  stereo        50/50
  treble     ( 2) :  stereo        50/50
  synth      ( 3) :  stereo        0/0
  pcm        ( 4) :  stereo        54/54
  speaker    ( 5) :  mono          0
  line       ( 6) :  stereo        100/100
  mic        ( 7) :  stereo        0/0
  cd         ( 8) :  stereo        0/0
  pcm2       (10) :  stereo        0/0
  line1      (14) :  stereo        0/0
  dig1       (17) :  mono          0
  phin       (20) :  mono          0
  phout      (21) :  mono          0
/dev/mixer1 = bt878 (Brooktree Bt878 audio)
  line1      (14) :  mono    rec   0
  line2      (15) :  mono    rec*  46
  line3      (16) :  mono    rec   0
Nice looking stuff.

21 April 2005: tvtime

I began by running tvtime-scanner, which creates a list of detected stations in ~./tvtime. I then did this:

ssh -X chi
export DISPLAY=128.97.221.30:0.0
xhost +128.97.221.30
and got the receipt "128.97.221.30 being added to access control list".
tvtime -n NTSC -X 128.97.221.30:0.0
but no dice -- "xcommon: Cannot open display '128.97.221.30:0.0'." I don't know x-windows well enough.

However, on the local monitor, I was able to run tvtime and used these settings:
tvtime -d /dev/video1 -b /dev/vbi1 -n NTSC -f us-broadcast -x /dev/mixer1:line -m -S
That last -S tells tvtime to save these settings to the default configuration file -- where I also find ShowCC=1.

However, I don't actually see closed captioning.

You can also control tvtime with the tvtime-command (see user manual and tvtime.xml default).  For instance:
TOGGLE_CC

Enables closed caption information to be displayed in the tvtime window.
Closed captioning is only available if you have enabled VBI reading in your tvtime.xml configuration file.
My tvtime.xml file says,
<option name="ShowCC" value="1"/>
<option name="VBIDevice" value="/dev/vbi1"/>
That's probably enough -- I also actually ran zvbi-chains and established a link to /dev/vbi1.  So technically this should work.

Doug Bell <drbell@users.sourceforge.net> wrote the closed captioning support for tvtime -- Kevin Ko did some work on it (I wrote him).

Now, in contrast to vbi on cx88, the /dev/vbi1 for the saa7134 card is nice and orderly:
ntsc-cc -d /dev/vbi -c -w -r 27
So this may well be working in tvtime or zapping or gstreamer.

21 April 2005: closed captioning with saa7134

20 April 2005: getting true mpeg

You should use

mencoder tv:// -tv driver=v4l2:device=/dev/video1:fps=30000/1001:
chanlist=us-cable:audiorate=32000:adevice=/dev/dsp1:input=0:
amode=1:normid=4 -ffourcc DIVX -ovc lavc -lavcoptsvcodec=mpeg4:
vhq -oac mp3lame -lameopts cbr:br=128 -endpos 60 -of mpeg -o /tv1/output1.mpg
to get true mpeg. Leaving out "-of mpeg" will give you an avi file. Not sure what this means exactly or which is better. But it turns out that the "-of mpeg" delays the audio, putting it out of sync! So stick with the avi for now.

20 April 2005: adjusting saa7133 settings

Now adjust the hue settings -- you don't need the 100% on the saa7134, while you still do on the cx88; you should also set stereo:

v4lctl -c /dev/video0 list (this looks fine -- current settings for cx88
v4lctl -c /dev/video1 list

config: invalid value for norm: NTSC-M
valid choices for "norm": "PAL", "PAL-BG", "PAL-I", "PAL-DK", "NTSC",
"SECAM", "PAL-M", "PAL-Nc", "PAL-60"

attribute  | type   | current | default | comment
-----------+--------+---------+---------+-------------------------------------
norm       | choice | PAL-DK  | PAL     | PAL PAL-BG PAL-I PAL-DK NTSC SECAM PAL-M PAL-Nc PAL-60
input      | choice | Televis | Televis | Television TV (mono only) Composite1 Composite2 S-Video
audio mode | choice | mono    | mono    | mono stereo lang1 lang2
bright     | int    |     128 |     128 | range is 0 => 255
contrast   | int    |      68 |      68 | range is 0 => 127
color      | int    |      63 |      64 | range is 0 => 127
hue        | int    |       0 |       0 | range is -128 => 127
volume     | int    |       0 |       0 | range is -15 => 15
mute       | bool   | on      | off     |
vertical f | bool   | off     | off     |
Invert     | bool   | off     | off     |
y offset o | int    |       0 |       0 | range is 0 => 128
y offset e | int    |       0 |       0 | range is 0 => 128
automute   | bool   | on      | on      |
Note the new values showing up for this card -- offsets and stuff. I try some adjustments:
v4lctl -c /dev/video1 norm=NTSC (I had to remove norm statements in .xawtv)
v4lctl -c /dev/video1 color "50%"
v4lctl -c /dev/video1 input Television
v4lctl -c /dev/video1 audio stereo
I then tried to capture with transcode:
transcode -x v4l2,v4l2 -M 2 -i /dev/video1 -p /dev/dsp1 -y ffmpeg -F mpeg4 -c 00:10 -g 704x480 -f 29.970,4 -I 1 -V --pre_clip 0,0,0,0 -u 1024 -Q 3 -E 32000,8,1 --lame_preset medium -o /tv1/saa7134-03.avi
This works well with x264:
transcode -x v4l2,v4l2 -M 2 -i /dev/video$DEV -p /dev/dsp$DEV -y ffmpeg -F h264 \
-c 00:$TIM -g 640x480 -f 29.970,4 threads=2 -u 1024,4 crop=0,0,0,0 -Q 5 -e 32000,16,2 \
--lame_preset medium -o $DIR/$FIL.avi
The files may have a sync problem, and they are larger than those encoded with mencoder, but they stream great in vlc.
Or the mencoder version:
mencoder tv:// -tv driver=v4l2:device=/dev/video0:fps=29.97:chanlist=us-cable:audiorate=32000:
 adevice=/dev/dsp1:input=0:amode=1:normid=4
mencoder tv:// -tv driver=v4l2:width=704:height=480:norm=ntsc:device=/dev/video1
chanlist=us-cable:audiorate=32000:adevice=/dev/dsp1:input=0:amode=1:normid=4
-ffourcc DIVX -fps 29.97 -ovc lavc -lavcopts vcodec=mpeg4:vhq -oac mp3lame -lameopts
cbr:br=128 -endpos 1 -o /tv1/saa7134-03.mpg
Wow, that works!  v4lctl -c /dev/video1 setchannel 5
# mencoder tv:// -tv driver=v4l2:device=/dev/video1:fps=29.97:chanlist=us-cable:audiorate=32000:
adevice=/dev/dsp1:input=0:amode=1:normid=4 -ffourcc DIVX -ovc lavc -lavcoptsvcodec=mpeg4:
vhq -oac mp3lame -lameopts cbr:br=128 -endpos 60 -o /tv1/saa7134-saa-01.mpg
MEncoder 1.0pre7-3.3.5 (C) 2000-2005 MPlayer Team
CPU: Advanced Micro Devices  (Family: 8, Stepping: 0)
Detected cache-line size is 64 bytes
CPUflags: Type: 8 MMX: 1 MMX2: 1 3DNow: 1 3DNow2: 1 SSE: 1 SSE2: 1
Compiled for x86 CPU with extensions: MMX MMX2 3DNow 3DNowEx SSE SSE2

File not found: 'frameno.avi'
Failed to open frameno.avi
success: format: 9  data: 0x0 - 0x0
TV detected! ;-)
Selected driver: v4l2
 name: Video 4 Linux 2 input
 author: Martin Olschewski <olschewski@zpr.uni-koeln.de>
 comment: first try, more to come ;-)
Selected device: LifeView FlyVIDEO3000
 Tuner cap: STEREO LANG1 LANG2
 Tuner rxs: MONO STEREO
 Capabilites:  video capture  video overlay  VBI capture device  tuner  read/write  streaming
 supported norms: 0 = PAL; 1 = PAL-BG; 2 = PAL-I; 3 = PAL-DK; 4 = NTSC; 5 = SECAM;
6 = PAL-M; 7= PAL-Nc; 8 = PAL-60;
 inputs: 0 = Television; 1 = TV (mono only); 2 = Composite1; 3 = Composite2; 4 = S-Video;
 Current input: 0
 Current format: BGR24
v4l2: current audio mode is : STEREO
Unable to set trigger: 1
audio block size too low, setting to 16384!
[V] filefmt:9  fourcc:0x32315659  size:640x480  fps:29.97  ftime:=0.0334
==================================================
Opening audio decoder: [pcm] Uncompressed PCM audio decoder
AUDIO: 32000 Hz, 2 ch, s16le, 1024.0 kbit/100.00% (ratio: 128000->128000)
Selected audio codec: [pcm] afm:pcm (Uncompressed PCM)
==================================================
Opening video filter: [expand osd=1]
Expand: -1 x -1, -1 ; -1  (-1=autodetect) osd: 1
==================================================
Opening video decoder: [raw] RAW Uncompressed Video
VDec: vo config request - 640 x 480 (preferred csp: Planar YV12)
VDec: using Planar YV12 as output csp (no 0)
Movie-Aspect is undefined - no prescaling applied.
videocodec: libavcodec (640x480 fourcc=34504d46 [FMP4])
High quality encoding selected (non real time)!
Selected video codec: [rawyv12] vfm:raw (RAW YV12)
==================================================
Forcing output fourcc to 58564944 [DIVX]
MP3 audio selected
Building audio filter chain for 32000Hz/2ch/s16le -> 32000Hz/2ch/s16le...
Writing AVI header...
ODML: Aspect information not (yet?) available or unspecified, not writing vprp header.
Forcing audio preload to 0, max pts correction to 0
New_Face failed. Maybe the font path is wrong.
Please supply the text font file (~/.mplayer/subfont.ttf).
subtitle font: load_sub_face failed.
ODML: Aspect information not (yet?) available or unspecified, not writing vprp header.
Pos:   0.1s      3f ( 0%)   0fps Trem:   0min   0mb  A-V:0.000 [0:0]
1 duplicate frame(s)!
Pos:  60.0s   1798f ( 0%)  30fps Trem:   0min   0mb  A-V:0.000 [837:127]]
Flushing video frames

CBR audio: 16000 bytes/sec, 576 bytes/block

Writing AVI index...
Fixing AVI header...
ODML: Aspect information not (yet?) available or unspecified, not writing vprp header.

Video stream:  837.226 kbit/s  (104653 bps)  size: 6281992 bytes  60.027 secs  1798 frames

Audio stream:  128.000 kbit/s  (15999 bps)  size: 960192 bytes  60.012 secs
v4l2: 1803 frames successfully processed, 0 frames dropped.
Wow -- it does work! Hebemus papam! 

Well, the sound is a fraction of a second too late -- how can I help that?

20 April 2005: sound from saa7133

After loading the saa7134 module with "oss=1", I get /dev/dsp1 and /dev/mixer1. Steve Dibbs explains you can use aumix to configure this second mixer device:

aumix -d /dev/mixer1 -I
In fact this works -- you get Line1, Line2, and Video. Steve writes, "By default, the "R" (recording) device will be set to Video. Change it to any of the other options (Line 1 or Line 2) to record onboard audio. In console mode for aumix, use the arrow keys to select Line1 or Line2, and then the space bar to select that one as the recording device." Press s to save and q to quit.

Surely you can also use alsamixer? But no -- "alsamixer -D /dev/mixer1" doesn't see the device! So you have to use aumix. Wow. I set the recording to line1, which is supposed to be all it takes.

You could also do this way:
aumix -d /dev/mixer1 -1 R
That works -- can be put in a script, otherwise this is reset at boot. Put it in /etc/init.d/bootmisc.sh for lack of a better place.

However, when I issue
v4lctl -c /dev/video1 audio stereo
I get "no handler for audio" -- it doesn't look like it's detected, or something's not seeing it. Similarly,
v4lctl -c /dev/video1 mute off
produces "no handler for mute", and the same for automute. Possibly, this doesn't matter, but Steve Dibbs had this working.

20 April 2005: saa7133 on Chianti

FlyVideo 3000

  • manufacturer
  • reviews: 3000 PAL, 3000FM (very close), 3000FM for sale
  • saa7133
  • /usr/src/linux-2.6.12-rc2/Documentation/video4linux/CARDLIST.saa7134
    •   2 -> LifeView FlyVIDEO3000             [5168:0138,4e42:0138]
    •   3 -> LifeView FlyVIDEO2000                    [5168:0138]
    • 34 -> LifeView FlyTV Platinum33 mini      [5168:0212]
  • /usr/src/linux-2.6.12-rc2/Documentation/video4linux/README.saa7134
  • Tuners -- /usr/src/linux-2.6.12-rc2/Documentation/video4linux/CARDLIST.tuner
    • Phillips -- but which?
    • cat CARDLIST.tuner | grep Philips | grep NTSC
      tuner=2 - Philips NTSC (FI1236,FM1236 and compatibles)
      tuner=17 - Philips NTSC_M (MK2)
      tuner=42 - Philips 1236D ATSC/NTSC dual in
      tuner=43 - Philips NTSC MK3 (FM1236MK3 or FM1236/F)
    • I have to reboot with this in /etc/modules:
      saa7134 card=2 tuner=17 oss=1
      saa7134 card=2,2 tuner=17,17 oss=1
  • PCI audio transfer
  • modprobe bttv i2c_debug=1 card=13 radio=0 tuner=2
  • modprobe btaudio analog=1 dsp1=1 dsp2=2 debug=1 rate=32000
  • modprobe bttv i2c_debug=1 card=11,22 radio=0  tuner=33,44 (for two cards)

lspci -vvv:

0000:02:0a.0 Multimedia controller: Philips Semiconductors SAA713X Audio+video broadcast decoder (rev 10)
        Subsystem: Unknown device 5169:0138

dmesg:

saa7130/34: v4l2 driver version 0.2.12 loaded
ACPI: PCI Interrupt Link [APC3] enabled at IRQ 18
ACPI: PCI Interrupt 0000:02:0a.0[A] -> Link [APC3] -> GSI 18 (level, low) -> IRQ 18
saa7133[0]: found at 0000:02:0a.0, rev: 16, irq: 18, latency: 32, mmio: 0xf400a000
saa7133[0]: subsystem: 5169:0138, board: LifeView FlyVIDEO3000 [card=2,insmod option]
saa7133[0]: board init: gpio is 39800
saa7133[0]: there are different flyvideo cards with different tuners
saa7133[0]: out there, you might have to use the tuner=<nr> insmod
saa7133[0]: option to override the default value.
saa7133[0]: registered input device for IR
saa7133[0]: dsp access wait timeout [bit=WRR]
saa7133[0]: dsp access wait timeout [bit=WRR]
tuner 4-0061: chip found @ 0xc2 (saa7133[0])
tuner 4-0061: type set to 17 (Philips NTSC_M (MK2))
saa7133[0]: i2c eeprom 00: 69 51 38 01 10 28 ff ff ff ff ff ff ff ff ff ff
saa7133[0]: i2c eeprom 10: ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff
saa7133[0]: i2c eeprom 20: ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff
saa7133[0]: i2c eeprom 30: ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff
saa7133[0]: registered device video1 [v4l2]
saa7133[0]: registered device vbi1
saa7133[0]: registered device radio1
saa7133[0]: registered device dsp1
saa7133[0]: registered device mixer1
So that works -- picture is good. One card was defective.

19 April 2005: some parts of mplayer/mencoder working on Chianti

This doesn't segfault, but the video is black:

mencoder tv:// -tv driver=v4l2:width=640:height=480:norm=ntsc:device=/dev/video1 -fps 29.97 -ovc raw -oac mp3lame -lameopts cbr:br=128
Note the -ovc raw -- that's the saving grace. So at least I'm narrowing the problem down to video codecs.

Here's the usual command:
mencoder -tv driver=v4l2:width=640:height=480:norm=ntsc:device=/dev/video$DEV -ffourcc DIVX -fps 29.97 -ovc lavc -lavcopts vcodec=mpeg4:vhq -oac mp3lame -lameopts cbr:br=128 -endpos $TIM -o $DIR/$FIL.mpg tv:// > /dev/null
Some variants:
mencoder tv:// -tv driver=v4l2:width=640:height=480:norm=ntsc:device=/dev/video0:noaudio -ffourcc DIVX -fps 29.97 -ovc raw -oac mp3lame -lameopts cbr:br=128 endpos 1 -o output.avi
Available codecs:
   copy     - frame copy, without re-encoding. Doesn't work with filters.
   frameno  - special audio-only file for 3-pass encoding, see DOCS.
   raw      - uncompressed video. Use fourcc option to set format explicitly.
   nuv      - nuppel video
   lavc     - libavcodec codecs - best quality!
   libdv    - DV encoding with libdv v0.9.5
   xvid     - XviD encoding

Of these, -ovc copy and raw work fine, also with the -ffourcc DIVX switch, but the result is black. The nuv  and xvid codecs segfault. But libdv works!
/tv1$ mencoder tv:// -tv driver=v4l2:width=640:height=480:norm=ntsc:device=/dev/video0:noaudio -fps 29.97-ovc libdv -vf scale=720:480 -oac mp3lame -lameopts cbr:br=128 endpos 1 -o output.dv
Note the -vf scale=720x480 to meet the dv format requirement. This one actually shows a picture that plays in kplayer -- but squished and all red, the way mplayer tv:// looks. So that may be the best you can get, until you get mplayer itself working.

The xvid codec fails on chianti but succeeds on trevi:
mencoder tv:// -tv driver=v4l2:width=640:height=480:norm=ntsc:device=/dev/video0:noaudio -fps 29.97 -ovc xvid -xvidencopts bitrate=900 -oac mp3lame -lameopts cbr:br=128 endpos 1 -o output.avi
Watching works, but the picture is in the upper half, distorted, and all red on chianti -- it works on trevi:
mplayer tv://5 -tv driver=v4l2:width=640:height=480:norm=ntsc:device=/dev/video1
Finally, mplayer works for watching recorded files on chianti.

This is all on the 2.6.12-rc2 kernel, which has RTC support (lacking in rc1).

15 April 2005: can't find capture channel in 2.6.12-rc2 on Clitunno

After installing 2.6.12-rc on Clitunno, I was unable to find the capture channel for the bttv card on the Audigy 2 Value card. The driver saw the card as SB0400, but the channels were very different from the ones I have under 2.6.9-ac6 and (I believe) alsa 1.0.8-rc1.

14 April 2005: picture adjustment for pcHDTV on Chianti

I tested the three cx88 (pcHDTV) cards and discovered they prefer medium settings with the exception of hue, which should be 0% or 100%. On two of the cards, the color has to be tuned all the way up.
  • v4lctl -c /dev/video0 hue "100%"   (or "0%" -- same thing)
  • v4lctl -c /dev/video0 bright "50%"
  • v4lctl -c /dev/video0 contrast "45%"
  • v4lctl -c /dev/video0 color "100%"
  • v4lctl -c /dev/video1 color "50%"
  • v4lctl -c /dev/video2 color "100%"
Note that the /dev/video1 card needs only color "50%".

10 April 2005: bttv on the Chianti machine (not implemented)

Since closed captioning is not working on the pcHDTV cards, I will for the moment leave them for digital television and use bttv or saa7134 cards for analog capture.  If you use bttv (unlikely now), you should make the following changes on Chianti:

1. Create /etc/modutils/alsa with this content -- cf. instructions and snd-bt87x section below for details)

# ALSA portion
alias char-major-116 snd
alias snd-card-0 snd-bt87x

# module options should go here

# OSS/Free portion
alias char-major-14 soundcore
alias sound-slot-0 snd-card-0

# card #1
alias sound-service-0-0 snd-mixer-oss
alias sound-service-0-1 snd-seq-oss
alias sound-service-0-3 snd-pcm-oss
alias sound-service-0-8 snd-seq-oss
alias sound-service-0-12 snd-pcm-oss
2. Remove all pcHDTV-related modules
# First remove the dvb modules

rmmod cx88_dvb
rmmod or51132
rmmod video_buf_dvb
rmmod mt352
rmmod dvb_pll
rmmod dvb_core

# Then remove the cx88 modules

rmmod cx8802 cx8800 tda9887
rmmod cx88xx tda9887

# Finally take the v4l modules

rmmod btcx_risc tveeprom ir_common video_buf videodev
rmmod tvaudio v4l2_common v4l1_compat tuner i2c_algo_bit
3. Move the AverTV98 Stereo card from Clitunno to Chianti

4. Insert the bttv modules

snd_bt87x
snd_pcm
snd_timer
snd
snd_page_alloc
tuner
tvaudio
bttv
video_buf
firmware_class
i2c_algo_bit
btcx_risc
5. Test recording with mencoder and transcode

9 April 2005: recording video and audio from pcHDTV

I started out with this, which works:

transcode -x v4l2,v4l2 -M 2 -i /dev/video0 -p /dev/dsp -y ffmpeg -F msmpeg4v2 -c 00:01:00 -g 640x480 -f 24.0,1 -I 1 -u 1024 -Q 3 -E 48000,16,2 --lame_preset medium -o /tv1/transcode-test-01.avi
That's both video and audio, but the framerate is wrong -- 23.97 rather than 29.97. Here's the right way to do it:
$ transcode -x v4l2,v4l2 -M 2 -i /dev/video0 -p /dev/dsp -y ffmpeg -F mpeg4-c 00:01:00 -g 640x480 -f 29.970,4 -I 1 -u 1024 -Q 3 -E 48000,16,2 --lame_preset medium -o /tv1/transcode-test-01.avi

transcode v0.6.14 (C) 2001-2003 Thomas Oestreich, 2003-2004 T. Bitterberg
[transcode] auto-probing source /dev/video0 (failed)
[transcode] V: import format    | unknown  (V=v4l2|A=v4l2)
[transcode] V: AV demux/sync    | (2) initial MPEG sequence / enforce frame rate
[transcode] V: import frame     | 640x480  1.33:1
[transcode] V: de-interlace     | (mode=1) interpolate scanlines (fast)
[transcode] V: bits/pixel       | 0.196
[transcode] V: decoding fps,frc | 29.970,4
[transcode] V: Y'CbCr           | YV12/I420
[transcode] A: import format    | 0x2000  AC3          [48000,16,2]
[transcode] A: export format    | 0x55    MPEG layer-3 [48000,16,2]  128 kbps
[transcode] V: encoding fps,frc | 29.970,4
[transcode] A: bytes per frame  | 6408 (6406.400000)
[transcode] A: adjustment       | -1600@1000
tc_memcpy: using libc for memcpy
[transcode] V: video buffer     | 1024 @ 640x480
[import_v4l2.so] v1.3.4 (2004-08-25) (video) v4l2 | (audio) pcm
[export_ffmpeg.so] v0.3.13 (2004-08-03) (video) FFmpegcvsb4736 | (audio) MPEG/AC3/PCM
[import_v4l2.so]: v4l2 audio grabbing
[import_v4l2.so]: v4l2 video grabbing
[import_v4l2.so]: resync disabled
[import_v4l2.so]: video grabbing, driver = cx8800, card = pcHDTV HD3000 HDTV
[import_v4l2.so]: VIDIOC_S_FMT: : Invalid argument
[import_v4l2.so]: VIDIOC_S_FMT: : Invalid argument
[import_v4l2.so]: Pixel format conversion: UYVY [packed] -> YUV420 [planar] (slow conversion)
[import_v4l2.so]: driver does not support setting parameters (ioctl(VIDIOC_S_PARM) returns "Invalid argument")
[import_v4l2.so]: checking colour & framerate standards: [NTSC-M]
[import_v4l2.so]: receiving 30 frames / sec
[import_v4l2.so]: driver does not support cropping (ioctl(VIDIOC_CROPCAP) returns "Invalid argument"), disabled
[import_v4l2.so]: 27 buffers available
[export_ffmpeg.so] Using FFMPEG codec 'mpeg4' (FourCC 'DIVX', MPEG4 compliant video).
[export_ffmpeg.so]: WARNING: Interlacing parameters unknown, use --encode_fields
[export_ffmpeg.so]: INFO: No profile selected
[export_ffmpeg.so] Neither './ffmpeg.cfg' nor '~/.transcode/ffmpeg.cfg'
[export_ffmpeg.so] found. Default settings will be used instead.
[export_ffmpeg.so]: INFO: Starting 1 thread(s)
[export_ffmpeg.so]: INFO: Set display aspect ratio to input
Audio: using new version
Audio: using lame-3.96.1
encoding frame [1797],  29.96 fps, 100.0%, ETA: 0:00:00, ( 0| 0| 0)
[import_v4l2.so]: Totals: sequence V/A: 1800/1800, frames C/D: 0/0

clean up | frame threads | unload modules | cancel signal | internal threads | done
[transcode] encoded 1798 frames (0 dropped, 0 cloned), clip length  59.99 s
Try to increase encoding quality Q to 5 (max):
transcode -x v4l2,v4l2 -M 2 -i /dev/video0 -p /dev/dsp -y ffmpeg -F mpeg4-c 00:01:00 -g 640x480 -f 29.970,4 -I 1 -u 1024 -Q 5 -E 48000,16,2 --lame_preset medium -o /tv1/transcode-test-01.avi
This increased the filesize for a one-minute clip from 5.3M to 8.7M!

On /dev/video0, you need to turn hue all the way up to get decent color:
v4lctl -c /dev/video0 hue "100%"

The result is somewhat better, but frankly the quality of recordings from the cx88 driver seems clearly inferior to that of the bttv driver -- less crisp, more grainy, poorer colors, smaller size.  To top it off, I can't get closed captioning off these cards:

ntsc-cc -c -r ntsc -w
ntsc-cc -d /dev/vbi -c -w -r 27

shows the vbi is full of junk.

Conclusion: don't use the pcHDTV cards for analog television capture. They may become relevant for HDTV, but in the meantime use bttv cards. A good start would be to buy a second avertv stereo card?

9 April 2005: recording sound from pcHDTV

I recalled that what you had to do was find the sound card setting that sent the audio to the recording application -- likely a "capture" channel.

amixer -q

gives you a list of all channels.

amixer -q | grep apture
shows capture channels -- it shows all the capture channels are either muted or their volume turned to zero. Alsamixergui may not have the controls you need.

Here are the candidate channels:
amixer controls | grep Capture

numid=26,iface=MIXER,name='Capture Source'
numid=27,iface=MIXER,name='Capture Switch'
numid=28,iface=MIXER,name='Capture Volume'
numid=39,iface=MIXER,name='IEC958 Capture Switch'
Check the values:
amixer -c 0 cget numid=26

numid=26,iface=MIXER,name='Capture Source'
  ; type=ENUMERATED,access=rw---,values=2,items=8
  ; Item #0 'Mic'
  ; Item #1 'CD'
  ; Item #2 'Video'
  ; Item #3 'Aux'
  ; Item #4 'Line'
  ; Item #5 'Mix'
  ; Item #6 'Mix Mono'
  ; Item #7 'Phone'
  : values=0,0

amixer -c 0 cget numid=27

numid=27,iface=MIXER,name='Capture Switch'
  ; type=BOOLEAN,access=rw---,values=1
  : values=on

amixer -c 0 cget numid=28

numid=28,iface=MIXER,name='Capture Volume'
  ; type=INTEGER,access=rw---,values=2,min=0,max=15,step=0
  : values=0,0

amixer -c 0 cget numid=39

numid=39,iface=MIXER,name='IEC958 Capture Switch'
  ; type=BOOLEAN,access=rw---,values=1
  : values=off
OK, how about setting the Capture Switch to Line and the Volume to 15?
amixer -c 0 cset numid=26 5,5
amixer -c 0 cset numid=28 15,15
To test recording, try
streamer -d -o /tv1/rgb24.avi -f rgb24 -F stereo -r 12 -t 0:10
So I quickly discovered that Capture Switch should be set to 5,5 (mix) and I have recording sound!!!

Of course this is only on one channel, as I'm relying on the sound card.

1 April 2005: pcHDTV on the new Gigabyte computer (Chianti)

The pcHDTV driver is supported in the 2.6.12-rc1 kernel, and works to watch television, including switching channels. Sound unknown so far.

However, the script fails. Someone writes,

Friday, March 18, 2005
Bug-fix for ATSC Channel Changing on MythTv 0.17
Finally managed to nail the channel-changing bug on MythTV that had been bugging me, and more or less making mythtv unusable for me.

You can reproduce the bug by switching channels when on (on my setup) a ATSC (OTA HDTV) source. On switching channels between two channels that have the same pid/stream type (not toooo sure of this), the old pes won't get cleared out properly.

The proper fix would be to ensure that the pid/pes stuff gets handled properly in av_remove_stream in utils.c. Anyways, here's my crappy fix (well, more of a hack)

In the file libmythtv/avformatdecoder.cpp, change the file to look like the following. The real bug is that this doesn't fixup the pmt_pid tables in the ts context thingymajig. This works great now, well for me anyway.

void AvFormatDecoder::Reset(void)
{
SeekReset();

// Clear out the existing mpeg streams
// so we can get a clean set from the
// new seek position.
// for (int i = ic->nb_streams - 1; i >= 0; i--)
// {
// AVStream *st = ic->streams[i];
// if (st->codec.codec_type == CODEC_TYPE_AUDIO)
// {
// if (st->codec.codec)
// avcodec_close(&st->codec);
// av_remove_stream(ic, st->id);
// }
// }

m_positionMap.clear();
framesPlayed = 0;
framesRead = 0;
seen_gop = false;
seq_count = 0;
}
That's how far I got. The card is working, but it's not recording. Incidentally, for the digital dimension, "'mplayer /dev/dtv' or 'mplayer /dev/video32' and be able to watch the first dtv subchannel for that station. Mplayer won't change channels (dtvsignal will though) but it will display the first subchannel coming from the device." I'm assuming I'm getting only analog.

19 February 2005: mplayer autosync

I discovered mplayer will sync audio to video on playback:

mplayer -autosync 30 <filename.mpg>
In Kplayer, under Settings | Configure kplayer | Advanced | Additional commandline arguments, add -autosync 30.

The kplayer settings are stored in ~/.kde/share/config/kplayerrc, under section [Player Options]:
Command Line=-autosync 30
Direct Rendering=true
In brief tests, this fixes the sync problem. Or does it? When I now play back files in Kaffeine, the sync problem has disappeared! I don't see it anywhere anymore. Maybe I need to play a file for a full hour to see it? I don't think I had to do that before -- it was always out of sync.

14 January 2005: xvid

I tested xvid like this:

mencoder -tv driver=v4l2:width=720:height=480:norm=ntsc -ovc xvid -xvidencopts \
bitrate=1000 -oac mp3lame -lameopts cbr:br=128 -endpos $TIM -o $DIR/$FIL.mpg \
 tv:// > /dev/null
The quality seemed to be distinctly superior to divx (mpeg4) with lavc -- in fact the quality was stunning. But the encoding used all available CPU power and after initially keeping up, soon started to drop frames like crazy. However, once xvid is optimized for amd64, it may be possible to use it. Note I used a bitrate of 1000 instead of 900 with divx. Hold off on this until xvid is ready for amd64.

Another option is of course H264, which should also be usable soon -- it's developed as a VLC encoder/decoder, and as a decoder only in ffmpeg (so far).

23 December 2004: finalizing the recording setup

So I see that mencoder does the best job keeping sync:

mencoder -tv driver=v4l2:width=720:height=480 -ovc lavc -lavcopts vcodec=mpeg4:vbitrate=900 -oac mp3lame -lameopts cbr:br=64 -o output.avi tv://

How to turn that into something that can record like a VCR? Here's a script:
#!/bin/sh

if [ "$1" = "" ] ; then
echo "Use VCR <recording time in minutes> <filename>";echo "Please give a
time!";exit fi

if [ "$2" = "" ] ; then
echo "Use VCR <recording time in minutes> <filename>";echo "Please give a
filename!";exit fi

sudo /usr/bin/aumix -lR -i70

/usr/bin/mencoder -tv driver=v4l2:width=720:height=480:input=1:norm=ntsc
-ovc lavc -lavcopts vcodec=mpeg4:vhq -oac mp3lame -lameopts cbr:br=128
-endpos $1:00 -o $2 tv:// > /dev/null
So the key is "-endpos" which takes a time argument in minutes:seconds. This works as a VCR -- you can run it immediately like this:
cd /ssa/clips/TV-capture-scripts
./vcr.sh 15 CNN-time.mpg
Or you can run it at some time in the future (and note you can do this remotely):
at 3:30 -f vcr.sh 30 CNN-time.mpg
at now + 10 minutes -f vcr.sh 30 CNN-time.mpg
And so on. Wow. Finally.

Here's a variant you may be able to learn from -- transcoding from a vob file:
-oac mp3lame -lameopts br=96:cbr:vol=0:mode=1 -mc 0 -ovc lavc -lavcopts vcodec=mpeg4:vbitrate=2100:trell:mbd=2:vmax_b_frames=1:v4mv:vb_strategy=0:
vlelim=0:vcelim=0:cmp=2:subcmp=2:precmp=2:predia=1:dia=1:vme=4:psnr:vpass=1 -vop scale=704:304,crop=704:432:8:72 -sws 1

22 December 2004: recording sound

Here's what Michel Bardiaux says on video4linux-list:

The sound from the speakers comes (almost) directly from the line and mike, it does not go through the ADC. IMHO it is a very bad feature of xawtv since it makes xawtv unusable to validate your recording setup, notably the mixer settings.

What we do is this:

(1) start xawtv, select a channel and unmute audio (which unmutes on the TV card, not on the sound board). Check: sound from speakers.

(2) Don't exit xawtv (it re-mutes the card!), kill it with 'kill -9' (or ctrl-\). Note: we do that because in debian woody v4lctl does not seem able to do it.

(3) Using setmixer or aumix or xmixer, turn every mixer control to 100%.
Check with dump-mixer.

(4) Using 'record' (in deb package xawtv-tools), check have volume on the audio signal. Check: make a WAV and listen to it.

Here's what Poobah says on the ffmpeg-devel list:

$aumix -q
vol 70, 70
pcm 79, 79
speaker 64, 64
line 60, 60, P
mic 64, 64, P
cd 64, 64, P
igain 20, 20, R
line1 64, 64, P
phin 64, 64, P
phout 64, 64
video 64, 64, P

See how I have R next to igain so that is where its recording the sound
but... if line is muted or low thats how the sound will come out.

My "aumix -q" doesn't have an igain channel:

# aumix -q
vol 100, 100
bass 50, 50
treble 50, 50
synth 0, 0
pcm 54, 54
speaker 0, 0
line 100, 100
mic 0, 0
cd 0, 0
pcm2 0, 0
line1 0, 0
dig1 0, 0
phin 0, 0
phout 0, 0

Here's the audio part of v4l-info:

audio
    VIDIOCGAUDIO
        audio                   : 0
        volume                  : 0
        bass                    : 0
        treble                  : 0

There's amixer (part of alsa-utils) -- command-line control of alsa.  Issue
amixer -q
for a massive list of all channels. Some capture candidates:
amixer controls | grep Capture

numid=7,iface=MIXER,name='PCM Capture Volume'
numid=8,iface=MIXER,name='Music Capture Volume'
numid=16,iface=MIXER,name='Line2 Capture Volume'
numid=10,iface=MIXER,name='Mic Capture Volume'
numid=20,iface=MIXER,name='Aux2 Capture Volume'
numid=14,iface=MIXER,name='IEC958 Optical Capture Volume'
numid=18,iface=MIXER,name='Analog Mix Capture Volume'
numid=12,iface=MIXER,name='Audigy CD Capture Volume'
Number 18 is a good candidate. To see its current value,
amixer -c 0 cget numid=18
numid=18,iface=MIXER,name='Analog Mix Capture Volume'
  ; type=INTEGER,access=rw---,values=2,min=0,max=100,step=0
  : values=0,0
To select a channel for capture and set the volume to 80% for both channels:
amixer -c 0 sset 'Analog Mix',0 80%,80% unmute cap
or said differently,
amixer -c 0 cset numid=18 80%,80% unmute cap
numid=18,iface=MIXER,name='Analog Mix Capture Volume'
  ; type=INTEGER,access=rw---,values=2,min=0,max=100,step=0
  : values=80,80
When I ran a record session,
ffmpeg -vd /dev/video0 -r 29.97 -b 2048 -s 720x480 -t 10 video-10.mpg
I got sound! The mic was unplugged this time, so I really got sound -- bull's eye the first time. I upped the volume to 100%, and the sound is now great. There's possibly another channel that also contributes to volume? What about 7:
amixer -c 0 cget numid=7
I set this to 100% also -- and again, recording is fine. Does this mean both channels are recording, or did 7 make no difference? I mute 18 and test again -- sound still captures fine! I mute 7 -- still captures fine. This makes it likely the muting isn't working. I set the volume to zero:
amixer -c 0 cset numid=18 0%,0% mute
That killed the sound. So it's the sound level that matters, not the "unmute" and "cap"? I try to see if 7 can do it on its own:
amixer -c 0 cset numid=7 100%,100% unmute cap
No sound. I reset with "alsactl restore" and try 8, 10, 12, and 20 -- no dice. 18 is my channel; nothing else seems to make a difference. The sound quality is adequate, so this is not a problem -- I guess it could be louder, but it's acceptable.

I included the new setting in "alsactl store", so that it is now default. In alsamixergui, it simply shows up as the second "Analog mix" component -- the first handles playback from the TV card, the second recording.

However, there's a nasty delay -- that is to say, the audio comes at least a tenth of a second too early, likely more. I tried using -muxpreload and -muxdelay, to no effect:
ffmpeg -muxdelay 2 -vd /dev/video0 -r 29.97 -b 2048 -s 720x480 -t 60 video-4.mpg
On the other hand, I can also record in motv (MS AVI (RIFF) format, 24-bit TrueColor, 30fps) and get perfect sync! So it's clearly possible.  Actually I take that back -- it's not perfect; over long captures it may not be that good. Not fully tested.

I just need a command-line way of doing it. But the motv or xawtv way is good enough to capture teaching material, so in a sense I've arrived.

Here's mplayer:
mencoder -tv driver=v4l2:width=720:height=480 -ovc lavc -lavcopts vcodec=mpeg4:vbitrate=900 -oac mp3lame -lameopts cbr:br=64 -o output.avi tv://
I get the receipt
Forcing audio preload to 0, max pts correction to 0
It looks like there's a parameter I could set here. And the sync is perfect! Yay! So there we go -- this is good enough for my purposes.

21 December 2004: sound to soundcard

The btaudio help file says "most TV cards come with a short cable which can be plugged into your sound card's line-in" -- and the Audigy2 Value guide says the blue input is for line-in and the red for the microphone.  So you don't need to use btaudio, but you do need to load snd-bt87x -- then sound works fine, provided the mixer is correctly configured.

See also the SoundFAQ from /usr/src/kernel-source-2.6.9/Documentation/video4linux/bttv/Sound-FAQ.

Alsamixergui need these components on and up:

  • Master
  • PCM is not needed
  • Line (the first of the three Line components)
  • Analog Mix (the first of two)
  • Audigy Analog Output Jack (unmute)
  • Front
IEC958 Optical Raw must be off (muted)

Since Master regulates the volume, you can leave the others on max. You could find the command-line equivalent. 

The recording volume for some reason is too low. I discovered the default settings are in the file /var/lib/alsa/asound.state, but you can store and restore different profiles like this:

  • alsactl store -f /var/lib/alsa/asound.state.bt87x
  • alsactl restore -f /var/lib/alsa/asound.state.bt87x
I discovered sound was being recorded circuitously, from the speakers to the microphone, even though I had the microphone component set to zero in the mixer. I was unable to record sound directly.

For normal playback, these components need to be on (without these two, there's no sound in amarok):
  • EMU10K1 PCM (both)
It appears to be fine to include all components in the active alsa configuration, so they are stored both in the default file and in /var/lib/alsa/asound.state.bt87x.

18 November 2004: mencoder

In this convoluted command most things are correct:
$ mencoder -tv driver=v4l2:width=720:height=480 -ovc lavc -lavcopts vcodec=mpeg4:vbitrate=900 -oac mp3lame -lameopts cbr:br=64 -o output.avi tv://
Here's how mplayer sees the audio if btaudio analog is loaded:
Opening audio decoder: [pcm] Uncompressed PCM audio decoder
AUDIO: 32000 Hz, 1 ch, 16 bit (0x10), ratio: 64000->64000 (512.0 kbit)
Selected audio codec: [pcm] afm:pcm (Uncompressed PCM)
or like this -- not sure how the rate got changed:
Opening audio decoder: [pcm] Uncompressed PCM audio decoder
AUDIO: 44800 Hz, 1 ch, 16 bit (0x10), ratio: 89600->89600 (716.8 kbit)
Selected audio codec: [pcm] afm:pcm (Uncompressed PCM)
MP3 audio selected
Building audio filter chain for 44800Hz/1ch/16bit -> 44800Hz/1ch/16bit...
Writing AVI header...
ODML: vprp aspect is 16384:10922.
Forcing audio preload to 0, max pts correction to 0
It all looks promising, but in fact nothing is captured.

If I now add this to turn off the audio, capture works:

$ mencoder -tv driver=v4l2:width=720:height=480:noaudio -ovc lavc -lavcopts vcodec=mpeg4:vbitrate=900 -o output.avi tv://
So that works -- no audio of course, but capture works, producing this file:
$ tcprobe -i out*
[tcprobe] RIFF data, AVI video
[avilib] V: 29.000 fps, codec=DIVX, frames=897, width=720, height=480
[tcprobe] summary for output.avi, (*) = not default, 0 = not detected
import frame size: -g 720x480 [720x576] (*)
       frame rate: -f 29.000 [25.000] frc=0 (*)
   no audio track: use "null" import module for audio
           length: 897 frames, frame_time=34 msec, duration=0:00:30.931
So you've got the hang of it, but the audio isn't working.

More mencoder variants:
mencoder -tv on:driver=v4l2:device=/dev/video0:width=320:height=240:norm=NTSC:
chanlist=us-cable:channel=3:adevice=/dev/dsp1:forceaudio:forcechan=1
-o output.avi -ovc lavc -lavcopts vcodec=mpeg4:vbitrate=900
-oac mp3lame -lameopts cbr:br=128

mencoder tv://TVN -tv
driver=v4l:input=0:norm=PAL:chanlist=europe-east:width=640:height=480:adevice=/dev/dsp
-oac mp3lame -lameopts cbr:br=96 -ovc lavc lavcopts vcodec=xvid:vbitrate=900 film.avi
Note that mencoder isn't really working on clitunno, so no surprise if it's not also working with television. The only package that really works is ffmpeg. Here's the record of an attempt to encode with xvid using mencoder:
mencoder carrie-sample.dv -oac mp3lame -lameopts vbr=3 -ovc lavc -lavcopts vcodec=xvid:vbitrate=1000 -o Carrie.xvid

Cannot find codec 'xvid' in libavcodec...
Couldn't open video filter 'lavc'.
I created clitunno:/usr/local/bin/dv2xvid-mencoder, but it's not working (the script may also still have bugs).

17 November 2004: making sound work in live TV

First see if the current settings work, then try to experiment:

bttv audiomux 0x0c, 0x04, 0x08, 0x04, 0
Well, it turns out that what lspci advertizes as
0000:00:09.1 Multimedia controller: Brooktree Corporation Bt878 Audio Capture (rev 11)
also has a driver, somewhat incomplete and experimental, called btaudio. I added SOUND_BT878 (btaudio) and SOUND_TVMIXER (bt878 mixer) to the kernal, rebuilt and rebooted. It uses OSS rather than ALSA, but it's not clear that matters. The good news is that when I inserted the module, the devices got created:
btaudio: driver version 0.7 loaded [digital+analog]
btaudio: Bt878 (rev 17) at 03:04.1, irq: 16, latency: 64, mmio: 0xff5ff000
btaudio: using card config "default"
btaudio: registered device dsp0 [digital]
btaudio: registered device dsp1 [analog]
btaudio: registered device mixer0
Apparently the digital has no hope of working, but the analog may work.  The kernel documentation says the driver only works for recording, no playback -- but that's enough for the TV project.  For the analog to work, you need to insert the module like this:
modprobe btaudio analog=1
First I'll try the digital -- I issued
ffmpeg -vd /dev/video0 -r 29.97 -ac /dev/dsp0 -s 720x480 -t 60 video.mpg
and got "Could not find audio grab device." Same with /dsp1 and /dsp.

Then I rmmod btaudio and modprobe btaudio analog=1 and got this:
btaudio: driver version 0.7 loaded [digital+analog]
btaudio: Bt878 (rev 17) at 03:04.1, irq: 16, latency: 64, mmio: 0xff5ff000
btaudio: using card config "default"
btaudio: registered device dsp0 [digital]
btaudio: registered device dsp1 [analog]
btaudio: registered device mixer0
Looks no different than above.  Again I tried grabbing, again no audio device found. But then I just left out any specification of the audio:
ffmpeg -vd /dev/video0 -r 29.97 -s 720x480 -t 60 video.mpg
and got this:
Input #0, video4linux, from '':
  Duration: N/A, bitrate: N/A
  Stream #0.0: Video: rawvideo, yuv420p, 720x480, 29.97 fps
Input #1, audio_device, from '':
  Duration: N/A, bitrate: N/A
  Stream #1.0: Audio: pcm_s16le, 32000 Hz, mono, 512 kb/s
Output #0, mpeg, to 'video.mpg':
  Stream #0.0: Video: mpeg1video, 720x480, 29.97 fps, q=2-31, 200 kb/s
  Stream #0.1: Audio: mp2, 44100 Hz, mono, 64 kb/s
Stream mapping:
  Stream #0.0 -> #0.0
  Stream #1.0 -> #0.1
Press [q] to stop encoding
Now it is just mono, but that's not a big problem. The file was no good, however -- instead, the sound went to the server's speakers!

Later, I ran across this remark:
I just played with and got the alsa btaudio driver working. I had to specify /dev/sound/adsp1 rather than /dev/sound/dsp1, because there's only the analog sound on my card.
This could be useful for recording? Not tested.

And watching television now works with sound -- yay!
ffmpeg -vd /dev/video0 -r 29.97 -s 720x480 -t 10 video.mpg
I also tried various mixers and none of them work -- so I tried issuing
ln -sf /dev/dsp1 /dev/dsp
but I don't think it made any difference.

I was even able to trick the TV card into playing the sound only:
# ffmpeg -vd /dev/video0 -r 1 -an -s 720x480 -t 60 video.mpg
ffmpeg version 0.4.9-pre1, build 4718, Copyright (c) 2000-2004 Fabrice Bellard
  built on Sep 17 2004 00:52:01, gcc: 3.3.4 (Debian 1:3.3.4-11)
Input #0, video4linux, from '':
  Duration: N/A, bitrate: N/A
  Stream #0.0: Video: rawvideo, yuv420p, 720x480, 5.00 fps
Output #0, mpeg, to 'video.mpg':
  Stream #0.0: Video: mpeg1video, 720x480, 5.00 fps, q=2-31, 200 kb/s
Stream mapping:
  Stream #0.0 -> #0.0
[mpeg1video @ 0x2a95a806a0]MPEG1/2 doesnt support 5/1 fps
Error while opening codec for stream #0.0 - maybe incorrect parameters such as bit_rate, rate, width or heigh
#
So we're back at the prompt, and the soundtrack of CNN is still playing, with no user-space application I can see controlling it -- nothing in ps aux. It's like a radio, started with ffmpeg, but continuing to run after it exited.

When I issue
modprobe btaudio analog=0

Nov 17 22:03:47 clitunno kernel: bttv0: timeout: drop=0 irq=181089/181089, risc=7bee903c,bits: HSYNC OFLOW
Nov 17 22:04:05 clitunno kernel: bttv0: reset, reinitialize
Nov 17 22:04:05 clitunno kernel: bttv0: PLL can sleep, using XTAL (28636363).
Nov 17 22:07:15 clitunno kernel: btaudio: driver version 0.7 loaded [digital]
Nov 17 22:07:15 clitunno kernel: btaudio: Bt878 (rev 17) at 03:04.1, irq: 16, latency: 64, mmio: 0xff5ff000
Nov 17 22:07:15 clitunno kernel: btaudio: using card config "default"
Nov 17 22:07:15 clitunno kernel: btaudio: registered device dsp0 [digital]
Note that now only one device got created, the digital one. I now get this:
# ffmpeg -vd /dev/video0 -r 25 -ad /dev/dsp1 -s 720x480 -t 60video.mpg
ffmpeg version 0.4.9-pre1, build 4718, Copyright (c) 2000-2004 Fabrice Bellard
  built on Sep 17 2004 00:52:01, gcc: 3.3.4 (Debian 1:3.3.4-11)
File 'video.mpg' already exists. Overwrite ? [y/N] y
Input #0, video4linux, from '':
  Duration: N/A, bitrate: N/A
  Stream #0.0: Video: rawvideo, yuv420p, 720x480, 25.00 fps
/dev/dsp1: No such device
Could not find audio grab device
So the audio grab device isn't found -- ffmpeg exits -- and the sound comes through the speakers loud and clear. xawtv also works fine.

With btaudio on /dev/dsp0 [digital] only, sound still works fine in xawtv -- this is very robust. No luck capturing, however.  I'm trying to listen carefully for noise and there may be some, but the quality is really excellent still.  In fact I can remove the btaudio module and the sound still keeps coming!

Here are the modules that are still loaded:
snd_pcm_oss            52136  0
snd_pcm                92232  1 snd_pcm_oss
snd_timer              22920  1 snd_pcm
snd_page_alloc          9424  1 snd_pcm
snd_mixer_oss          18112  1 snd_pcm_oss
snd                    49256  4 snd_pcm_oss,snd_pcm,snd_timer,snd_mixer_oss
I think these may be oss modules, as opposed to alsa? I removed all of them -- and the sound still comes through. I removed tuner.  The one module necessary to keep the sound coming is bttv itself -- it was cut off when I removed bttv.

I removed all bttv modules and reinserted, adding these:
tuner                  21220  0
tvaudio                23008  0
bttv                  172108  0
video_buf              19396  1 bttv
firmware_class          8896  1 bttv
i2c_algo_bit            9224  1 bttv
btcx_risc               4488  1 bttv

What seems to be happening is that btaudio creates the /dev/dsp0 and/or 1 device nodes, and these remain in place when the btaudio is removed. The bttv module, with the help of  tvaudio, is then able to produce sound.

If you start xawtv after inserting bttv but before inserting btaudio, sound works fine with no further modules being drawn in.

I then inserted analog mode:
modprobe btaudio analog=1
Syslog shows the "analog=1" flag is not respected:
btaudio: driver version 0.7 loaded [digital+analog]
btaudio: Bt878 (rev 17) at 03:04.1, irq: 16, latency: 64, mmio: 0xff5ff000
btaudio: using card config "default"
btaudio: registered device dsp0 [digital]
btaudio: registered device dsp1 [analog]
btaudio: registered device mixer0
If I do this while xawtv is running, sound is uninterrupted and no further modules are drawn in. Neither oss nor alsa sound is needed for this.

If I now run ffmpeg, sound comes through whether I use -ad /dev/dsp0 or 1 or -an.

At some point these sound modules were drawn in automatically, but now I can't reproduce it:
snd_pcm_oss
snd_pcm
snd_timer
snd_page_alloc
snd_mixer_oss
snd
Whatever I'm doing now -- running ffmpeg and xawtv -- doesn't require them.

I got the pchdtv-tools for the 2.6 kernel by Jack Kelliher of pchdtv and debianized it on clitunno; I had to leave out one of the functions, the getatsc, but tststd chopatscfile dtvscan dtvsignal compiles. I tried:
dtvsignal /dev/video0 3
but got only junk, so I removed the package.

btaudio

Test to see if ffmpeg sees a difference between the analog and the digital channels of the TV card.

First rmmod btaudio && modprobe btaudio analog=0. Syslog shows
btaudio: driver version 0.7 loaded [digital]
btaudio: registered device dsp0 [digital]
No mention of an analog channel. Running ffmpeg now shows:
ffmpeg -vd /dev/video0 -r 29.97 -s 720x480 -t 60 video.mpg
Audio: pcm_s16le, 32000 Hz, mono, 512 kb/s
Secondly, rmmod btaudio && modprobe btaudio analog=1. Syslog now shows,
btaudio: driver version 0.7 loaded [digital+analog]
btaudio: registered device dsp0 [digital]
btaudio: registered device dsp1 [analog]
btaudio: registered device mixer0
Note that with analog=0, you don't get the mixer0 device. ffmpeg is unchanged:
Audio: pcm_s16le, 32000 Hz, mono, 512 kb/s
In both cases, I also got this:
btaudio: using card config "default"
I had a look at the source, /usr/src/linux-2.6.9-ac6/sound/oss/btaudio.c, and there appear to be recording functions inside btaudio.

Here's a possible test line:
sox -c 1 -u -r 32000 -t ossdsp /dev/dsp1 test.wav
Given by Antonio Beamud Montero <antonio.beamud@linkend.com>, who has my problem -- he can hear the television, but not record, and this command hangs. Not yet tested.

Here's a btaudio patch:
btaudio module_param conversion

Signed-off-by: Jan Dittmer

diff -Nru a/sound/oss/btaudio.c b/sound/oss/btaudio.c
--- a/sound/oss/btaudio.c 2004-11-14 01:24:57 +01:00
+++ b/sound/oss/btaudio.c 2004-11-14 01:24:57 +01:00
@@ -1113,15 +1113,15 @@
module_init(btaudio_init_module);
module_exit(btaudio_cleanup_module);

-MODULE_PARM(dsp1,"i");
-MODULE_PARM(dsp2,"i");
-MODULE_PARM(mixer,"i");
-MODULE_PARM(debug,"i");
-MODULE_PARM(irq_debug,"i");
-MODULE_PARM(digital,"i");
-MODULE_PARM(analog,"i");
-MODULE_PARM(rate,"i");
-MODULE_PARM(latency,"i");
+module_param(dsp1, int, S_IRUGO);
+module_param(dsp2, int, S_IRUGO);
+module_param(mixer, int, S_IRUGO);
+module_param(debug, int, S_IRUGO | S_IWUSR);
+module_param(irq_debug, int, S_IRUGO | S_IWUSR);
+module_param(digital, int, S_IRUGO);
+module_param(analog, int, S_IRUGO);
+module_param(rate, int, S_IRUGO);
+module_param(latency, int, S_IRUGO);
MODULE_PARM_DESC(latency,"pci latency timer");

MODULE_DEVICE_TABLE(pci, btaudio_pci_tbl);
Applied to 2.6.9-ac6 (manually; not in deb 2.6.9-ac6-5). Source. This is a list of the legal parameters to btaudio, with a change for each one -- but what is the significance of this change? Ask Jan Dittmer <j.dittmer@portrix.net>

Here's the new modprobe, using some of these parameters:
modprobe btaudio analog=1 dsp1=1 dsp2=2 debug=1 rate=32000
This uses the more standard device nodes for TV cards -- but it doesn't seem to make any difference.

There's a pair of articles on the BT878A chip with some details -- see
Following the instructions from the second article, I unloaded all bttv and snd_bt87x modules, and then issued:
modprobe btaudio debug=1
which produces more detailed messages in syslog -- not on loading, but on usage. (Note that no further modules were pulled in -- no bttv, no sound, just btaudio.) This gets me some interesting stuff that I saw in the source. I started by issuing
sox -w -r 448000 -t ossdsp /dev/dsp1 -t .wav test.wav
btaudio: open analog dsp [19]
btaudio: fmt: bits=16
btaudio: stereo=0 channels=1
btaudio: rate: req=448000  dec=4 shift=0 hwrate=448000 swrate=448000
btaudio: bufsize=131072 - bs=8192 bc=16 - ls=2048, lc=64
btaudio: bufsize=131072 - bs=8192 bc=16 - ls=2048, lc=64
btaudio: recording started
After pressing Ctrl-C I got:
btaudio: recording stopped
So this shows that the chip is delivering a sample rate of 448kHz, and that it's mono and analog. The result is slightly different if I use the digital device node:
btaudio: open digital dsp [3]
btaudio: fmt: bits=16
btaudio: stereo=0 channels=1
btaudio: bufsize=131072 - bs=8192 bc=16 - ls=2048, lc=64
btaudio: bufsize=131072 - bs=8192 bc=16 - ls=2048, lc=64
btaudio: recording started
I got the error message,
sox: Unable to set audio speed to 448000 (set to 32000)
The kernel documentation says the sample rate for the digital device can be set using the "rate" parameter on insmod, so I try:
 modprobe btaudio analog=0 rate=44100 debug=1
I then issue again,
sox -w -r 448000 -t ossdsp /dev/dsp0 -t .wav test.wav
The error message now reads,
sox: Unable to set audio speed to 448000 (set to 44100)
So nominally this is working. If I now load bttv, I get sound fine -- and the analog device node has not been created. If I try to test that device:
sox: Can't open input file '/dev/dsp1': No such device
So I'll have to conclude that the digital device is in fact working. It's conceivable this gives you better sound quality, but the quality appears to be excellent on both and I can't tell them apart. I'm not, however, getting stereo, which the card obviously supports.

With a sound card, you would hear this in the speakers:
sox -t .wav /usr/share/tuxpaint/sounds/harp.wav -t ossdsp /dev/dsp
I don't, since the TV card doesn't support playback, but I see the system responding.

You have to run the mixer (Kmix) as user root, otherwise it doesn't show up (or change permissions).

To follow the guys from the article, I revert to analog, which shows the three lines. In KMix I can set them -- they say to up the recording level on line 1 and mute 2 and 3. They are then able to record with this string:
sox -w -r 448000 -t ossdsp /dev/dsp1 -t .wav sound.wav
No luck for me, however.

Note that if I use btaudio analog, I get this in KMix or aumix -q:
# aumix -q
line1 100, 100, R
line2 0, 0, P
line3 0, 0, P
The setting is not retained if I close KMix, and I can't change the setting using aumix, but it's show correctly as set. Compare with snd-bt87x below.

snd-bt87x

Looking around, I discovered there is an ALSA driver for the brooktree bt878 and 879 chips, called snd-bt87x.  It is in the 2.6.9 kernel -- see documentation. Wow.  Following instructions, I added this to /etc/modutils/alsa:
# ALSA portion
alias char-major-116 snd
alias snd-card-0 snd-bt87x

# module options should go here

# OSS/Free portion
alias char-major-14 soundcore
alias sound-slot-0 snd-card-0

# card #1
alias sound-service-0-0 snd-mixer-oss
alias sound-service-0-1 snd-seq-oss
alias sound-service-0-3 snd-pcm-oss
alias sound-service-0-8 snd-seq-oss
alias sound-service-0-12 snd-pcm-oss
and ran update-modules. Meanwhile I rebuilt the kernel and rebooted. On bootup, this was loaded:
snd_bt87x              12328  0
snd_pcm                92232  1 snd_bt87x
snd_timer              22920  1 snd_pcm
snd                    49256  3 snd_bt87x,snd_pcm,snd_timer
snd_page_alloc          9424  2 snd_bt87x,snd_pcm
tuner                  21220  0
tvaudio                23008  0
bttv                  172108  0
video_buf              19396  1 bttv
firmware_class          8896  1 bttv
i2c_algo_bit            9224  1 bttv
btcx_risc               4488  1 bttv
All right. So that's an entirely different audio driver. It is reputed to have stability problems. Tests:
  • live TV works -- great sound
  • no record in dmesg of audio device nodes being created

    • Audio: pcm_s16le, 44100 Hz, mono, 705 kb/s (btaudio was 32000 Hz, mono, 512 kb/s)
    • Same problem with timeout ignored and demuxing overhead huge
    • tcprobe shows no audio track
  • sox -c 1 -u -r 44100 -t ossdsp /dev/dsp0 test.wav
    • $ tcprobe -i test.wav
      [tcprobe] RIFF data, WAVE audio
      [tcprobe] summary for test.wav, (*) = not default, 0 = not detected
            audio track: -a 0 [0] -e 44100,8,1 [48000,16,2] -n 0x1 [0x2000] (*)
                         bitrate=352 kbps
    • file may be empty -- I can't hear anything
The mixer (KMix) in snd_bt87x is very interesting:
  • a single output channel, named "Capture", with a slider and recording button
  • no inputs
  • four switches
    • FM (red -- inactive)
    • Mic/Line (red -- inactive)
    • Capture/boost (green -- inactive)
    • TV Tuner (pink -- active)
If I switch between TV Tuner and FM, there's a sound in the speakers. The boost can be activated, turns light green. Switching between TV Tuner and Mic/Input makes a difference -- I'm not sure what exactly. It may be that there is less background noise with the Mic/Input choice. It may also be that the channels are less balanced with Mic/Input.

I left it on Mic/Input for now. In xawtv's record movie function, the sound sample rate format defaults to 44,100, and also provides 48k and half of 44.1 downwards to 11.250 and then 8k.

Recording sound is no better than with btaudio.

This module produces the following output of aumix -q:
$ aumix -q
synth 100, 100, P
igain 0, 0
I can set this in KMix --
$ aumix -q
synth 100, 100, P
igain 67, 67
What's being set is the Capture channel -- the one input channel -- and the capture boost. The other switches don't show up in KMix. You can set everything with aumix -- at least everything it can see -- cf. aumix -h. The curses version actually lets you set the igain, though not the synth. On the command line:
$ aumix -i 10
That works. Note that KMix is more up to date and lets you set a lot more.

16 November 2004: making video work

Moved the AverTV Stereo card to clitunno, recompiled the kernel to include bttv -- it works! Perfect picture in xawtv. I can also capture without seeing anything (works whether xawtv is running or not -- maybe because there's only one channel defined in ~/.xawtv?):

ffmpeg -vd /dev/video0 -r 29.97 -b 2048 -an -s 720x480 -t 10 video.mpg
That's grabbing ten seconds of video to the file "video.mpg", with a resolution of 720x480 at 29.97 fps and a 2k bitrate, without sound. Or increase the bitrate like this, for a minute of capture:
ffmpeg -vd /dev/video0 -r 29.97 -b 4096 -an -s 720x480 -t 60 video.mpg
This encodes from raw video input to mpeg1. Could you encode directly to mpeg4? Note that this is ffmpeg running on amd64, working great! I also discovered an mpeg4 codec that works:
ffmpeg -vd /dev/video0 -r 29.97 -b 512 -an -s 720x480 -t 60 0512.mp4
Neither one could go much below 500kbs, however. Quality-wise, we may be reaching a ceiling around 2048kbs. These take about 80% of one of clitunno's CPU's.

Here's a better one:
ffmpeg -vd /dev/video0 -y -hq -vcodec mpeg2video -f rawvideo -loop -t 60 -r 25 220kbs.mpv
Quality's not too great though. Weird codec -- and what's the loop about? You can add bitrate:
ffmpeg -vd /dev/video0 -y -hq -vcodec mpeg2video -f rawvideo-loop -t 60 -b 1000 -r 25 270kbs.mpv
This one takes only 5% of one CPU!! Quality really poor.

Converting *wav files with ffmpeg:
find "$DIR" -name "*.wav" | while read list ; do
echo "$list"
ffmpeg -y -hq -i "$list" "${list%%.*}.ra" </dev/null
done
Nice! In lame it's even simpler:
find "$DIR" -name "*.wav" | while read list; do
echo "$list"
lame -b $BITRATE -h -t "$list" "${list%%.*}.mp3"
done
Anyway, here is the new dmesg on clitunno:
bttv: driver version 0.9.15 loaded
bttv: using 8 buffers with 2080k (520 pages) each for capture
bttv: Bt8xx card found (0).
bttv0: Bt878 (rev 17) at 0000:03:04.0, irq: 16, latency: 64, mmio: 0xff5fe000
bttv0: detected: AVerMedia TVCapture 98 [card=13], PCI subsystem ID is 1461:0004
bttv0: using: AVerMedia TVCapture 98 [card=13,autodetected]
bttv0: gpio: en=00000000, out=00000000 in=00fff7c3 [init]
bttv0: Hauppauge/Voodoo msp34xx: reset line init [11]
tuner: chip found at addr 0xc2 i2c-bus bt878 #0 [sw]
bttv0: Avermedia eeprom[0x4002]: tuner=2 radio:no remote control:no
bttv0: using tuner=2
tuner: type set to 2 (Philips NTSC (FI1236,FM1236 and compatibles)) by bt878 #0 [sw]
bttv0: i2c: checking for MSP34xx @ 0x80... not found
bttv0: i2c: checking for MSP34xx (alternate address) @ 0x88... not found
bttv0: i2c: checking for TDA9875 @ 0xb0... not found
bttv0: i2c: checking for TDA7432 @ 0x8a... not found
tvaudio: Ignoring new-style parameters in presence of obsolete ones
tvaudio: TV audio decoder + audio/video mux driver
tvaudio: known chips: tda9840,tda9873h,tda9874h/a,tda9850,tda9855,tea6300,tea6420,tda8425,pic16
c54 (PV951),ta8874z
bttv0: registered device video0
bttv0: registered device vbi0
bttv0: PLL: 28636363 => 35468950 .. ok
bttv0: PLL can sleep, using XTAL (28636363).
I inserted the tuner a little later -- it doesn't seem to be needed:
tuner: TV freq (268435455.93) out of range (44-958)
tvaudio likely doesn't do anything:
tvaudio: Ignoring new-style parameters in presence of obsolete ones
tvaudio: TV audio decoder + audio/video mux driver
tvaudio: known chips: tda9840,tda9873h,tda9874h/a,tda9850,tda9855,tea6300,tea6420,tda8425,pic16 c54 (PV951),ta8874z
lsmod
bttv                  172108  1
video_buf              19396  1 bttv
firmware_class          8896  1 bttv
i2c_algo_bit            9224  1 bttv
btcx_risc               4488  1 bttv

Again, you're not seeing a sound device -- but then clitunno has no sound card.

15 November 2004

Gubbio is now set up in console mode to allow you to experiment with the capture card.  No need to sit by the computer -- you can do this remotely, finally. Give commands in the console and track the reulst with

tail -f /var/log/syslog

You can experiment with different settings by unloading the bttv module and reinserting it with new parameters --

rmmod bttv && rmmod tuner && rmmod tvaudio (add more?)
modprobe bttv card=6 tuner=2 audiomux=2 bttv_debug=1
and so on.  Start by testing the values below, the ones that differ between the two AverTV cards.

Once you've inserted the modules and seen the results, test with
atscpackets /dev/video0 3
The AverMedia TVPhone get this:
.audio_inputs:   1,
.audiomux:       { 0x0c, 0x04, 0x08, 0x04, 0},
 /*                0x04 for some cards ?? */
.svhs:           3,
.gpiomask:       0x0f,
.tuner_type     = -1,
while my card gets this:
audio_inputs:   4,
audiomux       = { 13, 14, 11, 7, 0, 0},
svhs:           2,
gpiomask:       15,
msp34xx_alt    = 1,
pll            = PLL_28,
Some or all of these might be wrong.  Here's an example of using modules.conf:
All my config is in /etc/modules.d/bttv

alias char-major-81     videodev
alias char-major-81-0   bttv0
alias char-major-89     i2c-dev
alias sound-slot-1      btaudio
alias sound-service-1-0 btaudio

pre-install bttv modprobe -k msp3400; modprobe -k tuner
options bttv card=63 tuner=2
Sample modprobes:
rmmod i2c-algo-bit && rmmod i2c-core && rmmod v4l2-common && rmmod video-buf
modprobe bttv bttv_verbose=3 gbuffers=32 bttv_debug=1 automute=0 v4l2=1 tuner=2
modprobe bttv bttv_verbose=3 gbuffers=32 bttv_debug=1 automute=0 v4l2=1 tuner=2 audiomux=1 audioall=1
modprobe tvmixer
modprobe bttv i2c_debug=1 card=13 radio=0 tuner=2
None of this gives anything better than a simple "modprobe bttv" -- my problem seems to be hardware:
rmmod bttv && rmmod tuner && rmmod tvaudio && rmmod btcx-risc

bttv: driver version 0.9.15 loaded
bttv: using 32 buffers with 2080k (520 pages) each for capture
bttv: Host bridge needs ETBF enabled.
bttv: Bt8xx card found (0).
PCI: Found IRQ 11 for device 00:09.0
PCI: Sharing IRQ 11 with 00:07.2
PCI: Sharing IRQ 11 with 00:09.1
PCI: Sharing IRQ 11 with 00:11.0
bttv0: Bt878 (rev 17) at 00:09.0, irq: 11, latency: 32, mmio: 0xdb00b000
bttv0: detected: AVerMedia TVCapture 98 [card=13], PCI subsystem ID is 1461:0004
bttv0: using: AVerMedia TVCapture 98 [card=13,autodetected]
bttv0: enabling ETBF (430FX/VP3 compatibilty)
bttv0: risc main @ 046e1000
bttv0: gpio: en=00000000, out=00000000 in=00fff7c3 [init]
bttv0: Hauppauge/Voodoo msp34xx: reset line init [11]
i2c-core.o: adapter bt878 #0 [sw] registered as adapter 0.
bttv0: Avermedia eeprom[0x4002]: tuner=2 radio:no remote control:no
bttv0: using tuner=2
bttv0: i2c: checking for MSP34xx @ 0x80... not found
bttv0: i2c: checking for MSP34xx (alternate address) @ 0x88... not found
bttv0: i2c: checking for TDA9875 @ 0xb0... not found
bttv0: i2c: checking for TDA7432 @ 0x8a... not found
tvaudio: TV audio decoder + audio/video mux driver
tvaudio: known chips: tda9840,tda9873h,tda9874h/a,tda9850,tda9855,tea6300,tea6420,tda8425,pic16c54 (PV951),ta8874z
i2c-core.o: driver generic i2c audio driver registered.
i2c-core.o: driver i2c TV tuner driver registered.
tuner: chip found at addr 0xc2 i2c-bus bt878 #0 [sw]
tuner: type set to 2 (Philips NTSC (FI1236,FM1236 and compatibles)) by bt878 #0 [sw]
bttv0: i2c attach [client=Philips NTSC (FI1236,FM1236 and]
i2c-core.o: client [Philips NTSC (FI1236,FM1236 and] registered to adapter [bt878 #0 [sw]](pos. 0).
bttv0: registered device video0
bttv0: registered device vbi0
bttv0: video mux: input=0 mux=2
bttv0: PLL: 28636363 => 35468950 .. ok
Now test:
atscpackets /dev/video0 3

channel 3
freq*16 = 980
main: ioctl 1 rtn 0
main: ioctl 2 rtn 0
atscpackets ver 0.1 - by Jack Kelliher (c) 2002

This is what you should be seeing:
$ signal /dev/dtv 13
main: argc 3 argv[1] /dev/dtv
channel 13
freq*16 = 3380
main: ioctl 1 rtn 0
main: ioctl 2 rtn 0
signal ver 0.1 - by Jack Kelliher (c) 2002
channel = 13 freq*16 = 3380
Signal: | . : . | .____:____.____|
Signal: 088 (-26) #############################
Note that the "main: ioctl 1 rtn 0" lines are correct! It's just the signal that is not coming through.

Finally, I discovered the command "v4l-info" -- it gives you reams of information on the card. Everything looks fine and I'm ready to conclude the problem is hardware -- gubbio just isn't up to the task.

14 November 2004

Seeing somewhere that someone else had the same error messages when they tried to get two cards to work, I removed the Radeon AIW 8500 card, which also has a tuner, and replaced it with the old Voodoo Banshee card. I managed to get MythTV to use it -- I had to boot it without the initrd, which likely contained the radeon driver, and reconfigure X11.

v4l-conf now shows:

dga: version 2.0
mode: 1024x768, depth=24, bpp=32, bpl=4096, base=0xd8041000
/dev/video0 [v4l2]: ioctl VIDIOC_QUERYCAP: Invalid argument

What does this mean? in-out control something?

Here I don't see a problem:

$ xawtv -hwscan
This is xawtv-3.88, running on Linux/i686 (2.4.25-chw)
looking for available devices
port 61-61
   type : Xvideo, image scaler
   name : 3dfx Video Overlay

/dev/video0: OK                         [ -device /dev/video0 ]
   type : v4l2
   name : BT878 video (AVerMedia TVCapturÆPCI:00:09.0
   flags: overlay capture tuner

When I try to switch channels in xawtv, I get

v4l2: read: Input/output error
v4l2: read: Input/output error

It looks like the wrong in/out control has been selected. I wrote the v4linux list to ask for help.

Here's a happy AverTV Stereo camper -- from a year ago, using MythTV with no customized settings.

I then discovered that you can update your KnoppMyth with the latest MythTV packages from the 0.16 release (the knoppmyth changelog says this was done in September, so I likely have an 0.16 version). Verify that
deb http://knoppmyth.geekweb.net/updates ./
is in /etc/apt/sources.list and issue as follows:
mythbackup
/etc/init.d/mythbackend stop
apt-get update
apt-get install mythtv-arch-option mythmodule-arch mythmodule-arch mythmodule-arch
ldconfig
/etc/init.d/mythbackend start
mythtv-setup
The available debs are:
mythnews_0.16-1_i386.deb
mythweb_0.16-1_i386.deb
mythdvd-i586_0.16-1_i386.deb
mythgallery-i586_0.16-1_i386.deb
mythgame-i586_0.16-1_i386.deb
mythmusic-i586_0.16-1_i386.deb
mythtv-i586-lirc-xvmc_0.16-1_i386.deb
mythtv-i586-lirc_0.16-1_i386.deb
mythvideo-i586_0.16-1_i386.deb
mythweather-i586_0.16-1_i386.deb
mythdvd-i686_0.16-1_i386.deb
mythgallery-i686_0.16-1_i386.deb
mythgame-i686_0.16-1_i386.deb
mythmusic-i686_0.16-1_i386.deb
mythtv-i686-lirc-xvmc_0.16-1_i386.deb
mythtv-i686-lirc_0.16-1_i386.deb
mythvideo-i686_0.16-1_i386.deb
mythweather-i686_0.16-1_i386.deb
You don't have to install them all -- get whatever you're using.

Running mythtv-setup just updates the db schema. Once the schema is updated, just answer no, no and quit. You can then run the frontend and enjoy!

Cecil and Dale (source)

I didn't install anything, since my problem is elsewhere, but once the TV card is working consider installing these:
mythtv-i686-lirc
mythgame-i686
mythgallery-i686
mythdvd-i686
mythnews
mythmusic-i686
mythweather-i686
mythweb

13 November 2004:

I purchased an AverMedia AverTV Stereo card from the company in early November 2004 and installed it on Gubbio. dmesg shows:

bttv: driver version 0.9.15 loaded
bttv: using 8 buffers with 2080k (520 pages) each for capture
bttv: Host bridge needs ETBF enabled.
bttv: Bt8xx card found (0).

bttv0: Bt878 (rev 17) at 0000:00:09.0, irq: 11, latency: 32, mmio: 0xe700b000
bttv0: detected: AVerMedia TVCapture 98 [card=13], PCI subsystem ID is 1461:0004
bttv0: using: AVerMedia TVCapture 98 [card=13,autodetected]
bttv0: enabling ETBF (430FX/VP3 compatibilty)
bttv0: gpio: en=00000000, out=00000000 in=00fff7c3 [init]
bttv0: Hauppauge/Voodoo msp34xx: reset line init [11]
bttv0: Avermedia eeprom[0x4002]: tuner=2 radio:no remote control:no
bttv0: using tuner=2
bttv0: i2c: checking for MSP34xx @ 0x80... not found
bttv0: i2c: checking for MSP34xx (alternate address) @ 0x88... not found
bttv0: i2c: checking for TDA9875 @ 0xb0... not found
bttv0: i2c: checking for TDA7432 @ 0x8a... not found
tvaudio: TV audio decoder + audio/video mux driver
tvaudio: known chips: tda9840,tda9873h,tda9874h/a,tda9850,tda9855,tea6300,tea6420,tda8425,pic16c54 (PV951),ta8874z
tuner: chip found at addr 0xc2 i2c-bus bt878 #0 [sw]
tuner: type set to 2 (Philips NTSC (FI1236,FM1236 and compatibles)) by bt878 #0 [sw]
bttv0: registered device video0
bttv0: registered device vbi0
bttv0: PLL: 28636363 => 35468950 .. ok

Note that you should probably be seeing this and you're not:

btaudio: Bt878 (rev 2) at 00:09.1, irq: 9, latency: 32, mmio: 0xe2002000
btaudio: using card config "default"
btaudio: registered device dsp1 [digital]
btaudio: registered device dsp2 [analog]
btaudio: registered device mixer1

You are getting reams of these, however:

Nov 14 00:32:12 gubbio kernel: bttv0: timeout: drop=0 irq=449/1382, risc=0f60f000, bits: VSYNC$
Nov 14 00:32:12 gubbio kernel: bttv0: reset, reinitialize
Nov 14 00:32:12 gubbio kernel: bttv0: PLL can sleep, using XTAL (28636363).
Nov 14 00:32:12 gubbio kernel: bttv0: SCERR @ 0f60f000,bits: VSYNC HSYNC OFLOW FBUS SCERR*
Nov 14 00:32:13 gubbio last message repeated 3 times
lspci -vvv
0000:00:09.0 Multimedia video controller: Brooktree Corporation Bt878 Video Capture (rev 11)
        Subsystem: Avermedia Technologies Inc AVerTV WDM Video Capture
        Control: I/O- Mem+ BusMaster+ SpecCycle- MemWINV- VGASnoop- ParErr- Stepping- SERR- FastB2B-
        Status: Cap+ 66MHz- UDF- FastB2B+ ParErr- DEVSEL=medium >TAbort- <TAbort- <MAbort- >SERR- <PERR-
        Latency: 32 (4000ns min, 10000ns max)
        Interrupt: pin A routed to IRQ 11
        Region 0: Memory at e700b000 (32-bit, prefetchable)
        Capabilities: [44] Vital Product Data
        Capabilities: [4c] Power Management version 2
                Flags: PMEClk- DSI+ D1- D2- AuxCurrent=0mA PME(D0-,D1-,D2-,D3hot-,D3cold-)
                Status: D0 PME-Enable- DSel=0 DScale=0 PME-

0000:00:09.1 Multimedia controller: Brooktree Corporation Bt878 Audio Capture (rev 11)
        Subsystem: Avermedia Technologies Inc AVerTV WDM Audio Capture
        Control: I/O- Mem+ BusMaster+ SpecCycle- MemWINV- VGASnoop- ParErr- Stepping- SERR- FastB2B-
        Status: Cap+ 66MHz- UDF- FastB2B+ ParErr- DEVSEL=medium >TAbort- <TAbort- <MAbort- >SERR- <PERR-
        Latency: 32 (1000ns min, 63750ns max)
        Interrupt: pin A routed to IRQ 11
        Region 0: Memory at e7008000 (32-bit, prefetchable)
        Capabilities: [44] Vital Product Data
        Capabilities: [4c] Power Management version 2
                Flags: PMEClk- DSI+ D1- D2- AuxCurrent=0mA PME(D0-,D1-,D2-,D3hot-,D3cold-)
                Status: D0 PME-Enable- DSel=0 DScale=0 PME-
lsmod
tuner                  12712   1  (autoclean)
tvaudio                13064   0  (autoclean) (unused)
bttv                  110572   0
video-buf              11392   0  [bttv]
btcx-risc               2216   0  [bttv]
i2c-algo-bit            7048   1  [bttv]
i2c-core               12452   0  [tuner tvaudio bttv i2c-algo-bit]
soundcore               3524   3  [snd bttv]
videodev                6016   2  [bttv]
v4l2-common             3104   0  [bttv]

So far so good. In the bttv tarball that came with KnoppMyth, and in the kernel bttv documentation, is a file called Cards. It lists mine as follows:
TVCapture98 (="AVerMedia TV98" in USA) (Bt878)

PCB      PCI-ID      Model-Name      Eeprom  Tuner  Sound    Country
--------------------------------------------------------------------
M168-U   1461:0004   TVCapture98     40:11   FI1216   --      D    w/Remote

That's a minor but possibly significant mistake: my card is the M168T, with PCI-ID, Eeprom, and Tuner as shown.

The bttv-card.c file has this:

static void avermedia_tv_stereo_audio(struct bttv *btv, struct video_audio *v, int set);

The PCI-ID is correct, shown in dmesg above. The card was added to the Cards file in October 2002. There a piture here:

 

This is the AverMedia AverTV Stereo, model M168T, with a little board, SONY NE41S 216. The user comments,

"the audio settings for card 6 work properly with my card, and the tuner type with card 13"
Now card=6 - AVerMedia TVPhone (see CARDLIST) -- which indeed has that same Sony board.  The bttv.cards.c file in bttv-0.9.15 (the version used in the KnoppMyth I installed on Gubbio) now has this same line for both cards:
static void avermedia_tvphone_audio(struct bttv *btv, struct video_audio *v,
                                    int set);
In that same file, the AverTV Stereo card is identified by its PCI-ID:
{ 0x00041461, BTTV_AVERMEDIA98,   "AVerMedia TVCapture 98" },
Further down, the AverMedia TVPhone get this:
.audio_inputs:   1,
.audiomux:       { 0x0c, 0x04, 0x08, 0x04, 0},
 /*                0x04 for some cards ?? */
.svhs:           3,
.gpiomask:       0x0f,
.tuner_type     = -1,
while my card gets this:
audio_inputs:   4,
audiomux       = { 13, 14, 11, 7, 0, 0},
svhs:           2,
gpiomask:       15,
msp34xx_alt    = 1,
pll            = PLL_28,
Some or all of these might be wrong.  For instance the msp34xx_alt    = 1 should be turned off; that's an addon tuner card (?). And the pll may be wrong.

Here is the whole entry in bttv.cards.c:
{
        .name           = "AVerMedia TVCapture 98",
        .video_inputs   = 3,
        .audio_inputs   = 4,
        .tuner          = 0,
        .svhs           = 2,
        .gpiomask       = 15,
        .muxsel         = { 2, 3, 1, 1},
        .audiomux       = { 13, 14, 11, 7, 0, 0},
        .needs_tvaudio  = 1,
        .msp34xx_alt    = 1,
        .pll            = PLL_28,
        .tuner_type     = TUNER_PHILIPS_PAL,
        .audio_hook     = avermedia_tv_stereo_audio,
},

The tuner is clearly not correct -- but it's still likely correctly detected.

Installations for Isabel says to use these settings in /etc/modules.conf:

AverMedia TVCapture98: options bttv card=1 pll=1

However, the list of cards shows the card as number 13 and these instructions use the 2.2 kernel, so way outdated.

# modinfo bttv | more
filename:    /lib/modules/2.4.25-chw/kernel/drivers/media/video/bttv.o
description: "bttv - v4l/v4l2 driver module for bt848/878 based cards"
author:      "Ralph Metzler & Marcus Metzler & Gerd Knorr"
license:     "GPL"
parm:        radio int array (min = 1, max = 16), description "The TV card supports radio, default is 0 (no)"
parm:        bigendian int, description "byte order of the framebuffer, default is native endian"
parm:        bttv_verbose int, description "verbose startup messages, default is 1 (yes)"
parm:        bttv_gpio int, description "log gpio changes, default is 0 (no)"
parm:        bttv_debug int, description "debug messages, default is 0 (no)"
parm:        irq_debug int, description "irq handler debug messages, default is 0 (no)"
parm:        gbuffers int, description "number of capture buffers. range 2-32, default 8"
parm:        gbufsize int, description "size of the capture buffers, default is 0x208000"
parm:        video_nr int
parm:        radio_nr int
parm:        vbi_nr int
parm:        debug_latency int
parm:        fdsr int
parm:        combfilter int
parm:        lumafilter int
parm:        automute int, description "mute audio on bad/missing video signal, default is 1 (y es)"
parm:        chroma_agc int, description "enables the AGC of chroma signal, default is 0 (no)"
parm:        adc_crush int, description "enables the luminance ADC crush, default is 1 (yes)"
parm:        whitecrush_upper int, description "sets the white crush upper value, default is 207"
parm:        whitecrush_lower int, description "sets the white crush lower value, default is 127"
parm:        vcr_hack int, description "enables the VCR hack (improves synch on poor VCR tapes), default is 0 (no)"
parm:        irq_iswitch int, description "switch inputs in irq handler"
parm:        v4l2 int
parm:        triton1 int, description "set ETBF pci config bit [enable bug compatibility for triton1 + others]"
parm:        vsfx int, description "set VSFX pci config bit [yet another chipset flaw workaround]"
parm:        no_overlay int
parm:        latency int, description "pci latency timer"
parm:        card int array (min = 1, max = 16), description "specify TV/grabber card model, see CARDLIST file for a list"
parm:        pll int array (min = 1, max = 16), description "specify installed crystal (0=none, 28=28 MHz, 35=35 MHz)"
parm:        tuner int array (min = 1, max = 16), description "specify installed tuner type"
parm:        autoload int, description "automatically load i2c modules like tuner.o, default is 1 (yes)"
parm:        svhs int array (min = 1, max = 16)
parm:        remote int array (min = 1, max = 16)
parm:        gpiomask int
parm:        audioall int
parm:        audiomux int array (min = 1, max = 6)
parm:        firm_altera string, description "WinTV/PVR firmware (driver CD => unzip pvr45xxx.exe => hcwamc.rbf)"
parm:        vbibufs int, description "number of vbi buffers, range 2-32, default 4"
parm:        vbi_debug int, description "vbi code debug messages, default is 0 (no)"
parm:        i2c_debug int
parm:        i2c_hw int



 

 

top
Debate
Evolution
CogSci

Maintained by Francis F. Steen, Communication Studies, University of California Los Angeles


CogWeb