Skip to content

Commit

Permalink
Merge pull request #674 from HaveAGitGat/ffmpeg_c
Browse files Browse the repository at this point in the history
Add toggles for preset and quality
  • Loading branch information
HaveAGitGat authored Jun 21, 2024
2 parents 27f0f31 + a9f367a commit fa784a1
Show file tree
Hide file tree
Showing 2 changed files with 132 additions and 22 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,16 @@ var details = function () { return ({
},
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 @@ -88,16 +98,56 @@ var details = function () { return ({
'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 @@ -159,10 +209,10 @@ var details = function () { return ({
exports.details = details;
// eslint-disable-next-line @typescript-eslint/no-unused-vars
var plugin = function (args) { return __awaiter(void 0, void 0, void 0, function () {
var lib, hardwareDecoding, hardwareType, i, stream, targetCodec, ffmpegPreset, ffmpegQuality, forceEncoding, hardwarEncoding, encoderProperties;
var _a, _b;
return __generator(this, function (_c) {
switch (_c.label) {
var lib, hardwareDecoding, hardwareType, i, stream, targetCodec, _a, ffmpegPresetEnabled, ffmpegQualityEnabled, ffmpegPreset, ffmpegQuality, forceEncoding, hardwarEncoding, encoderProperties;
var _b, _c;
return __generator(this, function (_d) {
switch (_d.label) {
case 0:
lib = require('../../../../../methods/lib')();
// eslint-disable-next-line @typescript-eslint/no-unused-vars,no-param-reassign
Expand All @@ -171,12 +221,13 @@ var plugin = function (args) { return __awaiter(void 0, void 0, void 0, function
hardwareType = String(args.inputs.hardwareType);
args.variables.ffmpegCommand.hardwareDecoding = hardwareDecoding;
i = 0;
_c.label = 1;
_d.label = 1;
case 1:
if (!(i < args.variables.ffmpegCommand.streams.length)) return [3 /*break*/, 4];
stream = args.variables.ffmpegCommand.streams[i];
if (!(stream.codec_type === 'video')) return [3 /*break*/, 3];
targetCodec = String(args.inputs.outputCodec);
_a = args.inputs, ffmpegPresetEnabled = _a.ffmpegPresetEnabled, ffmpegQualityEnabled = _a.ffmpegQualityEnabled;
ffmpegPreset = String(args.inputs.ffmpegPreset);
ffmpegQuality = String(args.inputs.ffmpegQuality);
forceEncoding = args.inputs.forceEncoding === true;
Expand All @@ -191,24 +242,28 @@ var plugin = function (args) { return __awaiter(void 0, void 0, void 0, function
args: args,
})];
case 2:
encoderProperties = _c.sent();
encoderProperties = _d.sent();
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) {
(_a = stream.inputArgs).push.apply(_a, encoderProperties.inputArgs);
(_b = stream.inputArgs).push.apply(_b, encoderProperties.inputArgs);
}
if (encoderProperties.outputArgs) {
(_b = stream.outputArgs).push.apply(_b, encoderProperties.outputArgs);
(_c = stream.outputArgs).push.apply(_c, encoderProperties.outputArgs);
}
_c.label = 3;
_d.label = 3;
case 3:
i += 1;
return [3 /*break*/, 1];
Expand Down
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 fa784a1

Please sign in to comment.