View Full Version : Help with ConditionalReader
bencahill
23rd December 2009, 23:06
Howdy!
I'm trying to figure out ConditionalReader so I can do a slow speed change from ten times faster (AssumeFPS(300).ChangeFPS(30).Timestretch(1000)) back to 1x over the course of 900 frames. I was thinking that if I changed the speed for every single frame, then it wouldn't work, since it would have half a frame, or a third of a frame (at 30fps), so I was thinking I might try first bumping up the framerate to a good bit higher and then changing it back to 30fps in the end with ChangeFPS.
Anyway, I went ahead and tried the simplistic way (assigning a different value for each frame), and it keeps giving me this error: Invalid arguments to function "ConditionalReader". Below is my script and ConditionalReader file. Any help would be greatly appreciated. :)
(yes, I know it's a bear of a script)
Woops, the script was too big, so I put it on pastebin:
http://pastebin.com/f39ddfd9c
txt:
http://pastebin.com/f3628b0a
Gavino
24th December 2009, 13:57
Your script is missing the clip argument to ConditionalReader.
I don't have time to study your script in detail, but you probably want ConditionalReader(s, "cr.txt", "myvar", true).
But I think this could be done more simply using Animate.
Write yourself a function with a float 'speed' parameter and Animate this function to vary the speed from 10 to 1 over the length of the clip. I think in any case the audio will give problems since neither Animate nor ScriptClip process audio.
bencahill
24th December 2009, 22:00
Duh! - I've known about animate, and used it a couple of times, I can't believe it didn't occur to me here! - The audio doesn't matter here, I can process it at the same time using the first method, and they should be fine (if not I'll tweak it to match). Thank you so much!
bencahill
24th December 2009, 22:30
What am I doing wrong here?
function ChangeSpeed(clip c, float speed)
{
as=AssumeFPS(c, 30 * speed)
cs=ChangeFPS(as, 30)
return cs
}
return Animate(s,246001,246901,"ChangeSpeed",10,1)
All I get is the whole video ten times faster. I'm thinking it doesn't know that the last "1" is the end arg, but how do I tell it it is?
Gavino
25th December 2009, 12:41
A few points here:
1. Animate will apply the starting parameter (here 10) to all frames prior to the starting frame. If you donīt want that, you have to extract the original frames separately.
2. When animating a function with float parameters, pass floats for the corresponding Animate arguments (eg 10.0, not 10), otherwise the interpolation will be done with integers only.
3. More subtly: To get the right frames selected by ChangeFPS at each point during the animation, it will need to be given the average speed for the animation so far, not the instantaneous speed at that point. So the animation (somewhat counter-intuitively) needs to run from 10.0 to 5.5 ((10+1)/2).
So I think for the animation part, you need something like this:
ss = s.Trim(246001, 0)
Animate(ss,0,900,"ChangeSpeed",10.0,5.5)
The final script will depend on whether you want to include the original frames 0-246000. Also, you might want to trim the animation since itīs not clear whether you want 901 output frames or the smaller number (901/5.5) corresponding to 901 input frames.
bencahill
29th January 2012, 04:08
I'm just now returning to this forum (to ask more questions :D), but I thought I'd post what I ended up doing so as to be helpful to future readers. (note: this is according to my memory and reading the script, as this was over 2 years ago)
I figured out that Animate() does not work with TimeStretch() (changing the audio speed)...so I came up with a decent solution for my problem: I divided the audio into ten portions, with each a bit faster than the last, and used the AnimateSpeed() function from here (http://forum.doom9.org/showthread.php?p=534384#post534384) to speed up the video. It turned out quite nice, as I am just changing the tempo of the audio, so the pitch stays constant.
fastaudio=trim(f,246001,246081).AssumeFPS(300).ChangeFPS(30).TimeStretch(1000)\
+trim(f,246081,246162).AssumeFPS(270).ChangeFPS(30).TimeStretch(900)\
+trim(f,246162,246250).AssumeFPS(240).ChangeFPS(30).TimeStretch(800)\
+trim(f,246250,246341).AssumeFPS(210).ChangeFPS(30).TimeStretch(700)\
+trim(f,246341,246437).AssumeFPS(180).ChangeFPS(30).TimeStretch(600)\
+trim(f,246437,246532).AssumeFPS(150).ChangeFPS(30).TimeStretch(500)\
+trim(f,246532,246628).AssumeFPS(120).ChangeFPS(30).TimeStretch(400)\
+trim(f,246628,246724).AssumeFPS(90).ChangeFPS(30).TimeStretch(300)\
+trim(f,246724,246822).AssumeFPS(60).ChangeFPS(30).TimeStretch(200)\
+trim(f,246822,246901).AssumeFPS(30).ChangeFPS(30).TimeStretch(100)
sfast=trim(f,246001,248608).AssumeFPS(30)\
.AnimateSpeed(orig_percent=1000,change_percent=50).AudioDub(fastaudio)
I believe the change_percent=50 was because 100 didn't work as expected.
I haven't tested the code recently, but it should work fine—I copied it verbatim out of the script I used (except for adding backslashes and linebreaks). If you have any questions about this code, feel free to ask, but I might not be able to answer them, as I don't know much about this. :D Someone else probably would though.
Gavino
29th January 2012, 21:01
fastaudio=trim(f,246001,246081).AssumeFPS(300).ChangeFPS(30).TimeStretch(1000)\
Since neither AssumeFPS (by default) nor ChangeFPS() affect the audio, they are redundant here. So it's enough to use:
fastaudio=trim(f,246001,246081).TimeStretch(1000)\
sfast=trim(f,246001,248608).AssumeFPS(30)\
.AnimateSpeed(orig_percent=1000,change_percent=50).AudioDub(fastaudio)
I believe the change_percent=50 was because 100 didn't work as expected.
That's because the AnimateSpeed function doesn't work properly.
I expect you had to adjust both the change_percent value and the 248608 frame number in the Trim by experiment to get roughly what you wanted, and even then it does not give a linear change in speed.
As I said in post #5 above, there are some subtle points involved in animating ChangeFPS.
See my function VarSpeed in this post, which I believe works correctly (though I see that sh0dan thought it was in principle impossible ;)), and further explanation in post #4 of the same thread.
You should be able to use
sfast=trim(f,246001,246901).VarSpeed(10.0, 1.0).AudioDub(fastaudio)
bencahill
29th January 2012, 23:04
Since neither AssumeFPS (by default) nor ChangeFPS() affect the audio, they are redundant here. So it's enough to use:
fastaudio=trim(f,246001,246081).TimeStretch(1000)\
You are correct. I was thinking that since it would still have the same number of frames, each clip would last longer, messing it all up, but since I'm doing unaligned splices (+) and then throwing away the video (AudioDub), it doesn't matter.
That's because the AnimateSpeed function doesn't work properly.
I expect you had to adjust both the change_percent value and the 248608 frame number in the Trim by experiment to get roughly what you wanted, and even then it does not give a linear change in speed.
Yes, it was trial-and-error, as I recall. :)
See my function VarSpeed in this post, which I believe works correctly (though I see that sh0dan thought it was in principle impossible ;)), and further explanation in post #4 of the same thread.
Awesome. I don't have much free time at present, but I will check it out if I need to do something similar in the present.
Thanks!
vBulletin® v3.8.11, Copyright ©2000-2026, vBulletin Solutions Inc.