2

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
  • What model is the camcorder? – llogan Nov 22 '15 at 1:46
  • @LordNeckbeard I have added the information to the question. – jbrock Nov 22 '15 at 2:21
  • Try plugging the audio output cable from the camcorder into the Hauppauge device (either the red or white input). Then you have to choose the appropriate device in Device Selection > Audio device name. See FFmpeg Wiki: ALSA for info about that. If you get that working, then we can move onto using ffmpeg to capture, or VLC if you prefer, but ffmpeg will be easier to script (for me at least). – llogan Nov 22 '15 at 21:38
  • @LordNeckbeard I appreciate it. I had already tried adding each of the three options listed at Device Selection > Audio device name. The aux cable is working fine, so I think I'll just stick with that. My comment above about the RCA audio cable was more of just a perfectionist thing, and I wanted to be thorough. I do however welcome any comments or corrections on the below script. – jbrock Nov 23 '15 at 6:12
2

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"
  • Why are you going from MPEG-2 video -> MPEG-2 video -> H.264? If the device already outputs MPEG-2 video then you should simply re-mux it, or if you want H.264 encode directly to that and skip handbrake. – llogan Dec 8 '15 at 20:24
  • I know the script can certainly be shortened with less processing. I teach and am going to look into this after my semester ends this week. I just wanted to update this post in the meantime because the previous information was incorrect. (See b. 5 above.) – jbrock Dec 8 '15 at 20:41
1

Here's an example for ffmpeg

ffmpeg -f v4l2 -i /dev/video0 -f alsa -i default -t 02:02:00 \
-c:v libx264 -crf 23 -preset medium \
-c:a aac -strict experimental -ac 1 -b:a 96k \
-vf yadif,hqdn3d,format=yuv420p -movflags +faststart output.mp4
  • -t is for duration. This example will make a 2 hr and 2 min output.

  • See FFmpeg Wiki: H.264 Video Encoding Guide for the x264 -crf and -preset info.

  • yadif is a deinterlacer. You should experiment with the settings to see what mode works best for your content. Alternatively, you could try w3fdif.

  • hqdn3d is a denoiser. May be useful if your content is noisy, but too much denoising will cause obvious blurriness, and this filter may be slow.

  • The format filter will ensure a chroma subsampling scheme that is widely compatible. Otherwise, ffmpeg will assume you want to avoid or minimize chroma subsampling and the output may not be playable by non-FFmpeg based players like QuickTime.

  • -movflags +faststart will move some data after encoding is complete from the end of the file to the beginning. This allows playback to begin before the file is completely downloaded if your viewers are watching via progressive download.

  • You can add -metadata title="Title" and other metadata if you feel like it.

Cutting out the extra junk

After watching the output and you want trim it, getting rid of any blue or black blank video for example, you can just re-mux without re-encoding. This will skip the first 10 seconds and make an output 600 seconds (10 minutes) long. It may not be frame exact, but it will probably be close enough.

ffmpeg -ss 10 -i input -c copy -t 600 output
  • The ffmpeg technically worked, but the audio was very scratchy and staticky sounding. It was still this way after taking out the denoiser you included. It did however, go through both of my computer speakers. Initially it did not for VLC, but I got it to work. I appreciate the alternative method. For now, VLC works basically perfect. So, I'll mark it as the accepted answer. However, I will likely make use of your suggestion for trimming the beginning and end of the video. Thanks! – jbrock Nov 24 '15 at 4:25
  • @jbrock hqdn3d is a video denoiser; sorry, the answer didn't really specify. I'm not sure why the audio sucks. I'll blame ALSA. – llogan Nov 24 '15 at 6:43
  • In working with this old technology and so many variables, I figure some things are best just left to be a mystery. I am glad at least there is an alternative option explained and more documentation than there was before for tape digitization in Ubuntu. – jbrock Nov 24 '15 at 18:16
  • Please feel free to make adjustments to the ffmpeg command based on my updated answer. Then if it works this time, I'll be glad to upvote it. – jbrock Dec 8 '15 at 18:01
  • @jbrock I don't think I can provide much without more info about your inputs, such as the console output of: ffmpeg -f v4l2 -i /dev/video0 -f alsa -i default – llogan Dec 8 '15 at 20:25
0

I was also using a variation on the ffmpeg method when I first got this hardware, but I observed that vlc's default transcode gave better visual results on my system than ffmpeg, so I goofed about with the vlc command line (cvlc) and figured out the command line to request what the GUI example above is doing.

cvlc  v4l2:///dev/video1:standard=NTSC :input-slave=alsa://hw:3,0 :live-caching=1000 --sout "#transcode{vcodec=h264,acodec=mpga,vb=3000,fps=29.97,ab=128,audio-sync,channels=2,deinterlace}:file{dst=rec122015.mp4,no-overwrite}" --sout-keep
  • I initially tried encoding to h264. The audio would be in sync at the beginning of the video. However, by the end the audio would always be about a second or two ahead of the video. I tried this version of your command above to be thorough, and it resulted in it being out of sync. cvlc -vvv v4l2:///dev/video0:standard=NTSC :input-slave=alsa://hw:2,0 :live-caching=1000 --sout "#transcode{vcodec=h264,acodec=mpga,vb=3000,fps=29.97,ab=128,audio-sync,channels=2,samplerate=48000,deinterlace}:file{dst=output.mp4,no-overwrite}" --sout-keep – jbrock Dec 27 '15 at 0:11
  • You may want to see b. 4. of my answer above. You may also want to ensure that your lip sync is okay. It is complicated to correct after the fact because the millisecond difference between audio and video is different throughout the encoded video. I would be interested to hear if you do not have any issues with lip sync. Wishing you the best of luck! – jbrock Dec 27 '15 at 0:18

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.