Detect NSFW Content from a Video in Ruby
The NSFW or ‘Not Safe for Work’ tag is used to identify online content that is inappropriate to view in the workplace. To ensure none of these types of videos are uploaded to your applications or downloaded into your system, you can utilize the following API in Ruby to automatically scan a video for NSFW content.
We will start things off by installing the Ruby client:
gem 'cloudmersive-video-api-client', '~> 2.0', '>= 2.0.5'
Next, we can call the VideoScanforNSFW function with the below example code:
# load the gem
require 'cloudmersive-video-api-client'
# setup authorization
CloudmersiveVideoApiClient.configure do |config|
# Configure API key authorization: Apikey
config.api_key['Apikey'] = 'YOUR API KEY'
# Uncomment the following line to set a prefix for the API key, e.g. 'Bearer' (defaults to nil)
#config.api_key_prefix['Apikey'] = 'Bearer'
endapi_instance = CloudmersiveVideoApiClient::VideoApi.newopts = {
input_file: File.new('/path/to/inputfile'), # File | Input file to perform the operation on.
file_url: 'file_url_example', # String | Optional; URL of a video file being scanned. Use this option for files larger than 2GB.
frames_per_second: 8.14 # Float | 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.
}begin
#Scan a Video for NSFW content.
result = api_instance.video_scan_for_nsfw(opts)
p result
rescue CloudmersiveVideoApiClient::ApiError => e
puts "Exception when calling VideoApi->video_scan_for_nsfw: #{e}"
end
The operation uses one API call per 10MB of file size, and one API call per frame scanned. To gain access to 800 monthly calls across our library of APIs, head over to the Cloudmersive website to register for a free account.