View Full Version : NLE-Like task using AviSynth?
resle
5th December 2010, 09:25
Hi,
I've got quite a particular problem and I've been hinted by another forum member that maybe AviSynth could be what I need to solve it.
I've got three things:
1) A list of frames in Jpg format
2) A list of audio clips in Mp3 format
3) A txt file which I can modify to my needs, containing information on when a certain audio clip should be used in the "timeline" of the output. Something like this:
00:00:00.00 first.mp3
00:00:25.10 second.mp3
00:01:03.22 third.mp3
I need to combine the three things in an Avi file, something that I could easily do by using some NLE application - but I have to do this by command line.
Can I actually use AviSynth to accomplish this? Any hints?
Thanks in advance,
andrea
Gavino
5th December 2010, 10:29
A rough outline would be something like this:
v = ImageSource(...) # video from jpg frames
# Build audio:
a = GetAudio("first.mp3")
a = a.Trim(2510, 0) + GetAudio("second.mp3")
a = a.Trim(6322, 0) + GetAudio("third.mp3")
... # and so on
return AudioDub(v, a)
function GetAudio(string file) {
BlankClip(30000, fps=100) # 1/100 sec accuracy, allows up to 5 mins
AudioDub(NicMPG123Source(file))
}
The translation from timecode "00:01:03.22" to 6322 (1/100 sec) can be done by hand or you could write a string handling function to do it. (Actually, maybe you meant .22 to be interpreted as a frame reference, not a fraction of a second, but the principle is the same.)
Malaksbane
5th December 2010, 13:33
Check out the command FOR (use HELP FOR on the commandline for an explanation), which allows you to read a file, parse it line by line and execute commands using data parsed. Echoing statements to a avs-script should pose no problem. Are familiar with the command shell?
function TCStringToFrame(float fps, string _tc) {
tc = LeftStr("0:00:00.00", 10 - StrLen(_tc)) + _tc
return Floor(Value(RightStr(tc,2))) + Round(fps * Value(MidStr(tc, 6,2)) + 60.0 * fps * Value(MidStr(tc, 3,2)) + 3600.0 * fps * Value(LeftStr(tc,1)))
}
resle
5th December 2010, 14:05
Hello, thanks a lot - just knowing that IT IS possible to do what I am trying to do, is great!
Now I'll have to explore Avisynth, which I've never used before, actually.
I'll have no problems in reworking the text file containing the timecode as it's the output of a software I coded myself - I'll just make it write the list as Gavino says, in 1/100ths of second.
If I get into troubles... I will bother you again :)
Thanks!
a.
resle
5th December 2010, 14:52
Ok, first problem and a couple questions
a = GetAudio("d:\music\prevail.mp3")
works
But then when I add
a = a.Trim(2510, 0) + GetAudio("d:\music\prevail.mp3")
this seems to extend the video to a puzzling duration of 4.37 minutes. Also, makes the audio track completely silent.
Another question: what if I need to have audio "layers"? I suspect I'll have to create N audio clips of the same length and then somehow "put" the subclips on them... and finally merge everything down. Is this correct?
Any suggestions on how to fix the first problem, too?
Malaksbane
5th December 2010, 16:31
I think the number and the zero should be swapped to trim(0,2510)
When the second argument to trim is zero it means 'until the end'. More details on Trim() are in Avisynth documentation, under "Core filters", then "Timeline editing filters"
You can use as many audiotracks as you want, and use GetChanel and MergeChannels to swap them around. Details are in the Avisynth documentation, under "Core filters", then "Audio".
Gavino
5th December 2010, 16:49
I think the number and the zero should be swapped to trim(0,2510)
Whoops, you're right - my mistake, sorry about that.
I knew what I meant, but typed it in wrong... :o
resle
5th December 2010, 20:40
Thanks everyone. I solved my problem and along the path I had the chance to witness the sheer elegance of AviSynth. Now I wonder why no one has created some NLE software around AS yet, I think I'll have a shoot at something super-simple which hides all the complex parameters and just let the user arrange a few audio and video material into a timeline. Thanks again!
a.
Gavino
5th December 2010, 22:14
Now I wonder why no one has created some NLE software around AS yet
There have been several failed, partial or abandoned attempts over the years.
For the most recent, see this thread.
vBulletin® v3.8.11, Copyright ©2000-2025, vBulletin Solutions Inc.