122 lines
2.4 KiB
JavaScript
122 lines
2.4 KiB
JavaScript
import React from 'react';
|
|
|
|
import Grid from '@mui/material/Grid';
|
|
|
|
import Video from '../../settings/Video';
|
|
|
|
function init(initialState) {
|
|
const state = {
|
|
bitrate: '4096',
|
|
fps: '25',
|
|
gop: '2',
|
|
profile: 'auto',
|
|
...initialState,
|
|
};
|
|
|
|
return state;
|
|
}
|
|
|
|
function createMapping(settings) {
|
|
const local = [
|
|
'-codec:v',
|
|
'h264_omx',
|
|
'-b:v',
|
|
`${settings.bitrate}k`,
|
|
'-maxrate',
|
|
`${settings.bitrate}k`,
|
|
'-bufsize',
|
|
`${settings.bitrate}k`,
|
|
'-r',
|
|
`${settings.fps}`,
|
|
'-pix_fmt',
|
|
'yuv420p',
|
|
];
|
|
|
|
if (settings.gop !== 'auto') {
|
|
local.push('-g', `${Math.round(parseInt(settings.fps) * parseInt(settings.gop)).toFixed(0)}`);
|
|
}
|
|
|
|
if (settings.profile !== 'auto') {
|
|
local.push('-profile:v', `${settings.profile}`);
|
|
}
|
|
|
|
const mapping = {
|
|
global: [],
|
|
local: local,
|
|
};
|
|
|
|
return mapping;
|
|
}
|
|
|
|
function Coder(props) {
|
|
const settings = init(props.settings);
|
|
|
|
const handleChange = (newSettings) => {
|
|
let automatic = false;
|
|
if (!newSettings) {
|
|
newSettings = settings;
|
|
automatic = true;
|
|
}
|
|
|
|
props.onChange(newSettings, createMapping(newSettings), automatic);
|
|
};
|
|
|
|
const update = (what) => (event) => {
|
|
const newSettings = {
|
|
...settings,
|
|
[what]: event.target.value,
|
|
};
|
|
|
|
handleChange(newSettings);
|
|
};
|
|
|
|
React.useEffect(() => {
|
|
handleChange(null);
|
|
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
}, []);
|
|
|
|
return (
|
|
<Grid container spacing={2}>
|
|
<Grid item xs={12}>
|
|
<Video.Bitrate value={settings.bitrate} onChange={update('bitrate')} allowCustom />
|
|
</Grid>
|
|
<Grid item xs={12}>
|
|
<Video.Framerate value={settings.fps} onChange={update('fps')} allowCustom />
|
|
</Grid>
|
|
<Grid item xs={12}>
|
|
<Video.GOP value={settings.gop} onChange={update('gop')} allowAuto allowCustom />
|
|
</Grid>
|
|
<Grid item xs={12}>
|
|
<Video.Profile value={settings.profile} onChange={update('profile')} />
|
|
</Grid>
|
|
</Grid>
|
|
);
|
|
}
|
|
|
|
Coder.defaultProps = {
|
|
stream: {},
|
|
settings: {},
|
|
onChange: function (settings, mapping) {},
|
|
};
|
|
|
|
const coder = 'h264_omx';
|
|
const name = 'H.264 (OpenMAX IL)';
|
|
const codec = 'h264';
|
|
const type = 'video';
|
|
const hwaccel = true;
|
|
|
|
function summarize(settings) {
|
|
return `${name}, ${settings.bitrate} kbit/s, ${settings.fps} FPS, Profile: ${settings.profile}`;
|
|
}
|
|
|
|
function defaults() {
|
|
const settings = init({});
|
|
|
|
return {
|
|
settings: settings,
|
|
mapping: createMapping(settings),
|
|
};
|
|
}
|
|
|
|
export { coder, name, codec, type, hwaccel, summarize, defaults, Coder as component };
|