Skip to content

Instantly share code, notes, and snippets.

@unitycoder
Forked from asus4/VideoSupportPlugin.java
Created February 21, 2025 09:43
Show Gist options
  • Save unitycoder/94553a61fb054646639db70927ad4603 to your computer and use it in GitHub Desktop.
Save unitycoder/94553a61fb054646639db70927ad4603 to your computer and use it in GitHub Desktop.
Check supported resolution from unity
using UnityEngine;
using System.Runtime.InteropServices;
namespace VRKit
{
public static class VideoSupported
{
public static bool IsSupported(int width, int height, float framerate)
{
#if UNITY_EDITOR
return true;
#elif UNITY_IPHONE
return isVideoSupportedFormat(width, height, framerate);
#elif UNITY_ANDROID
AndroidJavaObject jo = new AndroidJavaObject("asus4.videosupportedplugin.VideoSupportedPlugin");
return jo.CallStatic<bool>("isVideoSupportedFormat", width, height, framerate);
#else
Debug.LogError("Not supported platform");
return false;
#endif
}
public static bool Is4KSupported()
{
return IsSupported(3840, 1920, 29.97f);
}
#if UNITY_IPHONE
[DllImport("__Internal")]
private static extern bool isVideoSupportedFormat(int width, int heigt, float framerate);
#endif
}
}
package asus4.videosupportedplugin;
import android.media.MediaCodecInfo;
import android.media.MediaCodecList;
/**
* Created by ibu on 2017/03/12.
*/
public final class VideoSupportedPlugin {
public static boolean isVideoSupportedFormat(int width, int height, float framerate) {
MediaCodecList allCodecs = new MediaCodecList(MediaCodecList.ALL_CODECS);
MediaCodecInfo[] infos = allCodecs.getCodecInfos();
for (MediaCodecInfo info : infos) {
for (String type : info.getSupportedTypes()) {
MediaCodecInfo.CodecCapabilities caps = info.getCapabilitiesForType(type);
MediaCodecInfo.VideoCapabilities vcaps = caps.getVideoCapabilities();
if (vcaps == null) {
continue;
}
if (vcaps.areSizeAndRateSupported(width, height, framerate)) {
return true;
}
}
}
return false;
}
}
//
// VideoSupportPlugin.m
// VideoSupportiOS
//
// Created by Koki Ibukuro on 2017/03/12.
// Copyright © 2017 Koki Ibukuro. All rights reserved.
//
#import <AVFoundation/AVFoundation.h>
extern "C" {
BOOL isVideoSupportedFormat(int width, int height, float framerate) {
AVCaptureDevice *device = [AVCaptureDevice defaultDeviceWithMediaType:AVMediaTypeVideo];
for(AVCaptureDeviceFormat *format in device.formats) {
CMVideoDimensions dim = format.highResolutionStillImageDimensions;
if(dim.width < width || dim.height < height)
{
continue;
}
for(AVFrameRateRange *range in format.videoSupportedFrameRateRanges) {
// NSLog(@"\t %f - %f", range.minFrameRate, range.maxFrameRate);
if(range.minFrameRate <= framerate && framerate <= range.maxFrameRate){
return YES;
}
}
}
return NO;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment