Search in sources :

Example 1 with GetContentModerationRequest

use of software.amazon.awssdk.services.rekognition.model.GetContentModerationRequest in project aws-doc-sdk-examples by awsdocs.

the class VideoDetectInappropriate method GetModResults.

public static void GetModResults(RekognitionClient rekClient) {
    try {
        String paginationToken = null;
        GetContentModerationResponse modDetectionResponse = null;
        Boolean finished = false;
        String status = "";
        int yy = 0;
        do {
            if (modDetectionResponse != null)
                paginationToken = modDetectionResponse.nextToken();
            GetContentModerationRequest modRequest = GetContentModerationRequest.builder().jobId(startJobId).nextToken(paginationToken).maxResults(10).build();
            // Wait until the job succeeds
            while (!finished) {
                modDetectionResponse = rekClient.getContentModeration(modRequest);
                status = modDetectionResponse.jobStatusAsString();
                if (status.compareTo("SUCCEEDED") == 0)
                    finished = true;
                else {
                    System.out.println(yy + " status is: " + status);
                    Thread.sleep(1000);
                }
                yy++;
            }
            finished = false;
            // Proceed when the job is done - otherwise VideoMetadata is null
            VideoMetadata videoMetaData = modDetectionResponse.videoMetadata();
            System.out.println("Format: " + videoMetaData.format());
            System.out.println("Codec: " + videoMetaData.codec());
            System.out.println("Duration: " + videoMetaData.durationMillis());
            System.out.println("FrameRate: " + videoMetaData.frameRate());
            System.out.println("Job");
            List<ContentModerationDetection> mods = modDetectionResponse.moderationLabels();
            for (ContentModerationDetection mod : mods) {
                long seconds = mod.timestamp() / 1000;
                System.out.print("Mod label: " + seconds + " ");
                System.out.println(mod.moderationLabel().toString());
                System.out.println();
            }
        } while (modDetectionResponse != null && modDetectionResponse.nextToken() != null);
    } catch (RekognitionException | InterruptedException e) {
        System.out.println(e.getMessage());
        System.exit(1);
    }
}
Also used : GetContentModerationResponse(software.amazon.awssdk.services.rekognition.model.GetContentModerationResponse) RekognitionException(software.amazon.awssdk.services.rekognition.model.RekognitionException) GetContentModerationRequest(software.amazon.awssdk.services.rekognition.model.GetContentModerationRequest) ContentModerationDetection(software.amazon.awssdk.services.rekognition.model.ContentModerationDetection) VideoMetadata(software.amazon.awssdk.services.rekognition.model.VideoMetadata)

Aggregations

ContentModerationDetection (software.amazon.awssdk.services.rekognition.model.ContentModerationDetection)1 GetContentModerationRequest (software.amazon.awssdk.services.rekognition.model.GetContentModerationRequest)1 GetContentModerationResponse (software.amazon.awssdk.services.rekognition.model.GetContentModerationResponse)1 RekognitionException (software.amazon.awssdk.services.rekognition.model.RekognitionException)1 VideoMetadata (software.amazon.awssdk.services.rekognition.model.VideoMetadata)1