1

I am trying do slow motion for my video file along with audio. In my case, I have to do Ramped Slow motion(Gradually slowing down and speeding up like parabola not a "Linear Slow Motion".

Ref:Linear slow motion :

enter image description here

Ref : Ramped Slow Motion :

enter image description here

What have i done so far:

Used AVFoundation for first three bullets

  1. From video files, separated audio and video.

  2. Did slow motion for video using AVFoundation api (scaletimeRange).Its really working fine.

  3. The same is not working for audio. Seems there's a bug in apple api itself (Bug ID : 14616144). The relevant question is scaleTimeRange has no effect on audio type AVMutableCompositionTrack

  4. So i switched to Dirac. later found there is a limitation with Dirac's open source edition that it doesn't support Dynamic Time Stretching.

  5. Finally trying to do with OpenAL.

I've taken a sample OpenAL program from Apple developer forum and executed it.

Here are my questions:

  1. Can i store/save the processed audio in OpenAl?if its directly not possible with "OpenAl", can it be done with AVFoundation + OpenAL?

  2. Very importantly, how to do slow motion or stretch the time scale with OpenAL? If i know time stretching, i can apply logic for Ramp Slow Motion.

  3. Is there any other way?

Community
  • 1
  • 1
2vision2
  • 4,933
  • 16
  • 83
  • 164

2 Answers2

1

I can't really speak to 1 or 2, but time scaling audio can be as easy as resampling. If you have RAW/PCM audio sampled at 48 kHz and want to playback at half speed, resample to 96 kHz and play the audio at 48 kHz. Since you have twice the number of samples it will take twice as long to play. Generally:

scaledSampleRate = (orignalSampleRate / playRate);

or

playRate = (originalSampleRate / scaledSampleRate);

This will effect the pitch of the track, however that may be the desired effect since that behavior is somewhat is expected in "slow motion" audio. There are more advanced techniques that preserve pitch while scaling time. The open source software Audacity implements these algorithms. You could find inspiration there. There are many resources on the web that explain the tradeoffs of pitch shifting vs time stretching.

Another option you may not have considered is muting the audio during slow motion. That seems to be the technique employed by most AV playback utilities. However, depending on your use case, distorted audio does indicate time is being manipulated.

trukvl
  • 936
  • 7
  • 16
0

I have applied slow motion on complete video including audio this might help You check this link : How to do Slow Motion video in IOS

Community
  • 1
  • 1
objectiveCoder
  • 579
  • 5
  • 17