Welcome to Doom9's Forum, THE in-place to be for everyone interested in DVD conversion.

Before you start posting please read the forum rules. By posting to this forum you agree to abide by the rules.

 

Go Back   Doom9's Forum > Capturing and Editing Video > Avisynth Usage
Register FAQ Calendar Today's Posts Search

Reply
 
Thread Tools Search this Thread Display Modes
Old 4th May 2004, 14:41   #1  |  Link
DDogg
Retired, but still around
 
DDogg's Avatar
 
Join Date: Oct 2001
Location: Lone Star
Posts: 3,058
What is the quickest way to add a line in multiple avs files?

I thought the audience here might be best qualified to help me find an answer to this question. I seem to remember a dos utility that did this sort of thing.

Basically I want to add a filter line at the same location in the multiple avs files (might be 50-75 of these). They are named in a numerical order so a wildcard would work for the file names.

An example might be if the original is:


mpeg2source("D:\MyD2V.D2V")
BilinearResize(352,480)
ConvertToYUY2()


and I wanted to add undot() to them all:

mpeg2source("D:\MyD2V.D2V")
undot().whatever.whatever
BilinearResize(352,480)
ConvertToYUY2()


Any suggestions? I would appreciate them.
DDogg is offline   Reply With Quote
Old 4th May 2004, 14:52   #2  |  Link
Mug Funky
interlace this!
 
Mug Funky's Avatar
 
Join Date: Jun 2003
Location: i'm in ur transfers, addin noise
Posts: 4,555
hmm... usually this is best done with a bit of programming. last i did this sort of thing was with macromedia director (AAAAAARRGH! the PAIN!), so i'm not much help here...

how many scripts do you need to change? i find with something like an episodic DVD, there's only an average of 5 scripts needed, so it doesn't take much of my time to edit them all with a ctrl+v.

i recommend something like TextPad - it keeps a list of open files, so you just need to open them all up, then go "click, ctrl+v, click, ctrl+v, click, ctrl+v, click, ctrl+v" until you're done.

it would be handy to have a little app to do this... i wonder if one exists?

[edit]

ah... 50-75 scripts? hmm. i'd say overall that it'd be quicker using textpad than writing a whole program. unless this becomes something you have to do often.
__________________
sucking the life out of your videos since 2004
Mug Funky is offline   Reply With Quote
Old 4th May 2004, 15:13   #3  |  Link
Guest
Guest
 
Join Date: Jan 2002
Posts: 21,901
A C program for this would be less than 15 minutes.
Guest is offline   Reply With Quote
Old 4th May 2004, 15:36   #4  |  Link
DDogg
Retired, but still around
 
DDogg's Avatar
 
Join Date: Oct 2001
Location: Lone Star
Posts: 3,058
Quote:
A C program for this would be less than 15 minutes
Perhaps somebody with that skill will consider doing it. I think it would be useful for some, especially if it were an easy thing for someone to do.
DDogg is offline   Reply With Quote
Old 4th May 2004, 15:53   #5  |  Link
Malcolm
Registered User
 
Join Date: Sep 2002
Location: Germany
Posts: 352
there are some Texteditors that can do Search&Replace in multiple Files. A whole folder for example or via wildcards (*.avs).
there are also some IDEs which can do that.
Or do you ask for a commandline utility? do you have to do this once or do you try to find a solution to do this repeatedly in the future?

g*
Malcolm
Malcolm is offline   Reply With Quote
Old 4th May 2004, 16:16   #6  |  Link
Mug Funky
interlace this!
 
Mug Funky's Avatar
 
Join Date: Jun 2003
Location: i'm in ur transfers, addin noise
Posts: 4,555
Quote:
A C program for this would be less than 15 minutes.
well, if you know C it does... i have a hopeless memory, and even languages i'm familiar with (mostly multimedia related ones, crap like Lingo and ActionScript) i have to work with the help files open.
__________________
sucking the life out of your videos since 2004
Mug Funky is offline   Reply With Quote
Old 4th May 2004, 17:22   #7  |  Link
DDogg
Retired, but still around
 
DDogg's Avatar
 
