mirror of
https://github.com/gabehf/Tdarr_Plugins.git
synced 2026-03-14 01:36:08 -07:00
Option to use perc bitrate
This commit is contained in:
parent
09a7edf755
commit
7e22f3d2fe
1 changed files with 104 additions and 3 deletions
|
|
@ -6,7 +6,7 @@ import {
|
||||||
import { getFfType } from '../../../../FlowHelpers/1.0.0/fileUtils';
|
import { getFfType } from '../../../../FlowHelpers/1.0.0/fileUtils';
|
||||||
|
|
||||||
/* eslint no-plusplus: ["error", { "allowForLoopAfterthoughts": true }] */
|
/* eslint no-plusplus: ["error", { "allowForLoopAfterthoughts": true }] */
|
||||||
const details = () :IpluginDetails => ({
|
const details = (): IpluginDetails => ({
|
||||||
name: 'Set Video Bitrate',
|
name: 'Set Video Bitrate',
|
||||||
description: 'Set Video Bitrate',
|
description: 'Set Video Bitrate',
|
||||||
style: {
|
style: {
|
||||||
|
|
@ -19,6 +19,67 @@ const details = () :IpluginDetails => ({
|
||||||
sidebarPosition: -1,
|
sidebarPosition: -1,
|
||||||
icon: '',
|
icon: '',
|
||||||
inputs: [
|
inputs: [
|
||||||
|
{
|
||||||
|
label: 'Use % of Input Bitrate',
|
||||||
|
name: 'useInputBitrate',
|
||||||
|
type: 'boolean',
|
||||||
|
defaultValue: 'false',
|
||||||
|
inputUI: {
|
||||||
|
type: 'switch',
|
||||||
|
},
|
||||||
|
tooltip: 'Specify whether to use a % of input bitrate as the output bitrate',
|
||||||
|
},
|
||||||
|
|
||||||
|
{
|
||||||
|
label: 'Target Bitrate %',
|
||||||
|
name: 'targetBitratePercent',
|
||||||
|
type: 'string',
|
||||||
|
defaultValue: '50',
|
||||||
|
inputUI: {
|
||||||
|
type: 'text',
|
||||||
|
displayConditions: {
|
||||||
|
logic: 'AND',
|
||||||
|
sets: [
|
||||||
|
{
|
||||||
|
logic: 'AND',
|
||||||
|
inputs: [
|
||||||
|
{
|
||||||
|
name: 'useInputBitrate',
|
||||||
|
value: 'true',
|
||||||
|
condition: '===',
|
||||||
|
},
|
||||||
|
],
|
||||||
|
},
|
||||||
|
],
|
||||||
|
},
|
||||||
|
},
|
||||||
|
tooltip: 'Specify the target bitrate as a % of the input bitrate',
|
||||||
|
},
|
||||||
|
{
|
||||||
|
label: 'Fallback Bitrate',
|
||||||
|
name: 'fallbackBitrate',
|
||||||
|
type: 'string',
|
||||||
|
defaultValue: '4000',
|
||||||
|
inputUI: {
|
||||||
|
type: 'text',
|
||||||
|
displayConditions: {
|
||||||
|
logic: 'AND',
|
||||||
|
sets: [
|
||||||
|
{
|
||||||
|
logic: 'AND',
|
||||||
|
inputs: [
|
||||||
|
{
|
||||||
|
name: 'useInputBitrate',
|
||||||
|
value: 'true',
|
||||||
|
condition: '===',
|
||||||
|
},
|
||||||
|
],
|
||||||
|
},
|
||||||
|
],
|
||||||
|
},
|
||||||
|
},
|
||||||
|
tooltip: 'Specify fallback bitrate in kbps if input bitrate is not available',
|
||||||
|
},
|
||||||
{
|
{
|
||||||
label: 'Bitrate',
|
label: 'Bitrate',
|
||||||
name: 'bitrate',
|
name: 'bitrate',
|
||||||
|
|
@ -26,6 +87,21 @@ const details = () :IpluginDetails => ({
|
||||||
defaultValue: '5000',
|
defaultValue: '5000',
|
||||||
inputUI: {
|
inputUI: {
|
||||||
type: 'text',
|
type: 'text',
|
||||||
|
displayConditions: {
|
||||||
|
logic: 'AND',
|
||||||
|
sets: [
|
||||||
|
{
|
||||||
|
logic: 'AND',
|
||||||
|
inputs: [
|
||||||
|
{
|
||||||
|
name: 'useInputBitrate',
|
||||||
|
value: 'true',
|
||||||
|
condition: '!==',
|
||||||
|
},
|
||||||
|
],
|
||||||
|
},
|
||||||
|
],
|
||||||
|
},
|
||||||
},
|
},
|
||||||
tooltip: 'Specify bitrate in kbps',
|
tooltip: 'Specify bitrate in kbps',
|
||||||
},
|
},
|
||||||
|
|
@ -39,15 +115,40 @@ const details = () :IpluginDetails => ({
|
||||||
});
|
});
|
||||||
|
|
||||||
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
||||||
const plugin = (args:IpluginInputArgs):IpluginOutputArgs => {
|
const plugin = (args: IpluginInputArgs): IpluginOutputArgs => {
|
||||||
const lib = require('../../../../../methods/lib')();
|
const lib = require('../../../../../methods/lib')();
|
||||||
// eslint-disable-next-line @typescript-eslint/no-unused-vars,no-param-reassign
|
// eslint-disable-next-line @typescript-eslint/no-unused-vars,no-param-reassign
|
||||||
args.inputs = lib.loadDefaultValues(args.inputs, details);
|
args.inputs = lib.loadDefaultValues(args.inputs, details);
|
||||||
|
|
||||||
|
const { useInputBitrate } = args.inputs;
|
||||||
|
const targetBitratePercent = String(args.inputs.targetBitratePercent);
|
||||||
|
const fallbackBitrate = String(args.inputs.fallbackBitrate);
|
||||||
|
const bitrate = String(args.inputs.bitrate);
|
||||||
|
|
||||||
args.variables.ffmpegCommand.streams.forEach((stream) => {
|
args.variables.ffmpegCommand.streams.forEach((stream) => {
|
||||||
if (stream.codec_type === 'video') {
|
if (stream.codec_type === 'video') {
|
||||||
const ffType = getFfType(stream.codec_type);
|
const ffType = getFfType(stream.codec_type);
|
||||||
stream.outputArgs.push(`-b:${ffType}:{outputTypeIndex}`, `${String(args.inputs.bitrate)}k`);
|
if (useInputBitrate) {
|
||||||
|
args.jobLog('Attempting to use % of input bitrate as output bitrate');
|
||||||
|
// check if input bitrate is available
|
||||||
|
const mediainfoIndex = stream.index + 1;
|
||||||
|
|
||||||
|
let inputBitrate = args?.inputFileObj?.mediaInfo?.track?.[mediainfoIndex]?.BitRate;
|
||||||
|
if (inputBitrate) {
|
||||||
|
args.jobLog(`Found input bitrate: ${inputBitrate}`);
|
||||||
|
// @ts-expect-error type
|
||||||
|
inputBitrate = parseInt(inputBitrate, 10) / 1000;
|
||||||
|
const targetBitrate = (inputBitrate * (parseInt(targetBitratePercent, 10) / 100));
|
||||||
|
args.jobLog(`Setting video bitrate as ${targetBitrate}k`);
|
||||||
|
stream.outputArgs.push(`-b:${ffType}:{outputTypeIndex}`, `${targetBitrate}k`);
|
||||||
|
} else {
|
||||||
|
args.jobLog(`Unable to find input bitrate, setting fallback bitrate as ${fallbackBitrate}k`);
|
||||||
|
stream.outputArgs.push(`-b:${ffType}:{outputTypeIndex}`, `${fallbackBitrate}k`);
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
args.jobLog(`Using fixed bitrate. Setting video bitrate as ${bitrate}k`);
|
||||||
|
stream.outputArgs.push(`-b:${ffType}:{outputTypeIndex}`, `${bitrate}k`);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue