code: protected final @Nullable MediaFormat getFirstMediaFormatWithRatio(@NotNull Media media) {
      MediaFormat[] mediaFormats = media.getMediaRequest().getMediaArgs().getMediaFormats();
      if (mediaFormats != null) {
        for (MediaFormat mediaFormat : mediaFormats) {
          if (mediaFormat.hasRatio()) {
            return mediaFormat;
          }
        }
      }
      return null;
    }
docs: Get first media format from the media formats of the media args that has a ratio set.
  @param media Media
  @return Media format or null if none found