Converting Video Tapes to DVD

Playing TV on the PC

This command plays video on the screen, getting the video from the composite input and the audio from the sound card:

mplayer tv:// -tv driver=v4l2:device=/dev/video0:input=1:norm=ntsc:adevice=/dev/audio0

This command plays video and audio to the screen, getting the video from the coax and the audio from the sound card.

mplayer tv:// \ -tv driver=v4l2:device=/dev/video0:input=0:norm=ntsc:chanlist=us-bcast:channel=3:adevice=/dev/audio0

I also installed xawtv, which worked well. Right click on the tv window to see the xawtv options.

Capturing TV input to a File

This command worked for video (mpeg4), but not sound:

mencoder tv:// -tv driver=v4l2:device=/dev/video0:input=1:norm=ntsc:adevice=/dev/audio0 \ -ovc lavc -oac lavc -lavcopts acodec=ac3:vcodec=mpeg4:vbitrate=1800 \ -o tv.avi

This command works for video (mpeg2) and sound (ac3):

mencoder tv:// -tv driver=v4l2:device=/dev/video0:input=1:norm=ntsc:adevice=/dev/audio0 \ -ovc lavc -oac lavc -lavcopts acodec=ac3:vcodec=mpeg2video:vbitrate=5000 \ -of mpeg -ofps 30000/1001 \ -o tv.mpeg

This command also seems to work well for sound and video:

mencoder tv:// -tv driver=v4l2:device=/dev/video0:input=1:norm=ntsc:adevice=/dev/audio0 \ -of mpeg -mpegopts format=dvd -ofps 30000/1001 -vf scale=720:480,harddup \ -ovc lavc -oac lavc -lavcopts acodec=ac3:abitrate=192:keyint=25:vcodec=mpeg2video:vbitrate=5000:aspect=4/3 \ -o tv.mpeg

The problem is that the PC encodes at less than realtime, so after about 50 seconds the video buffer runs out of space. I wonder if it might be better to do this encoding in two passes.

This command dumps raw video and pcm sound to a file:

mencoder tv:// -tv driver=v4l2:device=/dev/video0:input=1:norm=ntsc:adevice=/dev/audio0:amode=1 \ -ovc raw -oac pcm \ -o tv.avi

But strangely, I find that mencoder performs faster if I encode the audio channel to ac3, like this:

mencoder tv:// -tv driver=v4l2:device=/dev/video0:input=1:norm=ntsc:adevice=/dev/audio0 \ -ovc raw -oac lavc -lavcopts acodec=ac3:abitrate=192 \ -o tv.avi

Trimming and Editing (timewise)

Sometimes I need to get rid of a few seconds from the beginning or end of a recording. This works best on the uncompressed video data. To do it, I use the -ss and -endpos switches. For instance, suppose I want to remove the first 8 seconds and end at the 8 minutes and 40 seconds mark, then I would use the command:

mencoder tv.avi -oac copy -ovc copy \ -ss 8 -endpos 8:32 \ -o tv2.avi

Note that I subtracted the 8 seconds from 8:40 to get 8:32, because the endpos counter starts at the start position of this run, not the start position of the original file.

Encoding the Video

Finally I can transcode the raw video to a mpeg file. I can do it in one pass using this command:

mencoder tv3.avi \ -of mpeg -mpegopts format=dvd -ofps 30000/1001 -vf scale=720:480,harddup \ -ovc lavc -oac copy -lavcopts vcodec=mpeg2video:vbitrate=6000:aspect=4/3 \ -o dvd.mpeg

Problem is, sometimes during scene changes I get weird artifacts, because the motion compression frames (B frames) can't change the entire scene. Really we want the P frames to line up with scene changes. So we need two pass compression. I don't know that this works with mpeg2 - most of the documentation was for mpeg4 (divx). But I will try it anyway. In our case the audio is already encoded, so we will just copy the audio stream. The first pass analyzes the video stream and creates a log file called divx2pass.log. The third pass uses the log file to more accurately position the different frame types. Here it is:

First pass:

mencoder tv3.avi \ -of mpeg -mpegopts format=dvd -ofps 30000/1001 -vf scale=720:480,harddup \ -ovc lavc -oac copy -lavcopts turbo:vpass=1:vcodec=mpeg2video:vbitrate=5000:aspect=4/3 \ -o dvd.mpeg

Notice that there is no output file name - the vpass option forces output to a log file named divx2pass.log

Third pass:

mencoder tv3.avi \ -of mpeg -mpegopts format=dvd -ofps 30000/1001 -vf scale=720:480,harddup \ -ovc lavc -oac copy -lavcopts turbo:vpass=2:vcodec=mpeg2video:vbitrate=5000:aspect=4/3 \ -o dvd.mpeg

Squeaks and Pops in the sound channel

The on-board sound chip picks up a lot of electrical noise from the mainboard. For instance, when I open and close windows in the X display, I can hear pops on the line in channel. Nothing I can do about that, except try a different audio card.

Setting Capture Values in ALSA

I borrowed an ensoniq 1371 from Dan Eriksen (thanks Dan!). Ran alsa-config, works great. But here's some interesting stuff about mixer applications:

I use kmix. kmix does not display all the channels. Try alsa-mixer, which uses character graphics on a console. Shows more, but still not everything. Use the amixer application. Read the amixer man page now! Very useful. The command "amixer contents" shows all the channels and the properties that can be set. The important channel that doesn't show up under either kmix or alsa-mixer is the capture channel. Use amixer to turn on this channel, set the capture channel to line-in, and set the capture volume level as follows:

Use "amixer contents" to see the contents of all the mixer registers. Here's the end of mine:

numid=24,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=4,4 numid=25,iface=MIXER,name='Capture Switch' ; type=BOOLEAN,access=rw---,values=1 : values=off numid=26,iface=MIXER,name='Capture Volume' ; type=INTEGER,access=rw---,values=2,min=0,max=15,step=0 : values=0,0

The problem is the last two settings. The capture switch is set off and the capture volume is set to zero. We need to make sure that the capture switch is on and that the volume is at a reasonable level:

$ amixer cset numid=26 90% 90% numid=26,iface=MIXER,name='Capture Volume' ; type=INTEGER,access=rw---,values=2,min=0,max=15,step=0 : values=14,14 $ amixer cset numid=25 1 numid=25,iface=MIXER,name='Capture Switch' ; type=BOOLEAN,access=rw---,values=1 : values=on

Handy web sites

My favourite:

Some other sites: