HomeAndroidMedia transcoding and modifying, remodel and roll out!

Media transcoding and modifying, remodel and roll out!



Posted by Andrew Lewis – Software program Engineer, Android Media Options

The creation of user-generated content material is on the rise, and customers are on the lookout for extra methods to personalize and add uniqueness to their creations. These creations are then shared to an enormous community of gadgets, every with its personal capabilities. The Jetpack Media3 1.0 launch consists of new performance within the Transformer module for changing media information between codecs, or transcoding, and making use of modifying operations. For instance, you possibly can trim a clip from an extended piece of media and apply results to the video observe to share over social media, or transcode media right into a extra environment friendly codec for add to a server.

The general objective of Transformer is to offer a straightforward to make use of, dependable and performant API for transcoding and modifying media, together with assist for customizing performance, following the identical API design rules to ExoPlayer. The library is supported on gadgets operating Android 5.0 Lollipop (API 21) onwards and consists of device-specific optimizations, giving builders a robust basis to construct on. This submit provides an introduction to the brand new performance and describes a few of the many options we’re planning for upcoming releases!

Getting Began

Most operations with Transformer will comply with the identical basic sample:

  1. Configure a TransformationRequest with settings like your required output format
  2. Create a Transformer and go it your TransformationRequest
  3. Apply further results and edits
  4. Connect a listener to react to completion occasions
  5. Begin the transformation

After all, relying in your desired transformations, it’s possible you’ll not want each step. Here is an instance of transcoding an enter video to the H.265/HEVC video format and eradicating the audio observe.


val transformationRequest = TransformationRequest.Builder().setVideoMimeType(MimeTypes.VIDEO_H265).construct()

val transformer = Transformer.Builder(context)
.setTransformationRequest(transformationRequest)
.setRemoveAudio(true)
.addListener(transformerListener)
.construct()

val inputMediaItem = MediaItem.fromUri("path_to_input_file")
transformer.startTransformation(inputMediaItem, outputPath)

Throughout transformation you may get progress updates with Transformer.getProgress. When the transformation completes the listener is notified in its onTransformationCompleted or onTransformationError callback, and you’ll course of the output media as wanted.

Take a look at our documentation to study additional capabilities within the Transformer APIs. You too can discover particulars about utilizing Transformer to precisely convert 10-bit HDR content material to 8-bit SDR within the “Coping with colour washout” weblog submit to make sure your video’s colours stay as vibrant as potential within the case that your app or the machine would not assist HDR content material.

Edits, results, and extensions

Media3 features a set of core video results for easy edits, comparable to scaling, cropping, and colour filters, which you should utilize with Transformer. For instance, you possibly can create a Presentation impact to scale the enter to 480p decision whereas sustaining the unique facet ratio, and apply it with setVideoEffects:

Transformer.Builder(context)
.setVideoEffects(listOf(Presentation.createForHeight(480)))
.construct()

You too can chain a number of results to create extra advanced outcomes. This instance converts the enter video to grayscale and rotates it by 30 levels:

Transformer.Builder(context)
.setVideoEffects(listOf(
RgbFilter.createGrayscaleFilter(),
ScaleToFitTransformation.Builder()
.setRotationDegrees(30f)
.construct()))
.construct()

It is also potential to increase Transformer’s performance by implementing customized results that construct on present ones. Right here is an instance of subclassing MatrixTransformation, the place we begin zoomed in by 2 occasions, then zoom out steadily because the body presentation time will increase:

val zoomOutEffect = MatrixTransformation { presentationTimeUs ->
val transformationMatrix = Matrix()
val scale = 2 - min(1f, presentationTimeUs / 1_000_000f)
transformationMatrix.postScale( scale, scale)
transformationMatrix
}
Transformer.Builder(context)
.setVideoEffects(listOf(zoomOutEffect))
.construct()

Here is a display screen recording that exhibits this impact being utilized within the Transformer demo app:

moving image showing what subclassing matrix transformation looks like in the Transformer demo app

For much more superior use instances, you possibly can wrap your individual OpenGL code or different processing libraries in a customized GL texture processor and plug these into Transformer as customized results. See the demo app for some examples of customized results. The README additionally has directions for making an attempt a demo of MediaPipe integration with Transformer.

Coming quickly

Transformer is actively underneath growth however prepared to make use of, so please give it a attempt to share your suggestions! The Media3 growth department features a sneak peek into a number of new options constructing on the 1.0 launch described right here, together with assist for tone-mapping HDR movies to SDR utilizing OpenGL, previewing video results utilizing ExoPlayer.setVideoEffects, and customized audio processing. We’re additionally engaged on assist for modifying a number of movies in additional versatile compositions, with export from Transformer and playback by ExoPlayer, making Media3 an end-to-end resolution for remodeling media.

We hope you will discover Transformer an easy-to-use and highly effective device for implementing implausible media modifying experiences on Android! You’ll be able to ship us function requests and bug stories within the Media3 GitHub problem tracker, and comply with this weblog to get updates on new options. Keep tuned for our upcoming speak “Top quality Android media experiences” at Google I/O.

RELATED ARTICLES

LEAVE A REPLY

Please enter your comment!
Please enter your name here

Most Popular

Recent Comments