Remove ads from HDHomerun recording (featured image)

Best way to remove ads from HDHomeRun recordings (no intermediate file required)

Introduction

This guide is a follow up to the post called How to remove ads from HDHomeRun recordings and still encode with Handbrake. I record lots of TV shows using the HDHomeRun. I sometime want to keep recordings on a disk for archiving or to watch later. The following article explains how to remove ads from HDHomeRun recordings and encode the final video with Handbrake without quality loss. The whole process is executed using only FREE tools! With all TV shows comes a bunch of TV ads that I do not want to keep and waste time and disk space for. I encode all my videos using Handbrake because it supports quality based H264 encoding and 5.1 surround sounds but unfortunately, it does not support removing ads.

What’s the trick ?

The trick is to use VirtualDub’s frame server ability and other software to create a virtual file instead of an intermediate file as my old guide suggests. This option is much faster (takes 1 minute instead of hours) and uses much less disk space (2 KB instead of 8 GB) since there is no intermediate file to encode. VirtualDub is still required to cut ads as you would normally do. The process is also lossless (it does not add any quality degradation). Once the virtual file is generated (mounted), use Handbrake to encode the final video for best results.

Download & Install required software

The following software must be downloaded and installed:

Register VirtualDub AVIFile handler

For the process to work, you must register the AVIFile handler on your computer. After installing VirtualDub, run the following file: VirtualDub auxsetup.exe icon auxsetup.exe. The following dialog will be displayed:
VirtualDub auxsetup.exe Dialog

VirtualDub auxsetup.exe Dialog

Click on the Install handler button and the following dialog will be displayed:
VirtualDub Installing AVIFile frameclient

VirtualDub Installing AVIFile frameclient

Click on OK button and you should get the following confirmation message: AVIFile frameclient install successful.

VirtualDub FFMpeg Input Plugin

By default, VirtualDub is only able to read AVI files which is not helpful because my local channels are broadcasting in MPEG2 format. For instance, Montreal’s CBFT-DT is broadcasting in HDV 720p, MPEG layer 2, with two AC-3 audio channels. Full NFO available here. This plugin allows reading files that are not AVI and works perfectly with Montreal’s CBFT-DT MPEG 2 files. The installation is pretty strait forward, simply run the installer and select the location of where VirtualDub is installed. Once the process is completed, you should see the plugin available (*.vdf) within the plugins32 folder.

Avisynth

Avisynth as its name implies is an AVI file generator. The Avisynth web site describes their tool as “a scripting language and a collection of filters for simple (and not so simple!) non-linear video editing tasks. It frameserves video to applications“. In this scenario, Avisynth is used to parse VirtualDub’s frame server reference file (*.vdr) and wrap the results as an AVI file for AVFS to use. To install, run the installer and follow the on-screen instructions.

Pismo File Mount Audit Package

Pismo File Mount is an operating system extension that enables application controlled virtual and user mode file systems. Using Pismo File Mount, applications can expose all kinds of program and user data through the file system interface“. This software does not have any interaction with the user but it is required by AVFS to create the virtual folder containing the virtual files (*.AVI, *.WAV).
Pismo File Mount Audit Package Install

Pismo File Mount Audit Package Install

To install, run pfmap-173-win.exe and following the on-screen instructions.

AVFS

AVFS is the heart of the whole process. It allows the user to create a virtual file from an Avisynth script file using the Pismo File Mount system extension. “AVFS is a virtual file system that exposes the output of Avisynth scripts through the file system as a set of virtual media files. This allows Avisynth to feed media applications and converters that do not use the VFW API“. In this scenario, AVFS is used to create the virtual AVI file for Handbrake to use.

Installing version 1.0.0.5 (and previous versions)

Version 1.0.0.5 (and previous versions) are released with avfs.dll. To install, run the following commands:
  1. Copy avfs.dll to a folder of your choosing. The c:\windows folder will work or use any other folder.
  2. Open a cmd prompt by clicking on the Start Menu and enter cmd.exe and press Enter.
  3. Type pfm register c:\windows\avfs.dll. This will register avfs.dll to the Prismo File Mount application.
