JpegMotionPhotoExtractor: Don't emit an image track with no metadata

The current implementation of `JpegMotionPhotoExtractor.sniff` returns
`true` for any image with Exif data (not just motion photos). Improving
this is tracked by b/324033919. In the meantime, when we 'extract' a
non-motion photo with `JpegMotionPhotoExtractor`, the result is
currently a single empty image track and no video track (since there's
no video, since this isn't a motion photo). This 'empty' image track
is usually used to transmit metadata about the video parts of the
image file (in the form of `MotionPhotoMetadata`), but this metadata is
also (understandably) absent for non-motion photos. Therefore there's
no need to emit this image track at all, and it's clearer to emit no
tracks at all when extracting a non-motion photo using
`JpegMotionPhotoExtractor`.

This change also removes a `TODO` that is misplaced, since there's no
image bytes being emitted here (and never was).

PiperOrigin-RevId: 604688053
This commit is contained in:
ibaker 2024-02-06 10:19:27 -08:00 committed by Copybara-Service
parent c768e60bf2
commit 7ae3d69e00
9 changed files with 14 additions and 64 deletions

View File

@ -202,7 +202,7 @@ import org.checkerframework.checker.nullness.qual.MonotonicNonNull;
if (mp4StartPosition != C.INDEX_UNSET) { if (mp4StartPosition != C.INDEX_UNSET) {
state = STATE_SNIFFING_MOTION_PHOTO_VIDEO; state = STATE_SNIFFING_MOTION_PHOTO_VIDEO;
} else { } else {
endReadingWithImageTrack(); endReading();
} }
} else if ((marker < 0xFFD0 || marker > 0xFFD9) && marker != 0xFF01) { } else if ((marker < 0xFFD0 || marker > 0xFFD9) && marker != 0xFF01) {
state = STATE_READING_SEGMENT_LENGTH; state = STATE_READING_SEGMENT_LENGTH;
@ -242,7 +242,7 @@ import org.checkerframework.checker.nullness.qual.MonotonicNonNull;
input.peekFully( input.peekFully(
scratch.getData(), /* offset= */ 0, /* length= */ 1, /* allowEndOfInput= */ true); scratch.getData(), /* offset= */ 0, /* length= */ 1, /* allowEndOfInput= */ true);
if (!peekedData) { if (!peekedData) {
endReadingWithImageTrack(); endReading();
} else { } else {
input.resetPeekPosition(); input.resetPeekPosition();
if (mp4Extractor == null) { if (mp4Extractor == null) {
@ -257,7 +257,7 @@ import org.checkerframework.checker.nullness.qual.MonotonicNonNull;
new StartOffsetExtractorOutput(mp4StartPosition, checkNotNull(extractorOutput))); new StartOffsetExtractorOutput(mp4StartPosition, checkNotNull(extractorOutput)));
startReadingMotionPhoto(); startReadingMotionPhoto();
} else { } else {
endReadingWithImageTrack(); endReading();
} }
} }
} }
@ -267,21 +267,19 @@ import org.checkerframework.checker.nullness.qual.MonotonicNonNull;
state = STATE_READING_MOTION_PHOTO_VIDEO; state = STATE_READING_MOTION_PHOTO_VIDEO;
} }
private void endReadingWithImageTrack() { private void endReading() {
outputImageTrack();
checkNotNull(extractorOutput).endTracks(); checkNotNull(extractorOutput).endTracks();
extractorOutput.seekMap(new SeekMap.Unseekable(/* durationUs= */ C.TIME_UNSET)); extractorOutput.seekMap(new SeekMap.Unseekable(/* durationUs= */ C.TIME_UNSET));
state = STATE_ENDED; state = STATE_ENDED;
} }
private void outputImageTrack(Metadata.Entry... metadataEntries) { private void outputImageTrack(MotionPhotoMetadata motionPhotoMetadata) {
TrackOutput imageTrackOutput = TrackOutput imageTrackOutput =
checkNotNull(extractorOutput).track(IMAGE_TRACK_ID, C.TRACK_TYPE_IMAGE); checkNotNull(extractorOutput).track(IMAGE_TRACK_ID, C.TRACK_TYPE_IMAGE);
// TODO(b/289989902): Set the rotationDegrees in format so images can be decoded correctly.
imageTrackOutput.format( imageTrackOutput.format(
new Format.Builder() new Format.Builder()
.setContainerMimeType(MimeTypes.IMAGE_JPEG) .setContainerMimeType(MimeTypes.IMAGE_JPEG)
.setMetadata(new Metadata(metadataEntries)) .setMetadata(new Metadata(motionPhotoMetadata))
.build()); .build());
} }

