Add librav1e AV1 encoder

This commit is contained in:
Ingo Oppermann 2024-03-27 21:01:20 +01:00
parent 44657181a0
commit 82bd4f2d76
No known key found for this signature in database
GPG Key ID: 2AB32426E9DD229E
6 changed files with 268 additions and 54 deletions

View File

@ -22,6 +22,7 @@ import * as VideoCopy from './video/Copy';
import * as VideoNone from './video/None'; import * as VideoNone from './video/None';
import * as VideoRaw from './video/Raw'; import * as VideoRaw from './video/Raw';
import * as VP9 from './video/VP9'; import * as VP9 from './video/VP9';
import * as AV1Rav1e from './video/AV1Rav1e';
class Registry { class Registry {
constructor(type) { constructor(type) {
@ -135,5 +136,6 @@ videoRegistry.Register(HEVCVideoToolbox);
videoRegistry.Register(VP9VAAPI); videoRegistry.Register(VP9VAAPI);
videoRegistry.Register(VP9); videoRegistry.Register(VP9);
videoRegistry.Register(VideoRaw); videoRegistry.Register(VideoRaw);
videoRegistry.Register(AV1Rav1e);
export { audioRegistry as Audio, videoRegistry as Video }; export { audioRegistry as Audio, videoRegistry as Video };

View File

@ -0,0 +1,255 @@
import React from 'react';
import Grid from '@mui/material/Grid';
import MenuItem from '@mui/material/MenuItem';
import TextField from '@mui/material/TextField';
import Typography from '@mui/material/Typography';
import { Trans } from '@lingui/macro';
import Select from '../../../Select';
import Video from '../../settings/Video';
import Helper from '../../helper';
function init(initialState) {
const state = {
bitrate: '4096',
fps: '25',
fps_mode: 'auto',
gop: '2',
qp: '-1',
speed: '-1',
tiles: '0',
tile_rows: '0',
tile_columns: '0',
params: '',
...initialState,
};
return state;
}
function createMapping(settings, stream, skills) {
stream = Helper.InitStream(stream);
skills = Helper.InitSkills(skills);
const local = [
'-codec:v',
'librav1e',
'-b:v',
`${settings.bitrate}k`,
'-maxrate:v',
`${settings.bitrate}k`,
'-bufsize:v',
`${settings.bitrate}k`,
'-r',
`${settings.fps}`,
'-pix_fmt',
'yuv420p',
'-qp',
`${settings.qp}`,
'-speed',
`${settings.speed}`,
'-tiles',
`${settings.tiles}`,
'-tile-rows',
`${settings.tile_rows}`,
'-tile-columns',
`${settings.tile_columns}`,
];
if (settings.params.length !== 0) {
local.push('-rav1e-params', `${settings.params}`);
}
if (settings.gop !== 'auto') {
local.push(
'-g',
`${Math.round(parseInt(settings.fps) * parseInt(settings.gop)).toFixed(0)}`,
'-keyint_min',
`${Math.round(parseInt(settings.fps) * parseInt(settings.gop)).toFixed(0)}`,
);
}
if (skills.ffmpeg.version_major >= 5) {
local.push('-fps_mode', `${settings.fps_mode}`);
}
const mapping = {
global: [],
local: local,
};
return mapping;
}
function Speed(props) {
return (
<React.Fragment>
<Select label={<Trans>Speed Preset</Trans>} value={props.value} onChange={props.onChange}>
<MenuItem value="-1">auto (-1)</MenuItem>
<MenuItem value="0">slowest (0)</MenuItem>
<MenuItem value="1">1</MenuItem>
<MenuItem value="2">2</MenuItem>
<MenuItem value="3">3</MenuItem>
<MenuItem value="4">4</MenuItem>
<MenuItem value="5">5</MenuItem>
<MenuItem value="6">6</MenuItem>
<MenuItem value="7">7</MenuItem>
<MenuItem value="8">8</MenuItem>
<MenuItem value="9">9</MenuItem>
<MenuItem value="10">fastest (10)</MenuItem>
</Select>
<Typography variant="caption">
<Trans>What speed preset to use.</Trans>
</Typography>
</React.Fragment>
);
}
Speed.defaultProps = {
value: '-1',
onChange: function (event) {},
};
function Coder(props) {
const settings = init(props.settings);
const stream = Helper.InitStream(props.stream);
const skills = Helper.InitSkills(props.skills);
const handleChange = (newSettings) => {
let automatic = false;
if (!newSettings) {
newSettings = settings;
automatic = true;
}
props.onChange(newSettings, createMapping(newSettings, stream, skills), 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} md={6}>
<Video.Framerate value={settings.fps} onChange={update('fps')} allowCustom />
</Grid>
<Grid item xs={12} md={6}>
<Video.GOP value={settings.gop} onChange={update('gop')} allowAuto allowCustom />
</Grid>
{skills.ffmpeg.version_major >= 5 && (
<Grid item xs={12}>
<Video.FpsMode value={settings.fps_mode} onChange={update('fps_mode')} />
</Grid>
)}
<Grid item xs={6}>
<Speed value={settings.speed} onChange={update('speed')} />
</Grid>
<Grid item xs={6}>
<TextField
variant="outlined"
fullWidth
type="number"
inputProps={{ min: -1, max: 255 }}
label={<Trans>QP</Trans>}
value={settings.qp}
onChange={update('qp')}
/>
<Typography variant="caption">
<Trans>Constant Quantizer Mode (-1 to 255).</Trans>
</Typography>
</Grid>
<Grid item xs={4}>
<TextField
variant="outlined"
fullWidth
type="number"
inputProps={{ min: -1 }}
label={<Trans>Tiles</Trans>}
value={settings.tiles}
onChange={update('tiles')}
/>
<Typography variant="caption">
<Trans>Number of tiles encode with.</Trans>
</Typography>
</Grid>
<Grid item xs={4}>
<TextField
variant="outlined"
fullWidth
type="number"
inputProps={{ min: -1 }}
label={<Trans>Tile Rows</Trans>}
value={settings.tile_rows}
onChange={update('tile_rows')}
/>
<Typography variant="caption">
<Trans>Number of tiles rows to encode with.</Trans>
</Typography>
</Grid>
<Grid item xs={4}>
<TextField
variant="outlined"
fullWidth
type="number"
inputProps={{ min: -1 }}
label={<Trans>Tile Columns</Trans>}
value={settings.tile_columns}
onChange={update('tile_columns')}
/>
<Typography variant="caption">
<Trans>Number of tiles columns to encode with.</Trans>
</Typography>
</Grid>
<Grid item xs={12}>
<TextField variant="outlined" fullWidth label={<Trans>rav1e Parameters</Trans>} value={settings.params} onChange={update('params')} />
<Typography variant="caption">
<Trans>Set the rav1e configuration using a :-separated list of key=value parameters.</Trans>
</Typography>
</Grid>
</Grid>
);
}
Coder.defaultProps = {
stream: {},
settings: {},
skills: {},
onChange: function (settings, mapping) {},
};
const coder = 'librav1e';
const name = 'AV1 (librav1e)';
const codec = 'av1';
const type = 'video';
const hwaccel = false;
function summarize(settings) {
return `${name}, ${settings.bitrate} kbit/s, ${settings.fps} FPS, Speed: ${settings.speed}, QP: ${settings.qp}`;
}
function defaults(stream, skills) {
const settings = init({});
return {
settings: settings,
mapping: createMapping(settings, stream, skills),
};
}
export { coder, name, codec, type, hwaccel, summarize, defaults, Coder as component };

View File

@ -1,5 +1,4 @@
import React from 'react'; import React from 'react';
import SemverSatisfies from 'semver/functions/satisfies';
import Grid from '@mui/material/Grid'; import Grid from '@mui/material/Grid';
import Typography from '@mui/material/Typography'; import Typography from '@mui/material/Typography';
@ -80,10 +79,6 @@ function createMapping(settings, stream, skills) {
stream = Helper.InitStream(stream); stream = Helper.InitStream(stream);
skills = Helper.InitSkills(skills); skills = Helper.InitSkills(skills);
let ffversion = 4;
if (SemverSatisfies(skills.ffmpeg.version, '^5.0.0')) {
ffversion = 5;
}
const local = [ const local = [
'-codec:v', '-codec:v',
'h264_v4l2m2m', 'h264_v4l2m2m',
@ -119,7 +114,7 @@ function createMapping(settings, stream, skills) {
local.push('-keyint_min', `${parseInt(settings.fps)}`); local.push('-keyint_min', `${parseInt(settings.fps)}`);
} }
if (ffversion === 5) { if (skills.ffmpeg.version_major >= 5) {
local.push('-fps_mode', `${settings.fps_mode}`); local.push('-fps_mode', `${settings.fps_mode}`);
} }
@ -140,11 +135,6 @@ function Coder(props) {
const stream = Helper.InitStream(props.stream); const stream = Helper.InitStream(props.stream);
const skills = Helper.InitSkills(props.skills); const skills = Helper.InitSkills(props.skills);
let ffversion = 4;
if (SemverSatisfies(skills.ffmpeg.version, '^5.0.0')) {
ffversion = 5;
}
const handleChange = (newSettings) => { const handleChange = (newSettings) => {
let automatic = false; let automatic = false;
if (!newSettings) { if (!newSettings) {
@ -190,7 +180,7 @@ function Coder(props) {
<Trans>To stabilize the system, increase the HLS segment length for the keyframe interval by 2-3 * (Processing and Control).</Trans> <Trans>To stabilize the system, increase the HLS segment length for the keyframe interval by 2-3 * (Processing and Control).</Trans>
</Typography> </Typography>
</Grid> </Grid>
{ffversion === 5 && ( {skills.ffmpeg.version_major >= 5 && (
<Grid item xs={12}> <Grid item xs={12}>
<Video.FpsMode value={settings.fps_mode} onChange={update('fps_mode')} /> <Video.FpsMode value={settings.fps_mode} onChange={update('fps_mode')} />
</Grid> </Grid>

View File

@ -1,5 +1,4 @@
import React from 'react'; import React from 'react';
import SemverSatisfies from 'semver/functions/satisfies';
import Grid from '@mui/material/Grid'; import Grid from '@mui/material/Grid';
@ -22,11 +21,6 @@ function createMapping(settings, stream, skills) {
stream = Helper.InitStream(stream); stream = Helper.InitStream(stream);
skills = Helper.InitSkills(skills); skills = Helper.InitSkills(skills);
let ffversion = 4;
if (SemverSatisfies(skills.ffmpeg.version, '^5.0.0')) {
ffversion = 5;
}
const local = [ const local = [
'-codec:v', '-codec:v',
'libvpx-vp9', 'libvpx-vp9',
@ -49,11 +43,11 @@ function createMapping(settings, stream, skills) {
'-g', '-g',
`${Math.round(parseInt(settings.fps) * parseInt(settings.gop)).toFixed(0)}`, `${Math.round(parseInt(settings.fps) * parseInt(settings.gop)).toFixed(0)}`,
'-keyint_min', '-keyint_min',
`${Math.round(parseInt(settings.fps) * parseInt(settings.gop)).toFixed(0)}` `${Math.round(parseInt(settings.fps) * parseInt(settings.gop)).toFixed(0)}`,
); );
} }
if (ffversion === 5) { if (skills.ffmpeg.version_major >= 5) {
local.push('-fps_mode', `${settings.fps_mode}`); local.push('-fps_mode', `${settings.fps_mode}`);
} }
@ -70,11 +64,6 @@ function Coder(props) {
const stream = Helper.InitStream(props.stream); const stream = Helper.InitStream(props.stream);
const skills = Helper.InitSkills(props.skills); const skills = Helper.InitSkills(props.skills);
let ffversion = 4;
if (SemverSatisfies(skills.ffmpeg.version, '^5.0.0')) {
ffversion = 5;
}
const handleChange = (newSettings) => { const handleChange = (newSettings) => {
let automatic = false; let automatic = false;
if (!newSettings) { if (!newSettings) {
@ -110,7 +99,7 @@ function Coder(props) {
<Grid item xs={12} md={6}> <Grid item xs={12} md={6}>
<Video.GOP value={settings.gop} onChange={update('gop')} allowAuto allowCustom /> <Video.GOP value={settings.gop} onChange={update('gop')} allowAuto allowCustom />
</Grid> </Grid>
{ffversion === 5 && ( {skills.ffmpeg.version_major >= 5 && (
<Grid item xs={12}> <Grid item xs={12}>
<Video.FpsMode value={settings.fps_mode} onChange={update('fps_mode')} /> <Video.FpsMode value={settings.fps_mode} onChange={update('fps_mode')} />
</Grid> </Grid>

View File

@ -1,5 +1,4 @@
import React from 'react'; import React from 'react';
import SemverSatisfies from 'semver/functions/satisfies';
import Grid from '@mui/material/Grid'; import Grid from '@mui/material/Grid';
import MenuItem from '@mui/material/MenuItem'; import MenuItem from '@mui/material/MenuItem';
@ -29,11 +28,6 @@ function createMapping(settings, stream, skills) {
stream = Helper.InitStream(stream); stream = Helper.InitStream(stream);
skills = Helper.InitSkills(skills); skills = Helper.InitSkills(skills);
let ffversion = 4;
if (SemverSatisfies(skills.ffmpeg.version, '^5.0.0')) {
ffversion = 5;
}
const local = [ const local = [
'-codec:v', '-codec:v',
'libx264', 'libx264',
@ -58,11 +52,11 @@ function createMapping(settings, stream, skills) {
'-g', '-g',
`${Math.round(parseInt(settings.fps) * parseInt(settings.gop)).toFixed(0)}`, `${Math.round(parseInt(settings.fps) * parseInt(settings.gop)).toFixed(0)}`,
'-keyint_min', '-keyint_min',
`${Math.round(parseInt(settings.fps) * parseInt(settings.gop)).toFixed(0)}` `${Math.round(parseInt(settings.fps) * parseInt(settings.gop)).toFixed(0)}`,
); );
} }
if (ffversion === 5) { if (skills.ffmpeg.version_major >= 5) {
local.push('-fps_mode', `${settings.fps_mode}`); local.push('-fps_mode', `${settings.fps_mode}`);
} }
@ -127,11 +121,6 @@ function Coder(props) {
const stream = Helper.InitStream(props.stream); const stream = Helper.InitStream(props.stream);
const skills = Helper.InitSkills(props.skills); const skills = Helper.InitSkills(props.skills);
let ffversion = 4;
if (SemverSatisfies(skills.ffmpeg.version, '^5.0.0')) {
ffversion = 5;
}
const handleChange = (newSettings) => { const handleChange = (newSettings) => {
let automatic = false; let automatic = false;
if (!newSettings) { if (!newSettings) {
@ -167,7 +156,7 @@ function Coder(props) {
<Grid item xs={12} md={6}> <Grid item xs={12} md={6}>
<Video.GOP value={settings.gop} onChange={update('gop')} allowAuto allowCustom /> <Video.GOP value={settings.gop} onChange={update('gop')} allowAuto allowCustom />
</Grid> </Grid>
{ffversion === 5 && ( {skills.ffmpeg.version_major >= 5 && (
<Grid item xs={12}> <Grid item xs={12}>
<Video.FpsMode value={settings.fps_mode} onChange={update('fps_mode')} /> <Video.FpsMode value={settings.fps_mode} onChange={update('fps_mode')} />
</Grid> </Grid>

View File

@ -1,5 +1,4 @@
import React from 'react'; import React from 'react';
import SemverSatisfies from 'semver/functions/satisfies';
import Grid from '@mui/material/Grid'; import Grid from '@mui/material/Grid';
import MenuItem from '@mui/material/MenuItem'; import MenuItem from '@mui/material/MenuItem';
@ -29,11 +28,6 @@ function createMapping(settings, stream, skills) {
stream = Helper.InitStream(stream); stream = Helper.InitStream(stream);
skills = Helper.InitSkills(skills); skills = Helper.InitSkills(skills);
let ffversion = 4;
if (SemverSatisfies(skills.ffmpeg.version, '^5.0.0')) {
ffversion = 5;
}
const local = [ const local = [
'-codec:v', '-codec:v',
'libx265', 'libx265',
@ -62,7 +56,7 @@ function createMapping(settings, stream, skills) {
); );
} }
if (ffversion === 5) { if (skills.ffmpeg.version_major >= 5) {
local.push('-fps_mode', `${settings.fps_mode}`); local.push('-fps_mode', `${settings.fps_mode}`);
} }
@ -127,11 +121,6 @@ function Coder(props) {
const stream = Helper.InitStream(props.stream); const stream = Helper.InitStream(props.stream);
const skills = Helper.InitSkills(props.skills); const skills = Helper.InitSkills(props.skills);
let ffversion = 4;
if (SemverSatisfies(skills.ffmpeg.version, '^5.0.0')) {
ffversion = 5;
}
const handleChange = (newSettings) => { const handleChange = (newSettings) => {
let automatic = false; let automatic = false;
if (!newSettings) { if (!newSettings) {
@ -167,7 +156,7 @@ function Coder(props) {
<Grid item xs={12} md={6}> <Grid item xs={12} md={6}>
<Video.GOP value={settings.gop} onChange={update('gop')} allowAuto allowCustom /> <Video.GOP value={settings.gop} onChange={update('gop')} allowAuto allowCustom />
</Grid> </Grid>
{ffversion === 5 && ( {skills.ffmpeg.version_major >= 5 && (
<Grid item xs={12}> <Grid item xs={12}>
<Video.FpsMode value={settings.fps_mode} onChange={update('fps_mode')} /> <Video.FpsMode value={settings.fps_mode} onChange={update('fps_mode')} />
</Grid> </Grid>
@ -193,7 +182,7 @@ Coder.defaultProps = {
}; };
const coder = 'libx265'; const coder = 'libx265';
const name = 'H.265 (libx265)'; const name = 'HEVC (libx265)';
const codec = 'hevc'; const codec = 'hevc';
const type = 'video'; const type = 'video';
const hwaccel = false; const hwaccel = false;