Search in sources :

Example 11 with MotionPhotoMetadata

use of androidx.media3.extractor.metadata.mp4.MotionPhotoMetadata in project media by androidx.

the class MotionPhotoDescriptionTest method getMotionPhotoMetadata_withPrimaryAndSecondaryItemSharingData_returnsPrimaryItemAsPhotoAndVideo.

@Test
public void getMotionPhotoMetadata_withPrimaryAndSecondaryItemSharingData_returnsPrimaryItemAsPhotoAndVideo() {
    // Theoretical example of an HEIF file that has both an image and a video represented in the
    // same file, which looks like an MP4.
    MotionPhotoDescription motionPhotoDescription = new MotionPhotoDescription(TEST_PRESENTATION_TIMESTAMP_US, ImmutableList.of(new MotionPhotoDescription.ContainerItem(MimeTypes.VIDEO_MP4, "Primary", /* length= */
    0, TEST_MOTION_PHOTO_PHOTO_PADDING_BYTES), new MotionPhotoDescription.ContainerItem(MimeTypes.VIDEO_MP4, "MotionPhoto", /* length= */
    0, /* padding= */
    0)));
    @Nullable MotionPhotoMetadata metadata = motionPhotoDescription.getMotionPhotoMetadata(TEST_MOTION_PHOTO_LENGTH_BYTES);
    assertThat(metadata.photoStartPosition).isEqualTo(0);
    assertThat(metadata.photoSize).isEqualTo(TEST_MOTION_PHOTO_LENGTH_BYTES - TEST_MOTION_PHOTO_PHOTO_PADDING_BYTES);
    assertThat(metadata.photoPresentationTimestampUs).isEqualTo(TEST_PRESENTATION_TIMESTAMP_US);
    assertThat(metadata.videoStartPosition).isEqualTo(0);
    assertThat(metadata.videoSize).isEqualTo(TEST_MOTION_PHOTO_LENGTH_BYTES - TEST_MOTION_PHOTO_PHOTO_PADDING_BYTES);
}
Also used : MotionPhotoMetadata(androidx.media3.extractor.metadata.mp4.MotionPhotoMetadata) Nullable(androidx.annotation.Nullable) Test(org.junit.Test)

Example 12 with MotionPhotoMetadata

use of androidx.media3.extractor.metadata.mp4.MotionPhotoMetadata in project media by androidx.

the class MotionPhotoDescriptionTest method getMotionPhotoMetadata_withOnlyPrimaryItem_returnsNull.

@Test
public void getMotionPhotoMetadata_withOnlyPrimaryItem_returnsNull() {
    MotionPhotoDescription motionPhotoDescription = new MotionPhotoDescription(TEST_PRESENTATION_TIMESTAMP_US, ImmutableList.of(new MotionPhotoDescription.ContainerItem(MimeTypes.VIDEO_MP4, "Primary", /* length= */
    0, TEST_MOTION_PHOTO_PHOTO_PADDING_BYTES)));
    @Nullable MotionPhotoMetadata metadata = motionPhotoDescription.getMotionPhotoMetadata(TEST_MOTION_PHOTO_LENGTH_BYTES);
    assertThat(metadata).isNull();
}
Also used : MotionPhotoMetadata(androidx.media3.extractor.metadata.mp4.MotionPhotoMetadata) Nullable(androidx.annotation.Nullable) Test(org.junit.Test)

Example 13 with MotionPhotoMetadata

use of androidx.media3.extractor.metadata.mp4.MotionPhotoMetadata in project media by androidx.

the class MetadataRetrieverTest method retrieveMetadata_heicMotionPhoto_outputsExpectedMetadata.

@Test
public void retrieveMetadata_heicMotionPhoto_outputsExpectedMetadata() throws Exception {
    MediaItem mediaItem = MediaItem.fromUri(Uri.parse("asset://android_asset/media/mp4/sample_MP.heic"));
    MotionPhotoMetadata expectedMotionPhotoMetadata = new MotionPhotoMetadata(/* photoStartPosition= */
    0, /* photoSize= */
    28_853, /* photoPresentationTimestampUs= */
    C.TIME_UNSET, /* videoStartPosition= */
    28_869, /* videoSize= */
    28_803);
    ListenableFuture<TrackGroupArray> trackGroupsFuture = retrieveMetadata(context, mediaItem, clock);
    ShadowLooper.idleMainLooper();
    TrackGroupArray trackGroups = trackGroupsFuture.get(TEST_TIMEOUT_SEC, TimeUnit.SECONDS);
    assertThat(trackGroups.length).isEqualTo(1);
    assertThat(trackGroups.get(0).length).isEqualTo(1);
    assertThat(trackGroups.get(0).getFormat(0).metadata.length()).isEqualTo(1);
    assertThat(trackGroups.get(0).getFormat(0).metadata.get(0)).isEqualTo(expectedMotionPhotoMetadata);
}
Also used : MotionPhotoMetadata(androidx.media3.extractor.metadata.mp4.MotionPhotoMetadata) MediaItem(androidx.media3.common.MediaItem) TrackGroupArray(androidx.media3.common.TrackGroupArray) Test(org.junit.Test)

Aggregations

Nullable (androidx.annotation.Nullable)11 Test (org.junit.Test)10 MotionPhotoMetadata (androidx.media3.extractor.metadata.mp4.MotionPhotoMetadata)6 MotionPhotoMetadata (com.google.android.exoplayer2.metadata.mp4.MotionPhotoMetadata)6 Format (androidx.media3.common.Format)1 MediaItem (androidx.media3.common.MediaItem)1 Metadata (androidx.media3.common.Metadata)1 TrackGroupArray (androidx.media3.common.TrackGroupArray)1 ParsableByteArray (androidx.media3.common.util.ParsableByteArray)1 ExtractorOutput (androidx.media3.extractor.ExtractorOutput)1 SeekMap (androidx.media3.extractor.SeekMap)1 TrackOutput (androidx.media3.extractor.TrackOutput)1 Format (com.google.android.exoplayer2.Format)1 ExtractorOutput (com.google.android.exoplayer2.extractor.ExtractorOutput)1 SeekMap (com.google.android.exoplayer2.extractor.SeekMap)1 TrackOutput (com.google.android.exoplayer2.extractor.TrackOutput)1 Metadata (com.google.android.exoplayer2.metadata.Metadata)1 TrackGroupArray (com.google.android.exoplayer2.source.TrackGroupArray)1