Log in

View Full Version : Pass variables to a script from a program and audio question?


StifflerStealth
19th May 2007, 16:18
What I am wanting to do is save on the amount of files I have to work with. I need to break a film up into 43 parts. I have a avs script that has some filters in it to lightly clean the film and then a Trim to get the precise location that I wish to cut. Now I am wondering if I really need 43 files which only differ by the frames in a Trim statement. Can the encoder pass numbers to it to fill in variables for something like: trim(_start,_end)?

I realize that I could write another avs script that could list this script 43 times passing in the Trim vaules, but I need separtely encoded files. That one avs script would return the whole movie to the encoder, so I am wondering if there is a way to pass the encoder a script that can pass the encoder a part of the film and tell it where to save it or in the the open file dialog, select the avs script and pass it the trim arguments, or can the encoder actually do the trimming and not the avs script?

The encoders that I have to work with are: HC and QuENc on my personal system, I could get other free ones, but I need a really great quality encode, or I can pass the files off to the CCE machine.

Now for my audio question. I have an ac3 source that goes with the film. I did:
v = mpeg2source(...
a = DirectShowSource(... ,seek=true, seekzero=false ...
AudioDub(v,a)

However, when I do the Trim, the video starts at the start frame, but the audio starts at the very begining. How can I sync up the audio and video at trims? Also, how can I cut the audio as a separate ac3 file. When I am done, I want the film cut up into pieces with the audio and video as separate m2v and ac3 files.

I am using the latest stable version of everything, DGIndex and co, avisynth and the clean up filters. I read about the 1.4.8 beta and the DirectShowFixes it had, do I need to upgrade to that version to make audio seekable, or am I just doing the ac3 audio source wrong? The AC3 audio is 5.1 channel and I need to keep it that way.

-SS

P.S. Okay these questions seem a bit more complicated than what I thought they would be. I am a very new beginner at avisynth and I have been reading on it, but it is still vastly confusing.

ChiDragon
19th May 2007, 16:53
How can I sync up the audio and video at trims? Also, how can I cut the audio as a separate ac3 file. When I am done, I want the film cut up into pieces with the audio and video as separate m2v and ac3 files.

Well you may as well forget about the first question if you don't want to do re-encoding. Current AviSynth can only output decompressed video and audio. You should use an MPEG2 cutter (MPEG2Cut, VideoReDo, I'm sure you can find more) if you need to keep the sources compressed.

gzarkadas
19th May 2007, 17:24
To use just one script for all 43 files, do the following (see working examples of this technique here (http://avslib.sourceforge.net/examples/index.html), particularrly the 8th and 12th):

1. Write you script as usual and make the following modification to the trim line:

ts = Import("ts.txt")
te = Import("te.txt")
Trim(ts, te)


2. Write a windows batch file with the following format (say your first trim is (34, 518) and HC is assumed to be the encoder):

echo 34 > ts.txt
echo 518 > te.txt
hc -i c:\video\myscript.avs -o c:\video\encodes\cut1.m2v [additional parameters]
echo 734 > ts.txt
echo 1237 > te.txt
hc -i c:\video\myscript.avs -o c:\video\encodes\cut2.m2v [additional parameters]
...


You may not escape from manually editing a long batch file, but things are more tidy regarding the number of files.

Regarding the audio I can't help you without test material in my hands; check though that you don't accidentally access v or a after the AudioDub (you must access the trimed clip, usually it is in the last variable).

StifflerStealth
19th May 2007, 17:33
I do need to re-encode the video at least, because I am applying various cleanup filters to it. The cutters don't really do that. I found that avisynth has some very powerful filters that do the job perfectly. Also, in trying to use various cutters, I found some bugs that I emailed the authors about. Some are serious, some are not so serious. But it boils down to the fact that AviSynth is the only solution I found for the frame accuracy I need and the quality I need. The video was encoded in such a way that most cutters just blow up on it. :P So, my hopes in re-encoding is to provide a version of the film that is pristine and corrected and cleaned up with the filters. :)

Edit: Thanks, I will look at that function.
EDIT2: How would I use that function to ecode each clip as a separate file? So I would have a folder with:
clip1.m2v, clip2.m2v, clip3.m2v, ... and so on? The source of the clips is the one long film.

gzarkadas
19th May 2007, 17:58
Edit: Thanks, I will look at that function.
EDIT2: How would I use that function to ecode each clip as a separate file? So I would have a folder with:
clip1.m2v, clip2.m2v, clip3.m2v, ... and so on? The source of the clips is the one long film.

Well, I have edited my post meanwhile as you can see :). Please excuse me, but when reading large posts it is easy to miss a sentence. I think that now I address the issue.

StifflerStealth
19th May 2007, 18:54
Okay. Thanks for you help. :) I never thought about a command line script. The script is repetitive, but hopefully it will make it a lot easier than configuring 43 individual files. :P I was hoping there would be some kind of AviSynth command that can call the encoder or some kind of gui that has the features of batching multiple trims. This is also handy because if I need to change the filters, I just need to do that for one file.

Thanks again.

gzarkadas
19th May 2007, 19:16
...The script is repetitive, but ...

I did some research meantime and I propose the following to make the batch script even shorter (assumes all trims are put in a file trims.txt at the same folder with the following format):

File

;num-file trim-start trim-end
1 34 512
2 674 1003
3 1200 2345


Script

@echo off
for /f "eol=; tokens=1,2,3" %%i in (trims.txt) do (
echo %%j > ts.txt
echo %%k > te.txt
hc -i c:\video\myscript.avs -o c:\video\encodes\cut%%i.m2v [additional parameters]
)


That way you only have to write a text file with the trim points. The rest can be reused to other clips as is (tip: you can control other parts of the hc commandline also by adding tokens in the for command).

StifflerStealth
19th May 2007, 19:38
Oh, that is nice script. :D

Would it be possible to do a foreach in Windows Commandline? Then I wouldn't need to do tokens=01,02,03, ... 43. The foreach would grab each line and the first number would be the cut number to add to the file name, then the first frame then the last frame. I am not good at Windows commandline at all so I don't know if this is possible. That is definately looking a lot better. :D A very usable script for multiple films and such.

gzarkadas
19th May 2007, 20:21
Then I wouldn't need to do tokens=01,02,03, ... 43.
But you don't have to. The tokens=1,2,3 part of the line is to inform that you have three fileds per column. You can have thousands of lines with filenum, trimstart, trimend triplets (if you can afford to wait so long to finish :D).

Also, you can easily make this stuff in a spreadsheet and export it as a tab sepatated text file.

StifflerStealth
19th May 2007, 21:28
Oh, okay. :D I understand now. Only one slight modification I can make to the script: Have it take Commandline parameters that point to the various files, then that one script could be used for Film1, Film2, and so on without having to change the script by changing the file location. :)

Thanks again for your tips. This helps out a lot.