owncast/web/components/config/video-variant-form.tsx

232 lines
7.5 KiB
TypeScript
Raw Normal View History

// This content populates the video variant modal, which is spawned from the variants table.
2021-01-10 13:37:22 +03:00
import React from 'react';
import { Slider, Switch, Collapse } from 'antd';
import { FieldUpdaterFunc, VideoVariant, UpdateArgs } from '../../types/config-section';
import TextField from './form-textfield';
import { DEFAULT_VARIANT_STATE } from '../../utils/config-constants';
2021-01-10 13:37:22 +03:00
import InfoTip from '../info-tip';
2021-01-31 09:53:00 +03:00
import CPUUsageSelector from './cpu-usage';
2021-01-10 13:37:22 +03:00
const { Panel } = Collapse;
const VIDEO_VARIANT_DEFAULTS = {
framerate: {
min: 10,
max: 90,
2021-01-10 13:37:22 +03:00
defaultValue: 24,
unit: 'fps',
incrementBy: 1,
tip: 'You prob wont need to touch this unless youre a hardcore gamer and need all the bitties',
},
videoBitrate: {
min: 600,
max: 6000,
defaultValue: 1200,
2021-01-10 13:37:22 +03:00
unit: 'kbps',
incrementBy: 100,
tip: 'This is importatnt yo',
},
audioBitrate: {
min: 600,
max: 1200,
defaultValue: 800,
unit: 'kbps',
incrementBy: 100,
2021-01-31 12:38:20 +03:00
tip: 'nothing to see here',
2021-01-10 13:37:22 +03:00
},
videoPassthrough: {
2021-01-31 12:38:20 +03:00
tip: 'If No is selected, then you should set your desired Video Bitrate.',
2021-01-10 13:37:22 +03:00
},
audioPassthrough: {
2021-01-31 12:38:20 +03:00
tip: 'If No is selected, then you should set your desired Audio Bitrate.',
2021-01-10 13:37:22 +03:00
},
scaledWidth: {
fieldName: 'scaledWidth',
label: 'Resized Width',
maxLength: 4,
placeholder: '1080',
tip: "Optionally resize this content's width.",
},
scaledHeight: {
fieldName: 'scaledHeight',
label: 'Resized Height',
maxLength: 4,
placeholder: '720',
tip: "Optionally resize this content's height.",
},
2021-01-10 13:37:22 +03:00
};
interface VideoVariantFormProps {
dataState: VideoVariant;
onUpdateField: FieldUpdaterFunc;
2021-01-10 13:37:22 +03:00
}
2021-01-31 12:38:20 +03:00
export default function VideoVariantForm({
dataState = DEFAULT_VARIANT_STATE,
onUpdateField,
}: VideoVariantFormProps) {
2021-01-10 13:37:22 +03:00
const handleFramerateChange = (value: number) => {
onUpdateField({ fieldName: 'framerate', value });
2021-01-10 13:37:22 +03:00
};
const handleVideoBitrateChange = (value: number) => {
onUpdateField({ fieldName: 'videoBitrate', value });
2021-01-10 13:37:22 +03:00
};
const handleVideoPassChange = (value: boolean) => {
onUpdateField({ fieldName: 'videoPassthrough', value });
2021-01-10 13:37:22 +03:00
};
2021-01-31 09:53:00 +03:00
const handleVideoCpuUsageLevelChange = (value: number) => {
2021-01-31 12:38:20 +03:00
onUpdateField({ fieldName: 'cpuUsageLevel', value });
};
const handleScaledWidthChanged = (args: UpdateArgs) => {
const value = Number(args.value);
if (isNaN(value)) {
return;
}
onUpdateField({ fieldName: 'scaledWidth', value: value || '' });
};
const handleScaledHeightChanged = (args: UpdateArgs) => {
const value = Number(args.value);
if (isNaN(value)) {
return;
}
2021-01-10 13:37:22 +03:00
onUpdateField({ fieldName: 'scaledHeight', value: value || '' });
};
2021-01-10 13:37:22 +03:00
const framerateDefaults = VIDEO_VARIANT_DEFAULTS.framerate;
const framerateMin = framerateDefaults.min;
const framerateMax = framerateDefaults.max;
const framerateUnit = framerateDefaults.unit;
const videoBitrateDefaults = VIDEO_VARIANT_DEFAULTS.videoBitrate;
const videoBRMin = videoBitrateDefaults.min;
const videoBRMax = videoBitrateDefaults.max;
const videoBRUnit = videoBitrateDefaults.unit;
const selectedVideoBRnote = `Selected: ${dataState.videoBitrate}${videoBRUnit} - it sucks`;
const selectedFramerateNote = `Selected: ${dataState.framerate}${framerateUnit} - whoa there`;
const selectedPresetNote = '';
return (
<div className="config-variant-form">
2021-01-10 13:37:22 +03:00
<div className="section-intro">
2021-01-31 12:38:20 +03:00
Say a thing here about how this all works. Read more{' '}
<a href="https://owncast.online/docs/configuration/">here</a>.
<br />
<br />
2021-01-10 13:37:22 +03:00
</div>
{/* ENCODER PRESET FIELD */}
<div className="field">
<div className="form-component">
2021-01-31 12:38:20 +03:00
<CPUUsageSelector
defaultValue={dataState.cpuUsageLevel}
onChange={handleVideoCpuUsageLevelChange}
/>
{selectedPresetNote ? (
<span className="selected-value-note">{selectedPresetNote}</span>
) : null}
2021-01-10 13:37:22 +03:00
</div>
</div>
{/* VIDEO PASSTHROUGH FIELD */}
2021-01-31 12:38:20 +03:00
<div style={{ display: 'none' }}>
2021-01-10 13:37:22 +03:00
<div className="field">
<p className="label">
<InfoTip tip={VIDEO_VARIANT_DEFAULTS.videoPassthrough.tip} />
Use Video Passthrough?
</p>
<div className="form-component">
<Switch
defaultChecked={dataState.videoPassthrough}
checked={dataState.videoPassthrough}
2021-01-10 13:37:22 +03:00
onChange={handleVideoPassChange}
checkedChildren="Yes"
unCheckedChildren="No"
/>
</div>
</div>
</div>
2021-01-10 13:37:22 +03:00
{/* VIDEO BITRATE FIELD */}
<div className={`field ${dataState.videoPassthrough ? 'disabled' : ''}`}>
<p className="label">
<InfoTip tip={VIDEO_VARIANT_DEFAULTS.videoBitrate.tip} />
Video Bitrate:
</p>
<div className="form-component">
<Slider
tipFormatter={value => `${value} ${videoBRUnit}`}
disabled={dataState.videoPassthrough === true}
defaultValue={dataState.videoBitrate}
value={dataState.videoBitrate}
2021-01-10 13:37:22 +03:00
onChange={handleVideoBitrateChange}
step={videoBitrateDefaults.incrementBy}
min={videoBRMin}
max={videoBRMax}
marks={{
[videoBRMin]: `${videoBRMin} ${videoBRUnit}`,
[videoBRMax]: `${videoBRMax} ${videoBRUnit}`,
}}
/>
2021-01-31 12:38:20 +03:00
{selectedVideoBRnote ? (
<span className="selected-value-note">{selectedVideoBRnote}</span>
) : null}
2021-01-10 13:37:22 +03:00
</div>
</div>
<Collapse>
<Panel header="Advanced Settings" key="1">
<div className="section-intro">
Resizing your content will take additional resources on your server. If you wish to
optionally resize your output for this stream variant then you should either set the
width <strong>or</strong> the height to keep your aspect ratio.
</div>
<div className="field">
<TextField
type="number"
{...VIDEO_VARIANT_DEFAULTS.scaledWidth}
value={dataState.scaledWidth}
onChange={handleScaledWidthChanged}
/>
</div>
<div className="field">
<TextField
type="number"
{...VIDEO_VARIANT_DEFAULTS.scaledHeight}
value={dataState.scaledHeight}
onChange={handleScaledHeightChanged}
/>
</div>
2021-01-10 13:37:22 +03:00
{/* FRAME RATE FIELD */}
<div className="field">
<p className="label">
<InfoTip tip={VIDEO_VARIANT_DEFAULTS.framerate.tip} />
Frame rate:
</p>
<div className="form-component">
<Slider
// tooltipVisible
tipFormatter={value => `${value} ${framerateUnit}`}
defaultValue={dataState.framerate}
value={dataState.framerate}
2021-01-10 13:37:22 +03:00
onChange={handleFramerateChange}
step={framerateDefaults.incrementBy}
min={framerateMin}
max={framerateMax}
marks={{
[framerateMin]: `${framerateMin} ${framerateUnit}`,
[framerateMax]: `${framerateMax} ${framerateUnit}`,
}}
/>
2021-01-31 12:38:20 +03:00
{selectedFramerateNote ? (
<span className="selected-value-note">{selectedFramerateNote}</span>
) : null}
2021-01-10 13:37:22 +03:00
</div>
</div>
</Panel>
</Collapse>
</div>
);
2021-01-31 12:38:20 +03:00
}