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

Reply
 
Thread Tools Search this Thread Display Modes
Old 12th December 2024, 11:24   #1  |  Link
buddha9
Registered User
 
buddha9's Avatar
 
Join Date: Nov 2023
Posts: 18
shift video to audio synch with another source

PHP Code:
path="..."
pathDGD="..."
filename1="...mkv"
filename2="...mkv"

##################################################

LoadPlugin(pathDGD+"dgdecode.dll")

clip1 FFmpegSource2(path+filename1)
clip2 FFmpegSource2(path+filename2)

StackHorizontal(clip1clip2
Hi, how can I add a frame offset (Ex.: 5245 from frame 0) to the clip2 ?
Thanks!

Last edited by buddha9; 16th December 2024 at 16:06.
buddha9 is offline   Reply With Quote
Old 12th December 2024, 11:46   #2  |  Link
tebasuna51
Moderator
 
tebasuna51's Avatar
 
Join Date: Feb 2005
Location: Spain
Posts: 7,160
Quote:
Originally Posted by buddha9 View Post
LoadPlugin(pathDGD+"dgdecode.dll") # Not used, you need ffms2.dll

clip1 = FFmpegSource2(path+filename1)
clip2 = FFmpegSource2(path+filename2).Trim(5245,0)

StackHorizontal(clip1, clip2)
Maybe a trim()?
__________________
BeHappy, AviSynth audio transcoder.
tebasuna51 is offline   Reply With Quote
Old 12th December 2024, 11:53   #3  |  Link
buddha9
Registered User
 
buddha9's Avatar
 
Join Date: Nov 2023
Posts: 18
Quote:
Originally Posted by tebasuna51 View Post
Maybe a trim()?
Thanks for quick reply
I need add a +5245 (positive shift) offset frames/milliseconds to the clipv2

And what about need to -3520 (negative shift) offset frames/milliseconds? Does trim support negative values?

How can I do? Has Trim function this parameter?
__________________
AviSynth+ 3.7.3

Last edited by buddha9; 12th December 2024 at 13:42.
buddha9 is offline   Reply With Quote
Old 12th December 2024, 12:46   #4  |  Link
VoodooFX
Banana User
 
VoodooFX's Avatar
 
Join Date: Sep 2008
Posts: 1,066
Be aware that you desync with audio by "shifting" video frames:


PHP Code:
clip1 FFmpegSource2(path+filename1)
clip2 FFmpegSource2(path+filename2)

blank BlankClip(clip2length=5245)
clip2_shifted blank clip2

StackHorizontal
(clip1clip2_shifted

Last edited by VoodooFX; 12th December 2024 at 12:51.
VoodooFX is offline   Reply With Quote
Old 12th December 2024, 13:29   #5  |  Link
buddha9
Registered User
 
buddha9's Avatar
 
Join Date: Nov 2023
Posts: 18
Quote:
Originally Posted by VoodooFX View Post
Be aware that you desync with audio by "shifting" video frames:


PHP Code:
clip1 FFmpegSource2(path+filename1)
clip2 FFmpegSource2(path+filename2)

blank BlankClip(clip2length=5245)
clip2_shifted blank clip2

StackHorizontal
(clip1clip2_shifted
on MKVToolNix GUI there is this option



You can insert positive/negative millisecond values for a video/audio track.

I need something like that on AVS+

Is there any addons?

Thanks

Trim and BlankClip aren't not good for my needs
__________________
AviSynth+ 3.7.3

Last edited by buddha9; 12th December 2024 at 13:37.
buddha9 is offline   Reply With Quote
Old 12th December 2024, 13:48   #6  |  Link
VoodooFX
Banana User
 
VoodooFX's Avatar
 
Join Date: Sep 2008
Posts: 1,066
Quote:
Originally Posted by buddha9 View Post
Trim and BlankClip aren't not good for my needs
It does what you described.
Why it's not good?
VoodooFX is offline   Reply With Quote
Old 12th December 2024, 14:22   #7  |  Link
buddha9
Registered User
 
buddha9's Avatar
 
Join Date: Nov 2023
Posts: 18
Quote:
Originally Posted by VoodooFX View Post
It does what you described.
Why it's not good?
I need possibility to shift forward/backward (specifying frames or milliseconds) video (w/o audio desynch)

It wolud be nice to have something like this

Quote:
clip1 = FFmpegSource2(path+filename1)
clip2 = FFmpegSource2(path+filename2)

StackHorizontal(clip1, clip2.offset(type="frames", n="5344")) # or other possibility --> .offset(type="ms", n="-2345")
__________________
AviSynth+ 3.7.3

Last edited by buddha9; 12th December 2024 at 14:36.
buddha9 is offline   Reply With Quote
Old 12th December 2024, 14:40   #8  |  Link
poisondeathray
Registered User
 
Join Date: Sep 2007
Posts: 5,599
Quote:
Originally Posted by buddha9 View Post
I need possibility to shift forward/backward (specifying frames or milliseconds) video (w/o audio desynch)

It wolud be nice to have something like this

eg.
Code:
StackHorizontal(clip1, clip2.offset(5344) )
Code:
function Offset(clip c, int "frames")
{
frames   = Default(frames, 0)
c1=BlankClip(c,length=frames)+c
return c1
}
poisondeathray is offline   Reply With Quote
Old 12th December 2024, 14:42   #9  |  Link
buddha9
Registered User
 
buddha9's Avatar
 
Join Date: Nov 2023
Posts: 18
Quote:
Originally Posted by poisondeathray View Post
eg.
StackHorizontal(clip1, clip2.offset(5344) )


Code:
function Offset(clip c, int "frames")
{
frames   = Default(frames, 0)
c1=BlankClip(c,length=frames)+c
return c1
}
Thanks poisondeathray!
does it work with a negative need?
__________________
AviSynth+ 3.7.3
buddha9 is offline   Reply With Quote
Old 12th December 2024, 14:46   #10  |  Link
VoodooFX
Banana User
 
VoodooFX's Avatar
 
Join Date: Sep 2008
Posts: 1,066
Quote:
Originally Posted by buddha9 View Post
I need possibility to shift forward/backward (specifying frames or milliseconds) video (w/o audio desynch)
Sorry but that doesn't make sense.
And of course MKVToolNix doesn't do such nonsense.

Last edited by VoodooFX; 12th December 2024 at 14:49.
VoodooFX is offline   Reply With Quote
Old 12th December 2024, 14:52   #11  |  Link
buddha9
Registered User
 
buddha9's Avatar
 
Join Date: Nov 2023
Posts: 18
Quote:
Originally Posted by VoodooFX View Post
Sorry but that doesn't make sense.
Example:

You have a movie (OPEN MATTE version). [vid1]
You have also the same movie but "standard" version. [vid2]

These 2 are from different sources. Vid1 from HDTV, vid2 from DVD.

Same FPS but the "real" movie (on vid2) starts after some milliseconds comparing with first version [vid1]

You can play with Audacity. But my solution (with AVS+) is more "visual"

PHP Code:
path1="I:\_WIP\path1"
filename1="file1.mkv"
path2="I:\_WIP\path2"
filename2="file2.avi"

clipv1 FFmpegSource2(path1+filename1)
clipa1 FFAudioSource(path1+filename1)

clipv2 FFmpegSource2(path2+filename2)
clipa2 FFAudioSource(path2+filename2)

clipt1AudioDub(clipv1,clipa1)
clipt2AudioDub(clipv2,clipa2)

StackHorizontal(Waveform(clipt1window=5height=0.333zoom=5.0under=falsesmooth=trueaa=true), \
Waveform(clipt2.BilinearResize(968,720), window=5height=0.333zoom=5.0under=falsesmooth=trueaa=true)) 
__________________
AviSynth+ 3.7.3

Last edited by buddha9; 12th December 2024 at 17:52.
buddha9 is offline   Reply With Quote
Old 12th December 2024, 15:17   #12  |  Link
poisondeathray
Registered User
 
Join Date: Sep 2007
Posts: 5,599
Quote:
Originally Posted by buddha9 View Post
Thanks poisondeathray!
does it work with a negative need?
It appears to work ok, but it's pretty easy for you to test it
poisondeathray is offline   Reply With Quote
Old 12th December 2024, 15:26   #13  |  Link
buddha9
Registered User
 
buddha9's Avatar
 
Join Date: Nov 2023
Posts: 18
Quote:
Originally Posted by poisondeathray View Post
It appears to work ok, but it's pretty easy for you to test it
PHP Code:
...

StackHorizontal(Waveform(clipt1window=4height=0.333zoom=5.0under=falsesmooth=trueaa=true), Waveform(clipt2.BilinearResize(968,720).Offset(-5200), window=4height=0.333zoom=5.0under=falsesmooth=trueaa=true))


function 
Offset(clip cint "frames")
{
frames   = Default(frames0)
c1=BlankClip(c,length=frames)+c
return c1
}

... 
It does work with positive and negative frames.
Thanks so much!

Ps
maybe do you have also a version with milliseconds?
__________________
AviSynth+ 3.7.3

Last edited by buddha9; 12th December 2024 at 15:31.
buddha9 is offline   Reply With Quote
Old 12th December 2024, 15:28   #14  |  Link
VoodooFX
Banana User
 
VoodooFX's Avatar
 
Join Date: Sep 2008
Posts: 1,066
Quote:
Originally Posted by buddha9 View Post
Same FPS but the "real" movie (on vid2) starts after some milliseconds comparing with first version [vid1]
Then we back again, why Trim and BlankClip is not good for you?
VoodooFX is offline   Reply With Quote
Old 12th December 2024, 16:21   #15  |  Link
poisondeathray
Registered User
 
Join Date: Sep 2007
Posts: 5,599
Quote:
Originally Posted by buddha9 View Post
Ps
maybe do you have also a version with milliseconds?
Not really possible for ms accuracy because video "frames" have a quantized ms duration. eg. a "23.976p" film source would have about 41.708 ms duration per frame. You cannot have something like a quarter frame
poisondeathray is offline   Reply With Quote
Old 12th December 2024, 17:02   #16  |  Link
buddha9
Registered User
 
buddha9's Avatar
 
Join Date: Nov 2023
Posts: 18
Quote:
Originally Posted by poisondeathray View Post
Not really possible for ms accuracy because video "frames" have a quantized ms duration. eg. a "23.976p" film source would have about 41.708 ms duration per frame. You cannot have something like a quarter frame
Ok no problem.
I calculate ms (difference btw 2 points on timeline) with help of AVS+ status bar
Thans so much for support!

PHP Code:
# film 1
path1="I:\_WIP\path1\"
filename1="
file1.mkv"
clipv1 = FFmpegSource2(path1+filename1)
clipa1 = FFAudioSource(path1+filename1)
src1w=Width(clipv1)
src1h=Height(clipv1)
clipt1= AudioDub(clipv1,clipa1)

# film 2
path2="
I:\_WIP\path2\"
filename2="
file2.avi"
clipv2 = FFmpegSource2(path2+filename2)
clipa2 = FFAudioSource(path2+filename2)
clipt2= AudioDub(clipv2,clipa2)

# HorizontalStack
StackHorizontal(Waveform(clipt1.DelayAudio(-1.6), window=4, height=0.333, zoom=5.0, under=false, smooth=true, aa=true), Waveform(clipt2.BilinearResize(src1w,src1h).AssumeFPS(23.976,sync_audio=true).Offset(25).DelayAudio(0.18), window=4, height=0.333, zoom=5.0, under=false, smooth=true, aa=true))

# Thanks to poisondeathray
function Offset(clip c, int "
frames")
{
frames   = Default(frames, 0)
c1=BlankClip(c,length=frames)+c
return c1

__________________
AviSynth+ 3.7.3

Last edited by buddha9; 12th December 2024 at 17:06.
buddha9 is offline   Reply With Quote
Old 12th December 2024, 21:13   #17  |  Link
VoodooFX
Banana User
 
VoodooFX's Avatar
 
Join Date: Sep 2008
Posts: 1,066
So, in the end BlankClip IS good.
VoodooFX is offline   Reply With Quote
Old 13th December 2024, 02:40   #18  |  Link
StainlessS
HeartlessS Usurer
 
StainlessS's Avatar
 
Join Date: Dec 2009
Location: Over the rainbow
Posts: 11,042
Nifty Offset() function PDR.
Possibility of 0 or -ve Length not mentioned on Wiki.

Some time ago, Pinterf [EDIT: qyot27] was gonna throw error (I think) on BlankClip(Length=0), because it caused some problem if not used correctly.
I was a bit miffed about it (I used Length=0 in some scripts), but accepted decision to make it illegal, but then
I think he changed his mind and accepted as legal again.

Looks like he also allowed for -ve length [as your Offset() func works], maybe could do with a mention of it on wiki.
[Dont know if Length=-ve also accepted in v2.60 Std or v2.58.]

EDIT: I think the problem with allowing 0 length clip was the possibility of trying to display a zero length clip in VDub/Player
which caused some kind of exception/illegal instruction. [but only if used incorrectly, ie trying to show a 0 len clip]

BlankClip on Wiki:- http://avisynth.nl/index.php/BlankClip
__________________
I sometimes post sober.
StainlessS@MediaFire ::: AND/OR ::: StainlessS@SendSpace

"Some infinities are bigger than other infinities", but how many of them are infinitely bigger ???

Last edited by StainlessS; 13th December 2024 at 17:33.
StainlessS is offline   Reply With Quote
Old 13th December 2024, 03:06   #19  |  Link
poisondeathray
Registered User
 
Join Date: Sep 2007
Posts: 5,599
Quote:
Originally Posted by StainlessS View Post
Nifty Offset() function PDR.
Possibility of 0 or -ve Length not mentioned on Wiki.

Honestly I had no idea (-) would work. I just wrapped VoodooFX's suggestion into a helper function. ( "Wrapped" because some people like presents to be wrapped this time of year )

Quote:

Some time ago, Pinterf was gonna throw error (I think) on BlankClip(Length=0), because it caused some problem if not used correctly.
I was a bit miffed about it (I used Length=0 in some scripts), but accepted decision to make it illegal, but then
I think he changed his mind and accepted as legal again.
Probably this
https://github.com/AviSynth/AviSynth...aa2621d4b333a8

Quote:
EDIT: I think the problem with allowing 0 length clip was the possibility of trying to display a zero length clip in VDub/Player
which caused some kind of exception/illegal instruction. [but only if used incorrectly, ie trying to show a 0 len clip]

BlankClip on Wiki:- http://avisynth.nl/index.php/BlankClip
I think zero total frames still throws an error in some programs - but when total number of frames is not zero - programs don't seem complain.

Code:
a=colorbars().trim(0,9).showframenumber() #10 total frames

#a.offset(-9) #works; 1 total frame

#a.offset(-10) #zero frames
# error message in avspmod about display_pitch, but still usable , can edit script, open other videos
# vdub2 doesn't crash , still usable, can open other scripts/videos
# mpchc doesn't crash, still usable, can open other vids/scripts
Or can you suggest a better way of handling it ? It seems ok to me
poisondeathray is offline   Reply With Quote
Old 13th December 2024, 17:46   #20  |  Link
StainlessS
HeartlessS Usurer
 
StainlessS's Avatar
 
Join Date: Dec 2009
Location: Over the rainbow
Posts: 11,042
by ssS
Quote:
Some time ago, Pinterf was gonna throw error
Actually qyot27.

by PDR
Quote:
Probably this
Yep, and this is the point where Length=0 was initially (temporarily) made illegal
https://github.com/AviSynth/AviSynth...eee829223d1d54

Avisynth Developement thread, post about illegal Length=0,
https://forum.doom9.org/showthread.p...58#post1986258

And a thread from about same time as above changes about Length=0, actually using Length=0 example.
https://forum.doom9.org/showthread.p...D0#post1986352

Post in avs/devs where qyot27 got a bit spooked by the Length=0 whotsit
Quote:
Originally Posted by qyot27 View Post
This. FFmpeg reads video and audio packets separately, and if either reaches EOF, it attempts to read the other one before exiting, because it is easily possible - and not a bug - that either video or audio might be longer than the other, and it shouldn't be truncated.

The error is that length=0 is treated by BlankClip as somehow valid when it isn't, and ends up creating an audio stream of infinite length, which FFmpeg then attempts to read/output. Forcing an output length via the -t parameter would probably demonstrate that it is indeed attempting to write an ever-increasing number of audio samples, until the process is killed.

Post in avs/devs where qyot27 reverted from the illegal Length=0 thingy.
Quote:
Originally Posted by qyot27 View Post
There happened to be some stuff concerning general timestamps/duration/framecount in FFmpeg during April (and coincidentally after the no zero-length clips commit on our side), and if I had to guess, those commits addressed this from FFmpeg's side without ever touching the AviSynth demuxer, since a reverted version of AviSynth+ no longer seems to trip anything with a script consisting of just BlankClip(length=0) (ffplay doesn't reject it as empty, but that's probably just ffplay being ffplay; it doesn't close regular videos when they finish).

So tentatively, it's been reverted. If it re-emerges, though, it will have to be addressed. Memory overflows are not something I'm willing to roll the dice with just because there's useful edge cases.
by PDR
Quote:
Or can you suggest a better way of handling it ? It seems ok to me
Seems ok to me tooooo.
__________________
I sometimes post sober.
StainlessS@MediaFire ::: AND/OR ::: StainlessS@SendSpace

"Some infinities are bigger than other infinities", but how many of them are infinitely bigger ???

Last edited by StainlessS; 13th December 2024 at 17:58.
StainlessS is offline   Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

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 18:08.


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