Pinterest: Turbocharge your Android videos with these easy steps

c9bb744f shutterstock 1180124074


Social media giant Pinterest improved Android video performance by optimizing warm-up, configuration, and player pools in a few simple steps, according to a recent blog post by the company’s engineers. .

The engineers at this site see their work as a “never-ending” investigation into the inner workings of their favorite application-level media player for Android, ExoPlayer.

While this blog post is for Android, blog posts written by Former Android Video Engineer Gray Skold, Android Performance Engineer Lin Wang, and Android Performance Engineer Sheng Liu at Pinterest also apply to other areas. Basic concepts are covered.

Let’s see:

warm up

The key lesson learned here was to establish a network connection immediately. Instead of waiting for the video URL to be returned from the server, establish a network connection via a dummy HTTP HEAD request when the application starts. This same connection will be used for playing future videos.

8c719c3b p opennetwork

This same strategy applies to UI rendering.

UI rendering employs a similar pre-establishment strategy. By default, ExoPlayer parses video URLs as follows:

  • Calculate aspect ratio
  • call onContentAspectRarioChanged()
  • Inform AspectRatioFrameLayout of aspect ratio.

Since most video aspect ratios are predetermined, the following function prevents that from happening.

  • Set video aspect ratio AspectRatioFrameLayout.setAspectRatio()
  • override PlayerView.onContentAspectRatioChanged() A method with an empty body (this prevents the player from trying to recalculate the aspect ratio).


short-term buffering

Buffering delays playback until enough data has been buffered. Since most videos on Pinterest are short-form, our engineers chose a short buffering time. The result is less latency and faster load times. setBufferDurationMs() ExoPlayer function for setting the buffering period. The rebuffer rate has increased, but the overall video UX has improved.

84e58341 p bufferduration

Size and sound limits

The two parameters below will load the video in-feed and limit the size to the correct viewport size. This eliminates 1080p video size on a 360px viewport.

7f70fd75 p size

This set of parameters disables audio rendering and allows Pinterest to play multiple muted videos simultaneously. This saves network bandwidth from downloading and memory consumption from processing.

16027cc8 p sound

Clean dirty cache

ExoPlayer provides a caching interface that persists downloaded media files to disk. The problem, however, is that when Pinterest encountered a fatal error caused by a backend bug, long after the bug was fixed, the bad content was also stuck in the cache, causing the error.

The solution is to use SimpleCache.removeResource() I get the following fatal IO error Player.Listener.onPlayerError():


player pooling

Pinterest builds a cache to pool players as needed. Historically, a new player instantiated his instance on the fly, which resulted in significant memory and bandwidth overhead. Their high level learning is:

delimited by encoding

It takes an incredible amount of work to context switch between different decoders. A player instance keeps an underlying decoder reference based on the encoding type of the last rendered media. Pinterest has moved towards pooling players based on their initial decoding format. This eliminated the lag caused by switching encoders and recycled the persistent player with an encoder that matched the media encoding.

smart sizing

Finding the ideal pool size was also a challenge. Multiple iterations were required to find the ideal space needed to store multiple video playbacks, avoiding OutOfMemory (OOM) and Application Not Responding (ANR) errors. To help with this, we’ve adopted two APIs:

This callback notified Pinterest that it was time to clear the player cache pool when the OOM was about to be sent.

This flag allows the ExoPlayer to keep a direct reference to the video decoder and keep it in memory even when idle. This has a big impact on memory and device stability. To save both, Pinterest has built conservative logic around methods based on the current application lifecycle and available memory on the device.

group Created by sketch.


Source link

What do you think?

Leave a Reply

GIPHY App Key not set. Please check settings

    Simple Steps to Mobile first Web Design

    Easy steps to mobile-first web design

    128383470 beyoncedubaiindex

    Beyoncé divides fans with Dubai Atlantis Royal live show