Search in sources :

Example 1 with ExplicitContentFrame

use of com.google.cloud.videointelligence.v1p3beta1.ExplicitContentFrame in project java-video-intelligence by googleapis.

the class StreamingExplicitContentDetection method streamingExplicitContentDetection.

// Perform streaming video detection for explicit content
static void streamingExplicitContentDetection(String filePath) throws IOException, TimeoutException, StatusRuntimeException {
    try (StreamingVideoIntelligenceServiceClient client = StreamingVideoIntelligenceServiceClient.create()) {
        Path path = Paths.get(filePath);
        byte[] data = Files.readAllBytes(path);
        // Set the chunk size to 5MB (recommended less than 10MB).
        int chunkSize = 5 * 1024 * 1024;
        int numChunks = (int) Math.ceil((double) data.length / chunkSize);
        StreamingLabelDetectionConfig labelConfig = StreamingLabelDetectionConfig.newBuilder().setStationaryCamera(false).build();
        StreamingVideoConfig streamingVideoConfig = StreamingVideoConfig.newBuilder().setFeature(StreamingFeature.STREAMING_EXPLICIT_CONTENT_DETECTION).setLabelDetectionConfig(labelConfig).build();
        BidiStream<StreamingAnnotateVideoRequest, StreamingAnnotateVideoResponse> call = client.streamingAnnotateVideoCallable().call();
        // The first request must **only** contain the audio configuration:
        call.send(StreamingAnnotateVideoRequest.newBuilder().setVideoConfig(streamingVideoConfig).build());
        // Send the requests in chunks
        for (int i = 0; i < numChunks; i++) {
            call.send(StreamingAnnotateVideoRequest.newBuilder().setInputContent(ByteString.copyFrom(Arrays.copyOfRange(data, i * chunkSize, i * chunkSize + chunkSize))).build());
        }
        // Tell the service you are done sending data
        call.closeSend();
        for (StreamingAnnotateVideoResponse response : call) {
            StreamingVideoAnnotationResults annotationResults = response.getAnnotationResults();
            for (ExplicitContentFrame frame : annotationResults.getExplicitAnnotation().getFramesList()) {
                double offset = frame.getTimeOffset().getSeconds() + frame.getTimeOffset().getNanos() / 1e9;
                System.out.format("Offset: %f\n", offset);
                System.out.format("\tPornography: %s", frame.getPornographyLikelihood());
            }
        }
    }
}
Also used : Path(java.nio.file.Path) StreamingVideoIntelligenceServiceClient(com.google.cloud.videointelligence.v1p3beta1.StreamingVideoIntelligenceServiceClient) StreamingVideoAnnotationResults(com.google.cloud.videointelligence.v1p3beta1.StreamingVideoAnnotationResults) StreamingAnnotateVideoResponse(com.google.cloud.videointelligence.v1p3beta1.StreamingAnnotateVideoResponse) ExplicitContentFrame(com.google.cloud.videointelligence.v1p3beta1.ExplicitContentFrame) StreamingLabelDetectionConfig(com.google.cloud.videointelligence.v1p3beta1.StreamingLabelDetectionConfig) StreamingAnnotateVideoRequest(com.google.cloud.videointelligence.v1p3beta1.StreamingAnnotateVideoRequest) StreamingVideoConfig(com.google.cloud.videointelligence.v1p3beta1.StreamingVideoConfig)

Example 2 with ExplicitContentFrame

use of com.google.cloud.videointelligence.v1p3beta1.ExplicitContentFrame in project java-video-intelligence by googleapis.

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 video_analyze_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)

Example 3 with ExplicitContentFrame

use of com.google.cloud.videointelligence.v1p3beta1.ExplicitContentFrame in project java-video-intelligence by googleapis.

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 video_analyze_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)

Example 4 with ExplicitContentFrame

use of com.google.cloud.videointelligence.v1p3beta1.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)3 AnnotateVideoRequest (com.google.cloud.videointelligence.v1.AnnotateVideoRequest)3 AnnotateVideoResponse (com.google.cloud.videointelligence.v1.AnnotateVideoResponse)3 ExplicitContentFrame (com.google.cloud.videointelligence.v1.ExplicitContentFrame)3 VideoAnnotationResults (com.google.cloud.videointelligence.v1.VideoAnnotationResults)3 VideoIntelligenceServiceClient (com.google.cloud.videointelligence.v1.VideoIntelligenceServiceClient)3 ExplicitContentFrame (com.google.cloud.videointelligence.v1p3beta1.ExplicitContentFrame)1 StreamingAnnotateVideoRequest (com.google.cloud.videointelligence.v1p3beta1.StreamingAnnotateVideoRequest)1 StreamingAnnotateVideoResponse (com.google.cloud.videointelligence.v1p3beta1.StreamingAnnotateVideoResponse)1 StreamingLabelDetectionConfig (com.google.cloud.videointelligence.v1p3beta1.StreamingLabelDetectionConfig)1 StreamingVideoAnnotationResults (com.google.cloud.videointelligence.v1p3beta1.StreamingVideoAnnotationResults)1 StreamingVideoConfig (com.google.cloud.videointelligence.v1p3beta1.StreamingVideoConfig)1 StreamingVideoIntelligenceServiceClient (com.google.cloud.videointelligence.v1p3beta1.StreamingVideoIntelligenceServiceClient)1 Path (java.nio.file.Path)1