Skip to content

Commit

Permalink
Add check bitrate
Browse files Browse the repository at this point in the history
  • Loading branch information
HaveAGitGat committed Nov 28, 2023
1 parent 6ef5e2f commit 581deb7
Show file tree
Hide file tree
Showing 2 changed files with 186 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,70 @@ var details = function () { return ({
},
tooltip: 'Specify the codec check for',
},
{
label: 'Check Bitrate',
name: 'checkBitrate',
type: 'boolean',
defaultValue: 'false',
inputUI: {
type: 'dropdown',
options: [
'false',
'true',
],
},
tooltip: 'Toggle whether to check the bitrate of the audio codec is within a range.',
},
{
label: 'Greater Than',
name: 'greaterThan',
type: 'number',
defaultValue: '50000',
inputUI: {
type: 'text',
displayConditions: {
logic: 'AND',
sets: [
{
logic: 'AND',
inputs: [
{
name: 'checkBitrate',
value: 'true',
condition: '===',
},
],
},
],
},
},
tooltip: 'Specify lower bound.',
},
{
label: 'Less Than',
name: 'lessThan',
type: 'number',
defaultValue: '1000000',
inputUI: {
type: 'text',
displayConditions: {
logic: 'AND',
sets: [
{
logic: 'AND',
inputs: [
{
name: 'checkBitrate',
value: 'true',
condition: '===',
},
],
},
],
},
},
tooltip: 'Specify upper bound.',
},
],
outputs: [
{
Expand All @@ -58,14 +122,39 @@ 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 checkBitrate = Boolean(args.inputs.checkBitrate);
var greaterThan = Number(args.inputs.greaterThan);
var lessThan = Number(args.inputs.lessThan);
var hasCodec = false;
if (args.inputFileObj.ffProbeData.streams) {
args.inputFileObj.ffProbeData.streams.forEach(function (stream) {
args.inputFileObj.ffProbeData.streams.forEach(function (stream, index) {
var _a, _b, _c;
if (stream.codec_type === 'audio' && stream.codec_name === args.inputs.codec) {
hasCodec = true;
if (!checkBitrate) {
args.jobLog("File has codec: ".concat(args.inputs.codec));
hasCodec = true;
}
else {
var ffprobeBitrate = Number(stream.bit_rate || 0);
if (ffprobeBitrate > greaterThan && ffprobeBitrate < lessThan) {
args.jobLog("File has codec: ".concat(args.inputs.codec, " with bitrate")
+ " ".concat(ffprobeBitrate, " between ").concat(greaterThan, " and ").concat(lessThan));
hasCodec = true;
}
var mediaInfoBitrate = Number(((_c = (_b = (_a = args.inputFileObj.mediaInfo) === null || _a === void 0 ? void 0 : _a.track) === null || _b === void 0 ? void 0 : _b[index + 1]) === null || _c === void 0 ? void 0 : _c.BitRate) || 0);
if (mediaInfoBitrate > greaterThan && mediaInfoBitrate < lessThan) {
args.jobLog("File has codec: ".concat(args.inputs.codec, " with bitrate")
+ " ".concat(mediaInfoBitrate, " between ").concat(greaterThan, " and ").concat(lessThan));
hasCodec = true;
}
}
}
});
}
if (!hasCodec) {
args.jobLog("File does not have codec: ".concat(args.inputs.codec, " ").concat(checkBitrate ? "with "
+ "bitrate between ".concat(greaterThan, " and ").concat(lessThan) : ''));
}
return {
outputFileObj: args.inputFileObj,
outputNumber: hasCodec ? 1 : 2,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,72 @@ const details = ():IpluginDetails => ({
},
tooltip: 'Specify the codec check for',
},
{
label: 'Check Bitrate',
name: 'checkBitrate',
type: 'boolean',
defaultValue: 'false',
inputUI: {
type: 'dropdown',
options: [
'false',
'true',
],
},
tooltip:
'Toggle whether to check the bitrate of the audio codec is within a range.',
},

{
label: 'Greater Than',
name: 'greaterThan',
type: 'number',
defaultValue: '50000',
inputUI: {
type: 'text',
displayConditions: {
logic: 'AND',
sets: [
{
logic: 'AND',
inputs: [
{
name: 'checkBitrate',
value: 'true',
condition: '===',
},
],
},
],
},
},
tooltip: 'Specify lower bound.',
},
{
label: 'Less Than',
name: 'lessThan',
type: 'number',
defaultValue: '1000000',
inputUI: {
type: 'text',
displayConditions: {
logic: 'AND',
sets: [
{
logic: 'AND',
inputs: [
{
name: 'checkBitrate',
value: 'true',
condition: '===',
},
],
},
],
},
},
tooltip: 'Specify upper bound.',
},
],
outputs: [
{
Expand All @@ -62,16 +128,43 @@ const plugin = (args:IpluginInputArgs):IpluginOutputArgs => {
// eslint-disable-next-line @typescript-eslint/no-unused-vars,no-param-reassign
args.inputs = lib.loadDefaultValues(args.inputs, details);

const checkBitrate = Boolean(args.inputs.checkBitrate);
const greaterThan = Number(args.inputs.greaterThan);
const lessThan = Number(args.inputs.lessThan);

let hasCodec = false;

if (args.inputFileObj.ffProbeData.streams) {
args.inputFileObj.ffProbeData.streams.forEach((stream) => {
args.inputFileObj.ffProbeData.streams.forEach((stream, index) => {
if (stream.codec_type === 'audio' && stream.codec_name === args.inputs.codec) {
hasCodec = true;
if (!checkBitrate) {
args.jobLog(`File has codec: ${args.inputs.codec}`);
hasCodec = true;
} else {
const ffprobeBitrate = Number(stream.bit_rate || 0);
if (ffprobeBitrate > greaterThan && ffprobeBitrate < lessThan) {
args.jobLog(`File has codec: ${args.inputs.codec} with bitrate`
+ ` ${ffprobeBitrate} between ${greaterThan} and ${lessThan}`);
hasCodec = true;
}

const mediaInfoBitrate = Number(args.inputFileObj.mediaInfo?.track?.[index + 1]?.BitRate || 0);

if (mediaInfoBitrate > greaterThan && mediaInfoBitrate < lessThan) {
args.jobLog(`File has codec: ${args.inputs.codec} with bitrate`
+ ` ${mediaInfoBitrate} between ${greaterThan} and ${lessThan}`);
hasCodec = true;
}
}
}
});
}

if (!hasCodec) {
args.jobLog(`File does not have codec: ${args.inputs.codec} ${checkBitrate ? 'with '
+ `bitrate between ${greaterThan} and ${lessThan}` : ''}`);
}

return {
outputFileObj: args.inputFileObj,
outputNumber: hasCodec ? 1 : 2,
Expand Down

0 comments on commit 581deb7

Please sign in to comment.