Ubuntu – Hauppauge 610 Analog Video Capture Script or Command

avconvffmpegscriptsvideovlc

I have Xubuntu 14.04. The camcorder I am using is the Sony CCD-TRV16 NTSC 180x Digital Zoom. I am using the Hauppauge 610 USB-Live 2 Analog Video Digitizer and Video Capture Device to convert 8mm tapes to mp4. I am using VLC to convert the videos.

I will be converting quite a few tapes. It would be nice to have my exact same VLC GUI settings I use in a command or script. Also the ability to cut off recording after a certain time period would be great. I do not care what program I use to convert these. This customer said they were able to successfully use ffmpeg. However, I am fine with using any program that works. Much thanks in advance!

Here is the output of ffmpeg -f v4l2 -i /dev/video0 -f alsa -i hw:2,0.

Input #0, video4linux2,v4l2, from '/dev/video0':
  Duration: N/A, start: 8535.656468, bitrate: 165722 kb/s
    Stream #0:0: Video: rawvideo (YUY2 / 0x32595559), yuyv422, 720x480, 165722 kb/s, 29.97 fps, 29.97 tbr, 1000k tbn, 1000k tbc
Guessed Channel Layout for  Input Stream #1.0 : stereo
Input #1, alsa, from 'hw:2,0':
  Duration: N/A, start: 1450034548.361553, bitrate: 1536 kb/s
    Stream #1:0: Audio: pcm_s16le, 48000 Hz, 2 channels, s16, 1536 kb/s

Best Answer

Preliminary Steps

Launch VLC with vlc -vvv. This turns on verbosity to 2 (debug). This can also be seen in VLC GUI by going to Tools > Messages. Then follow the steps listed above in the screen shots to display the needed information for the command in the debug log. Then you can adjust the appropriate syntax by looking at the script below and online. You can also see the code and syntax by selecting Show more options. (The first screenshot in my question above.) However, this is only how I was able to create the cvlc command below. You may simply want to adjust the below script to your needs.

Initially, I was unable to get the audio to work with the one RCA audio port on my camcorder. I fixed this by going to Tools > Preferences > All (radio button, bottom left). Then I went to Input / Codecs > Access modules > ALSA. I changed the Sample rate to 48000 Hz. After changing this setting you will be able to stream your video. The other sample rates were causing an error.

Go to Media > Open Capture Device. Select Video device name and Audio device name (note that in the screen shot above it is default because I was using the microphone port instead. Yours will be different if you're using the RCA connection on your Hauppauge device.) Select NTSC (or whatever format your video tapes are). Click Play. While playing, go to Tools > Codec Information. You will want to adjust the below script according to the information given there. I adjusted the frame rate to 29.97 and sample rate to 48000 Hz. in my script because of the information given there.

About the Script

a. You are prompted to input the filename and metadata. Files are set to save to ~/Videos.

b. VLC (cvlc)

  1. I set the timeout to 122 minutes because my 8mm tapes are two hours. The --foreground option allows you to hit 'ctrl c,' and it will stop only this portion of the script and continue to the next part. (Some videos I have are shorter.)
  2. You can use VLC GUI to find the audio and video device names. (See the above screenshot.)
  3. Know whether your video is NTSC or another format.
  4. vcodec and acodec are set set to mpeg2 and mpga. The Amazon product page for the Hauppauge 610 states that it encodes to MPEG-2.
  5. For MPEG-2, VLC GUI only gave the option for .ts format. (See second screenshot above.) Therefore I am using mux=ts. Initially I was using vcodec=h264 acodec=mpga and mux=mp4. However, there were audio sync issues and the sound would drop out at certain places in the video. Also see the mux= section here.
  6. I needed samplerate=48000 for it to work.
  7. The frames per second given on the Codec Information were 29.97. This is standard for VHS / 8mm tapes. Therefore, I decided to match it.
  8. I chose to deinterlace. I thought this looked better.
  9. Using mux=ts will create a large file. My two hour videos are 5-7 GB.

c. FFmpeg compresses further with libx264 (from about 5 GB to about 1.5 GB) and adds in the metadata. There were additional handwritten notes about each 8mm tape and I wanted to include this additional information with the file. In the same command, FFmpeg moves left channel audio from only left to both left and right channels as a stream copy with no additional audio compression. My camcorder has only one RCA audio port. So this fixes the one speaker issue. Thanks to mondaugen for their answer on the one-channel audio issue.

d. Lastly, you are notified when the script finishes. For my personal script, I am actually using the following instead.

On my computer:

exo-open --launch WebBrowser $HOME/Videos/video-finished.htm

File contains: <p style="font-size: 128px; color: green; font-family: sans; text-align: center; margin-top: 10%; font-weight: bold;">VIDEO FINISHED</p>

On my phone: You can install gcalcli to receive a notification on your phone via Google Calendar when the script completes. Below, the date and time for two minutes in the future is put into a variable. Then a calendar entry is created for that time. A reminder is set for the start of that event. Google Calendar needs a two minute buffer. (I tried one minute.) So, you would be notified two minutes after the encode finishes.

new_date=`date --date="2min"`
gcalcli --calendar 'Name of Your Calendar' --title 'Video Finished' --where '' --when \'"$new_date"\' --duration 5 --description '' --reminder 0 add

End Product

The final result produces the larger .ts file and a further compressed .mp4.

CPU Usage

I have an AMD A8-6500B processor. cvlc runs at about 15% cpu usage. However, ffmpeg was running at about 97%. Therefore, in my script (not in the one below), I added the -threads 3 option to keep CPU usage at an overall 75%. I am able to do this because my processor is quad core.

#!/bin/bash

# Name:         Hauppauge 610 USB-Live 2 Analog Video Digitizer and Video Capture Device Conversion Script
# Author:       jbrock
# Dependencies: VLC media player; ffmpeg, in Ubuntu you will need to add a ppa to install.  
# License:      GNU GPLv3 (http://www.gnu.de/documents/gpl-3.0.en.html)
# Usage:        Digitize analog tapes to .ts format. Then convert to mp4, add metadata, and make sound work on left and right channels.

# Enter the name of the file.
echo -n "Enter file name: "
read archivo

# This is for metadata. It will show up in the media player playlist or after clicking Properties (in OS X Info) on the file context.
echo -n "Enter a description: "
read comentarios

# Encode video and stop after 122 minutes. The foreground option allows you to hit 'ctrl c,' and it will only stop this portion of the script.
timeout --foreground 122m cvlc v4l2:///dev/video0 :input-slave=alsa://hw:2,0 :v4l2-standard=NTSC :live-caching=300 --sout '#transcode{vcodec=mpeg2,acodec=mpga,ab=128,channels=2,samplerate=48000,fps=29.97,deinterlace}:std{access=file{no-overwrite},mux=ts,dst='$HOME/Videos/$archivo.ts'}'

# Convert to H.264 to compress further, add in the metadata comments, and make output from the left speaker to both speakers. 
ffmpeg -i $HOME/Videos/$archivo.ts -c:v libx264 -preset medium -crf 22 -metadata comment="$comentarios" -af "pan=mono|c0=FL" $HOME/Videos/$archivo.mp4

# Show the 'finished' message. 
notify-send "VIDEO FINISHED"