[ Web Proxy ]
URL:
Viewing: https://developer.android.com/media/media3/inspector/extract-frames [Back]  [Original]

Extract video frames  |  Android media  |  Android Developers Skip to main content
Essentials Design & Plan Develop Google Play Blog
Search:
Android Studio
Android Developers [Android Developers]

Extract video frames Stay organized with collections Save and categorize content based on your preferences.

The FrameExtractor class provides an efficient way to extract decoded frames from a MediaItem.

Common use cases include:

Overview

Using FrameExtractor is a two-step process:

  1. Build the extractor: Create an instance using FrameExtractor.Builder. Pass a Context and the MediaItem that you want to inspect to the builder. You can also chain configuration methods on the Builder for advanced settings.
  2. Extract frames: Call getFrame() to extract a frame at a specific timestamp or getThumbnail() to request a representative thumbnail. These methods are asynchronous and return a ListenableFuture. Hence, the complex decoding work doesn't block the main thread.
Important: FrameExtractor instances must be accessed from a single application thread.

Kotlin

suspend fun extractFrames(context: Context, mediaItem: MediaItem) {
  try {
    // 1. Build the frame extractor.
    // `FrameExtractor` implements `AutoCloseable`, so wrap it in
    // a Kotlin `.use` block, which calls `close()` automatically.
    FrameExtractor.Builder(context, mediaItem).build().use { extractor ->
      // 2. Extract frames asynchronously.
      val frame = extractor.getFrame(5000L).await()
      val thumbnail = extractor.thumbnail.await()
      handleFrame(frame, thumbnail)
    }
  } catch (e: Exception) {
    handleFailure(e)
  }
}

Java

public void extractFrames(Context context, MediaItem mediaItem) {
  // 1. Build the frame extractor.
  // `FrameExtractor` implements `AutoCloseable`, so use try-with-resources
  // so that the resources are automatically released.
  try (FrameExtractor frameExtractor = new FrameExtractor.Builder(context, mediaItem).build()) {
    // 2. Extract frames asynchronously.
    ListenableFuture<FrameExtractor.Frame> frameFuture = frameExtractor.getFrame(5000L);
    ListenableFuture<FrameExtractor.Frame> thumbnailFuture = frameExtractor.getThumbnail();

    ListenableFuture<List<Object>> allFutures = Futures.allAsList(frameFuture, thumbnailFuture);
    Futures.addCallback(
        allFutures,
        new FutureCallback<List<Object>>() {
          @Override
          public void onSuccess(List<Object> result) {
            handleFrame(Futures.getUnchecked(frameFuture), Futures.getUnchecked(thumbnailFuture));
          }

          @Override
          public void onFailure(Throwable t) {
            handleFailure(t);
          }
        },
        directExecutor());
  }
}

Content and code samples on this page are subject to the licenses described in the Content License. Java and OpenJDK are trademarks or registered trademarks of Oracle and/or its affiliates.

Last updated 2026-03-25 UTC.

[[["Easy to understand","easyToUnderstand","thumb-up"],["Solved my problem","solvedMyProblem","thumb-up"],["Other","otherUp","thumb-up"]],[["Missing the information I need","missingTheInformationINeed","thumb-down"],["Too complicated / too many steps","tooComplicatedTooManySteps","thumb-down"],["Out of date","outOfDate","thumb-down"],["Samples / code issue","samplesCodeIssue","thumb-down"],["Other","otherDown","thumb-down"]],["Last updated 2026-03-25 UTC."],[],[]]

Web Proxy Viewer  |  New URL  |  Original Page