Skip to content

Instantly share code, notes, and snippets.

@erikusaj
Last active May 15, 2023 13:23
Show Gist options
  • Save erikusaj/bae5b8051ec520465c30d30f31503473 to your computer and use it in GitHub Desktop.
Save erikusaj/bae5b8051ec520465c30d30f31503473 to your computer and use it in GitHub Desktop.
<html>
<head>
<title>HEVC Support test</title>
<script>
// preverjanje za resolucijo: How to verify certain profile or resolution is supported?
var video_canPlay = [];
var MediaSource_supported = [];
var encrypted_support = [];
async function hevcTests(){
const mediaConfig = {
/**
* You can use `file` or `media-source` and the result are same here,
* don't use `webrtc` since HEVC webrtc is not supported currently.
*/
type: 'file',
video: {
/**
* HEVC Profile
*
* Main: `hev1.1.6.L93.B0`
* Main 10: `hev1.2.4.L93.B0`
* Main still-picture: `hvc1.3.E.L93.B0`
* Range extensions: `hvc1.4.10.L93.B0`
*/
contentType : 'video/mp4;codecs="hev1.1.6.L120.90"',
/* Width */
width: 1920,
/* Height */
height: 1080,
/* Any number */
bitrate: 10000,
/* Any number */
framerate: 30
}
}
navigator.mediaCapabilities.decodingInfo(mediaConfig)
.then(result => {
/* Indicate whether or not the video with given profile, width, and height can played well on the browser */
if (result.supported) {
console.log('Video can play!');
} else {
console.log('Video can\'t play!');
}
});
const HEVC_main_supported = 'HEVC main profile is supported!';
const HEVC_main_10_supported = 'HEVC main 10 profile is supported!';
const HEVC_main_still_picture_supported = 'HEVC main still-picture profile is supported!';
const HEVC_range_ext_supported ='HEVC range extensions profile is supported!';
if (MediaSource.isTypeSupported('video/mp4;codecs="hev1.1.6.L120.90"')) {
console.log(HEVC_main_supported);
MediaSource_supported.push(HEVC_main_supported);
}
if (MediaSource.isTypeSupported('video/mp4;codecs="hev1.2.4.L120.90"')) {
console.log(HEVC_main_10_supported);
MediaSource_supported.push(HEVC_main_10_supported);
}
if (MediaSource.isTypeSupported('video/mp4;codecs="hev1.3.E.L120.90"')) {
console.log(HEVC_main_still_picture_supported);
MediaSource_supported.push(HEVC_main_still_picture_supported);
}
if (MediaSource.isTypeSupported('video/mp4;codecs="hev1.4.10.L120.90"')) {
console.log(HEVC_range_ext_supported);
MediaSource_supported.push(HEVC_range_ext_supported);
}
const video = document.createElement('video');
if (video.canPlayType('video/mp4;codecs="hev1.1.6.L120.90"') === 'probably') {
console.log(HEVC_main_supported);
video_canPlay.push(HEVC_main_supported);
}
if (video.canPlayType('video/mp4;codecs="hev1.2.4.L120.90"') === 'probably') {
console.log(HEVC_main_10_supported);
video_canPlay.push(HEVC_main_10_supported);
}
if (video.canPlayType('video/mp4;codecs="hev1.3.E.L120.90"') === 'probably') {
console.log(HEVC_main_still_picture_supported);
video_canPlay.push(HEVC_main_still_picture_supported);
}
if (video.canPlayType('video/mp4;codecs="hev1.4.10.L120.90"') === 'probably') {
console.log(HEVC_range_ext_supported);
video_canPlay.push(HEVC_range_ext_supported);
}
const HEVC_Widevine_L1_supported ='Widevine L1 HEVC main profile is supported!';
const HEVC_Widevine_L1__NOT_supported='Widevine L1 HEVC main profile is NOT supported!';
const HEVX_DolbyVision_Widevine_L1_supported = 'Widevine L1 Dolby Vision profile 5 is supported!';
const HEVX_DolbyVision_Widevine_L1_NOT_supported='Widevine L1 Dolby Vision profile 5 is NOT supported!'
// Encrypted Content
/** Detect HEVC Widevine L1 support (only Windows is supported). */
try {
await navigator.requestMediaKeySystemAccess('com.widevine.alpha.experiment', [
{
initDataTypes: ['cenc'],
distinctiveIdentifier: 'required',
persistentState: 'required',
sessionTypes: ['temporary'],
videoCapabilities: [
{
robustness: 'HW_SECURE_ALL',
contentType: 'video/mp4; codecs="hev1.1.6.L120.90"',
},
],
},
]);
console.log(HEVC_Widevine_L1_supported);
encrypted_support.push(HEVC_Widevine_L1_supported)
} catch (e) {
console.log(HEVC_Widevine_L1__NOT_supported);
encrypted_support.push(HEVC_Widevine_L1__NOT_supported)
}
/**
* Detect Dolby Vision Widevine L1 support (only Windows is supported, and only if
* `--enable-features=PlatformEncryptedDolbyVision` switch has been passed).
*/
try {
await navigator.requestMediaKeySystemAccess('com.widevine.alpha.experiment', [
{
initDataTypes: ['cenc'],
distinctiveIdentifier: 'required',
persistentState: 'required',
sessionTypes: ['temporary'],
videoCapabilities: [
{
robustness: 'HW_SECURE_ALL',
contentType: 'video/mp4; codecs="dvhe.05.07"',
},
],
},
]);
console.log(HEVX_DolbyVision_Widevine_L1_supported);
encrypted_support.push(HEVX_DolbyVision_Widevine_L1_supported)
} catch (e) {
console.log(HEVX_DolbyVision_Widevine_L1_NOT_supported);
encrypted_support.push(HEVX_DolbyVision_Widevine_L1_NOT_supported)
}
}
function start() {
return hevcTests();
}
// Call start
(async() => {
console.log('before start');
await start();
console.log('after start');
})();
function browserDetails()
{
var txt = ""
txt+= "<p>Browser Vendor: " + navigator.vendor + "</p>";
txt+= "<p>Browser Version: " + navigator.appVersion + "</p>";
txt+= "<p>Cookies Enabled: " + navigator.cookieEnabled + "</p>";
txt+= "<p>Platform: " + navigator.platform + "</p>";
txt+= "<p>User-agent header: " + navigator.userAgent + "</p>";
return txt;
}
function printResults() {
document.getElementById('browser').innerHTML = browserDetails()
document.getElementById('results').innerHTML = "Test results<br><h4>Video elemennt canPlay</h4>" + video_canPlay.toString().replaceAll(',', '<br>') + '<h4>MediaSource Supported</h4>' + MediaSource_supported.toString().replaceAll(',', '<br>') + '<h4>Widevine</h4>' + encrypted_support.toString().replaceAll(',', '<br>');
}
</script>
</head>
<body onload="printResults()">
<h1 id="title">HEVC capability</h1>
<div id="browser"></div>
<hr>
<div id="results"></div>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment