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());
}
}
}
}
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]
}
}
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]
}
}
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]
}
}
Aggregations