Sunday, March 16, 2014

Playing Librarian/Curator Made Easier with Video File Metadata

My video file collection is a mess. There is duplicate content, and files ranging in resolution from 1080p to generic HD to DVD-level and many that are older and even lower than that. Similarly, some have surround sound tracks, and others only have super low-bitrate stereo tracks. I wanted to know what may need to be re-encoded, and to have the ability to sort through the vast volume of data relatively quickly based on various parameters built into the metadata.

This means that I needed to be able to read the metadata, grab some key information from each file, and have the ability to make decisions quickly. For reading the metadata, I chose ffprobe, which is part of the ffmpeg Windows binaries made available from Zeranoe.


Then, I fired up cygwin and used the following bash script to grab the stuff I cared about:

for file in *; 
do ls "$file" >> list.txt;
ffprobe.exe -v quiet -show_streams -show_data -pretty -of json "$file" | egrep codec_name\|width\|height\|bit_rate\|channel_layout\|sample_rate >> list.txt;
done
The double quotes ward off undesirable behavior when the file names have spaces and other characters that would need to be escaped out in them. The sequence of "OR"ed parameters that egrep is filtering from the output are what allow me to find out what I need to know about both the video and audio parts of each file.

Here's an example of the output for two versions of the same source material that were inadvertently created:

VERSION_A.m4v
            "codec_name": "h264",
            "width": 704,
            "height": 384,
            "bit_rate": "863.986000 Kbit/s",
            "codec_name": "aac",
            "sample_rate": "48000 KHz",
            "channel_layout": "stereo",
            "bit_rate": "164.469000 Kbit/s",
VERSION_B.m4v
            "codec_name": "h264",
            "width": 1920,
            "height": 800,
            "bit_rate": "5.983516 Mbit/s",
            "codec_name": "aac",
            "sample_rate": "48000 KHz",
            "channel_layout": "stereo",
            "bit_rate": "198.056000 Kbit/s",
            "codec_name": "ac3",
            "sample_rate": "48000 KHz",
            "channel_layout": "5.1(side)",
            "bit_rate": "640000 Kbit/s",

In this case, there's a clear winner. Version A is "DVD quality" and only contains a stereo soundtrack. Version B is "full HD" and includes not only a slightly higher bit-rate stereo audio track, but also a 5.1 surround audio track. As you can guess, the file sizes are significantly different, so you'd think you can just keep the larger file...  In this case, that would work, but the distinctions are not always so clear, and the data makes the job of curating a bit easier.

With a small amount of work, I should be able to get this output file into a CSV format and then quickly merge, sort, and filter the whole list as a spreadsheet.  

Friday, March 14, 2014

OpenVPN Client on Windows 8.1

After realizing that my L2TP VPN connection wasn't actually working when the PSK was provided, and therefore was not encrypting anything, I decided to implement OpenVPN instead.



I installed the latest OpenVPN x64 Windows client from http://openvpn.net/index.php/open-source/downloads.html and quickly discovered -- to my dismay -- that OpenVPN-GUI.exe would not run properly under Windows 8.1.

Mercifully, others had encountered the same problem and documented the basic and simple fact that the CLI application still functions properly, even if the GUI is completely borked in this version of Windows. They were right, and running openvpn.exe from the command line connects like a champ, and works beautifully.

But, this is windows and therefore I reserve the right to be too lazy to type every time I wish to connect.  So, I created a simple two-line batch file, and stuck a shortcut to it on the desktop. Now I just have to run this shortcut as administrator, check the status messages, and minimize the cmd window until I'm ready to disconnect.

The batch file looks a bit like this, but without the obfuscation listed here:
cd c:\users\USERNAME\documents\openvpn\
cmd /K C:\Progra~1\openvpn\bin\openvpn.exe MYVPNPROFILE.ovpn
As you likely guessed, the connection profile file and its corresponding certificate are contained in the C::\users\USERNAME\documents\openvpn\ directory. The "/K" parameter causes the command prompt window to remain open, which is necessary; the same is true of running the batch file as Administrator.  Terminating the window will drop the TAP network connection which is essential for the VPN to function, but it can be safely and easily minimized. If you don't run as admin, there aren't permissions to build the network connection...