Scan a Video for NSFW Content in Java

We have previously show you how to use an API to scan video files for NSFW content in Node.JS. Doing so will ensure that any content associated with your organization meets your standards without having to scrub through each video on your own. In this article, we will be showing you how to use the same API in Java. This API supports several input video formats including AVI, ASF, FLV, MP4, MPEG/MPG, Matroska/WEBM, 3G2, OGV, MKV, M4V and MOV.

Image for post
Image for post

We need to install our SDK, so first, we will add a reference to the repository in pom.xml:

<repositories>
<repository>
<id>jitpack.io</id>
<url>https://jitpack.io</url>
</repository>
</repositories>

Then, add a reference to the dependency:

<dependencies>
<dependency>
<groupId>com.github.Cloudmersive</groupId>
<artifactId>Cloudmersive.APIClient.Java</artifactId>
<version>v3.54</version>
</dependency>
</dependencies>

Now, we can call our function:

// Import classes:
//import com.cloudmersive.client.invoker.ApiClient;
//import com.cloudmersive.client.invoker.ApiException;
//import com.cloudmersive.client.invoker.Configuration;
//import com.cloudmersive.client.invoker.auth.*;
//import com.cloudmersive.client.VideoApi;
ApiClient defaultClient = Configuration.getDefaultApiClient();// Configure API key authorization: Apikey
ApiKeyAuth Apikey = (ApiKeyAuth) defaultClient.getAuthentication("Apikey");
Apikey.setApiKey("YOUR API KEY");
// Uncomment the following line to set a prefix for the API key, e.g. "Token" (defaults to null)
//Apikey.setApiKeyPrefix("Token");
VideoApi apiInstance = new VideoApi();
File inputFile = new File("/path/to/inputfile"); // File | Input file to perform the operation on.
String fileUrl = "fileUrl_example"; // String | Optional; URL of a video file being scanned. Use this option for files larger than 2GB.
BigDecimal framesPerSecond = new BigDecimal(); // BigDecimal | 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.
try {
NsfwResult result = apiInstance.videoScanForNsfw(inputFile, fileUrl, framesPerSecond);
System.out.println(result);
} catch (ApiException e) {
System.err.println("Exception when calling VideoApi#videoScanForNsfw");
e.printStackTrace();
}

With that, you can instantly scan any video file and ensure that you have a safety net for any video content associated with your organization. You can retrieve your free API Key from Cloudmersive. This will give you access to 800 monthly calls across our entire API library.

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