DeepMedia logo
Open Source

Search...

Other versions of this page

Improve this page on GitHub

Search

Advanced Options

Video rotation

You can set the output video rotation with the setRotation(int) method. This will apply a clockwise rotation to the input video frames. Accepted values are 0, 90, 180, 270:

kotlin logokotlin
Transcoder.into(filePath) .setVideoRotation(rotation) // 0, 90, 180, 270 // ...

Time interpolation

We offer APIs to change the timestamp of each video and audio frame. You can pass a TimeInterpolator to the transcoder builder to be able to receive the frame timestamp as input, and return a new one as output.

kotlin logokotlin
Transcoder.into(filePath) .setTimeInterpolator(timeInterpolator) // ...

As an example, this is the implementation of the default interpolator, called DefaultTimeInterpolator, that will just return the input time unchanged:

kotlin logokotlin
override fun interpolate(type: TrackType, time: Long): Long { // Receive input time in microseconds and return a possibly different one. return time }

It should be obvious that returning invalid times can make the process crash at any point, or at least the transcoding operation fail.

Video speed

We also offer a special time interpolator called SpeedTimeInterpolator that accepts a float parameter and will modify the video speed.

  • A speed factor equal to 1 will leave speed unchanged
  • A speed factor < 1 will slow the video down
  • A speed factor > 1 will accelerate the video

This interpolator can be set using setTimeInterpolator(TimeInterpolator), or, as a shorthand, using setSpeed(float):

kotlin logokotlin
Transcoder.into(filePath) .setSpeed(0.5F) // 0.5x .setSpeed(1F) // Unchanged .setSpeed(2F) // Twice as fast // ...

Audio stretching

When a time interpolator alters the frames and samples timestamps, you can either remove audio or stretch the audio samples to the new length. This is done through the AudioStretcher interface:

kotlin logokotlin
Transcoder.into(filePath) .setAudioStretcher(audioStretcher) // ...

The default audio stretcher, DefaultAudioStretcher, will:

  • When we need to shrink a group of samples, cut the last ones
  • When we need to stretch a group of samples, insert noise samples in between

Please take a look at the implementation and read class documentation.

Audio resampling

When a sample rate different than the input is specified (by the TrackStrategy, or, when using the default audio strategy, by DefaultAudioStrategy.Builder.sampleRate()), this library will automatically perform sample rate conversion for you.

This operation is performed by a class called AudioResampler. We offer the option to pass your own resamplers through the transcoder builder:

kotlin logokotlin
Transcoder.into(filePath) .setAudioResampler(audioResampler) // ...

The default audio resampler, DefaultAudioResampler, will perform both upsampling and downsampling with very basic algorithms (drop samples when downsampling, repeat samples when upsampling). Upsampling is generally discouraged - implementing a real upsampling algorithm is probably out of the scope of this library.

Please take a look at the implementation and read class documentation.

Subscribe to the DeepMedia Newsletter

The latest news about DeepMedia products, open source projects and software development at our company.

By clicking “Subscribe”, you agree that DeepMedia may use your email address to send you newsletters, including commercial communications, and to process your personal data for this purpose. You agree that DeepMedia may process said data using third-party services for this purpose in accordance with the DeepMedia Privacy Policy. You can revoke this consent at any time using the unsubscribe link included in each email or by writing at contact@deepmedia.io.