How to remove commercials in AVI files using ComSkip
Tools Required
VirtualDub 1.6.12
http://www.virtualdub.org/
QuEnc 0.61
http://nic.dnsalias.com/QuEnc.html
ComSkip 0.79.30 or higher
http://mk.kaashoek.com/comskip/
AVISynth 2.5 or higher
http://www.avisynth.com
MEncoder (optional)
http://www.mplayerhq.hu/
Those of us who capture television programs directly to AVI files (not MPEG files) have had to watch from the sidelines while ComSkip worked its magic for everyone else. To get around this problem, I have devised a method for detecting commercials in AVI files and removing them.
Please note that I don't go into detailed explanations of explicitly setting out folders, or explaining how to create and run batch files. I am merely providing the framework for going about the process.
Step 1 - Convert to MPEG
There are a number of programs out there that will covert an AVI file to an MPEG file. I have found QuEnc to be useful. QuEnc can be run using the command line and gives good quality conversions in a relatively short time. For example, the follwing command executed in a DOS window has given me sufficient quality in a short time:
Code:
quenc.exe -i capture.avs -o capture.mpg -b 3000 -aspectratio 4:3 -mpeg1 -novbr -auto -nohq -priority 4 -close
Before running the above command, create a file called "capture.avs" file with the following command:
Code:
AVISource(capture.avi)
Note: Don't use 0.70. It doesn't work for me for some reason.
Step 2 - Run Comskip (0.79.22 or higher)Now run ComSkip on the MPEG file you created in step 1.
Code:
comskip.exe capture.mpg
If you want to use VirtualDub make sure that you change the following line in the comskip.ini file from
Code:
output_vcf=0
to
Code:
output_vcf=1
Step 3 - Apply Commercial Cuts to AVI fileUsing VirtualDub (1.6.12 or higher)
Use the following three commands from a command prompt to make the cuts using VirtualDub.
Code:
vdub.exe /c
vdub.exe /s capture.vcf /p capture.avi capturecut.avi
vdub.exe /r
where capture.vcf was created by comskip, capturecut.avi is the new file created by VirtualDub.
Why am I wasting your time with all this command line nonsense? Because command line based programs allow us to make batch files to automate the process. Below are example batch files that you need to modify to match your own desired directories. The resulting files in the CUTDIR folder are in the same format as the capture format. The total processing time is about 20-25 minutes for an hour of programs on an AMD 2400.
Example Batch File 1 - BasicThis batch file is a basic setup for using the above method for your own system. Modify the initial variables to match your directories.
Code:
setlocal
REM The variables below need to be changed to match your setup
REM Please don't change the presence or absence of quotation marks as it may interfere with the functionality of the batch file
set CAPDIR=X:\DigitalVCR\temp
REM Set the directory where the original AVI files are captured
set CAPDIRBACKUP=X:\DigitalVCR\temp3
REM Set the directory where the original AVI files are backed up
set CUTDIR=X:\DigitalVCR\converted
REM Set the directory where the cut versions of the original AVI files are placed
set COMSKIP="C:\Program Files\ComSkip\comskip.exe"
set VDUB="C:\Program Files\VirtualDub\vdub.exe"
set QUENC="C:\Program Files\QuEnc\QuEnc.exe"
REM Set Program Locations
%CAPDIR:~0,2%
REM Change working drive to CAPDIR's drive
cd %CAPDIR%
REM Change working directory to CAPDIR
FOR %%C in (%CAPDIR%\*.avi) DO echo AVISource("""%%C""")>"%CAPDIR%\%%~nC.avs"
REM Create AVS files for use by QuEnc
FOR %%C in (%CAPDIR%\*.avs) DO start "Quenc" /wait %QUENC% -i "%%C" -o "%CAPDIR%\%%~nC.mpg" -b 3000 -aspectratio 4:3 -mpeg1 -novbr -auto -nohq -priority 4 -close
REM Use QuEnc to convert captures to MPG files in CAPDIR
FOR %%D in (%CAPDIR%\*.mpg) DO %COMSKIP% "%%D"
REM Use Comskip to read commercial locations in MPEG files
FOR %%A in (%CAPDIR%\*.avi) DO echo VirtualDub.Open(u"%%A"); > "%CAPDIR%\%%~nAnew.vcf"
FOR %%A in (%CAPDIR%\*.avi) DO type "%CAPDIR%\%%~nA.vcf" >> "%CAPDIR%\%%~nAnew.vcf"
FOR %%A in (%CAPDIR%\*.avi) DO echo VirtualDub.SaveAVI(u"%CUTDIR%\%%~nA.avi"); >> "%CAPDIR%\%%~nAnew.vcf"
REM Create VirtualDub script
REM You can add additional lines to add video or audio processing to the vcf script file.
REM If you are going to add Video processing of the file you need to add the line "VirtualDub.video.SetMode(1);" before your video processing commands.
REM See http://www.virtualdub.org/docs/vdscript.txt for more info on Virtualdub scripts.
FOR %%F in (%CAPDIR%\*.avi) DO %VDUB% /s "%CAPDIR%\%%~nFnew.vcf"
REM Run VirtualDub script
REM You can add additional commands for postprocessing here.
move %CAPDIR%\*.avi %CAPDIRBACKUP%
REM Move original AVI captured files to backup directory
del %CAPDIR%\*.* /Q
REM Remove all temporary files in original capture directory
endlocal
Example Batch File 2 - Adding AVISynth commands and VirtualDub to the processing.This batch file is the same as the basic batch file except that it allows you to add some AVISynth processing commands before. Modify the initial variables to match your directories.
Code:
setlocal
REM The variables below need to be changed to match your setup
REM Please don't change the presence or absence of quotation marks as it may interfere with the functionality of the batch file
set CAPDIR=X:\DigitalVCR\temp
REM Set the directory where the original AVI files are captured
set CAPDIRBACKUP=X:\DigitalVCR\temp3
REM Set the directory where the original AVI files are backed up
set CUTDIR=X:\DigitalVCR\converted
REM Set the directory where the cut versions of the original AVI files are placed
set COMSKIP="C:\Program Files\ComSkip\comskip.exe"
set VDUB="C:\Program Files\VirtualDub\vdub.exe"
set QUENC="C:\Program Files\QuEnc\QuEnc.exe"
REM Set Program Locations
set AVISYNTH1=Crop (30, 0, 30,0)
set AVISYNTH2=AssumeTFF()
set AVISYNTH3=Telecide()
set AVISYNTH4=Decimate()
REM Replace these example AVISynth commands here with your commands. Add more variables if required.
set VDUB1=VirtualDub.video.SetMode(3);
set VDUB2=VirtualDub.video.SetFrameRate(0,1);
set VDUB3=VirtualDub.video.SetTargetFrameRate(250000,10000);
set VDUB4=VirtualDub.video.SetCompression(0x64697678,0,10000,0);
REM Replace these example VirtualDub script commands here with your commands. Add more variables if required.
REM See http://www.virtualdub.org/docs/vdscript.txt for more info on Virtualdub scripts.
%CAPDIR:~0,2%
REM Change working drive to CAPDIR's drive
cd %CAPDIR%
REM Change working directory to CAPDIR
FOR %%C in (%CAPDIR%\*.avi) DO echo AVISource("""%%C""")>"%CAPDIR%\%%~nC.avs"
REM Create AVS files for use by QuEnc
FOR %%C in (%CAPDIR%\*.avs) DO start "Quenc" /wait %QUENC% -i "%%C" -o "%CAPDIR%\%%~nC.mpg" -b 3000 -aspectratio 4:3 -mpeg1 -novbr -auto -nohq -priority 4 -close
REM Use QuEnc to convert captures to MPG files in CAPDIR
FOR %%D in (%CAPDIR%\*.mpg) DO %COMSKIP% "%%D"
REM Use Comskip to read commercial locations in MPEG files
FOR %%B in (%CAPDIR%\*.avi) DO echo AVISYNTH1 >>"%CAPDIR%\%%~nB.avs"
FOR %%B in (%CAPDIR%\*.avi) DO echo AVISYNTH2 >>"%CAPDIR%\%%~nB.avs"
FOR %%B in (%CAPDIR%\*.avi) DO echo AVISYNTH3 >>"%CAPDIR%\%%~nB.avs"
FOR %%B in (%CAPDIR%\*.avi) DO echo AVISYNTH4 >>"%CAPDIR%\%%~nB.avs"
REM Add AVISynth commands to avs file created above. Add more lines if required
FOR %%A in (%CAPDIR%\*.avs) DO echo VirtualDub.Open(u"%%A"); > "%CAPDIR%\%%~nAnew.vcf"
FOR %%A in (%CAPDIR%\*.avs) DO type "%CAPDIR%\%%~nA.vcf" >> "%CAPDIR%\%%~nAnew.vcf"
FOR %%A in (%CAPDIR%\*.avs) DO echo "VirtualDub.video.SetMode(1);" >> "%CAPDIR%\%%~nAnew.vcf"
FOR %%A in (%CAPDIR%\*.avs) DO echo VDUB1 >> "%CAPDIR%\%%~nAnew.vcf"
FOR %%A in (%CAPDIR%\*.avs) DO echo VDUB2 >> "%CAPDIR%\%%~nAnew.vcf"
FOR %%A in (%CAPDIR%\*.avs) DO echo VDUB3 >> "%CAPDIR%\%%~nAnew.vcf"
FOR %%A in (%CAPDIR%\*.avs) DO echo VDUB4 >> "%CAPDIR%\%%~nAnew.vcf"
FOR %%A in (%CAPDIR%\*.avs) DO echo VirtualDub.SaveAVI(u"%CUTDIR%\%%~nA.avi"); >> "%CAPDIR%\%%~nAnew.vcf"
REM Create VirtualDub script
REM You can add additional lines to add video or audio processing to the vcf script file.
FOR %%F in (%CAPDIR%\*.avi) DO %VDUB% /s "%CAPDIR%\%%~nFnew.vcf"
REM Run VirtualDub script
REM You can add additional commands for postprocessing here.
move %CAPDIR%\*.avi %CAPDIRBACKUP%
REM Move original AVI captured files to backup diretory
del %CAPDIR%\*.* /Q
REM Remove all temporary files in original capture directory
endlocal
Example Batch File 3 - PocketPC versionThis batch file is the same as the basic setup except that it uses MEncoder to convert the cut file to be playable on a PocketPC (248 kbps Video, 320 pixels wide, original aspect ratio, MPEG4; 96 kbps Audio, MP3). Modify the initial variables to match your directories.
Code:
setlocal
REM The variables below need to be changed to match your setup
REM Please don't change the presence or absence of quotation marks as it may interfere with the functionality of the batch file
set CAPDIR=X:\DigitalVCR\temp
REM Set the directory where the original AVI files are captured
set CAPDIRBACKUP=X:\DigitalVCR\temp3
REM Set the directory where the original AVI files are backed up
set CUTDIR=X:\DigitalVCR\converted
REM Set the directory where the cut versions of the original AVI files are placed
set PPCDIR=X:\DigitalVCR\PPC
REM Set the directory where the PocketPC versions of the captures are stored
set COMSKIP="C:\Program Files\ComSkip\comskip.exe"
set VDUB="C:\Program Files\VirtualDub\vdub.exe"
set QUENC="C:\Program Files\QuEnc\QuEnc.exe"
set MENCODER="C:\Program Files\mplayer\mencoder.exe"
REM Set Program Locations
%CAPDIR:~0,2%
REM Change working drive to CAPDIR's drive
cd %CAPDIR%
REM Change working directory to CAPDIR
FOR %%C in (%CAPDIR%\*.avi) DO echo AVISource("""%%C""")>"%CAPDIR%\%%~nC.avs"
REM Create AVS files for use by QuEnc
FOR %%C in (%CAPDIR%\*.avs) DO start "Quenc" /wait %QUENC% -i "%%C" -o "%CAPDIR%\%%~nC.mpg" -b 3000 -aspectratio 4:3 -mpeg1 -novbr -auto -nohq -priority 4 -close
REM Use QuEnc to convert captures to MPG files in CAPDIR
FOR %%D in (%CAPDIR%\*.mpg) DO %COMSKIP% "%%D"
REM Use Comskip to read commercial locations in MPEG files
FOR %%A in (%CAPDIR%\*.avi) DO echo VirtualDub.Open(u"%%A"); > "%CAPDIR%\%%~nAnew.vcf"
FOR %%A in (%CAPDIR%\*.avi) DO type "%CAPDIR%\%%~nA.vcf" >> "%CAPDIR%\%%~nAnew.vcf"
FOR %%A in (%CAPDIR%\*.avi) DO echo VirtualDub.SaveAVI(u"%CUTDIR%\%%~nA.avi"); >> "%CAPDIR%\%%~nAnew.vcf"
REM Create VirtualDub script
REM You can add additional lines to add video or audio processing to the vcf script file.
REM If you are going to add Video processing of the file you need to add the line "VirtualDub.video.SetMode(1);" before your video processing commands.
REM See http://www.virtualdub.org/docs/vdscript.txt for more info on Virtualdub scripts.
FOR %%F in (%CAPDIR%\*.avi) DO %VDUB% /s "%CAPDIR%\%%~nFnew.vcf"
REM Run VirtualDub script
FOR %%E in (%CAPDIR%\*.avi) DO %MENCODER% "%CUTDIR%\%%~nE.avi" -o "%PPCDIR%\%%~nE PPC.avi" -oac mp3lame -lameopts cbr:br=96 -ovc lavc -lavcopts vcodec=mpeg4:vhq:vbitrate=248 -vf scale=320:-11 -ffourcc DX50
REM Convert Cut files to AVI compatible with PocketPC's (248 kbps Video, 320 pixels wide, original aspect ratio MPEG4; 96 kbps Audio, MP3)
REM See http://www.mplayerhq.hu/DOCS/man/en/mplayer.1.html for more options
move %CAPDIR%\*.avi %CAPDIRBACKUP%
REM Move original AVI captured files to backup directory
del %CAPDIR%\*.* /Q
REM Remove all temporary files in original capture directory
endlocal