Useful Perl scripting

If you’re one of those people who cut your transport streams in YMC (or Avisynth in general) and want to keep the original audio, this script is for you. It will read a given Avisynth script, look for the first trim line (or the first one labeled by a configurable label), generate a list of timecodes (based on the framerate, assumed to be 30000/1001 fps but also configurable), run mkvmerge to split a given file (usually the .aac given to you by DGindex; the “DELAY Xms” syntax is supported) at the given timecodes and finally (if so desired) attempt to merge the parts you wanted back together.

If you’re not me you probably got fed up with doing this manually months ago and wrote your own variant, but I thought I’d share mine anyway (because I hadn’t posted anything here in like three months and it’s getting time for the quarterly contribution).

Download: split_aud_0.22.

Example usage:
perl split_aud.pl -mr -i "someaudio DELAY -15ms.aac" -o test.mka trimfile.avs
Where trimfile.avs has a line somewhere that looks like
trim(u,v)+trim(x,y)+trim(...)
etc.

Use -h to get help. Switches can be grouped (i.e. -v -r means the same thing as -vr).

Comments (6)

  1. KGSubs wrote:

    the most easy way to cut commercials in audio ^^
    thanks Fluff

    Friday, July 31, 2009 at 04:59 #
  2. heavyburdens wrote:

    i use it for splitting everyting.
    thanks :D

    Monday, November 23, 2009 at 07:47 #
  3. PhillipDS wrote:

    Hey! after looking for a good while, I finally found your script, and it’d be awesome to trim the audio without having to re-encode it… but I’m having some problems. my AVS currently looks like this:

    LoadPlugin(“C:\Program Files\AviSynth 2.5\plugins\DGDecode\DGDecode.dll”)
    MPEG2Source(“[Elitist_Fags]_Seitokai_Yakuindomo_-_03_[07-18_00-30-00]_(TVK_1440x1080_MPEG2_TS).d2v”, cpu=0)
    Trim(0, 5527) ++ Trim(7328, 17426) ++ Trim(19226, 33100) ++ Trim(34900, 48518)

    So it has both the source and the trims, but when I run it with this command line:

    perl split_aud.pl -f 24000/1001 -l trim -i sy03notrim.aac -o trimmed.mka sy03rawcode.avs -mr 2> log.txt

    I get this in the log:

    Use of uninitialized value $cuttimes[0] in string eq at split_aud.pl line 51, line 3.
    No trims found on any line(s) marked by “trim” in sy03rawcode.avs at split_aud.pl line 58, line 3.

    What could be the problem? Could you please help me? Thanks in advanced!

    Sunday, July 25, 2010 at 05:50 #
  4. TheFluff wrote:

    Some versions of it hates spaces between trims and/or between commas. This version should accept your trim line: http://www.mod16.org/fansub/split_aud_0.22.7z

    Sunday, July 25, 2010 at 17:00 #
  5. PhillipDS wrote:

    Thanks a lot, TheFluff!

    I tried with the new one you posted, and even though this one did not leave that same error, it has a different one:

    Global symbol “$cfile” requires explicit package name at split_aud.pl line 48.
    Global symbol “$cfile” requires explicit package name at split_aud.pl line 49.
    Global symbol “$cfile” requires explicit package name at split_aud.pl line 49.
    Execution of split_aud.pl aborted due to compilation errors.

    So I checked the perl script along those lines (48-49), and saw that you added some lines related to that $cfile (also on line 31 but it’s # so maybe not). I don’t know if that could be the problem.

    BUT! I removed the spaces as you suggested and the previous script worked perfectly ^^! Thanks a whole bunch!

    Sunday, July 25, 2010 at 18:19 #
  6. Fred wrote:

    ^
    I fixed this by overwriting the new “open(INFILE…” section with the old one.

    Thursday, September 30, 2010 at 12:39 #

Trackback/Pingback (1)

  1. Trims y Corte de Audio » コちゃん on Friday, April 20, 2012 at 20:51

    […] split_aud.pl […]