use of com.google.cloud.videointelligence.v1p3beta1.StreamingStorageConfig in project java-video-intelligence by googleapis.
the class StreamingAnnotationToStorage method streamingAnnotationToStorage.
// Perform streaming video detection for explicit content
static void streamingAnnotationToStorage(String filePath, String gcsUri) 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);
StreamingStorageConfig streamingStorageConfig = StreamingStorageConfig.newBuilder().setEnableStorageAnnotationResult(true).setAnnotationResultStorageDirectory(gcsUri).build();
StreamingLabelDetectionConfig labelConfig = StreamingLabelDetectionConfig.newBuilder().setStationaryCamera(false).build();
StreamingVideoConfig streamingVideoConfig = StreamingVideoConfig.newBuilder().setFeature(StreamingFeature.STREAMING_LABEL_DETECTION).setLabelDetectionConfig(labelConfig).setStorageConfig(streamingStorageConfig).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) {
System.out.format("Storage Uri: %s\n", response.getAnnotationResultsUri());
}
}
}
Aggregations