View Full Version : AviSynth clip timing
puins
27th September 2010, 16:13
Hello
I have a avs reel with 15 clips. I need to capture the play start and end time for each clip in a millisecond level. I have added code to perfrom this task.
My problem is when I play the reel the total time to play the reel is around 2 seconds shorter than the actual time of the reel noted from virtualdub. This reel is based on xvid codec. Not sure why it is playing 2 seconds faster. I have tried with WMP and MPC. I set the buffering on WMP to 1 sec which is the minimum level.
I am using the QueryPerformanceCounter which I believe is very accurate. Thank you in advance.
IanB
12th October 2010, 22:39
Sorry, I didn't notice this post earlier.
Physical timing within an Avisynth script bears little relation to the intended playback rate of the resultant output. The playback rate is just a clip property.
The external interface model for Avisynth is basically "give me frame N now!", Avisynth then calculates that frame as fast as the cpu will allow.
With media players in general there is buffering at every stage of the process. Each stages goal is to fill it's assigned buffers as fast as possible then wait for the upstream elements to request some data. Only the final renderer implements the playback timing, painting 1 frame every 1.0/fps seconds, and even then it may be buffered, with buffer flips happening every 1.0/fps seconds in the video hardware.
So what you will see with time stamping inside Avisynth is a great flurry of frame fetching as the stream is opened and all the player elements fill their buffers, followed by a chunkiness of delivery as each player elements refill their buffers. The final frame will be delivered from Avisynth well before it is finally displayed.
Of course if the Avisynth script has some very cpu intensive filtering then it may take longer to calculate each frame than the rate required for real time playback, in this case the player elements may implement some strategy, like skipping frames to catch up.
Also setting the buffering in WMP will only set the buffers in the splitter, not all the buffering.
puins
14th October 2010, 17:25
Hello IanB
Thank you for clarifying that. I did additional tests after my first post and found out that the frames were getting dropped. WMP was playing it couple of seconds faster. I see that there are additional buffers involved in the pipe. My timing code seems to be pretty accurate(at least on a second level). I used a stop watch to verify it.
As you were saying, there is no way for me to be very accurate with the timing code in Avisynth. I have kept that in mind and try to keep it as simple as possible.
Thanks.
IanB
14th October 2010, 21:41
@puins,
To get the timing you apparently want you will need to look into the final display renderer used by the media player.
Unfortunately the windows API's, like Direct Show, to do with this are an extreme maze of twisty passages all not quite the same.
puins
22nd December 2010, 17:48
IanB or anyone with expertise in this area
Just wanted some tips on this thread. I have a avs file with around 20 avi clips. The start time and end time seems to be fine in most of them except a few. I have used WMP and Media classic, and also various Windows OSs and hardware and same result. Why could it be that just those clips don't behave in a consistent manner? These clips that are misbehaving come from various sources and I think there is something in the clip that makes the player treat it differently. I have made sure fps, audio format, etc are all the same. Could it be just the general quality of the avi clip. I would appreciate you help. Thank you.
IanB
22nd December 2010, 21:53
Going to need a little more detail on what you are doing.
:script:
A MediaInfo output for a working and non-working clip couldn't hurt.
vBulletin® v3.8.11, Copyright ©2000-2026, vBulletin Solutions Inc.