Search in sources :

Example 1 with GetSegmentDetectionResponse

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

the class VideoDetectSegment method getSegmentResults.

public static void getSegmentResults(RekognitionClient rekClient) {
    try {
        String paginationToken = null;
        GetSegmentDetectionResponse segDetectionResponse = null;
        Boolean finished = false;
        String status = "";
        int yy = 0;
        do {
            if (segDetectionResponse != null)
                paginationToken = segDetectionResponse.nextToken();
            GetSegmentDetectionRequest recognitionRequest = GetSegmentDetectionRequest.builder().jobId(startJobId).nextToken(paginationToken).maxResults(10).build();
            // Wait until the job succeeds
            while (!finished) {
                segDetectionResponse = rekClient.getSegmentDetection(recognitionRequest);
                status = segDetectionResponse.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
            List<VideoMetadata> videoMetaData = segDetectionResponse.videoMetadata();
            for (VideoMetadata metaData : videoMetaData) {
                System.out.println("Format: " + metaData.format());
                System.out.println("Codec: " + metaData.codec());
                System.out.println("Duration: " + metaData.durationMillis());
                System.out.println("FrameRate: " + metaData.frameRate());
                System.out.println("Job");
            }
            List<SegmentDetection> detectedSegment = segDetectionResponse.segments();
            String type = detectedSegment.get(0).type().toString();
            if (type.contains(SegmentType.TECHNICAL_CUE.toString())) {
                System.out.println("Technical Cue");
                TechnicalCueSegment segmentCue = detectedSegment.get(0).technicalCueSegment();
                System.out.println("\tType: " + segmentCue.type());
                System.out.println("\tConfidence: " + segmentCue.confidence().toString());
            }
            if (type.contains(SegmentType.SHOT.toString())) {
                System.out.println("Shot");
                ShotSegment segmentShot = detectedSegment.get(0).shotSegment();
                System.out.println("\tIndex " + segmentShot.index());
                System.out.println("\tConfidence: " + segmentShot.confidence().toString());
            }
            long seconds = detectedSegment.get(0).durationMillis();
            System.out.println("\tDuration : " + Long.toString(seconds) + " milliseconds");
            System.out.println("\tStart time code: " + detectedSegment.get(0).startTimecodeSMPTE());
            System.out.println("\tEnd time code: " + detectedSegment.get(0).endTimecodeSMPTE());
            System.out.println("\tDuration time code: " + detectedSegment.get(0).durationSMPTE());
            System.out.println();
        } while (segDetectionResponse != null && segDetectionResponse.nextToken() != null);
    } catch (RekognitionException | InterruptedException e) {
        System.out.println(e.getMessage());
        System.exit(1);
    }
}
Also used : GetSegmentDetectionResponse(software.amazon.awssdk.services.rekognition.model.GetSegmentDetectionResponse) RekognitionException(software.amazon.awssdk.services.rekognition.model.RekognitionException) VideoMetadata(software.amazon.awssdk.services.rekognition.model.VideoMetadata) SegmentDetection(software.amazon.awssdk.services.rekognition.model.SegmentDetection) TechnicalCueSegment(software.amazon.awssdk.services.rekognition.model.TechnicalCueSegment) ShotSegment(software.amazon.awssdk.services.rekognition.model.ShotSegment) GetSegmentDetectionRequest(software.amazon.awssdk.services.rekognition.model.GetSegmentDetectionRequest)

Aggregations

GetSegmentDetectionRequest (software.amazon.awssdk.services.rekognition.model.GetSegmentDetectionRequest)1 GetSegmentDetectionResponse (software.amazon.awssdk.services.rekognition.model.GetSegmentDetectionResponse)1 RekognitionException (software.amazon.awssdk.services.rekognition.model.RekognitionException)1 SegmentDetection (software.amazon.awssdk.services.rekognition.model.SegmentDetection)1 ShotSegment (software.amazon.awssdk.services.rekognition.model.ShotSegment)1 TechnicalCueSegment (software.amazon.awssdk.services.rekognition.model.TechnicalCueSegment)1 VideoMetadata (software.amazon.awssdk.services.rekognition.model.VideoMetadata)1