Posts Tagged amixer

TV Capture on Linux

I’d like to begin by saying that after testing vlc, ffmpeg and mencoder in that order, mencoder came out tops.

Capture using vlc
vlc is unable to do the volume mute. You have to do it yourself unlike mencoder.
#v4lctl list (To view the current status of the tuner)

To turn mute off so we get sound off the sound card when caputuring from the sound card using vlc:
#v4lctl volume mute off

To capture from vlc:
#vlc -vvv --color \
v4l:/dev/video:norm=pal:frequency=805750: \
size=640x480:channel=0:adev=/dev/dsp: \
audio=0 -sout '#transcode{vcodec=mp4v \
,acodec=mpga,vb=3000,ab=256, \
venc=ffmpeg{keyint=80,hurry-up,vt=800000}, \
deinterlace}:duplicate{dst=display}'

805750 is the channel frequency in KHz. If you do not know the frequency of your channel, use tvtime’s tvscanner to print out all channels available as shown below:
#tvtime-scanner -n PAL (Yours could be NTSC. Everytime it tunes into a frequency it’ll show you in MHz. That’s how to get the frequency)

To turn it on back again (or else the sound from the tuner will continue playing even after having closed vlc)
#v4lctl volume mute on

Enable sound capture from sound card audio device

1. View all commands available:
#amixer –help

2. View all controls available:
#amixer controls

3. Get the “Capture Source” Item numbers. In my case the Capture Source was number ID 26 from “amixer controls” command above:
#amixer cget numid=26

4. Select the “Line” Item number as displayed in the command above:
#amixer cset numid=26 4

This should now allow you to record sound from your sound card.

Capture from TV to file using ffmpeg

First tune the tvcard using xawtv which doesn’t lock the video and audio device:
#xawtv

Now capture to a file using ffpmeg. The sound’s very disappointing.
#ffmpeg -t 10 -y -vd /dev/video0 -ad /dev/dsp -deinterlace -r 25 -s 320×240 -f avi -vcodec mpeg4 -b 800 -g 128 -bf 2 -acodec mp3 -ab 64 -ar 44100 -benchmark output.avi

Capture TV to file using xawtv’s streamer
If you’ve configured xawtv ok, here’s an example that records to out.avi using streamer (29.97 is PAL’s fps)
#streamer -p 4 -q -r 29.97 -t 00:00:10 -q -o out.avi -j 90 -f mjpeg -F mono16

Capture from TV to file using mencoder
The quality, filters and encoding of mencoder are amazing. It came out the best for me.
This command should capture from TV to flv file:


#mencoder -tv driver=v4l2: \
device=/dev/video0:freq=775.500: \
adevice=/dev/dsp:fps=25:input=0: \
audiorate=48000:amode=1:norm=PAL \
-endpos 00:00:10 -vf pp=lb,scale=320:240 \
-o analog.flv -ovc lavc -lavcopts vcodec=flv \
:autoaspect:vbitrate=500:mbd=2:mv0:trell: \
v4mv:cbp:last_pred=3 -of lavf -lavfopts \
i_certify_that_my_video_stream_does_not_use_b_frames \
-oac mp3lame -lameopts abr:br=56:fast \
-srate 22050 tv://

If you are doing web streaming you might want to optimize the file by reducing the number of keyframes using keyint shown below:
#mencoder -tv driver=v4l2: \
device=/dev/video0:freq=775.500: \
adevice=/dev/dsp:fps=25:input=0: \
audiorate=48000:amode=1:norm=PAL \
-endpos 00:00:10 -vf pp=lb,scale=320:240 \
-o analog.flv -ovc lavc -lavcopts vcodec=flv: \
autoaspect:vbitrate=500:mbd=2:mv0:trell:v4mv: \
cbp:last_pred=3:keyint=150 -of lavf -lavfopts \
i_certify_that_my_video_stream_does_not_use_b_frames \
-oac mp3lame -lameopts abr:br=56:fast -srate 22050 tv://

You could reduce the bitrate and file size even further by using -ofps (output frames per second), but then you stream might look too jerky.

Watch TV using Mplayer

You may use the v4l2 drivers to watch TV on mplayer. Here’s an example:
# mplayer -tv driver=v4l2: \
device=/dev/video0:freq=775.500: \
adevice=/dev/dsp:fps=25:input=0: \
audiorate=48000:amode=1:norm=PAL \
-vf pp=lb tv://

Leave a Comment