Log in

View Full Version : Synching video to audio (not audio to video)?


FredMSloniker
13th May 2011, 23:09
I have some sound that I want to add to a video clip; the exact clip will vary based on application, but it can be as simple as a static image or as complex as a countdown timer. Now, I know how to add audio to a video clip (AudioDub) and how to adjust the audio length to match the video length (Trim, plus possibly DelayAudio if the problem is 'too short' instead of 'too long'). What I'd like to do, however, is the reverse: adjust the video length to match the audio length.

I suppose I could do some math involving AudioLength/AudioRate*FrameRate, but is there a more elegant solution?

Gavino
13th May 2011, 23:22
That's the only way, I think.
But use AudioLengthF for accuracy.

FredMSloniker
14th May 2011, 00:33
Why would AudioLengthF be more accurate? I mean, obviously I want to do the division in floating point, but I'd think a long integer would be more accurate, given that we're measuring an integer quantity (number of samples)...

Gavino
14th May 2011, 00:52
Perhaps 'accurate' was the wrong word.
The thing is, AudioLength() will overflow for very long clips (more than 2^31 samples). AudioLengthF() is a 64-bit floating point value so retains all the precision necessary. And as you say, you have to use a floating point division, so you might as well use AudioLengthF (instead of float(AudioLength)) even if there's no overflow risk.

IanB
14th May 2011, 01:08
AudioLengthF() is a 32-bit floating point value, so only has 24bits of precision. However it always has the correct magnitude.

AudioLength() is a 32-bit signed integer value. The internal audio length property of a clip is 64 bits, AudioLength() is just the bottom 32 bits of that property (Yuck!).

For a 48000Hz clip, you get integer range problems at 12.4 hours.