Terjemahan disediakan oleh mesin penerjemah. Jika konten terjemahan yang diberikan bertentangan dengan versi bahasa Inggris aslinya, utamakan versi bahasa Inggris.
Prosedur berikut menunjukkan cara mendeteksi segmen isyarat teknis dan segmen deteksi sorotan dalam video yang disimpan dalam bucket Amazon S3. Prosedur ini juga menunjukkan cara memfilter segmen yang terdeteksi berdasarkan kepercayaan yang dimiliki Amazon Rekognition Video tentang keakuratan deteksi.
Contoh meluas pada kode di Menganalisis video yang disimpan di bucket Amazon S3 dengan Java atau Python (SDK) yang menggunakan antrean Amazon Simple Queue Service untuk mendapatkan status penyelesaian permintaan analisis video.
Untuk mendeteksi segmen dalam video yang disimpan dalam bucket Amazon S3 (SDK)
-
Lakukan Menganalisis video yang disimpan di bucket Amazon S3 dengan Java atau Python (SDK).
-
Tambahkan berikut ke kode yang Anda gunakan pada langkah 1.
-
Tambahkan impor berikut.
import com.amazonaws.services.rekognition.model.GetSegmentDetectionRequest; import com.amazonaws.services.rekognition.model.GetSegmentDetectionResult; import com.amazonaws.services.rekognition.model.SegmentDetection; import com.amazonaws.services.rekognition.model.SegmentType; import com.amazonaws.services.rekognition.model.SegmentTypeInfo; import com.amazonaws.services.rekognition.model.ShotSegment; import com.amazonaws.services.rekognition.model.StartSegmentDetectionFilters; import com.amazonaws.services.rekognition.model.StartSegmentDetectionRequest; import com.amazonaws.services.rekognition.model.StartSegmentDetectionResult; import com.amazonaws.services.rekognition.model.StartShotDetectionFilter; import com.amazonaws.services.rekognition.model.StartTechnicalCueDetectionFilter; import com.amazonaws.services.rekognition.model.TechnicalCueSegment; import com.amazonaws.services.rekognition.model.AudioMetadata;
-
Tambahkan kode berikut ke kelas
VideoDetect
.//Copyright 2020 Amazon.com, Inc. or its affiliates. All Rights Reserved. //PDX-License-Identifier: MIT-0 (For details, see https://github.com/awsdocs/amazon-rekognition-developer-guide/blob/master/LICENSE-SAMPLECODE.) private static void StartSegmentDetection(String bucket, String video) throws Exception{ NotificationChannel channel= new NotificationChannel() .withSNSTopicArn(snsTopicArn) .withRoleArn(roleArn); float minTechnicalCueConfidence = 80F; float minShotConfidence = 80F; StartSegmentDetectionRequest req = new StartSegmentDetectionRequest() .withVideo(new Video() .withS3Object(new S3Object() .withBucket(bucket) .withName(video))) .withSegmentTypes("TECHNICAL_CUE" , "SHOT") .withFilters(new StartSegmentDetectionFilters() .withTechnicalCueFilter(new StartTechnicalCueDetectionFilter() .withMinSegmentConfidence(minTechnicalCueConfidence)) .withShotFilter(new StartShotDetectionFilter() .withMinSegmentConfidence(minShotConfidence))) .withJobTag("DetectingVideoSegments") .withNotificationChannel(channel); StartSegmentDetectionResult startLabelDetectionResult = rek.startSegmentDetection(req); startJobId=startLabelDetectionResult.getJobId(); } private static void GetSegmentDetectionResults() throws Exception{ int maxResults=10; String paginationToken=null; GetSegmentDetectionResult segmentDetectionResult=null; Boolean firstTime=true; do { if (segmentDetectionResult !=null){ paginationToken = segmentDetectionResult.getNextToken(); } GetSegmentDetectionRequest segmentDetectionRequest= new GetSegmentDetectionRequest() .withJobId(startJobId) .withMaxResults(maxResults) .withNextToken(paginationToken); segmentDetectionResult = rek.getSegmentDetection(segmentDetectionRequest); if(firstTime) { System.out.println("\nStatus\n------"); System.out.println(segmentDetectionResult.getJobStatus()); System.out.println("\nRequested features\n------------------"); for (SegmentTypeInfo requestedFeatures : segmentDetectionResult.getSelectedSegmentTypes()) { System.out.println(requestedFeatures.getType()); } int count=1; List<VideoMetadata> videoMetaDataList = segmentDetectionResult.getVideoMetadata(); System.out.println("\nVideo Streams\n-------------"); for (VideoMetadata videoMetaData: videoMetaDataList) { System.out.println("Stream: " + count++); System.out.println("\tFormat: " + videoMetaData.getFormat()); System.out.println("\tCodec: " + videoMetaData.getCodec()); System.out.println("\tDuration: " + videoMetaData.getDurationMillis()); System.out.println("\tFrameRate: " + videoMetaData.getFrameRate()); } List<AudioMetadata> audioMetaDataList = segmentDetectionResult.getAudioMetadata(); System.out.println("\nAudio streams\n-------------"); count=1; for (AudioMetadata audioMetaData: audioMetaDataList) { System.out.println("Stream: " + count++); System.out.println("\tSample Rate: " + audioMetaData.getSampleRate()); System.out.println("\tCodec: " + audioMetaData.getCodec()); System.out.println("\tDuration: " + audioMetaData.getDurationMillis()); System.out.println("\tNumber of Channels: " + audioMetaData.getNumberOfChannels()); } System.out.println("\nSegments\n--------"); firstTime=false; } //Show segment information List<SegmentDetection> detectedSegments= segmentDetectionResult.getSegments(); for (SegmentDetection detectedSegment: detectedSegments) { if (detectedSegment.getType().contains(SegmentType.TECHNICAL_CUE.toString())) { System.out.println("Technical Cue"); TechnicalCueSegment segmentCue=detectedSegment.getTechnicalCueSegment(); System.out.println("\tType: " + segmentCue.getType()); System.out.println("\tConfidence: " + segmentCue.getConfidence().toString()); } if (detectedSegment.getType().contains(SegmentType.SHOT.toString())) { System.out.println("Shot"); ShotSegment segmentShot=detectedSegment.getShotSegment(); System.out.println("\tIndex " + segmentShot.getIndex()); System.out.println("\tConfidence: " + segmentShot.getConfidence().toString()); } long seconds=detectedSegment.getDurationMillis(); System.out.println("\tDuration : " + Long.toString(seconds) + " milliseconds"); System.out.println("\tStart time code: " + detectedSegment.getStartTimecodeSMPTE()); System.out.println("\tEnd time code: " + detectedSegment.getEndTimecodeSMPTE()); System.out.println("\tDuration time code: " + detectedSegment.getDurationSMPTE()); System.out.println(); } } while (segmentDetectionResult !=null && segmentDetectionResult.getNextToken() != null); }
-
Dalam fungsi
main
, ganti baris:StartLabelDetection(amzn-s3-demo-bucket, video); if (GetSQSMessageSuccess()==true) GetLabelDetectionResults();
dengan:
StartSegmentDetection(amzn-s3-demo-bucket, video); if (GetSQSMessageSuccess()==true) GetSegmentDetectionResults();
catatan
Jika Anda sudah menjalankan contoh video selain Menganalisis video yang disimpan di bucket Amazon S3 dengan Java atau Python (SDK), kode yang akan diganti mungkin berbeda.
-
Jalankan kode tersebut. Informasi tentang segmen yang terdeteksi dalam video input akan ditampilkan.