Search in sources :

Example 1 with ExplicitContentFrame

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]
    }
}
Also used : VideoIntelligenceServiceClient(com.google.cloud.videointelligence.v1.VideoIntelligenceServiceClient) AnnotateVideoProgress(com.google.cloud.videointelligence.v1.AnnotateVideoProgress) ExplicitContentFrame(com.google.cloud.videointelligence.v1.ExplicitContentFrame) AnnotateVideoRequest(com.google.cloud.videointelligence.v1.AnnotateVideoRequest) VideoAnnotationResults(com.google.cloud.videointelligence.v1.VideoAnnotationResults) AnnotateVideoResponse(com.google.cloud.videointelligence.v1.AnnotateVideoResponse)

Aggregations

AnnotateVideoProgress (com.google.cloud.videointelligence.v1.AnnotateVideoProgress)1 AnnotateVideoRequest (com.google.cloud.videointelligence.v1.AnnotateVideoRequest)1 AnnotateVideoResponse (com.google.cloud.videointelligence.v1.AnnotateVideoResponse)1 ExplicitContentFrame (com.google.cloud.videointelligence.v1.ExplicitContentFrame)1 VideoAnnotationResults (com.google.cloud.videointelligence.v1.VideoAnnotationResults)1 VideoIntelligenceServiceClient (com.google.cloud.videointelligence.v1.VideoIntelligenceServiceClient)1