Skip to content

Commit

Permalink
Add toggles for preset and quality
Browse files Browse the repository at this point in the history
  • Loading branch information
HaveAGitGat committed Jun 21, 2024
1 parent 27f0f31 commit 9ce8ec2
Showing 1 changed file with 61 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,16 @@ const details = (): IpluginDetails => ({
},
tooltip: 'Specify codec of the output file',
},
{
label: 'Enable FFmpeg Preset',
name: 'ffmpegPresetEnabled',
type: 'boolean',
defaultValue: 'true',
inputUI: {
type: 'switch',
},
tooltip: 'Specify whether to use an FFmpeg preset',
},
{
label: 'FFmpeg Preset',
name: 'ffmpegPreset',
Expand All @@ -56,16 +66,56 @@ const details = (): IpluginDetails => ({
'superfast',
'ultrafast',
],
displayConditions: {
logic: 'AND',
sets: [
{
logic: 'AND',
inputs: [
{
name: 'ffmpegPresetEnabled',
value: 'true',
condition: '===',
},
],
},
],
},
},
tooltip: 'Specify ffmpeg preset',
},
{
label: 'Enable FFmpeg CRF',
name: 'ffmpegQualityEnabled',
type: 'boolean',
defaultValue: 'true',
inputUI: {
type: 'switch',
},
tooltip: 'Specify whether to set crf (or qp for GPU encoding)',
},
{
label: 'FFmpeg Quality',
name: 'ffmpegQuality',
type: 'number',
defaultValue: '25',
inputUI: {
type: 'text',
displayConditions: {
logic: 'AND',
sets: [
{
logic: 'AND',
inputs: [
{
name: 'ffmpegQualityEnabled',
value: 'true',
condition: '===',
},
],
},
],
},
},
tooltip: 'Specify ffmpeg quality',
},
Expand Down Expand Up @@ -140,6 +190,7 @@ const plugin = async (args: IpluginInputArgs): Promise<IpluginOutputArgs> => {

if (stream.codec_type === 'video') {
const targetCodec = String(args.inputs.outputCodec);
const { ffmpegPresetEnabled, ffmpegQualityEnabled } = args.inputs;
const ffmpegPreset = String(args.inputs.ffmpegPreset);
const ffmpegQuality = String(args.inputs.ffmpegQuality);
const forceEncoding = args.inputs.forceEncoding === true;
Expand All @@ -161,14 +212,18 @@ const plugin = async (args: IpluginInputArgs): Promise<IpluginOutputArgs> => {

stream.outputArgs.push('-c:{outputIndex}', encoderProperties.encoder);

if (encoderProperties.isGpu) {
stream.outputArgs.push('-qp', ffmpegQuality);
} else {
stream.outputArgs.push('-crf', ffmpegQuality);
if (ffmpegQualityEnabled) {
if (encoderProperties.isGpu) {
stream.outputArgs.push('-qp', ffmpegQuality);
} else {
stream.outputArgs.push('-crf', ffmpegQuality);
}
}

if (targetCodec !== 'av1' && ffmpegPreset) {
stream.outputArgs.push('-preset', ffmpegPreset);
if (ffmpegPresetEnabled) {
if (targetCodec !== 'av1' && ffmpegPreset) {
stream.outputArgs.push('-preset', ffmpegPreset);
}
}

if (hardwareDecoding) {
Expand Down

0 comments on commit 9ce8ec2

Please sign in to comment.