javagoogle-apigoogle-cloud-platformvideo-intelligence-api

Returning video information Video Intelligence API


I am not able to display the information of the local video, when I do the test with the videos examples are returning, but when I try with the files of the machine does not return anything.

public String consultar() throws Throwable {
        requisicaoVideo("C:\\Users\\Web Designer\\Desktop\\Placas de Carros\\cat.mp4");
        return "analiseForenseVideos.xhtml";
    }
    public void requisicaoVideo(String filePath) throws Exception {
        try (VideoIntelligenceServiceClient client = VideoIntelligenceServiceClient.create()) {
            // Read file and encode into Base64
            Path path = Paths.get(filePath);
            byte[] data = Files.readAllBytes(path);
            byte[] encodedBytes = Base64.encodeBase64(data);
            System.out.println(encodedBytes + "Linha 74");
            AnnotateVideoRequest request = AnnotateVideoRequest.newBuilder()
                    .setInputContent(ByteString.copyFrom(encodedBytes)).addFeatures(Feature.LABEL_DETECTION).build();
            // Create an operation that will contain the response when the operation
            // completes.
            OperationFuture<AnnotateVideoResponse, AnnotateVideoProgress> response = client.annotateVideoAsync(request);
            System.out.println("Waiting for operation to complete...");
            System.out.println(response.get().getAnnotationResultsList() + "Linha 83");
            for (VideoAnnotationResults results : response.get().getAnnotationResultsList()) {
                // process video / segment level label annotations
                System.out.println("Locations: ");
                for (LabelAnnotation labelAnnotation : results.getSegmentLabelAnnotationsList()) {
                    System.out.println("Video label: " + labelAnnotation.getEntity().getDescription());
                    // categories
                    for (Entity categoryEntity : labelAnnotation.getCategoryEntitiesList()) {
                        System.out.println("Video label category: " + categoryEntity.getDescription());
                    }
                    // segments
                    for (LabelSegment segment : labelAnnotation.getSegmentsList()) {
                        double startTime = segment.getSegment().getStartTimeOffset().getSeconds()
                                + segment.getSegment().getStartTimeOffset().getNanos() / 1e9;
                        double endTime = segment.getSegment().getEndTimeOffset().getSeconds()
                                + segment.getSegment().getEndTimeOffset().getNanos() / 1e9;
                        System.out.printf("Segment location: %.3f:%.2f\n", startTime, endTime);
                        System.out.println("Confidence: " + segment.getConfidence());
                    }
                }

Solution

  • I am with Google Cloud Support. Thank you for reporting this issue. I have been doing some tests and identified some kind of bug in analyzeLabelsFile function in Detect.java file.

    If you let the job run for a lot of time, it might get finished (for me takes 30sec importing the file from Google Cloud Storage and 16min using the local file), but anyway is not providing information, just "Locations: " message at the end.

    I have sent all the relevant information regarding this (how to reproduce the issue, possible cause, etc.) to Google Video Intelligence API team so they can have a look.

    I have not found a workaround for local files but you can process the file in GCS through its URL and the analyzeLabels function.