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:- VirtualDub 1.10.4
- Virtualdub FFMpeg Input Plugin
- Avisynth 2.6
- AVFS 1.0.0.5 – Avisynth Virtual File System
- Pismo File Mount Audit Package (build 173)
- Handbrake 0.10.2
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: auxsetup.exe. The following dialog will be displayed: Click on the Install handler button and the following dialog will be displayed: 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). 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:- Copy avfs.dll to a folder of your choosing. The c:\windows folder will work or use any other folder.
- Open a cmd prompt by clicking on the Start Menu and enter cmd.exe and press Enter.
- Type pfm register c:\windows\avfs.dll. This will register avfs.dll to the Prismo File Mount application.
- Open a cmd prompt by clicking on the Start Menu and enter cmd.exe and press Enter.
- Type pfm unregister c:\windows\avfs.dll.
- 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:- Copy avfs.exe to a folder of your choosing. The c:\windows folder will work or use any other folder.
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
- Click on File menu.
- Click on Open video file…
- 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!- 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.
- Click on Edit menu and select Set Selection Start to mark the beginning of the ad. You can also press the button.
- Move the cursor to the last frame of the same ad.
- Click on Edit menu and select Set Selection End to mark the end of the ad. You can also press the button.
- This will highlight the area that will be cut out of the final video:
- Click on Edit menu and select Delete to remove the selection from the video. You can also press the Delete key on your keyboard.
- Repeat all steps for each ads.
- Once all ad sections are removed, save your modifications in case something happens.
- Click on File menu and select Save processing settings…
- 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.- Click on Video menu and select Compression…
- 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.- 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.- Click on File menu.
- Select Start frame server…
- Enter a location for the VirtualDub AVIFile signpost (*.vdr) file. Click here for a sample file generated by VirtualDub.
- Leave options as is. It does not matter what you put here.
- Click on Start button to start the frame server.
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.- 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.
- 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).
- Save the file.
1 |
AviSource("G:\Movies\TV\1021_20150405183000\1021_20150405183000.vdr") |
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)
Mounting
Mount the *.avs file as a virtual folder containing the virtual AVI file.Using AVFS 1.0.0.5
- From the File Explorer, right click the AviSynth Script file (*.avs).
- Select the Mount option.
- The following dialog will be displayed.
- Select your desired options. The following options is suggested:
- Force read-only mount.
- Open after mount.
- Click the Mount button.
- 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.
Using AVFS 1.0.0.6
Mounting with AVFS 1.0.0.6 requires a different process.- Open a new Command Prompt.
- 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
- 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
- If command is executed properly, the application should display the following message: Press CTRL+C to exit.
- Leave the application running until the file is completely encoded in Handbrake.
- Press CTRL+C to stop the application properly.