Join Date: Oct 2001
Location: Lone Star
Posts: 3,058
Yes, it is something I expect to do repeatedly and I have some hope of slightly automating it, not completely of course, just trying to make it fairly brain-dead. The line I would actually insert would be an import statement that would import an avs with a set of filters I like to use. A key point is it needs to be able to insert location specific (directly under the mpeg2source line). I'm not suggesting any intelligence for dealing with a moving target, the mpeg2source line will always be on line X of the script group.
DDogg is offline   Reply With Quote
Old 4th May 2004, 17:53   #8  |  Link
albertgasset
Registered User
 
albertgasset's Avatar
 
Join Date: Jan 2003
Location: Barcelona
Posts: 68
This won't be helpful if you don't use Linux (or any OS with a bash shell), but this is a possible solution that works in a Linux shell:

Create a file named PATCHFILE with conent (replace 4 and 5 in "4a5" with the appropriate line numbers):
Code:
4a5
> This line will be added after line 4 of each file, and will become line 5
and then execute this command in a shell:

Code:
for file in DIR/*; do patch -i PATCHFILE $file; done
DIR is the folder with all the files where the line has to be added.

I'm sure there are simpler ways of doing this

Albert
albertgasset is offline   Reply With Quote
Old 4th May 2004, 21:45   #9  |  Link
DDogg
Retired, but still around
 
DDogg's Avatar
 
Join Date: Oct 2001
Location: Lone Star
Posts: 3,058
albertgasset, just plain old XP here and nobody too brilliant behind the keyboard. Well, out of town for a day, so I will not be able to respond till late tomorrow. Thanks for the replies, all.
DDogg is offline   Reply With Quote
Old 4th May 2004, 22:13   #10  |  Link
RB
Retired
 
Join Date: Nov 2002
Posts: 1,349
Here's a batch file that will do the job. Note, requires WinNT/2000/XP. Also note that empty and commentary lines (starting with #) are not counted.
Code:
@echo off
setlocal enabledelayedexpansion

Rem ===================================================================
Rem Batch for inserting a line into every AVS file in a specific
Rem directory
Rem
Rem Usage: insline [directory] [text] [line number]
Rem
Rem Make sure to use quotes around directory and text.
Rem
Rem Example: insline "d:\rebuild\d2vavs" "undot().deen()" 2
Rem
Rem          Recursively scans directory d:\rebuild\d2vavs for .AVS
Rem          files and inserts undot().deen() at line number 2 into
Rem          every .AVS. -1 for line number appends at end of file.
Rem ===================================================================

for /R %%F in ("%~1\*.avs") do (
  set line=0
  if "%~3" == "-1" (
    echo %~2>>"%%F"
  ) else (
    if exist "%%~dpnF.$$$" del "%%~dpnF.$$$"
    for /F "usebackq delims=" %%I in ("%%F") do for /F "tokens=1 delims= " %%J in ("%%I") do (
      set char=%%J
      set char=!char:~0,1!
      if not "!char!" == "#" (
        set /A "line += 1"
        if "!line!" == "%~3" echo %~2>>"%%~dpnF.$$$"
      )
      echo %%I>>"%%~dpnF.$$$"
    )
    del "%%F"
    ren "%%~dpnF.$$$" "%%~nxF"
  )
)
RB is offline   Reply With Quote
Old 4th May 2004, 22:59   #11  |  Link
DDogg
Retired, but still around
 
DDogg's Avatar
 
Join Date: Oct 2001
Location: Lone Star
Posts: 3,058
Was starting to head out the door and saw this. Wow! RB, this was extremely kind of you to do. I think quite a few will benefit. I did try it quickly with the commandline:

insline.bat "D:\WUTemp\D2VAVS" "Undot().Deen()" 3

and I got:

".Deen( was unexpected at this time." Quotes are mine of course. Inside is an exact copy & Paste from command.
DDogg is offline   Reply With Quote
Old 5th May 2004, 00:50   #12  |  Link
stax76
Registered User
 
stax76's Avatar
 
Join Date: Jun 2002
Location: On thin ice
Posts: 6,837
the easiest way to do such things is to use a text editor with windows shell support to open all files at once, support for multible documents to apply a search and replace action on all files at once and support for regular expressions to search and replace patterns. Regular expressions is a extremely powerful tool originated in the Unix world to deal with text. It works like this with NoteTab Light, it's Freeware of course.

Open your text files with the windows shell, for instance select all files with the mouse or the keyboard pressing shift and drag 'em on the opened program or on the executable or on a link to the executable or press enter if the program is the default program. For each file there should be a tab now

Now open the search and replace dialog, check "All Documents", check "Regular Expressions" and set the focus to "All"

enter now the following search patter:

{mpeg2source\(".+"\)}

now enter the replace patter:

\1\nundot\(\).whatever.whatever

it puts your undot line under every mpeg2source line in all documents. It takes time to learn regular expressions, for programming it's a very important thing often needed several times a day, be it for editing the source code or used by the program self to parse text

Last edited by stax76; 5th May 2004 at 00:52.
stax76 is offline   Reply With Quote
Old 5th May 2004, 01:14   #13  |  Link
Video Dude
Senior Member
 
Join Date: Apr 2004
Posts: 1,054
DDogg, sounds like you had the same idea I had to modify DVD Rebuilder's AVISynth scripts.

There is a program called "Simpli-File Find Replace and Insert". Its shareware but they offer a free 15 day trial.

It does everything you want. It does directory batch processing. You simply enter the line of text you want to enter and specify the line number and then hit the process button.

Or you could use the search and replace feature (if all your avs files refer to the same d2v file):

Search for:
mpeg2source("D:\MyD2V.D2V")
BilinearResize(352,480)
ConvertToYUY2()


Replace with:
mpeg2source("D:\MyD2V.D2V")
undot().whatever.whatever
BilinearResize(352,480)
ConvertToYUY2()



You can find it at http://www.batchtech.com

Last edited by Video Dude; 5th May 2004 at 01:37.
Video Dude is offline   Reply With Quote
Old 5th May 2004, 08:18   #14  |  Link
RB
Retired
 
Join Date: Nov 2002
Posts: 1,349
Quote:
Originally posted by DDogg
".Deen( was unexpected at this time." Quotes are mine of course. Inside is an exact copy & Paste from command.
LOL, should make sure my own examples work Sorry, here's the corrected version (actually it's an annoying quirk in the NT batch processor that I seem to constantly forget about)
Code:
@echo off
setlocal enabledelayedexpansion

Rem ===================================================================
Rem Batch for inserting a line into every AVS file in a specific
Rem directory
Rem
Rem Usage: insline [directory] [text] [line number]
Rem
Rem Make sure to use quotes around directory and text.
Rem
Rem Example: insline "d:\rebuild\d2vavs" "undot().deen()" 2
Rem
Rem          Recursively scans directory d:\rebuild\d2vavs for .AVS
Rem          files and inserts undot().deen() at line number 2 into
Rem          every .AVS. -1 for line number appends at end of file.
Rem ===================================================================

set text=%~2
for /R %%F in ("%~1\*.avs") do (
  set line=0
  if "%~3" == "-1" (
    echo !text!>>"%%F"
  ) else (
    if exist "%%~dpnF.$$$" del "%%~dpnF.$$$"
    for /F "usebackq delims=" %%I in ("%%F") do for /F "tokens=1 delims= " %%J in ("%%I") do (
      set char=%%J
      set char=!char:~0,1!
      if not "!char!" == "#" (
        set /A "line += 1"
        if "!line!" == "%~3" echo !text!>>"%%~dpnF.$$$"
      )
      echo %%I>>"%%~dpnF.$$$"
    )
    del "%%F"
    ren "%%~dpnF.$$$" "%%~nxF"
  )
)
RB is offline   Reply With Quote
Old 5th May 2004, 08:33   #15  |  Link
Eldritch
Registered User
 
Join Date: Jun 2002
Location: Germany
Posts: 2
Ok, after having lurked here for far more than a year now, I have finally found a thread to reply to.

A solution that works and that is very simple (I've tried it myself) is using the editor UltraEdit. It can do search & replace in multiple files. The dialog is somewhat hidden in the Edit-Menu but it's there.

There is a 30-day uncrippled trial version of UltraEdit. If you're looking for a completely free editor or similar tool look at www.tinyapps.org
Eldritch is offline   Reply With Quote
Old 5th May 2004, 09:42   #16  |  Link
DDogg
Retired, but still around
 
DDogg's Avatar
 
Join Date: Oct 2001
Location: Lone Star
Posts: 3,058
@All, thanks for the replies. I'm kinda hoping I can get RB's batch file to work. I can see from your posts that advanced text editors will do what I want to do. Thanks for those suggestions as I am not at all familiar with them.

@RB, are you using XP? I ask because the error is fixed, but no changes are being done to the avs files. This is when using 3 as line number or -1. I am wondering if my XP command line supports all the things your script needs. Thanks again for taking your time to do this batch. It is just what I'm looking for.
DDogg is offline   Reply With Quote
Old 5th May 2004, 12:38   #17  |  Link
actionman133
Movie buff & shine
 
Join Date: Jan 2004
Location: Logan, the only hole above ground.
Posts: 257
an inhouse solution

there is an scripting solution that i have used for the last couple months, precisely because of that.

i have ripped dvds on my computer, but being the quality freak i am, i didnt want to recompress; in fact i wanted to improve the quality beyond those of commercial dvd players. of course, the code was changing every 20 minutes, and it was tiresome to say the least.

i ended up creating an information script and a core script. the information script would simply collect the details, and pass it to the core. so any changes to the core affected all scripts using at once. i'll show you what i did by example (extract):

Code:
File: "Superbrawl.avs"

VideoName = "Superbrawl"   # Name of video D2V file
AudioDelay = -0.016    # Delay of audio as dictated by DVD Decrypter
Folder = "C:\Videos\DVD's\The Matrix Revolutions"   # Location
Speed = 24   # New framerate (I use PAL sources)
Import ("C:\Videos\DVD's\DVD AVS's\Core.avs")
the 'Import' line appends the following core script to the bottom.

Code:
File: "Core.avs"

SetWorkingDir (Folder)
MPEG2Source (VideoName + ".d2v")
AudioDub(WAVSource (VideoName + ".wav").DelayAudio (AudioDelay)
ConvertToYUY2 ()
LanczosResize (1024, 576).Sharpen (0.78)
AssumeFPS (Speed, True)
ResampleAudio (48000)

now this is a simplified example, but the point's the same. if create a file to store all necessary information, and then import a core to do all the processing, any changes you make to the core, will apply to all of the scripts.

did you get that? anyone?
__________________
I'm a boxer who can Bob () & Weave (). I like to Overlay () punches and Blur () his vision to ShowFiveVersions (). My KO punch will always Pulldown ().TimeStretch () and all he will hear is Tone ().
actionman133 is offline   Reply With Quote
Old 5th May 2004, 12:42   #18  |  Link
Malcolm
Registered User
 
Join Date: Sep 2002
Location: Germany
Posts: 352
i don't know if this helps here, but i find your way of working very clever and interesting! i think i'll adopt it for my scripts!

Greetings,
Malcolm
Malcolm is offline   Reply With Quote
Old 5th May 2004, 14:02   #19  |  Link
RB
Retired
 
Join Date: Nov 2002
Posts: 1,349
Quote:
Originally posted by DDogg
@RB, are you using XP? I ask because the error is fixed, but no changes are being done to the avs files. This is when using 3 as line number or -1.
Yes, using XP, it's working just fine here. It is the default, but make sure that in both HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Command Processor and HKEY_CURRENT_USER\Software\Microsoft\Command Processor the "EnableExtensions" DWORD value is set to 1.
RB is offline   Reply With Quote
Old 5th May 2004, 15:13   #20  |  Link
stax76
Registered User
 
stax76's Avatar
 
Join Date: Jun 2002
Location: On thin ice
Posts: 6,837
I'll try to explain the regular expression

mpeg2source("any file")

because parenthesis "(" and ")" is part of the regular expression language a backslash has to be put in front of the parenthesis so the regualr expression engine knows the actual character is meant, so the expresion must be written as this:

mpeg2source\("any file"\)

the file name can be any character one or more times, any character is . and one or more times is + so the expression is now this:

mpeg2source\(".+"\)

this expression is required in the replace pattern, if we put the expression in curly braces we can in the replace pattern refer to it with \1, so the search regular expression is now finished:

{mpeg2source\(".+"\)}

the replace pattern consist of \1 which is everything between the curly braces in the search pattern plus \n which is a new line plus the Undot line

\1\nundot\(\).whatever.whatever

quite simple isn't it
stax76 is offline   Reply With Quote
Reply


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 17:16.


Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2024, vBulletin Solutions Inc.