To uninstall, run the following commands:
  1. Open a cmd prompt by clicking on the Start Menu and enter cmd.exe and press Enter.
  2. Type pfm unregister c:\windows\avfs.dll.
  3. Delete the c:\windows\avfs.dll file.

Installing version 1.0.0.6 (and previous versions)

AVSF 1.0.0.6 is not compatible with build 173 of Pismo File Mount. Build 178 must be downloaded to be able to create a virtual file. Version 1.0.0.6 (and future versions) are released with avfs.exe. To install, run the following commands:
  1. Copy avfs.exe to a folder of your choosing. The c:\windows folder will work or use any other folder.
To uninstall, delete the c:\windows\avfs.exe file.

Instructions

Chaining application

The basic principle in this procedure is to chain application one after the other. The output from a software becomes the input of the next and so on until the video & audio streams reaches handbrake. The process is as follows:

MPEG2 recording VirtualDub Editing  VirtualDub *.vdscript file (Editing backup)  VirtualDub frame serving (*.vdr file) Avisynth script (*.avs) AVSF Virtual *.AVI file Handbrake encoding.

Open video file in Virtualdub

VirtualDub default video

VirtualDub default video

  1. Click on File menu.
  2. Click on Open video file…
  3. Browse to your MPEG2 video file.

Cut ads / video section

Virtualdub is the best video editing application I know. It supports video resizing, splitting, joining, filters but mostly removing ADS!
  1. Move the cursor to the first frame of an ad. Note: you can use your keyboard arrows to move 1 frame forward or backward to set the cursor at the exact desired frame.
  2. Click on Edit menu and select Set Selection Start to mark the beginning of the ad. You can also press the VirtualDub Set Selection Start button.
  3. Move the cursor to the last frame of the same ad.
  4. Click on Edit menu and select Set Selection End to mark the end of the ad. You can also press the VirtualDub Set Selection End button.
  5. This will highlight the area that will be cut out of the final video:
    Virtualdub Selection

    Virtualdub Selection

  6. Click on Edit menu and select Delete to remove the selection from the video. You can also press the Delete key on your keyboard.
  7. Repeat all steps for each ads.
  8. Once all ad sections are removed, save your modifications in case something happens.
  9. Click on File menu and select Save processing settings…
  10. Save your modifications to a VirtualDub script file (*.vdscript) file

Video codec selection

Since we are chaining application one into the other, there is no need to use video codec compression between application. Compressing frames between application will only slow down the speed at which each frames are pushed in the chain. You computer is more than capable dealing with uncompressed frames even in full HD resolution. You also reduce the risk of loosing quality between applications so leave the video compression to “Uncompressed RGB/YCbCr“. The final video compression will occur within Handbrake.
Virtualdub Uncompressed RGB Video Codec Selection

Virtualdub Uncompressed RGB Video Codec Selection

  1. Click on Video menu and select Compression
  2. Select Uncompressed RGB/YCbCr

Audio codec

There is no need to use any compression codec for the audio. A typical TV show is 45 minutes long which only takes ~2.9 GiB (66 MiB / min) for 5.1 Surround sound and ~495 MiB (11 MiB / min) for Stereo sound. Transferring this amount of data within memory should not be an issue. The final audio compression codec selection will occur within Handbrake.
  1. Click on Audio menu and select Full Processing Mode.

Start VirtualDub’s frame server

Now that your are done editing and removing ads from your video, you need to enable VirtualDub’s frame server.
  1. Click on File menu.
  2. Select Start frame server
  3. Enter a location for the VirtualDub AVIFile signpost (*.vdr) file. Click here for a sample file generated by VirtualDub.
The following dialog should be displayed:
VirtualDub Frameserver Options Window

VirtualDub Frameserver Options Window

  1. Leave options as is. It does not matter what you put here.
  2. Click on Start button to start the frame server.
The following dialog will be displayed:
VirtualDub Frameserver Mode

VirtualDub Frameserver Mode

The frameserver is now ready to provide frames to other applications. Leave the dialog running until the encoding with handbrake is complete. Press Stop serving button to return to VirtualDub’s editing mode. A safe way to know if VirtualDub is done serving frames is to look at the “Number of frames served” value. If it stopped increasing, it means that Handbrake and the frameclient is done processing all frames. * Warning: Pressing Stop serving button while the frame server is serving frames to Handbrake might corrupt your output (compressed) video.

