Search in sources :

Example 6 with SlowMotionData

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);
}
Also used : SlowMotionData(androidx.media3.extractor.metadata.mp4.SlowMotionData) ArrayList(java.util.ArrayList) Metadata(androidx.media3.common.Metadata) Segment(androidx.media3.extractor.metadata.mp4.SlowMotionData.Segment) Nullable(androidx.annotation.Nullable)

Example 7 with SlowMotionData

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);
}
Also used : SmtaMetadataEntry(com.google.android.exoplayer2.metadata.mp4.SmtaMetadataEntry) SlowMotionData(com.google.android.exoplayer2.metadata.mp4.SlowMotionData) ArrayList(java.util.ArrayList) TrackGroupArray(com.google.android.exoplayer2.source.TrackGroupArray) MdtaMetadataEntry(com.google.android.exoplayer2.metadata.mp4.MdtaMetadataEntry) Test(org.junit.Test)

Example 8 with SlowMotionData

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();
}
Also used : SmtaMetadataEntry(com.google.android.exoplayer2.metadata.mp4.SmtaMetadataEntry) Format(com.google.android.exoplayer2.Format) SlowMotionData(com.google.android.exoplayer2.metadata.mp4.SlowMotionData) Metadata(com.google.android.exoplayer2.metadata.Metadata)

Example 9 with SlowMotionData

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);
}
Also used : Format(com.google.android.exoplayer2.Format) SlowMotionData(com.google.android.exoplayer2.metadata.mp4.SlowMotionData) Metadata(com.google.android.exoplayer2.metadata.Metadata) Segment(com.google.android.exoplayer2.metadata.mp4.SlowMotionData.Segment) Test(org.junit.Test)

Example 10 with SlowMotionData

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);
}
Also used : Format(androidx.media3.common.Format) SlowMotionData(androidx.media3.extractor.metadata.mp4.SlowMotionData) Metadata(androidx.media3.common.Metadata) Segment(androidx.media3.extractor.metadata.mp4.SlowMotionData.Segment) Test(org.junit.Test)

Aggregations

SlowMotionData (androidx.media3.extractor.metadata.mp4.SlowMotionData)6 SlowMotionData (com.google.android.exoplayer2.metadata.mp4.SlowMotionData)6 ArrayList (java.util.ArrayList)6 Test (org.junit.Test)6 Metadata (androidx.media3.common.Metadata)4 Metadata (com.google.android.exoplayer2.metadata.Metadata)4 SmtaMetadataEntry (androidx.media3.extractor.metadata.mp4.SmtaMetadataEntry)3 SmtaMetadataEntry (com.google.android.exoplayer2.metadata.mp4.SmtaMetadataEntry)3 Parcel (android.os.Parcel)2 Nullable (androidx.annotation.Nullable)2 Format (androidx.media3.common.Format)2 Segment (androidx.media3.extractor.metadata.mp4.SlowMotionData.Segment)2 Format (com.google.android.exoplayer2.Format)2 Segment (com.google.android.exoplayer2.metadata.mp4.SlowMotionData.Segment)2 MediaItem (androidx.media3.common.MediaItem)1 TrackGroupArray (androidx.media3.common.TrackGroupArray)1 MdtaMetadataEntry (androidx.media3.extractor.metadata.mp4.MdtaMetadataEntry)1 MdtaMetadataEntry (com.google.android.exoplayer2.metadata.mp4.MdtaMetadataEntry)1 TrackGroupArray (com.google.android.exoplayer2.source.TrackGroupArray)1