use of com.google.cloud.videointelligence.v1.ExplicitContentFrame in project java-docs-samples by GoogleCloudPlatform.
the class Detect method analyzeExplicitContent.
/**
* Performs explicit content analysis on the video at the provided Cloud Storage path.
*
* @param gcsUri the path to the video file to analyze.
*/
public static void analyzeExplicitContent(String gcsUri) throws Exception {
// 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());
}
}
// [END detect_explicit_content]
}
}
Aggregations