2021-02-27 10:44:13 +03:00
|
|
|
// This content populates the video variant modal, which is spawned from the variants table. This relies on the `dataState` prop fed in by the table.
|
2022-09-07 10:00:28 +03:00
|
|
|
import React, { FC } from 'react';
|
2021-02-21 02:14:50 +03:00
|
|
|
import { Popconfirm, Row, Col, Slider, Collapse, Typography } from 'antd';
|
|
|
|
import { ExclamationCircleFilled } from '@ant-design/icons';
|
2021-02-27 10:44:13 +03:00
|
|
|
import classNames from 'classnames';
|
2021-02-08 04:03:02 +03:00
|
|
|
import { FieldUpdaterFunc, VideoVariant, UpdateArgs } from '../../types/config-section';
|
2022-09-07 10:00:28 +03:00
|
|
|
import { TextField } from './TextField';
|
2021-02-27 10:44:13 +03:00
|
|
|
import {
|
|
|
|
DEFAULT_VARIANT_STATE,
|
|
|
|
VIDEO_VARIANT_SETTING_DEFAULTS,
|
2021-03-12 00:39:36 +03:00
|
|
|
VIDEO_NAME_DEFAULTS,
|
2021-02-27 10:44:13 +03:00
|
|
|
ENCODER_PRESET_SLIDER_MARKS,
|
|
|
|
ENCODER_PRESET_TOOLTIPS,
|
|
|
|
VIDEO_BITRATE_DEFAULTS,
|
|
|
|
VIDEO_BITRATE_SLIDER_MARKS,
|
|
|
|
FRAMERATE_SLIDER_MARKS,
|
|
|
|
FRAMERATE_DEFAULTS,
|
|
|
|
FRAMERATE_TOOLTIPS,
|
|
|
|
} from '../../utils/config-constants';
|
2022-09-07 10:00:28 +03:00
|
|
|
import { ToggleSwitch } from './ToggleSwitch';
|
2021-01-10 13:37:22 +03:00
|
|
|
|
|
|
|
const { Panel } = Collapse;
|
|
|
|
|
2022-09-07 10:00:28 +03:00
|
|
|
export type VideoVariantFormProps = {
|
2021-01-10 13:37:22 +03:00
|
|
|
dataState: VideoVariant;
|
2021-01-17 06:46:19 +03:00
|
|
|
onUpdateField: FieldUpdaterFunc;
|
2022-09-07 10:00:28 +03:00
|
|
|
};
|
2021-01-10 13:37:22 +03:00
|
|
|
|
2022-09-07 10:00:28 +03:00
|
|
|
export const VideoVariantForm: FC<VideoVariantFormProps> = ({
|
2021-01-31 12:38:20 +03:00
|
|
|
dataState = DEFAULT_VARIANT_STATE,
|
|
|
|
onUpdateField,
|
2022-09-07 10:00:28 +03:00
|
|
|
}) => {
|
2021-02-27 10:44:13 +03:00
|
|
|
const videoPassthroughEnabled = dataState.videoPassthrough;
|
|
|
|
|
2021-01-10 13:37:22 +03:00
|
|
|
const handleFramerateChange = (value: number) => {
|
2021-01-17 06:46:19 +03:00
|
|
|
onUpdateField({ fieldName: 'framerate', value });
|
2021-01-10 13:37:22 +03:00
|
|
|
};
|
|
|
|
const handleVideoBitrateChange = (value: number) => {
|
2021-01-17 06:46:19 +03:00
|
|
|
onUpdateField({ fieldName: 'videoBitrate', 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 });
|
|
|
|
};
|
2021-02-08 04:03:02 +03:00
|
|
|
const handleScaledWidthChanged = (args: UpdateArgs) => {
|
|
|
|
const value = Number(args.value);
|
2021-02-13 10:55:59 +03:00
|
|
|
// eslint-disable-next-line no-restricted-globals
|
2021-02-08 06:41:52 +03:00
|
|
|
if (isNaN(value)) {
|
2021-02-08 04:03:02 +03:00
|
|
|
return;
|
|
|
|
}
|
2021-03-03 06:10:23 +03:00
|
|
|
onUpdateField({ fieldName: 'scaledWidth', value: value || 0 });
|
2021-02-08 04:03:02 +03:00
|
|
|
};
|
|
|
|
const handleScaledHeightChanged = (args: UpdateArgs) => {
|
|
|
|
const value = Number(args.value);
|
2021-02-13 10:55:59 +03:00
|
|
|
// eslint-disable-next-line no-restricted-globals
|
2021-02-08 06:41:52 +03:00
|
|
|
if (isNaN(value)) {
|
2021-02-08 04:03:02 +03:00
|
|
|
return;
|
|
|
|
}
|
2021-03-03 06:10:23 +03:00
|
|
|
onUpdateField({ fieldName: 'scaledHeight', value: value || 0 });
|
2021-02-08 04:03:02 +03:00
|
|
|
};
|
2021-02-21 02:14:50 +03:00
|
|
|
|
|
|
|
// Video passthrough handling
|
|
|
|
const handleVideoPassConfirm = () => {
|
|
|
|
onUpdateField({ fieldName: 'videoPassthrough', value: true });
|
|
|
|
};
|
|
|
|
// If passthrough is currently on, set it back to false on toggle.
|
|
|
|
// Else let the Popconfirm turn it on.
|
|
|
|
const handleVideoPassthroughToggle = (value: boolean) => {
|
2021-02-27 10:44:13 +03:00
|
|
|
if (videoPassthroughEnabled) {
|
2021-02-21 02:14:50 +03:00
|
|
|
onUpdateField({ fieldName: 'videoPassthrough', value });
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2021-03-12 00:39:36 +03:00
|
|
|
const handleNameChanged = (args: UpdateArgs) => {
|
|
|
|
onUpdateField({ fieldName: 'name', value: args.value });
|
|
|
|
};
|
|
|
|
|
2021-02-27 10:44:13 +03:00
|
|
|
// Slider notes
|
2021-02-14 03:44:16 +03:00
|
|
|
const selectedVideoBRnote = () => {
|
2021-02-27 10:44:13 +03:00
|
|
|
if (videoPassthroughEnabled) {
|
2021-02-21 03:08:59 +03:00
|
|
|
return 'Bitrate selection is disabled when Video Passthrough is enabled.';
|
|
|
|
}
|
2021-02-27 10:44:13 +03:00
|
|
|
let note = `${dataState.videoBitrate}${VIDEO_BITRATE_DEFAULTS.unit}`;
|
2021-02-16 01:08:47 +03:00
|
|
|
if (dataState.videoBitrate < 2000) {
|
2021-02-14 03:44:16 +03:00
|
|
|
note = `${note} - Good for low bandwidth environments.`;
|
2021-02-16 01:08:47 +03:00
|
|
|
} else if (dataState.videoBitrate < 3500) {
|
2021-02-14 03:44:16 +03:00
|
|
|
note = `${note} - Good for most bandwidth environments.`;
|
|
|
|
} else {
|
|
|
|
note = `${note} - Good for high bandwidth environments.`;
|
|
|
|
}
|
|
|
|
return note;
|
|
|
|
};
|
|
|
|
const selectedFramerateNote = () => {
|
2021-02-27 10:44:13 +03:00
|
|
|
if (videoPassthroughEnabled) {
|
2021-02-21 03:08:59 +03:00
|
|
|
return 'Framerate selection is disabled when Video Passthrough is enabled.';
|
|
|
|
}
|
2021-02-27 10:44:13 +03:00
|
|
|
return FRAMERATE_TOOLTIPS[dataState.framerate] || '';
|
|
|
|
};
|
|
|
|
const cpuUsageNote = () => {
|
|
|
|
if (videoPassthroughEnabled) {
|
|
|
|
return 'CPU usage selection is disabled when Video Passthrough is enabled.';
|
2021-02-14 03:44:16 +03:00
|
|
|
}
|
2021-02-27 10:44:13 +03:00
|
|
|
return ENCODER_PRESET_TOOLTIPS[dataState.cpuUsageLevel] || '';
|
2021-02-14 03:44:16 +03:00
|
|
|
};
|
2021-01-10 13:37:22 +03:00
|
|
|
|
2021-02-27 10:44:13 +03:00
|
|
|
const classes = classNames({
|
|
|
|
'config-variant-form': true,
|
|
|
|
'video-passthrough-enabled': videoPassthroughEnabled,
|
|
|
|
});
|
2021-01-10 13:37:22 +03:00
|
|
|
return (
|
2021-02-27 10:44:13 +03:00
|
|
|
<div className={classes}>
|
2021-02-13 10:55:59 +03:00
|
|
|
<p className="description">
|
2021-03-04 11:54:26 +03:00
|
|
|
<a
|
|
|
|
href="https://owncast.online/docs/video?source=admin"
|
|
|
|
target="_blank"
|
|
|
|
rel="noopener noreferrer"
|
|
|
|
>
|
2021-02-26 23:38:55 +03:00
|
|
|
Learn more
|
|
|
|
</a>{' '}
|
|
|
|
about how each of these settings can impact the performance of your server.
|
2021-02-13 10:55:59 +03:00
|
|
|
</p>
|
2021-01-10 13:37:22 +03:00
|
|
|
|
2021-02-27 10:44:13 +03:00
|
|
|
{videoPassthroughEnabled && (
|
|
|
|
<p className="passthrough-warning">
|
|
|
|
NOTE: Video Passthrough for this output stream variant is <em>enabled</em>, disabling the
|
|
|
|
below video encoding settings.
|
|
|
|
</p>
|
|
|
|
)}
|
|
|
|
|
2021-02-15 05:46:34 +03:00
|
|
|
<Row gutter={16}>
|
2021-03-12 00:39:36 +03:00
|
|
|
<TextField
|
|
|
|
maxLength="10"
|
|
|
|
{...VIDEO_NAME_DEFAULTS}
|
|
|
|
value={dataState.name}
|
|
|
|
onChange={handleNameChanged}
|
|
|
|
/>
|
2021-02-15 09:20:25 +03:00
|
|
|
<Col sm={24} md={12}>
|
2021-02-13 10:55:59 +03:00
|
|
|
<div className="form-module cpu-usage-container">
|
2021-04-02 08:00:31 +03:00
|
|
|
<Typography.Title level={3}>CPU or GPU Utilization</Typography.Title>
|
2021-02-27 10:44:13 +03:00
|
|
|
<p className="description">
|
|
|
|
Reduce to improve server performance, or increase it to improve video quality.
|
|
|
|
</p>
|
|
|
|
<div className="segment-slider-container">
|
|
|
|
<Slider
|
|
|
|
tipFormatter={value => ENCODER_PRESET_TOOLTIPS[value]}
|
|
|
|
onChange={handleVideoCpuUsageLevelChange}
|
|
|
|
min={1}
|
|
|
|
max={Object.keys(ENCODER_PRESET_SLIDER_MARKS).length}
|
|
|
|
marks={ENCODER_PRESET_SLIDER_MARKS}
|
|
|
|
defaultValue={dataState.cpuUsageLevel}
|
|
|
|
value={dataState.cpuUsageLevel}
|
|
|
|
disabled={dataState.videoPassthrough}
|
|
|
|
/>
|
|
|
|
<p className="selected-value-note">{cpuUsageNote()}</p>
|
|
|
|
</div>
|
2021-02-16 01:09:34 +03:00
|
|
|
<p className="read-more-subtext">
|
2021-05-23 09:27:51 +03:00
|
|
|
This could mean GPU or CPU usage depending on your server environment.{' '}
|
2021-02-26 23:38:55 +03:00
|
|
|
<a
|
2021-03-26 09:05:13 +03:00
|
|
|
href="https://owncast.online/docs/video/?source=admin#cpu-usage"
|
2021-02-26 23:38:55 +03:00
|
|
|
target="_blank"
|
|
|
|
rel="noopener noreferrer"
|
|
|
|
>
|
2021-04-02 08:00:31 +03:00
|
|
|
Read more about hardware performance.
|
2021-02-26 23:38:55 +03:00
|
|
|
</a>
|
2021-02-16 01:09:34 +03:00
|
|
|
</p>
|
2021-01-10 13:37:22 +03:00
|
|
|
</div>
|
2021-02-15 05:46:34 +03:00
|
|
|
</Col>
|
2021-02-13 10:55:59 +03:00
|
|
|
|
2021-02-15 09:20:25 +03:00
|
|
|
<Col sm={24} md={12}>
|
2021-02-13 10:55:59 +03:00
|
|
|
{/* VIDEO BITRATE FIELD */}
|
2021-02-15 05:46:34 +03:00
|
|
|
<div
|
2021-02-16 01:09:34 +03:00
|
|
|
className={`form-module bitrate-container ${
|
|
|
|
dataState.videoPassthrough ? 'disabled' : ''
|
|
|
|
}`}
|
2021-02-15 05:46:34 +03:00
|
|
|
>
|
|
|
|
<Typography.Title level={3}>Video Bitrate</Typography.Title>
|
2021-02-27 10:44:13 +03:00
|
|
|
<p className="description">{VIDEO_BITRATE_DEFAULTS.tip}</p>
|
2021-02-13 10:55:59 +03:00
|
|
|
<div className="segment-slider-container">
|
2021-01-10 13:37:22 +03:00
|
|
|
<Slider
|
2021-02-27 10:44:13 +03:00
|
|
|
tipFormatter={value => `${value} ${VIDEO_BITRATE_DEFAULTS.unit}`}
|
2021-02-21 03:08:59 +03:00
|
|
|
disabled={dataState.videoPassthrough}
|
2021-02-13 10:55:59 +03:00
|
|
|
defaultValue={dataState.videoBitrate}
|
|
|
|
value={dataState.videoBitrate}
|
|
|
|
onChange={handleVideoBitrateChange}
|
2021-02-27 10:44:13 +03:00
|
|
|
step={VIDEO_BITRATE_DEFAULTS.incrementBy}
|
|
|
|
min={VIDEO_BITRATE_DEFAULTS.min}
|
|
|
|
max={VIDEO_BITRATE_DEFAULTS.max}
|
|
|
|
marks={VIDEO_BITRATE_SLIDER_MARKS}
|
2021-01-10 13:37:22 +03:00
|
|
|
/>
|
2021-02-15 05:46:34 +03:00
|
|
|
<p className="selected-value-note">{selectedVideoBRnote()}</p>
|
2021-01-10 13:37:22 +03:00
|
|
|
</div>
|
2021-02-16 01:09:34 +03:00
|
|
|
<p className="read-more-subtext">
|
2021-02-26 23:38:55 +03:00
|
|
|
<a
|
2021-03-26 09:05:13 +03:00
|
|
|
href="https://owncast.online/docs/video/?source=admin"
|
2021-02-26 23:38:55 +03:00
|
|
|
target="_blank"
|
|
|
|
rel="noopener noreferrer"
|
|
|
|
>
|
|
|
|
Read more about bitrates.
|
|
|
|
</a>
|
2021-02-16 01:09:34 +03:00
|
|
|
</p>
|
2021-01-10 13:37:22 +03:00
|
|
|
</div>
|
2021-02-15 05:46:34 +03:00
|
|
|
</Col>
|
|
|
|
</Row>
|
|
|
|
<Collapse className="advanced-settings">
|
|
|
|
<Panel header="Advanced Settings" key="1">
|
2021-02-21 02:14:50 +03:00
|
|
|
<Row gutter={16}>
|
|
|
|
<Col sm={24} md={12}>
|
|
|
|
<div className="form-module resolution-module">
|
|
|
|
<Typography.Title level={3}>Resolution</Typography.Title>
|
|
|
|
<p className="description">
|
2021-02-21 03:09:40 +03:00
|
|
|
Resizing your content will take additional resources on your server. If you wish
|
|
|
|
to optionally resize your content for this stream output then you should either
|
|
|
|
set the width <strong>or</strong> the height to keep your aspect ratio.{' '}
|
2021-02-26 23:38:55 +03:00
|
|
|
<a
|
2021-03-26 09:05:13 +03:00
|
|
|
href="https://owncast.online/docs/video/?source=admin"
|
2021-02-26 23:38:55 +03:00
|
|
|
target="_blank"
|
|
|
|
rel="noopener noreferrer"
|
|
|
|
>
|
2021-02-21 03:09:40 +03:00
|
|
|
Read more about resolutions.
|
|
|
|
</a>
|
2021-02-21 02:14:50 +03:00
|
|
|
</p>
|
|
|
|
<br />
|
|
|
|
<TextField
|
|
|
|
type="number"
|
2021-02-27 10:44:13 +03:00
|
|
|
{...VIDEO_VARIANT_SETTING_DEFAULTS.scaledWidth}
|
2021-02-21 02:14:50 +03:00
|
|
|
value={dataState.scaledWidth}
|
|
|
|
onChange={handleScaledWidthChanged}
|
2021-02-21 03:08:59 +03:00
|
|
|
disabled={dataState.videoPassthrough}
|
2021-02-21 02:14:50 +03:00
|
|
|
/>
|
|
|
|
<TextField
|
|
|
|
type="number"
|
2021-02-27 10:44:13 +03:00
|
|
|
{...VIDEO_VARIANT_SETTING_DEFAULTS.scaledHeight}
|
2021-02-21 02:14:50 +03:00
|
|
|
value={dataState.scaledHeight}
|
|
|
|
onChange={handleScaledHeightChanged}
|
2021-02-21 03:08:59 +03:00
|
|
|
disabled={dataState.videoPassthrough}
|
2021-02-21 02:14:50 +03:00
|
|
|
/>
|
|
|
|
</div>
|
|
|
|
</Col>
|
|
|
|
<Col sm={24} md={12}>
|
|
|
|
{/* VIDEO PASSTHROUGH FIELD */}
|
2021-02-27 10:44:13 +03:00
|
|
|
<div className="form-module video-passthrough-module">
|
2021-02-21 02:14:50 +03:00
|
|
|
<Typography.Title level={3}>Video Passthrough</Typography.Title>
|
2021-03-03 09:39:27 +03:00
|
|
|
<div className="description">
|
2021-02-21 03:09:40 +03:00
|
|
|
<p>
|
|
|
|
Enabling video passthrough may allow for less hardware utilization, but may also
|
|
|
|
make your stream <strong>unplayable</strong>.
|
|
|
|
</p>
|
|
|
|
<p>
|
|
|
|
All other settings for this stream output will be disabled if passthrough is
|
|
|
|
used.
|
|
|
|
</p>
|
|
|
|
<p>
|
2021-02-26 23:38:55 +03:00
|
|
|
<a
|
2021-03-26 09:05:13 +03:00
|
|
|
href="https://owncast.online/docs/video/?source=admin#video-passthrough"
|
2021-02-26 23:38:55 +03:00
|
|
|
target="_blank"
|
|
|
|
rel="noopener noreferrer"
|
|
|
|
>
|
2021-02-21 03:09:40 +03:00
|
|
|
Read the documentation before enabling, as it impacts your stream.
|
|
|
|
</a>
|
|
|
|
</p>
|
2021-03-03 09:39:27 +03:00
|
|
|
</div>
|
2021-02-21 02:14:50 +03:00
|
|
|
<Popconfirm
|
|
|
|
disabled={dataState.videoPassthrough === true}
|
2021-02-21 03:08:59 +03:00
|
|
|
title="Did you read the documentation about video passthrough and understand the risks involved with enabling it?"
|
2021-02-21 02:14:50 +03:00
|
|
|
icon={<ExclamationCircleFilled />}
|
|
|
|
onConfirm={handleVideoPassConfirm}
|
|
|
|
okText="Yes"
|
|
|
|
cancelText="No"
|
|
|
|
>
|
|
|
|
{/* adding an <a> tag to force Popcofirm to register click on toggle */}
|
|
|
|
{/* eslint-disable-next-line jsx-a11y/anchor-is-valid */}
|
|
|
|
<a href="#">
|
|
|
|
<ToggleSwitch
|
|
|
|
label="Use Video Passthrough?"
|
|
|
|
fieldName="video-passthrough"
|
2021-02-27 10:44:13 +03:00
|
|
|
tip={VIDEO_VARIANT_SETTING_DEFAULTS.videoPassthrough.tip}
|
2021-02-21 02:14:50 +03:00
|
|
|
checked={dataState.videoPassthrough}
|
|
|
|
onChange={handleVideoPassthroughToggle}
|
|
|
|
/>
|
|
|
|
</a>
|
|
|
|
</Popconfirm>
|
|
|
|
</div>
|
|
|
|
</Col>
|
|
|
|
</Row>
|
2021-02-13 10:55:59 +03:00
|
|
|
|
2021-02-15 05:46:34 +03:00
|
|
|
{/* FRAME RATE FIELD */}
|
2021-02-21 02:14:50 +03:00
|
|
|
<div className="form-module frame-rate-module">
|
2021-02-15 05:46:34 +03:00
|
|
|
<Typography.Title level={3}>Frame rate</Typography.Title>
|
2021-02-27 10:44:13 +03:00
|
|
|
<p className="description">{FRAMERATE_DEFAULTS.tip}</p>
|
2021-02-15 05:46:34 +03:00
|
|
|
<div className="segment-slider-container">
|
|
|
|
<Slider
|
2021-02-27 10:44:13 +03:00
|
|
|
tipFormatter={value => `${value} ${FRAMERATE_DEFAULTS.unit}`}
|
2021-02-15 05:46:34 +03:00
|
|
|
defaultValue={dataState.framerate}
|
|
|
|
value={dataState.framerate}
|
|
|
|
onChange={handleFramerateChange}
|
2021-02-27 10:44:13 +03:00
|
|
|
step={FRAMERATE_DEFAULTS.incrementBy}
|
|
|
|
min={FRAMERATE_DEFAULTS.min}
|
|
|
|
max={FRAMERATE_DEFAULTS.max}
|
|
|
|
marks={FRAMERATE_SLIDER_MARKS}
|
2021-02-21 03:08:59 +03:00
|
|
|
disabled={dataState.videoPassthrough}
|
2021-02-15 05:46:34 +03:00
|
|
|
/>
|
|
|
|
<p className="selected-value-note">{selectedFramerateNote()}</p>
|
2021-02-13 10:55:59 +03:00
|
|
|
</div>
|
2021-02-16 01:09:34 +03:00
|
|
|
<p className="read-more-subtext">
|
2021-02-26 23:38:55 +03:00
|
|
|
<a
|
2021-03-26 09:05:13 +03:00
|
|
|
href="https://owncast.online/docs/video/?source=admin#framerate"
|
2021-02-26 23:38:55 +03:00
|
|
|
target="_blank"
|
|
|
|
rel="noopener noreferrer"
|
|
|
|
>
|
|
|
|
Read more about framerates.
|
|
|
|
</a>
|
2021-02-16 01:09:34 +03:00
|
|
|
</p>
|
2021-02-15 05:46:34 +03:00
|
|
|
</div>
|
|
|
|
</Panel>
|
|
|
|
</Collapse>
|
2021-01-10 13:37:22 +03:00
|
|
|
</div>
|
|
|
|
);
|
2022-09-07 10:00:28 +03:00
|
|
|
};
|