64 lines
1.8 KiB
JavaScript
64 lines
1.8 KiB
JavaScript
import { Mp4OutputFormat, QUALITY_HIGH, QUALITY_LOW, QUALITY_MEDIUM, QUALITY_VERY_HIGH, QUALITY_VERY_LOW, WebMOutputFormat, } from 'mediabunny';
|
|
export const codecToMediabunnyCodec = (codec) => {
|
|
switch (codec) {
|
|
case 'h264':
|
|
return 'avc';
|
|
case 'h265':
|
|
return 'hevc';
|
|
case 'vp8':
|
|
return 'vp8';
|
|
case 'vp9':
|
|
return 'vp9';
|
|
case 'av1':
|
|
return 'av1';
|
|
default:
|
|
throw new Error(`Unsupported codec: ${codec}`);
|
|
}
|
|
};
|
|
export const containerToMediabunnyContainer = (container) => {
|
|
switch (container) {
|
|
case 'mp4':
|
|
return new Mp4OutputFormat();
|
|
case 'webm':
|
|
return new WebMOutputFormat();
|
|
default:
|
|
throw new Error(`Unsupported container: ${container}`);
|
|
}
|
|
};
|
|
export const getDefaultVideoCodecForContainer = (container) => {
|
|
switch (container) {
|
|
case 'mp4':
|
|
return 'h264';
|
|
case 'webm':
|
|
return 'vp8';
|
|
default:
|
|
throw new Error(`Unsupported container: ${container}`);
|
|
}
|
|
};
|
|
export const getQualityForWebRendererQuality = (quality) => {
|
|
switch (quality) {
|
|
case 'very-low':
|
|
return QUALITY_VERY_LOW;
|
|
case 'low':
|
|
return QUALITY_LOW;
|
|
case 'medium':
|
|
return QUALITY_MEDIUM;
|
|
case 'high':
|
|
return QUALITY_HIGH;
|
|
case 'very-high':
|
|
return QUALITY_VERY_HIGH;
|
|
default:
|
|
throw new Error(`Unsupported quality: ${quality}`);
|
|
}
|
|
};
|
|
export const getMimeType = (container) => {
|
|
switch (container) {
|
|
case 'mp4':
|
|
return 'video/mp4';
|
|
case 'webm':
|
|
return 'video/webm';
|
|
default:
|
|
throw new Error(`Unsupported container: ${container}`);
|
|
}
|
|
};
|