From 491e40b885938619f16251c3f51ff7d46fcf626d Mon Sep 17 00:00:00 2001 From: Stickie Date: Thu, 5 Oct 2023 13:16:44 +0200 Subject: [PATCH 1/3] Added `CheckVideoChannelsAmount` Flow plugin. --- .../CheckVideoChannelsAmount/1.0.0/index.js | 50 +++++++++++++++ .../CheckVideoChannelsAmount/1.0.0/index.ts | 63 +++++++++++++++++++ 2 files changed, 113 insertions(+) create mode 100644 FlowPlugins/CommunityFlowPlugins/video/CheckVideoChannelsAmount/1.0.0/index.js create mode 100644 FlowPluginsTs/CommunityFlowPlugins/video/CheckVideoChannelsAmount/1.0.0/index.ts diff --git a/FlowPlugins/CommunityFlowPlugins/video/CheckVideoChannelsAmount/1.0.0/index.js b/FlowPlugins/CommunityFlowPlugins/video/CheckVideoChannelsAmount/1.0.0/index.js new file mode 100644 index 0000000..4c2cafb --- /dev/null +++ b/FlowPlugins/CommunityFlowPlugins/video/CheckVideoChannelsAmount/1.0.0/index.js @@ -0,0 +1,50 @@ +"use strict"; +Object.defineProperty(exports, "__esModule", { value: true }); +exports.plugin = exports.details = void 0; +/* eslint no-plusplus: ["error", { "allowForLoopAfterthoughts": true }] */ +var details = function () { return ({ + name: 'Check Multiple Video Streams', + description: 'This plugin checks if an input file has more than one video stream.', + style: { + borderColor: 'orange', + }, + tags: 'video', + isStartPlugin: false, + pType: '', + requiresVersion: '2.11.01', + sidebarPosition: -1, + icon: 'faQuestion', + inputs: [], + outputs: [ + { + number: 1, + tooltip: 'File has one video stream', + }, + { + number: 2, + tooltip: 'File has more than one video stream', + }, + ], +}); }; +exports.details = details; +// eslint-disable-next-line @typescript-eslint/no-unused-vars +var plugin = function (args) { + var lib = require('../../../../../methods/lib')(); + // eslint-disable-next-line @typescript-eslint/no-unused-vars,no-param-reassign + args.inputs = lib.loadDefaultValues(args.inputs, details); + var outputNumber = 2; // Default to 'Special case' (> 1 video tracks) + var ffProbeData = args.inputFileObj.ffProbeData; + if (!ffProbeData || !ffProbeData.streams) { + throw new Error('ffProbeData or ffProbeData.streams is not available.'); + } + var videoStreams = ffProbeData.streams.filter(function (stream) { return stream.codec_type === 'video'; }).length; + if (videoStreams === 1) { + outputNumber = 1; // 'Success' (has exactly one video stream) + } + return { + outputFileObj: args.inputFileObj, + outputNumber: outputNumber, + variables: args.variables, + }; +}; +exports.plugin = plugin; diff --git a/FlowPluginsTs/CommunityFlowPlugins/video/CheckVideoChannelsAmount/1.0.0/index.ts b/FlowPluginsTs/CommunityFlowPlugins/video/CheckVideoChannelsAmount/1.0.0/index.ts new file mode 100644 index 0000000..940aa2a --- /dev/null +++ b/FlowPluginsTs/CommunityFlowPlugins/video/CheckVideoChannelsAmount/1.0.0/index.ts @@ -0,0 +1,63 @@ +import { + IpluginDetails, + IpluginInputArgs, + IpluginOutputArgs, +} from '../../../../FlowHelpers/1.0.0/interfaces/interfaces'; + +/* eslint no-plusplus: ["error", { "allowForLoopAfterthoughts": true }] */ +const details = (): IpluginDetails => ({ + name: 'Check Multiple Video Streams', + description: 'This plugin checks if an input file has more than one video stream.', + style: { + borderColor: 'orange', + }, + tags: 'video', + isStartPlugin: false, + pType: '', + requiresVersion: '2.11.01', + sidebarPosition: -1, + icon: 'faQuestion', + inputs: [], + outputs: [ + { + number: 1, + tooltip: 'File has one video stream', + }, + { + number: 2, + tooltip: 'File has more than one video stream', + }, + ], +}); + +// eslint-disable-next-line @typescript-eslint/no-unused-vars +const plugin = (args: IpluginInputArgs): IpluginOutputArgs => { + const lib = require('../../../../../methods/lib')(); + // eslint-disable-next-line @typescript-eslint/no-unused-vars,no-param-reassign + args.inputs = lib.loadDefaultValues(args.inputs, details); + + let outputNumber = 2; // Default to 'Special case' (> 1 video tracks) + + const { ffProbeData } = args.inputFileObj; + + if (!ffProbeData || !ffProbeData.streams) { + throw new Error('ffProbeData or ffProbeData.streams is not available.'); + } + + const videoStreams = ffProbeData.streams.filter((stream) => stream.codec_type === 'video').length; + + if (videoStreams === 1) { + outputNumber = 1; // 'Success' (has exactly one video stream) + } + + return { + outputFileObj: args.inputFileObj, + outputNumber, + variables: args.variables, + }; +}; + +export { + details, + plugin, +}; From 6af54253ba3bed94e915bddd0476d88e6498a8b7 Mon Sep 17 00:00:00 2001 From: HaveAGitGat <43864057+HaveAGitGat@users.noreply.github.com> Date: Mon, 9 Oct 2023 08:44:58 +0100 Subject: [PATCH 2/3] Rename plugin, throw error if no video streams found --- .../1.0.0/index.js | 16 +++++++++++----- .../1.0.0/index.ts | 16 ++++++++++------ 2 files changed, 21 insertions(+), 11 deletions(-) rename FlowPlugins/CommunityFlowPlugins/video/{CheckVideoChannelsAmount => checkVideoStreamsCount}/1.0.0/index.js (76%) rename FlowPluginsTs/CommunityFlowPlugins/video/{CheckVideoChannelsAmount => checkVideoStreamsCount}/1.0.0/index.ts (76%) diff --git a/FlowPlugins/CommunityFlowPlugins/video/CheckVideoChannelsAmount/1.0.0/index.js b/FlowPlugins/CommunityFlowPlugins/video/checkVideoStreamsCount/1.0.0/index.js similarity index 76% rename from FlowPlugins/CommunityFlowPlugins/video/CheckVideoChannelsAmount/1.0.0/index.js rename to FlowPlugins/CommunityFlowPlugins/video/checkVideoStreamsCount/1.0.0/index.js index 4c2cafb..8eb66f7 100644 --- a/FlowPlugins/CommunityFlowPlugins/video/CheckVideoChannelsAmount/1.0.0/index.js +++ b/FlowPlugins/CommunityFlowPlugins/video/checkVideoStreamsCount/1.0.0/index.js @@ -3,8 +3,8 @@ Object.defineProperty(exports, "__esModule", { value: true }); exports.plugin = exports.details = void 0; /* eslint no-plusplus: ["error", { "allowForLoopAfterthoughts": true }] */ var details = function () { return ({ - name: 'Check Multiple Video Streams', - description: 'This plugin checks if an input file has more than one video stream.', + name: 'Check Video Streams Count', + description: 'This plugin checks if the number of video streams is 1 or more.', style: { borderColor: 'orange', }, @@ -32,14 +32,20 @@ var plugin = function (args) { var lib = require('../../../../../methods/lib')(); // eslint-disable-next-line @typescript-eslint/no-unused-vars,no-param-reassign args.inputs = lib.loadDefaultValues(args.inputs, details); - var outputNumber = 2; // Default to 'Special case' (> 1 video tracks) var ffProbeData = args.inputFileObj.ffProbeData; if (!ffProbeData || !ffProbeData.streams) { throw new Error('ffProbeData or ffProbeData.streams is not available.'); } var videoStreams = ffProbeData.streams.filter(function (stream) { return stream.codec_type === 'video'; }).length; - if (videoStreams === 1) { - outputNumber = 1; // 'Success' (has exactly one video stream) + var outputNumber = 1; // Default to one video stream + if (videoStreams === 0) { + throw new Error('No video streams found in file.'); + } + else if (videoStreams === 1) { + outputNumber = 1; // One video stream + } + else if (videoStreams > 1) { + outputNumber = 3; // More than one video stream } return { outputFileObj: args.inputFileObj, diff --git a/FlowPluginsTs/CommunityFlowPlugins/video/CheckVideoChannelsAmount/1.0.0/index.ts b/FlowPluginsTs/CommunityFlowPlugins/video/checkVideoStreamsCount/1.0.0/index.ts similarity index 76% rename from FlowPluginsTs/CommunityFlowPlugins/video/CheckVideoChannelsAmount/1.0.0/index.ts rename to FlowPluginsTs/CommunityFlowPlugins/video/checkVideoStreamsCount/1.0.0/index.ts index 940aa2a..5f6f1c2 100644 --- a/FlowPluginsTs/CommunityFlowPlugins/video/CheckVideoChannelsAmount/1.0.0/index.ts +++ b/FlowPluginsTs/CommunityFlowPlugins/video/checkVideoStreamsCount/1.0.0/index.ts @@ -6,8 +6,8 @@ import { /* eslint no-plusplus: ["error", { "allowForLoopAfterthoughts": true }] */ const details = (): IpluginDetails => ({ - name: 'Check Multiple Video Streams', - description: 'This plugin checks if an input file has more than one video stream.', + name: 'Check Video Streams Count', + description: 'This plugin checks if the number of video streams is 1 or more.', style: { borderColor: 'orange', }, @@ -36,8 +36,6 @@ const plugin = (args: IpluginInputArgs): IpluginOutputArgs => { // eslint-disable-next-line @typescript-eslint/no-unused-vars,no-param-reassign args.inputs = lib.loadDefaultValues(args.inputs, details); - let outputNumber = 2; // Default to 'Special case' (> 1 video tracks) - const { ffProbeData } = args.inputFileObj; if (!ffProbeData || !ffProbeData.streams) { @@ -46,8 +44,14 @@ const plugin = (args: IpluginInputArgs): IpluginOutputArgs => { const videoStreams = ffProbeData.streams.filter((stream) => stream.codec_type === 'video').length; - if (videoStreams === 1) { - outputNumber = 1; // 'Success' (has exactly one video stream) + let outputNumber = 1; // Default to one video stream + + if (videoStreams === 0) { + throw new Error('No video streams found in file.'); + } else if (videoStreams === 1) { + outputNumber = 1; // One video stream + } else if (videoStreams > 1) { + outputNumber = 2; // More than one video stream } return { From e2146819555b634fd682a197671c592e801352a2 Mon Sep 17 00:00:00 2001 From: HaveAGitGat <43864057+HaveAGitGat@users.noreply.github.com> Date: Mon, 9 Oct 2023 08:50:47 +0100 Subject: [PATCH 3/3] Add log, fix output --- .../video/checkVideoStreamsCount/1.0.0/index.js | 3 ++- .../video/checkVideoStreamsCount/1.0.0/index.ts | 2 ++ 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/FlowPlugins/CommunityFlowPlugins/video/checkVideoStreamsCount/1.0.0/index.js b/FlowPlugins/CommunityFlowPlugins/video/checkVideoStreamsCount/1.0.0/index.js index 8eb66f7..dbd649e 100644 --- a/FlowPlugins/CommunityFlowPlugins/video/checkVideoStreamsCount/1.0.0/index.js +++ b/FlowPlugins/CommunityFlowPlugins/video/checkVideoStreamsCount/1.0.0/index.js @@ -45,8 +45,9 @@ var plugin = function (args) { outputNumber = 1; // One video stream } else if (videoStreams > 1) { - outputNumber = 3; // More than one video stream + outputNumber = 2; // More than one video stream } + args.jobLog("Number of video streams: ".concat(videoStreams)); return { outputFileObj: args.inputFileObj, outputNumber: outputNumber, diff --git a/FlowPluginsTs/CommunityFlowPlugins/video/checkVideoStreamsCount/1.0.0/index.ts b/FlowPluginsTs/CommunityFlowPlugins/video/checkVideoStreamsCount/1.0.0/index.ts index 5f6f1c2..d7c530c 100644 --- a/FlowPluginsTs/CommunityFlowPlugins/video/checkVideoStreamsCount/1.0.0/index.ts +++ b/FlowPluginsTs/CommunityFlowPlugins/video/checkVideoStreamsCount/1.0.0/index.ts @@ -54,6 +54,8 @@ const plugin = (args: IpluginInputArgs): IpluginOutputArgs => { outputNumber = 2; // More than one video stream } + args.jobLog(`Number of video streams: ${videoStreams}`); + return { outputFileObj: args.inputFileObj, outputNumber,