Home

Awesome

Transcoding video on Windows, the Lisa Melton way

Lisa Melton provides some amazing scripts that wrap HandBrake to produce high quality, portable versions of Blu-ray rips. The tools Lisa provides are written in Ruby, and they're packaged as a Ruby Gem. All the tools are cross platform, requiring only the Ruby runtime to be installed. But they do depend on external programs to get anything useful done. These dependencies are cross platform as well, but Windows has no standard package management system (de facto or otherwise), so installing these dependencies for Windows can be a bit of a pain. But it is possible! There are several ways to go about installing these tools and their dependencies, the two discussed here are to use Bash on Ubuntu on Windows (which is what we recommend for users of Windows 10), but if you have an older version of Windows you can also download Windows versions of everything that's needed.

Windows 10

If you're using an up-to-date version of Windows 10, you have access to "Bash on Ubuntu on Windows". This feature allows you to run command line Linux programs on Windows without using a virtual machine, and it also gives you access to Ubuntu's extensive package archives. Everything you need to run these scripts is easily installable with apt-get.

  1. First up, you need to activate Bash.
    1. Follow Microsoft's instructions to enable the Windows Subsystem for Linux, then install Ubuntu 18.04 from the Microsoft Store
  2. Next you install the dependencies for video_transcoding. Inside of bash:
    1. Run sudo apt-get update && sudo apt-get upgrade to ensure everything's up to date
    2. Run sudo apt-get install ruby ffmpeg mp4v2-utils mkvtoolnix
    3. Install HandBrakeCLI
      1. sudo add-apt-repository ppa:stebbins/handbrake-releases
      2. sudo apt-get update
      3. sudo apt-get install handbrake-cli
  3. Now you can install video_transcoding
    1. sudo gem install video_transcoding

The detect-crop command has an optional dependency on mpv for previewing crops. You can't launch graphical Linux apps using "Bash on Ubuntu on Windows", but it is capable of launching Windows programs; this means you can install mpv for Windows, then use an alias to launch it from bash:

  1. Create C:\bin and add it to your path
  2. Download a Windows build of mpv from here
  3. Extract it to C:\bin
  4. Create an alias for mpv: echo "alias mpv=mpv.exe" >> .bashrc
  5. Reload .bashrc by running source ~/.bashrc

If you have your movie files in the Windows file system (so NOT in ~userfolder/AppData/Local/lxss/home), for example on your desktop, you have to provide the path to it via /mnt/[drive letter]/path/to/your/file/location. You can also navigate to the folder in Explorer, then type bash in the address bar to open a bash instance to that location

Pre Windows 10 Creators Update and earlier

In old versions of Windows 10, or in Windows 8.1 and earlier, you either don't have access to Bash on Ubuntu on Windows or the version that's there can't be used to do this. All the dependencies are available for Windows though, you just need to track them down:

  1. Download everything from the links above
  2. Run the Ruby installer and make sure "Add to path" is ticked during install. Don't run the ridk install step at the end, you don't need this for video_transcoding
  3. Create C:\bin and add it to your PATH
  4. From the HandBrake zip file extract HandBrakeCLI.exe to C:\bin
  5. From the ffmpeg zip file extract bin\ffmpeg.exe to C:\bin
  6. From the MKVToolNix 7z file extract mkvpropedit and the data\ directory to C:\bin
  7. From the MP4v2 7z file extract libmp4v2.dll and mp4track.exe to C:\bin
  8. From the mpv 7z file extract mpv.exe to C:\bin
    C:\bin should now contain:
    • data\
    • ffmpeg.exe
    • HandBrakeCLI.exe
    • libmp4v2.dll
    • mkvpropedit.exe
    • mp4track.exe
    • mpv.exe
  9. Open cmd.exe and run gem install video_transcoding

Adding a folder to your PATH

  1. Right click Start
  2. Open Control Panel
  3. Search for "Path"
  4. Click "Edit System Environment Variables"
  5. Click the "Environment Variables" button in the lower right corner
  6. In the System Variables box find "PATH" and select it
  7. Click the "Edit" button

Further information

Batch control in cmd.exe

Batch control can be achieved with the following .bat file:

@echo off

setlocal EnableDelayedExpansion

set work=%cd%
set queue=%work%\queue.txt
set crops=%work%\Crops

for /F "tokens=*" %%I in (queue.txt) do (
    set title_name=%%~nI
    set crop_file=%crops%\!title_name!.txt

    if exist !crop_file! (
        for /F "tokens=* USEBACKQ" %%F in (`type "!crop_file!"`) do set crop_option=--crop %%F
    ) else (
        set crop_option=
    )

    call transcode-video !crop_option! "%%I"
)

It works in much the same way that Lisa's bash script works, although it does have the limitation of not being able to "resume" the queue in the way that Lisa's does. I would recommend creating a batch-transcode.bat file in your C:\bin folder, then you can create the necesarry file structure anywhere:

Crops\
queue.txt

In CMD you can CD to that directory, populate the queue.txt file then simply call batch-transcode and it'll transcode everything in the queue

To create a queue.txt with every mkv file in a directory you can use the following command:
for %a in (*.mkv) do echo %~fa >> queue.txt