use of androidx.media3.extractor.metadata.mp4.SlowMotionData in project media by androidx.
the class SegmentSpeedProvider method extractSlowMotionSegments.
private static ImmutableList<Segment> extractSlowMotionSegments(Format format) {
List<Segment> segments = new ArrayList<>();
@Nullable Metadata metadata = format.metadata;
if (metadata != null) {
for (int i = 0; i < metadata.length(); i++) {
Metadata.Entry entry = metadata.get(i);
if (entry instanceof SlowMotionData) {
segments.addAll(((SlowMotionData) entry).segments);
}
}
}
return ImmutableList.sortedCopyOf(BY_START_THEN_END_THEN_DIVISOR, segments);
}
use of androidx.media3.extractor.metadata.mp4.SlowMotionData in project ExoPlayer by google.
the class MetadataRetrieverTest method retrieveMetadata_sefSlowMotion_outputsExpectedMetadata.
@Test
public void retrieveMetadata_sefSlowMotion_outputsExpectedMetadata() throws Exception {
MediaItem mediaItem = MediaItem.fromUri(Uri.parse("asset://android_asset/media/mp4/sample_sef_slow_motion.mp4"));
SmtaMetadataEntry expectedSmtaEntry = new SmtaMetadataEntry(/* captureFrameRate= */
240, /* svcTemporalLayerCount= */
4);
List<SlowMotionData.Segment> segments = new ArrayList<>();
segments.add(new SlowMotionData.Segment(/* startTimeMs= */
88, /* endTimeMs= */
879, /* speedDivisor= */
2));
segments.add(new SlowMotionData.Segment(/* startTimeMs= */
1255, /* endTimeMs= */
1970, /* speedDivisor= */
8));
SlowMotionData expectedSlowMotionData = new SlowMotionData(segments);
MdtaMetadataEntry expectedMdtaEntry = new MdtaMetadataEntry(KEY_ANDROID_CAPTURE_FPS, /* value= */
new byte[] { 67, 112, 0, 0 }, /* localeIndicator= */
0, /* typeIndicator= */
23);
ListenableFuture<TrackGroupArray> trackGroupsFuture = retrieveMetadata(context, mediaItem, clock);
ShadowLooper.idleMainLooper();
TrackGroupArray trackGroups = trackGroupsFuture.get(TEST_TIMEOUT_SEC, TimeUnit.SECONDS);
// Video and audio
assertThat(trackGroups.length).isEqualTo(2);
// Audio
assertThat(trackGroups.get(0).getFormat(0).metadata.length()).isEqualTo(2);
assertThat(trackGroups.get(0).getFormat(0).metadata.get(0)).isEqualTo(expectedSmtaEntry);
assertThat(trackGroups.get(0).getFormat(0).metadata.get(1)).isEqualTo(expectedSlowMotionData);
// Video
assertThat(trackGroups.get(1).getFormat(0).metadata.length()).isEqualTo(3);
assertThat(trackGroups.get(1).getFormat(0).metadata.get(0)).isEqualTo(expectedMdtaEntry);
assertThat(trackGroups.get(1).getFormat(0).metadata.get(1)).isEqualTo(expectedSmtaEntry);
assertThat(trackGroups.get(1).getFormat(0).metadata.get(2)).isEqualTo(expectedSlowMotionData);
}
use of androidx.media3.extractor.metadata.mp4.SlowMotionData in project ExoPlayer by google.
the class SefSlowMotionFlattenerTest method createSefSlowMotionFormat.
/**
* Creates a {@link Format} for an SEF slow motion video track.
*/
private static Format createSefSlowMotionFormat(int captureFrameRate, int inputMaxLayer, List<SlowMotionData.Segment> segments) {
SmtaMetadataEntry smtaMetadataEntry = new SmtaMetadataEntry(captureFrameRate, /* svcTemporalLayerCount= */
inputMaxLayer + 1);
SlowMotionData slowMotionData = new SlowMotionData(segments);
Metadata metadata = new Metadata(smtaMetadataEntry, slowMotionData);
return new Format.Builder().setSampleMimeType(MimeTypes.VIDEO_H264).setMetadata(metadata).build();
}
use of androidx.media3.extractor.metadata.mp4.SlowMotionData in project ExoPlayer by google.
the class SegmentSpeedProviderTest method getSpeed_returnsCorrectSpeed.
@Test
public void getSpeed_returnsCorrectSpeed() {
List<Segment> segments = ImmutableList.of(new Segment(/* startTimeMs= */
500, /* endTimeMs= */
1000, /* speedDivisor= */
8), new Segment(/* startTimeMs= */
1500, /* endTimeMs= */
2000, /* speedDivisor= */
4), new Segment(/* startTimeMs= */
2000, /* endTimeMs= */
2500, /* speedDivisor= */
2));
SegmentSpeedProvider provider = new SegmentSpeedProvider(new Format.Builder().setMetadata(new Metadata(new SlowMotionData(segments), SMTA_SPEED_8)).build());
assertThat(provider.getSpeed(Util.msToUs(0))).isEqualTo(8);
assertThat(provider.getSpeed(Util.msToUs(500))).isEqualTo(1);
assertThat(provider.getSpeed(Util.msToUs(800))).isEqualTo(1);
assertThat(provider.getSpeed(Util.msToUs(1000))).isEqualTo(8);
assertThat(provider.getSpeed(Util.msToUs(1250))).isEqualTo(8);
assertThat(provider.getSpeed(Util.msToUs(1500))).isEqualTo(2);
assertThat(provider.getSpeed(Util.msToUs(1650))).isEqualTo(2);
assertThat(provider.getSpeed(Util.msToUs(2000))).isEqualTo(4);
assertThat(provider.getSpeed(Util.msToUs(2400))).isEqualTo(4);
assertThat(provider.getSpeed(Util.msToUs(2500))).isEqualTo(8);
assertThat(provider.getSpeed(Util.msToUs(3000))).isEqualTo(8);
}
use of androidx.media3.extractor.metadata.mp4.SlowMotionData in project media by androidx.
the class SegmentSpeedProviderTest method getSpeed_returnsCorrectSpeed.
@Test
public void getSpeed_returnsCorrectSpeed() {
List<Segment> segments = ImmutableList.of(new Segment(/* startTimeMs= */
500, /* endTimeMs= */
1000, /* speedDivisor= */
8), new Segment(/* startTimeMs= */
1500, /* endTimeMs= */
2000, /* speedDivisor= */
4), new Segment(/* startTimeMs= */
2000, /* endTimeMs= */
2500, /* speedDivisor= */
2));
SegmentSpeedProvider provider = new SegmentSpeedProvider(new Format.Builder().setMetadata(new Metadata(new SlowMotionData(segments), SMTA_SPEED_8)).build());
assertThat(provider.getSpeed(Util.msToUs(0))).isEqualTo(8);
assertThat(provider.getSpeed(Util.msToUs(500))).isEqualTo(1);
assertThat(provider.getSpeed(Util.msToUs(800))).isEqualTo(1);
assertThat(provider.getSpeed(Util.msToUs(1000))).isEqualTo(8);
assertThat(provider.getSpeed(Util.msToUs(1250))).isEqualTo(8);
assertThat(provider.getSpeed(Util.msToUs(1500))).isEqualTo(2);
assertThat(provider.getSpeed(Util.msToUs(1650))).isEqualTo(2);
assertThat(provider.getSpeed(Util.msToUs(2000))).isEqualTo(4);
assertThat(provider.getSpeed(Util.msToUs(2400))).isEqualTo(4);
assertThat(provider.getSpeed(Util.msToUs(2500))).isEqualTo(8);
assertThat(provider.getSpeed(Util.msToUs(3000))).isEqualTo(8);
}
Aggregations