How to Scan a Video for NSFW Content in Node.JS

Cloudmersive
2 min readSep 10, 2020

To ensure that your clients and partners always maintain high regard for your organization and work, it is important to curate the best for your websites or other media material. To eliminate the risk of your associates running into anything undesirable when browsing your content, the following Cloudmersive API will allow you to scan videos for anything “Not Safe for Work” (NSFW) using Node.JS.

First, we need to run this command to install the SDK:

npm install cloudmersive-video-api-client --save

Or, you can add this snippet to your package.json:

"dependencies": {
"cloudmersive-video-api-client": "^2.0.1"
}

Then, you can call our function, VideoScanForNsfw:

var CloudmersiveVideoApiClient = require('cloudmersive-video-api-client');
var defaultClient = CloudmersiveVideoApiClient.ApiClient.instance;
// Configure API key authorization: Apikey
var Apikey = defaultClient.authentications['Apikey'];
Apikey.apiKey = 'YOUR API KEY';
var apiInstance = new CloudmersiveVideoApiClient.VideoApi();var opts = {
'inputFile': Buffer.from(fs.readFileSync("C:\\temp\\inputfile").buffer), // File | Input file to perform the operation on.
'fileUrl': "fileUrl_example", // String | Optional; URL of a video file being scanned. Use this option for files larger than 2GB.
'framesPerSecond': 8.14 // Number | Optional; How many video frames per second to be scanned. Minimum value is 0.05 (1 frame per 20 seconds), maximum is 1. Default is 0.33 frame per second (1 frame scanned every 3 seconds). Maximum of 1000 total frames can be scanned, potentially adjusting the framerate for longer videos.
};
var callback = function(error, data, response) {
if (error) {
console.error(error);
} else {
console.log('API called successfully. Returned data: ' + data);
}
};
apiInstance.videoScanForNsfw(opts, callback);

You can relax knowing that after following these steps, your content will be safe from anything NSFW. Find your free API Key on the Cloudmersive website, providing you with up to 800 calls across our available APIs.

--

--

Cloudmersive

There’s an API for that. Cloudmersive is a leader in Highly Scalable Cloud APIs.