// Instantiate a com.google.cloud.videointelligence.v1.VideoIntelligenceServiceClient
try (VideoIntelligenceServiceClient client = VideoIntelligenceServiceClient.create()) {
// Create an operation that will contain the response when the operation completes.
AnnotateVideoRequest request =
AnnotateVideoRequest.newBuilder()
.setInputUri(gcsUri)
.addFeatures(Feature.EXPLICIT_CONTENT_DETECTION)
.build();
OperationFuture<AnnotateVideoResponse, AnnotateVideoProgress> response =
client.annotateVideoAsync(request);
System.out.println("Waiting for operation to complete...");
// Print detected annotations and their positions in the analyzed video.
for (VideoAnnotationResults result : response.get().getAnnotationResultsList()) {
for (ExplicitContentFrame frame : result.getExplicitAnnotation().getFramesList()) {
double frameTime =
frame.getTimeOffset().getSeconds() + frame.getTimeOffset().getNanos() / 1e9;
System.out.printf("Location: %.3fs\n", frameTime);
System.out.println("Adult: " + frame.getPornographyLikelihood());
}
}
"""Detects explicit content from the GCS path to a video."""
video_client = videointelligence.VideoIntelligenceServiceClient()
features = [videointelligence.Feature.EXPLICIT_CONTENT_DETECTION]
operation = video_client.annotate_video(
request={"features": features, "input_uri": path}
)
print("\nProcessing video for explicit content annotations:")
result = operation.result(timeout=90)
print("\nFinished processing.")
# Retrieve first result because a single video was processed
for frame in result.annotation_results[0].explicit_annotation.frames:
likelihood = videointelligence.Likelihood(frame.pornography_likelihood)
frame_time = frame.time_offset.seconds + frame.time_offset.microseconds / 1e6
print("Time: {}s".format(frame_time))
print("\tpornography: {}".format(likelihood.name))