Missing frameclients issue ?

Note: if you see “Frameclients installed: AVIFile only“, you can skip this section. What ? My screenshot says “Frameclients installed: None“. What does that means ? This message means that your system does not have a valid AVIFile handler installed. You probably missed a step in the Register VirtualDub AVIFile handler section.

AviSynth Custom Script

Now that VirtualDub is ready to server frames to the next application, you need to create an AviSynth file that will wrap the VirtualDub AVIFile signpost (*.vdr) file and generate a valid AVI stream.
  1. Create a text file next to the VirtualDub AVIFile signpost (*.vdr) file with the avs file extension (*.avs). It is a good practice to use the same path & filename as the *.vdr file.
  2. Enter the following text in the file: AviSource(“full_path_to_vdr”) (replace full_path_to_vdr by the actual full path to your vdr file).
  3. Save the file.
Here is an example of a valid AviSynth Script file (*.avs):

Workspace

Your workspace should contains 4 files:
  • The original MPEG2 recording file (*.mpg)
  • The AviSynth Script file (*.avs)
  • The VirtualDub AVIFile signpost file (*.vdr)
  • The VirtualDub editing backup file (*.vdscript)
Remove ADS From TV Recording Workspace

Remove ADS From TV Recording Workspace

Mounting

Mount the *.avs file as a virtual folder containing the virtual AVI file.

Using AVFS 1.0.0.5

  1. From the File Explorer, right click the AviSynth Script file (*.avs).
  2. Select the Mount option.
  3. The following dialog will be displayed.
AVFS Mounting Options

AVFS Mounting Options

  1. Select your desired options. The following options is suggested:
    1. Force read-only mount.
    2. Open after mount.
  2. Click the Mount button.
If the mounting is successful, the AviSynth Script file (*.avs) should be removed from the file system and be replaced by a folder with the same name as the file. The new folder contains multiple virtual files:
  • a copy of the AviSynth Script file (*.avs).
  • an error log (error.log) containing errors found during the mount operation. If there is no error, this file contains video and audio codec properties.
  • multiple audio file (*.wav, *.w64) with the same encoding. As far as I know, they are all identical.
  • an uncompressed video file in the Audio Video Interleave (*.avi) format.
If you selected the option Open after mount, the following window will be displayed:
AVFS 375 GB Virtual AVI File

AVFS 375 GB Virtual AVI File

Using AVFS 1.0.0.6

Mounting with AVFS 1.0.0.6 requires a different process.
  1. Open a new Command Prompt.
  2. Change the current directory to the location where you installed AVFS 1.0.0.6. For example, if AVFS is installed in F:\Apps\avfs_1.0.0.6, enter the following command in the prompt: cd /d F:\Apps\avfs_1.0.0.6
  3. Enter the command to mount the file. For example, if the AVS file is located in folder G:\TV, enter the following command in the prompt: avfs.exe G:\TV\1021_20150405183000.avs
  4. If command is executed properly, the application should display the following message: Press CTRL+C to exit.
  5. Leave the application running until the file is completely encoded in Handbrake.
  6. Press CTRL+C to stop the application properly.
AVFS 1.0.0.6 running

AVFS 1.0.0.6 running

* Warning: Pressing CTRL+C key while the frame server is serving frames to Handbrake might corrupt your output (compressed) video.

Test the virtual AVI file

Make sure that the virtual AVI file is valid. Open the AVI file with a standard video player. The file may take longer than usual to open. While the file is opening or playing, take a look at the VirtualDub Frameserver window. You should see the value of Number of frames served increasing:
VirtualDub Frameserver Mode

VirtualDub Frameserver Mode

Encode final video with Handbrake

The AVI file is now ready for encoding using Handbrake. Enjoy your TV show episode without any ads. Just open the file in Handbrake and encode using your favorite video parameters.
Handbrake video settings

Handbrake video settings

What you get

In the end, you get a perfectly encoded video without any ADS! A 1 hour recording of Montreal’s CBFT-DT which is in 720p MPEG 2 format is 7.72 GB.  Removing ads from this recording and encoding with Handbrake using a quality based profile will reduce the file size to 1.20 GB.

Leave a Reply