from VCR to AVI

I have a bunch of old VCR tapes and started the project of converting them to digital format. Part of my setup features a MythTV box, which features a video capture card. One of the inputs is taken by the TV signal, but the coax input was available for input from the VCR. Here are a couple of scripts I put together to ease the process of converting the old VCR tapes.

Basically, the process comes down to 2 steps:

  1. Record the video to digital
  2. Cut the captured video down to the actual video

The second step basically gets rid of extra captured video. In addition, I also transcode the video down to a smaller format, since the quality isn't great to begin with.

Here is the first script:

v4l2-ctl -i 0
mencoder /dev/video0 -of mpeg -oac copy -ovc copy -endpos $END -o $FILE
v4l2-ctl -i 1

This script basically takes two options. The first option is the length of the video to grab. HH:MM:SS is the format for that. The second option is the name of the file to save the captured video to.

Note that the script changes the video 4 linux v4l2-ctl command to switch to the coax input. This might differ for your card. Once it's done it switches back to the input source I normally use. Again, you might want to change that based on your preference.

The script will run for as long as specified based on the time specified in the first parameter. Then it will exit.

The second script changes the size and converts it to AVI.

function time2sec() {
  SPLITS=$(echo $T | cut -s -f3 -d ':')
  if [ "$SPLITS" ]; then
    HOURS=$(echo $T | cut -f1 -d':')
    T=$(echo $T | cut -f2,3 -d':')
    HOURS=$((${HOURS} * 60 * 60))
  SPLITS=$(echo $T | cut -s -f2 -d':' | sed 's/^0*//')
  if [ "$SPLITS" ]; then
    MINUTES=$(echo $T | cut -f1 -d':')
    T=$(echo $T | cut -f2 -d':')
    SPLITS=$(($SPLITS - 1))
    MINUTES=$((${MINUTES} * 60))
  echo "${OT} = ${T}"
time2sec $START
time2sec $END
echo ffmpeg -async 2 -ss $ST -t $(($ET - $ST)) -i $FILE -sameq -target vcd ${FILE/.mpg/.avi}
ffmpeg -async 2 -ss $ST -t $(($ET - $ST)) -i $FILE -sameq -target svcd ${FILE/.mpg/.avi}

This script takes the name of the captured file as the first parameter. The second parameter is the time index at which the video begins. The third defines the time index where the video stops.

Running the script will produce a AVI with the same name of the file provided, but cut down to the time index provided and resized to svcd quality. Adjust variables to your liking.