8-millimeter video tapes seem to slowly fade to oblivion. In order to save old family videos recorded in this format, I’ve decided to digitize them.
After a quick try with
vlc, I’ve understood that it wasn’t the right tool for the task. It crashed with a cryptic error message every time I’ve tried to encode H.264 video, and it seemed that it best suited for real time encoding. Doing real time encoding, is sub-optimal as I can’t reach high quality encoding is a reasonable bit rate.
So I looked for another tool and recalled ffmpeg. While ffmpeg provided everything I looked: high quality video encoding using H.264 and stability, it wasn’t an easy start. ffmpeg’s defaults are notoriously ill-chosen. After hours of going through man pages, I’ve managed to capture and convert video tapes into high quality (encoded) digital video.
Basically the process involved capturing the raw video into a temporary file and then preform a two-pass encoding using H.264.
Capturing the raw video
ffmpeg -i /dev/video0 -t 1:30:00 -vcodec copy /tmp/video.mpg
-vcodec copy tells
ffmpeg to copy the raw codec data as is. It allows you to make an identical copy of the video from the capturing device
-t flag allows you to restrict the video capturing duration.
Performing the first encoding pass
ffmpeg -i /tmp/video.mpg -vcodec libx264 -vpre max -threads 0 \ -b 2100k -pass 1 -f mp4 -y /dev/null
-vcodec libx264 tells
ffmpeg to encode the video using H.264 encoding. The -vpre flag allows you to set a predefind presets that control (among other things) the quality of the encoded value. I used
max, other presets include
-threads 0 tells
ffmpeg to spawn as many threads it deems necessary.
-b 2100k tells it to target a bit rate of 2100kbps for video encoding. -pass 1 allows you to perform the first pass out two in a 2-pass encoding. In the first pass
ffmpeg will collect statistics and write them to a special log. When doing the second pass
ffmpeg can use this special log to better distribute the bit rate so it will achieve a constant quality at the specified average bit rate. The output of the first pass isn’t important so it’s directed to
-y switch tells
ffmpeg to ignore that this file already exists. As
ffmpeg can’t tell the format of the file by it’s name (
/dev/null) we specify it manually using
Performing the final encoding pass
ffmpeg -i /tmp/video.mpg -vcodec libx264 -vpre max -threads 0 \ -b 2100k -pass 2 ~/Videos/video-200108-200201-r1.mp4
This one is similiar to the last command except that we finally save the video. The
-pass 2 tells ffmpeg to perform the second and final pass. It will use the statistics log created by the previous command in order to optimize the encoding. The
-f flag isn’t necessary as the format is indicated by the output file’s name.
The encoding time is greatly effected by the preset that you chose. The
max preset is very slow, which wasn’t a problem for me in this case, but is something worth remembering. See Julian Simon’s x264 presets comparison for more information regarding the different presets available.