View Full Version : playing 2 videos side-by-side
lovelove
13th September 2011, 17:00
Hi. I want to get started with avisynth. I read the FAQ and got the basic idea.
I read that Virtualdubmod can be used to run Avisynth scripts. I followed the instructions (http://www.animemusicvideos.org/guides/avtech/amvappvdubmod.html) but upon pressing F5 nothing happened. Do I have to install Avisynth separately? From the link I got the impression, that Avisynth is integrated in Virtualdub(mod) and thus supported natively. If that is not the case, then what is the point in saying Virtualdub(mod) supports avisynth if avisynth can feed fake AVIs to any any program?
cobo
13th September 2011, 17:40
Yes, you need to install Avisynth separately, it's not included in an install of VirtualDub or VirtualDubMod. "Supports avisynth" just means it will accept avs files as input and additionally that VirtualDubMod has a built-in avs editor.
You can find links to download whatever Avisynth version you require on this page:
http://avisynth.org/mediawiki/Main_Page
sneaker_ger
13th September 2011, 17:41
AviSynth itself cannot simply feed AVIs to any program, AviSynth support has to be implemented in addition to AVI support. VirtualDub has that support, but yes, you need to install AviSynth. (There are ways to feed AviSynth to non-AviSynth-aware programs, though. (http://avisynth.org/mediawiki/FAQ_frameserving#Frameserving_to_applications_via_fake_AVI_files_and_proxy_utilities))
TheFluff
13th September 2011, 18:50
AviSynth itself cannot simply feed AVIs to any program, AviSynth support has to be implemented in addition to AVI support.
What? The entire point of Avisynth is (or at least used to be, back when people actually used VFW) that it inserts itself into the VFW framework and lets anything that supports the AVIFile API use it. Even the wiki page you linked points this out.
Of course, you can also use the Avisynth API directly (and I do believe VirtualDub does this), but it's certainly not necessary.
sneaker_ger
13th September 2011, 20:17
Yes, but only for programs that use VFW, not for any program. But you're correct, either AviSynth or VFW support has to be implemented, so my statement that AviSynth has to be implemented is not correct, strictly speaking.
lovelove
17th October 2011, 09:24
ok thank you all!
I'd like to play synchronously play 2 videos side-by-side.
I used
video1=AVISource("d:\file1.avi")
video2=AVISource("d:\file2.mpg")
StackHorizontal(video1,video2)
which leads to an "couldn't open file" error.
So I converted file2.mpg to file2.avi -> This results in an "AVISource: couldn't locate a decompressor for fourcc mpg2" error.
So I installed an mpg2 codec (http://www.videohelp.com/tools/Dscaler-5), but I still get the same error.
What should I do? Thank you.
LaTo
17th October 2011, 09:27
Use DirectShowSource or FFMpegSource instead of AVISource
lovelove
17th October 2011, 10:14
With FFMpegSource I get a “Script error: there is no function named “FFMpegSource””
But DirectShowSource works. Many thanks!
Now I get the error: "StackHorizontal: image heights don't match"
I suppose I have to padd or stretch the smaller image?
I tried this
video1=AVISource("d:\file1.avi")
video2=DirectShowSource("d:\file2.mpg")
BilinearResize(video1,400,300)
BilinearResize(video2,400,300)
StackHorizontal(video1,video2)
but still get the "StackHorizontal: image heights don't match" error
so I changed that to
video1=AVISource("d:\file1.avi")
video2=DirectShowSource("d:\file2.mpg")
video1=BilinearResize(video1,400,300)
video2=BilinearResize(video2,400,300)
StackHorizontal(video1,video2)
now I don’t get an error while processing the avs script,
but after loading the avs script, VirtualDubMod says
“[!] Couldn't locate decompressor for format 'YV12' (unknown).
VirtualDub requires a Video for Windows (VFW) compatible codec to
decompress video. DirectShow codecs, such as those used by Windows Media
Player, are not suitable. Only 'Direct stream copy' is available for this
video.”
and the video window stays blank/empty.
When I click on the “play output” button, I get audio, but video window stays blank/empty.
When I click on the “play input” button, VirtualDubMod crashes.
jmac698
17th October 2011, 10:26
Just a quick answer, try adding
converttorgb
StackHorizontal(video1,video2)
lovelove
17th October 2011, 10:53
Just a quick answer, try adding
converttorgb
StackHorizontal(video1,video2)
generates this error:
AviSynth open failure:
I don't know what "converttorgb" means
but
video1=converttorgb(video1)
video2=converttorgb(video2)
works for me now.
Many thanks!
*solved*
LaTo
17th October 2011, 11:16
With FFMpegSource I get a “Script error: there is no function named “FFMpegSource””
You need to download the plugin before, see here: http://forum.doom9.org/showthread.php?t=127037
Can I add a delay to one of the videos?
video1 has an intro sequence of 2 seconds which is not present in video2. So if I can add a delay of 2 seconds at the beginning of video2, or - alternatively - cut 2 seconds of video 1, both videos would be in sync ... so that I could compare the videos side-by-side ... is that possible? Thank you so much!
Cut 2 seconds in video1:
duration = 2
video1 = video1.Trim(duration*FrameRate(video1), 0)
Add 2 seconds in video2:
duration = 2
blank = BlankClip(video2, duration*FrameRate(video2))
video2 = blank++video2
Gavino
17th October 2011, 11:25
video1 = video1.Trim(duration*FrameRate(video1), 0)
...
blank = BlankClip(video2, duration*FrameRate(video2))
Since FrameRate returns a float, you need to use
round(duration*FrameRate(video1))
and similar for video2
Bloax
17th October 2011, 11:28
video1=AVISource("d:\file1.avi")
video2=DirectShowSource("d:\file2.mpg")
BilinearResize(video1,400,300)
BilinearResize(video2,400,300)
StackHorizontal(video1,video2)
Also that won't work, as you still specify it to use video1 and video2, and not the upscaled ones.
video1=AVISource("d:\file1.avi")
video2=DirectShowSource("d:\file2.mpg")
video3=BilinearResize(video1,400,300)
video4=BilinearResize(video2,400,300)
StackHorizontal(video3,video4)
Is how it should be. :p
lovelove
17th October 2011, 11:54
awesome, :thanks: everyone
special thanks to Gavino and Bloax for corrections and to for LaTo for coming up on your own with this elegant solution using framerate and specifiying duration separately. This makes it easy to use the script on a constant basis and quickly & easily change the input video and cut duration in the script.
I am a happy camper now :-)
thanks for jump-starting me into AviSynth to a point where i can now find out the rest for myself.
Taking into consideration all the advice above, the final "play 2 videos side-by-side" script is this:
input1="d:\video1.avi"
DirectShowSource(input1).Subtitle(input1)
BilinearResize(400,300)
converttoRGB
duration=2
a=Trim(round(duration*FrameRate),0)
input2="d:\video2.mpeg"
DirectShowSource(input2).Subtitle(input2)
BilinearResize(400,300)
converttoRGB
duration=0
b=Trim(round(duration*FrameRate),0)
StackHorizontal(a,b)
The trim command for the second file is unnecessary, but if I change the input video and have to trim video 2 instead of video 1, then I don't need to recode the script, but simply set duration=0 for video 1 and change the duration value for video 2 as needed.
jmac698
17th October 2011, 18:55
Ha,
I can do even better for ya...
dir="D:\project001a\sampleproblem2\"
fn1="SVHS-VERSION.mp4"
fn2="VHS-VERSION.mp4"
sbs(fn1, fn2, dir, true)
function sbs(string file1, string file2, string "dir", bool "resize", float "duration", int "frames", int "trimmode"){
#sbs (side-by-side) - an Avisynth function to conveniently show two video files side-by-side
#Ver 0.2 by jmac698
#No requirements
#dir - optional, a common directory in which the files reside. If you use this, specify *only* the filenames for file1, file2
#file1, file2 - the filenames. If you don't use the option dir, please include the full filename (i.e. d:\file1.avi)
#resize - set to true to resize the videos to the same dimensions, otherwise they are padded with black to be the same size
#duration - the duration in seconds to adjust the trimming of the file (see trimmode)
#frame - a fine tuning duration, in frames, this add to duration. Both or either can be used.
#trimmode - 0 means to trim the duration from file1, 1 means to add to file1, 2 means trim file2, 3 means add file2
#limitations: files must be of the same framerate
#Ver 0.2: added possibility of negative duration/frames
#Ver 0.1: first version
#Parse the filenames
dir=default(dir,"")
resize=default(resize,true)
duration=default(duration,0)
frames=default(frames,0)
trimmode=default(trimmode,0)
dir=strlen(dir)>0&&rightstr(dir,1)<>"\"?dir+"\":dir
v1=openfile(dir, file1)
v2=openfile(dir, file2)
mw=max(v1.width, v2.width)
mh=max(v1.height, v2.height)
v1=prepareclip(v1, resize, duration, frames, trimmode, mw, mh, 1)
v2=prepareclip(v2, resize, duration, frames, trimmode, mw, mh, 2)
StackHorizontal(v1, v2)
}
function prepareclip(clip v1, bool resize, float duration, int frames, int trimmode, int mw, int mh, int file){
v1
converttorgb
lb1=(mw-v1.width)/2
rb1=mw-v1.width-lb1
tb1=(mh-v1.height)/2
bb1=mh-v1.height-tb1
resize?bilinearresize(mw,mh):addborders(lb1,tb1,rb1,bb1)
#trimmode - 0 means to trim the duration from file1, 1 means to add to file1, 2 means trim file2, 3 means add file2
f1=round(duration*framerate(v1))+frames
alttrimmode=trimmode>1?trimmode-2:trimmode+2
trimmode=f1<0?alttrimmode:trimmode
f1=f1<0?-f1:f1
trimmode==0&&file==1?trim(f1,0):last
trimmode==1&&file==1?blankclip(last,f1)+last:last
trimmode==2&&file==2?trim(f1,0):last
trimmode==3&&file==2?blankclip(last,f1)+last:last
}
function openfile(string dir, string file1){
file1=FindStr(file1,"\")==0?dir+file1:file1
filetype1=lcase(leftstr(revstr(file1),3))
filetype1=="avi"?avisource(file1):directshowsource(file1)
}
You'll have to test all the options though...
Gavino
17th October 2011, 19:16
function prepareclip(...){
...
trimmode==0?trim(f1,0):blankclip(f1)+last
}
Should be BlankClip(last, f1)
(BlankClip is a special case - this parameter does not default to 'last')
jmac698
18th October 2011, 00:00
Thanks, updated and new feature: negative duration/frames
Gavino
18th October 2011, 00:27
alttrimmode=trimmode>1?trimmode-2:trimmode+2
trimmode=f1<0?alttrimmode:trimmode
trimmode==0&&file==1?trim(f1,0):last
trimmode==1&&file==1?blankclip(last,f1)+last:last
trimmode==2&&file==1?trim(f1,0):last
trimmode==3&&file==1?blankclip(last,f1)+last:last
This doesn't seem right:
- when file=2, nothing is done (f1 has no effect)
- when f1<0, negative argument passed to Trim and BlankClip
jmac698
18th October 2011, 01:45
ty, fixed
vBulletin® v3.8.11, Copyright ©2000-2026, vBulletin Solutions Inc.