Log in

View Full Version : Trim error using variable


broxburn
2nd August 2011, 21:56
I get an 'invalid argument' error in line six.
Trying to trim ten seconds from a video when/If I don't know the frame rate.
In addition, if it's supposed to work, how would I get a whole number if the frame rate was 29.97 and I wanted to round it to the nearest whole.


avisource("clip.avi") # framerate 25fps
time=10
fr=framerate()
fc=framecount()
ft=time*fr
trim(ft,fc)
last

IanB
2nd August 2011, 22:18
Framerate() returns a float, trim need integer.

See Round(), Ceil() and Floor()

broxburn
2nd August 2011, 23:56
Same error for trim - since it is 25fps wouldn't it be integers (25, 250) even without the 'ceil', 'round'?

avisource("clip.avi") # framerate 25fps
time=10
fr=framerate()
ceil(fr)
fc=framecount()
ft=time*fr
round(ft)
trim(ft,fc)
last

broxburn
3rd August 2011, 00:37
Got it - thank you!!

avisource("clip.avi") # framerate 25fps
time=10
fr=framerate()
a=FrameRateNumerator()
b=FrameRateDenominator()
c=a/b
round(c)
fc=framecount()
round(fc)
ft=time*c
round(ft)
trim(ft,fc)
last

IanB
3rd August 2011, 02:40
In your code you probably want :-
c=round(c)
fc=round(fc)
ft=round(ft)

But this is closer to the original post:-avisource("clip.avi") # framerate 25fps
time=10
fr=framerate()
fc=framecount()
ft=floor(time*fr)
trim(ft,fc) # Also trim(ft, 0) # 0 means to the end.

Gavino
3rd August 2011, 08:51
To add to what IanB is telling you, note that a line such as
round(c)
effectively does nothing - the result is calculated and then thrown away.
You have to assign the result to something:
c = round(c)

Also, frames are numbered from 0, so the last frame is framecount-1, not framecount. That's why it's more convenient to use trim(..., 0) to select up to the end of a clip.

broxburn
3rd August 2011, 11:25
Thank you both for the info.
Can you comment on why 'floor' instead of 'round' or 'ceil' - I don't see any difference in the result.
I made an addition to remove ten seconds from the end of the video - any comment?.


avisource("clip.avi") # framerate 25fps
time=10
fr=framerate()
fc=framecount()
ft=floor(time*fr)
trim(ft,0) # 0 means to the end.
reverse()
trim(ft,0)
reverse()

Gavino
3rd August 2011, 12:14
Can you comment on why 'floor' instead of 'round' or 'ceil' - I don't see any difference in the result.
It depends what you want to happen when the time does not correspond to a whole number of frames.
'floor' gives the nearest integer below - appropriate if your desire is not to trim any more than a given number of seconds (here 10).
'ceil' gives the nearest integer above, which would ensure you trim no less than 10 seconds.
'round' simply gives the nearest integer, which might be appropriate, depending on your needs.

If the framerate is a whole number, all three will end up giving the same result.

I made an addition to remove ten seconds from the end of the video - any comment?.
Yes, that should work.
It might seem a roundabout way of doing it, but the double reverse is actually quite efficient as the source will still be read in linear order.