View File

@ -2,11 +2,5 @@ seekMap:
isSeekable = false isSeekable = false
duration = UNSET TIME duration = UNSET TIME
getPosition(0) = [[timeUs=0, position=0]] getPosition(0) = [[timeUs=0, position=0]]
numberOfTracks = 1 numberOfTracks = 0
track 1024:
total output bytes = 0
sample count = 0
format 0:
containerMimeType = image/jpeg
metadata = entries=[]
tracksEnded = true tracksEnded = true

View File

@ -2,11 +2,5 @@ seekMap:
isSeekable = false isSeekable = false
duration = UNSET TIME duration = UNSET TIME
getPosition(0) = [[timeUs=0, position=0]] getPosition(0) = [[timeUs=0, position=0]]
numberOfTracks = 1 numberOfTracks = 0
track 1024:
total output bytes = 0
sample count = 0
format 0:
containerMimeType = image/jpeg
metadata = entries=[]
tracksEnded = true tracksEnded = true

View File

@ -2,11 +2,5 @@ seekMap:
isSeekable = false isSeekable = false
duration = UNSET TIME duration = UNSET TIME
getPosition(0) = [[timeUs=0, position=0]] getPosition(0) = [[timeUs=0, position=0]]
numberOfTracks = 1 numberOfTracks = 0
track 1024:
total output bytes = 0
sample count = 0
format 0:
containerMimeType = image/jpeg
metadata = entries=[]
tracksEnded = true tracksEnded = true

View File

@ -2,11 +2,5 @@ seekMap:
isSeekable = false isSeekable = false
duration = UNSET TIME duration = UNSET TIME
getPosition(0) = [[timeUs=0, position=0]] getPosition(0) = [[timeUs=0, position=0]]
numberOfTracks = 1 numberOfTracks = 0
track 1024:
total output bytes = 0
sample count = 0
format 0:
containerMimeType = image/jpeg
metadata = entries=[]
tracksEnded = true tracksEnded = true

View File

@ -2,11 +2,5 @@ seekMap:
isSeekable = false isSeekable = false
duration = UNSET TIME duration = UNSET TIME
getPosition(0) = [[timeUs=0, position=0]] getPosition(0) = [[timeUs=0, position=0]]
numberOfTracks = 1 numberOfTracks = 0
track 1024:
total output bytes = 0
sample count = 0
format 0:
containerMimeType = image/jpeg
metadata = entries=[]
tracksEnded = true tracksEnded = true

View File

@ -2,11 +2,5 @@ seekMap:
isSeekable = false isSeekable = false
duration = UNSET TIME duration = UNSET TIME
getPosition(0) = [[timeUs=0, position=0]] getPosition(0) = [[timeUs=0, position=0]]
numberOfTracks = 1 numberOfTracks = 0
track 1024:
total output bytes = 0
sample count = 0
format 0:
containerMimeType = image/jpeg
metadata = entries=[]
tracksEnded = true tracksEnded = true

View File

@ -2,11 +2,5 @@ seekMap:
isSeekable = false isSeekable = false
duration = UNSET TIME duration = UNSET TIME
getPosition(0) = [[timeUs=0, position=0]] getPosition(0) = [[timeUs=0, position=0]]
numberOfTracks = 1 numberOfTracks = 0
track 1024:
total output bytes = 0
sample count = 0
format 0:
containerMimeType = image/jpeg
metadata = entries=[]
tracksEnded = true tracksEnded = true

View File

@ -2,11 +2,5 @@ seekMap:
isSeekable = false isSeekable = false
duration = UNSET TIME duration = UNSET TIME
getPosition(0) = [[timeUs=0, position=0]] getPosition(0) = [[timeUs=0, position=0]]
numberOfTracks = 1 numberOfTracks = 0
track 1024:
total output bytes = 0
sample count = 0
format 0:
containerMimeType = image/jpeg
metadata = entries=[]
tracksEnded = true tracksEnded = true