#1424 fixed opening embedded video when video track is not the first one

This commit is contained in:
Thibault Deckers 2025-02-09 12:42:26 +01:00
parent 026cfebd49
commit de0cfb1431
2 changed files with 14 additions and 7 deletions

View file

@ -8,6 +8,10 @@ All notable changes to this project will be documented in this file.
- support for Samsung HEIC motion photos embedding video in sefd box
### Fixed
- opening motion photo embedded video when video track is not the first one
## <a id="v1.12.3"></a>[v1.12.3] - 2025-02-06
### Added

View file

@ -354,20 +354,23 @@ object MultiPage {
}
private fun getEmbedVideoInfo(context: Context, uri: Uri, videoOffset: Long, videoSize: Long): MediaFormat? {
var format: MediaFormat? = null
val extractor = MediaExtractor()
var pfd: ParcelFileDescriptor? = null
try {
pfd = context.contentResolver.openFileDescriptor(uri, "r")
pfd?.fileDescriptor?.let { fd ->
extractor.setDataSource(fd, videoOffset, videoSize)
if (extractor.trackCount > 0) {
// only consider the first track to represent the appended video
val trackIndex = 0
// video track may be after an audio track
for (trackIndex in 0 until extractor.trackCount) {
try {
format = extractor.getTrackFormat(trackIndex)
val format = extractor.getTrackFormat(trackIndex)
format.getString(MediaFormat.KEY_MIME)?.let {
if (MimeTypes.isVideo(it)) {
return format
}
}
} catch (e: Exception) {
Log.w(LOG_TAG, "failed to get motion photo track information for uri=$uri, track num=$trackIndex", e)
Log.w(LOG_TAG, "failed to get track information for uri=$uri, track num=$trackIndex", e)
}
}
}
@ -377,7 +380,7 @@ object MultiPage {
extractor.release()
pfd?.close()
}
return format
return null
}
fun getMotionPhotoVideoSizing(context: Context, uri: Uri, mimeType: String, sizeBytes: Long): Pair<Long, Long>? {