zigford.org/converting-vhs-and-dv-to-modern-formats---part-1.html
2020-07-21 06:49:32 +10:00

206 lines
12 KiB
HTML

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"><head>
<meta http-equiv="Content-type" content="text/html;charset=UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<link rel="stylesheet" href="main.css" type="text/css" />
<link rel="stylesheet" href="blog.css" type="text/css" />
<link rel="alternate" type="application/rss+xml" title="Subscribe to this page..." href="feed.rss" />
<title>Converting VHS and DV to Modern Formats - Part 1</title>
</head><body>
<div id="divbodyholder">
<div class="headerholder"><div class="header">
<div id="title">
<h1 class="nomargin"><a class="ablack" href="http://zigford.org/index.html">zigford.org</a></h1>
<div id="description"><a href="about.html">About</a><a href="links.html"> | Links</a><a href="scripts.html"> | Scripts</a><br>Sharing linux/windows scripts and tips</br></div>
</div></div></div>
<div id="divbody"><div class="content">
<!-- entry begin -->
<h3><a class="ablack" href="converting-vhs-and-dv-to-modern-formats---part-1.html">
Converting VHS and DV to Modern Formats - Part 1
</a></h3>
<!-- bashblog_timestamp: #201905261936.31# -->
<div class="subtitle">May 26, 2019 &mdash;
Jesse Harris
</div>
<!-- text begin -->
<p>Over the past 10 years I've been meaning to convert my family's VHS tapes to a
modern format. Originally that would have been DVD, but as it seems that DVD
and Blu-Ray would have a limited lifespan, I've opted to go directly to modern
encoding formats.</p>
<hr />
<p>This will be a multi-part series stepping through all the challenges with
converting these formats using Linux. This post, focuses around getting Video
Grabber's (USB Dongles) to work under Linux.</p>
<hr />
<p>In order to get VHS content to a modern video format, you will need a compatible
USB capture device, a VHS Player and a PC. </p>
<p>The process should be fairly straight forward, but there were a number of issues
which made the task difficult to achieve without compromise.</p>
<p>Conceptually it should be as follows:</p>
<ol>
<li>Connect VHS Player to USB Capture Device</li>
<li>Connect USB Capture Device to PC</li>
<li>Install->Launch Capture software</li>
<li>Press Record in the Software</li>
<li>Press Play on the VHS player</li>
</ol>
<p>Step 2 is where it get's tricky on Linux. While there are a significant number
of capture devices supported on Linux, it is still <em>luck-of-the-draw</em> when
purchasing a device with Linux in mind. </p>
<p>From what I have found many devices are rebranded. E.g. Four same branded
devices may contain 4 different chipsets. Maybe only 2 of them contain the Linux
supported chipset. To make matters worse, vendors don't typically list the
chipset on their site or packaging.</p>
<p>The following is a description of my journey to get a couple of different
capture devices to work on Linux. Your mileage may vary.</p>
<p>In my case, I had two USB capture devices. One was very old <em>Pinnacle Dazzle</em>
obtained from my Dad that he was throwing out and the other was purchased at
<a href="https://www.aldi.com.au/">Aldi</a> by my Mother-In-Law. This one had no label on
the device, but the box stated:<br />
<em>Bauhn DVD Maker</em></p>
<h3>Dazzle</h3>
<p>I started with the Dazzle. This unit looked very old. Sometimes with Linux, Old=
Good. As devices age, the likelihood that some enthusiastic Linux hacker will
add driver support goes up (I don't actually know this and cannot prove it, but
you probably can't disprove it either, so there).</p>
<p>So, I plugged it in and typed <code>lsusb</code></p>
<pre><code> Bus 003 Device 007: ID 2304:021d Pinnacle Systems, Inc. Dazzle DVC130
</code></pre>
<p><em>Figure 1. Content snipped for brevity</em></p>
<p>The important part of the <code>lsusb</code> output is the ID <code>2304:021d</code></p>
<p>We now know what this beast is. Let's check if the kernel has already recognized
it. You can usually do this by checking your kernel messages and see if a driver
module loaded and told you it registered anything. Therefore: <code>dmesg</code></p>
<pre><code> [14842.638559] usb 3-11.3: new high-speed USB device number 7 using xhci_hcd
[14842.714905] usb 3-11.3: New USB device found, idVendor=2304, idProduct=021d, bcdDevice= 0.00
[14842.714907] usb 3-11.3: New USB device strings: Mfr=1, Product=2, SerialNumber=0
[14842.714908] usb 3-11.3: Product: DVC 130
[14842.714909] usb 3-11.3: Manufacturer: Pinnacle Systems, Inc.
[14843.570702] usb 3-11.2: reset low-speed USB device number 5 using xhci_hcd
</code></pre>
<p><em>Figure 2</em></p>
<p>The output shows the <code>idVendor</code> and <code>idProduct</code> match the ID from the output of
<code>lsusb</code> in <em>Figure 1</em></p>
<p>Essentially, the kernel is reporting the USB device, but the absence of messages
from drivers other than <code>usb</code> are not a good sign.</p>
<p>We know by the output of <code>dmesg</code> that a kernel module has not loaded. It is time
to check that the kernel modules we need are indeed compiled and available.
Luckily for me, I'm running <a href="https://gentoo.org">Gentoo</a> so always have the
kernel source at hand. With video capture devices, these parts of the kernel are
referred to as the Video For Linux subsystem.
<em>(Technically, Video for Linux 2)</em></p>
<p>These kernel modules can be found under: Drivers->Media->USB. </p>
<pre><code> Device Drivers ---&gt;
&lt;*&gt; Multimedia support ---&gt;
[*] Analog TV support
[*] Media USB Adapters ---&gt;
&lt;M&gt; USB video devices based on Nogatech NT1003/1004/1005
&lt;M&gt; STK1160 USB video capture support
&lt;M&gt; WIS GO7007 MPEG encoder support
&lt;M&gt; WIS GO7007 USB support
&lt;M&gt; WIS GO7007 Loader support
&lt;M&gt; Conexant cx231xx USB video capture support
&lt;M&gt; Empia EM28xx USB devices support
</code></pre>
<p><em>Figure 3 shows kernel options to enable video capture</em></p>
<p>After enabling all the relevant looking ones, I compiled them all and unplugged
and re plugged my device, then checked <code>dmesg</code> again. Still no luck.</p>
<p>This is the point I recommend most people give up. I myself am not a big fan of
giving up. So what do I do? I bust out my trusty screw driver and pop that
sucker open to see whats <em>inside</em>. Under the magnifying glass I read out and
google all the names on the chips. One of them catches my eye:</p>
<p><em>go7007</em></p>
<p>Well would you look at that. There is a module for this chipset. Perhaps all we
need to do, is <em>teach</em> it to use my USB device. I start exploring the <code>.c</code> files
to find which one of them contains definitions looking like USB device and
product IDs. I began poking around in the source files looking for a <code>struct</code>
recording all the supported USB Product and Device ID's.</p>
<p>Here is the <code>struct</code> I found in <code>go7007-usb.c</code></p>
<pre><code> static const struct usb_device_id go7007_usb_id_table[] = {
{
.match_flags = USB_DEVICE_ID_MATCH_DEVICE_AND_VERSION |
USB_DEVICE_ID_MATCH_INT_INFO,
.idVendor = 0x0eb1, /* Vendor ID of WIS Technologies */
.idProduct = 0x7007, /* Product ID of GO7007SB chip */
.bcdDevice_lo = 0x200, /* Revision number of XMen */
.bcdDevice_hi = 0x200,
.bInterfaceClass = 255,
.bInterfaceSubClass = 0,
.bInterfaceProtocol = 255,
.driver_info = (kernel_ulong_t)GO7007_BOARDID_XMEN,
},
{}
};
</code></pre>
<p><em>Figure 4</em></p>
<p>The figure above is one device in the <code>struct,</code> so in <code>vim</code> of course, I yank
yank a bit of text here and there and try to add support for my own USB device.
The main thing to get right, is to substitute the <code>idVendor</code> and <code>idProduct</code>
from the <code>struct</code> with the ID's we discovered in <em>Figure 1 and Figure 2</em>.</p>
<p>For other interfaces of the <code>struct</code> I'm mostly guessing, but hoping I can just
copy some of the other devices, recompile and it might work. But if it doesn't
work, change things around a bit, like some of the other cards and try again. </p>
<p>If done correctly, the kernel module should load automatically when the device
is plugged in.</p>
<p>Sadly, I tried many combinations, caused a couple of kernel panics and sometimes
the card would load and I could get to see a blue screen when viewing the
device, but no content :( I was also able to setup a USB trace and see that the
driver was successfully uploading the firmware to the device.</p>
<p>In the end, I gave up on this device.</p>
<p>PS, I tried to capture using this device from a Windows VM. The device was so
old it would only work on 32-bit Windows 7 or older. While I was able to get
a driver, I could not find the original special software required to capture
and regular DirectShow capture to VirtualDub or OBS didn't work either.</p>
<h3>Bauhn DVD Maker</h3>
<p>This devices seemed a tad more modern. It has cables for capturing Component
and Composite. It came with a CD with drivers and software for Windows. Other
than that, there was little evidence online of this device. No-one mentioned
this model and certainly not in relation to Linux. I tried the obvious tests
(lsusb, dmesg) but didn't spend too much time trying to make it work for Linux.</p>
<p>On my Windows 7 VM though, I did have some luck. I got the software working
and was able to capture some VHS tapes. Although the capture was successful
there was no flexibility with the file format. The files came out in MPEG 2
(essentially DVD type files), which are okay, but if I wanted these files to
be online, I would need to re-encode them. That would mean a potential
degradation in quality. I mean, come on! Haven't these videos degraded in
quality enough!</p>
<p>What I wanted to do, was for the videos to be captured in a near lossless format
and then re-encode to 2 files. 1 for showing on the internets (so that means
smallish file size, optimized for streaming and compatibility) and 2 for
archival purposes (use the most forward leaning tech available large close to
lossless).</p>
<p>My thinking is that future generations will be having to convert historical
videos to another format and I want to make a large lossless file available
for that purpose.</p>
<p>I decided to crack open the Bauhn DVD maker and see what makes it tick.</p>
<p><img alt="Close up picture of circuit board" src="images/connexent.jpeg" /></p>
<p>Okay, I know how to do this, google all the little numbers and words. It didn't
take long to discover the chip and the existing Linux module for this baby.
Like the <code>go7007</code>, the <code>cx231xx</code> module supports many devices that use this
chip. Again, I had a crack at setting up the .c driver and adding in the Product
and Device ID's to make it work. And guess what?</p>
<p><em>Boom</em> It worked. And that, my friends is joy. I tested using VLC --&gt; Media --&gt;
Open Capture Device..., then click the 'Video device name' dropdown box and
choose /dev/video0</p>
<p>You can download my <a href="files/cx231xx.patch">patch file</a> against kernel 4.19.44</p>
<p>Now onto the task of actually doing something with the video files which I will
cover in my next post.</p>
<p>Tags: <a href='tag_linux.html'>linux</a>, <a href='tag_ffmpeg.html'>ffmpeg</a>, <a href='tag_gentoo.html'>gentoo</a>, <a href='tag_kernel.html'>kernel</a></p>
<!-- text end -->
<!-- entry end -->
</div>
<div id="footer">&copy <a href="http://twitter.com/zigford_org">Jesse Harris</a> &mdash; <a href="mailto:jesse&#64;zigford&#46;org">jesse&#64;zigford&#46;org</a><br/>
Generated with <a href="https://github.com/cfenollosa/bashblog">bashblog</a>, a single bash script to easily create blogs like this one</div>
</div></div>
</body></html>