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

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.

Image for post
Image for post

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.

Written by

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

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store