I always wanted one of those personal video recorders, like a Tivo or replayTV or something. With one of those, I could stop being a slave to the clock, always watching the time so that I could drop whatever I was doing to watch the latest episode of Cheat Commandos.
Needless to say, I was getting fed up with it. I had two choices: either give up TV altogether, or find some way to make my own Tivo equivalent.
Of course, I didn't really need to do that whole pause-live-TV thing. So I just went out to by a nice, cheap TV tuner card for my computer. With that in hand, I set up the included scheduler to record all my favorite shows (like The Daily Show with Jon Stewart) to AVI files.
This all worked out nicely, for a while.
And then I got mad.
Well, not mad. Just annoyed that I had to always step through those blasted commercials.
I began searching for a way to have my computer remove the commercials for me. After a while, I realized that commercials are punctuated before and after with a little bit of black space in the video stream. That meant that I could make a program that scans for these and automatically drop commercials from video files.
That's when I said "Sweet!" and went to work.
When all was said and done, I had a highly useful commercial removal utility. The source code is included, so feel free to grab it and make modifications, redistribute, etc. I release the source code to you under the terms of the GNU General Public License (GPL). I also ask that if you make any substantial additions to it, that you let me know so that I can put your variation on this page too.
Cbreak works by scanning every frame of a video file, taking note of any black frames in the video. It uses these frames to divide the video up into segments.
Once the segments are established, it has two modes that it can operate in:
When all this is done, it copies the good video segments into a new AVI file along with the corresponding audio. Pretty great, huh? You can also change any of the parameters Cbreak uses to make decisions about a video stream, so it can be adjusted to your specific needs.
- In autonomic mode, it discards any video segments shorter than a certain time length (60 seconds is the default).
- In manual mode, it plays each segment for you and asks whether it should keep it or not.
I included a batch file in the distribution that you can just drag and drop files onto, to have Cbreak run with default options. You can edit the batch file to set your own options.
Usage: cbreak infile outfile [options]
- infile is the AVI file you want to remove commercials from.
- outfile is the filename you want to save to.
Switch Description -m Activates manual mode. Without this, Cbreak defaults to autonomic mode. -fx Sets frameskip; with this Cbreak will process every x frames. Default is 1 (no skipped frames). -px Sets pixelskip; with this Cbreak processes every xth pixel in a frame. Default is 5. -bx Sets black threshold. All pixels of a video frame must be darker than this in order to be considered a black frame. Default is 30, range is from 0 (see none) to 255 (see all) as black. -lx Sets minimum segment length. Segments shorter than x frames will not even be considered. Default is 15. -sx Sets autonomic segment length. In auto mode, segments shorter than x seconds will be dropped. No effect in manual mode. Default 60. -dx Sets detection area. Cbreak will only process the center x% of pixels in a frame. This weeds out a lot of video noise that shows up in the top and bottom of frames. Default is 90. -r Ignores saved segment data for that video file. Use this if you've changed detection parameters and want to run detection again. -n Disable SNL filename detection (stops automatic skit mode from filenames starting with SNL) -k Skit mode. This splits every scene to a separate file, useful for skit shows such as Saturday Night Live.
Okay, I've been getting a lot of e-mails asking whether Cbreak can be modified to work on MPEG files, since that's what most TV recording programs use. I definitely don't have the time to add MPEG functionality to Cbreak, but I can give you these instructions for a lossless conversion.
Basically all that happens is the MPEG container is stripped and all the video/audio data is put into an AVI file without re-encoding it. Then, with the proper codecs installed and configured, you can use Cbreak on the resultant AVI files! Here's how:
Step 1: Get the necessary codecsSince MPEG/MPEG2 in AVI container is a very rare encoding scheme, most computers won't be able to play them (and if you can't play them, Cbreak can't decode them). So grab the codec ffdshow from AfterDawn.com (if you haven't already) and install it. Afterwards, navigate to its Start Menu folder and choose "VFW codec configuration". In the Decoder tab, under Codecs, find MPEG in AVI and change "disabled" to "libavcodec". Hit OK and your system is primed to play MPEG in AVI files.
Step 2: Get ffmpegffmpeg is a wonderful command-line video/audio encoder. You can grab it here (you'll need 7zip to extract). Download and extract it to a folder as you are accustomed. Make sure ffmpeg.exe is somewhere in your PATH (or in the same folder as cbreak.exe) if you're using the batch file below.
Step 3: Convert your MPEG fileStarting here are the parts that you need to do per-MPEG file you want to Cbreak. Fortunately they're all commandline so you can just add them to the Cbreak batch file. You need to put each MPEG into AVI like this:
ffmpeg -i "input-file.mpg" -acodec copy -vcodec copy "output-file.avi"
This command will run very quickly as it's just copying data from the MPEG file to AVI. From there just run Cbreak on it as normal.
The new Cbreak batch fileNow that you've read all these instructions, you can download the new Drag-n-drop batch file which will do the conversion for you, provided you've followed steps 1 and 2 above.
Here's the download link again. Enjoy!
Also, see more of my works at devices.natetrue.com
Copyright © by Nathan True. All rights reserved.