#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 - 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 ## <a id="v1.12.3"></a>[v1.12.3] - 2025-02-06
### Added ### Added

View file

@ -354,20 +354,23 @@ object MultiPage {
} }
private fun getEmbedVideoInfo(context: Context, uri: Uri, videoOffset: Long, videoSize: Long): MediaFormat? { private fun getEmbedVideoInfo(context: Context, uri: Uri, videoOffset: Long, videoSize: Long): MediaFormat? {
var format: MediaFormat? = null
val extractor = MediaExtractor() val extractor = MediaExtractor()
var pfd: ParcelFileDescriptor? = null var pfd: ParcelFileDescriptor? = null
try { try {
pfd = context.contentResolver.openFileDescriptor(uri, "r") pfd = context.contentResolver.openFileDescriptor(uri, "r")
pfd?.fileDescriptor?.let { fd -> pfd?.fileDescriptor?.let { fd ->
extractor.setDataSource(fd, videoOffset, videoSize) extractor.setDataSource(fd, videoOffset, videoSize)
if (extractor.trackCount > 0) { // video track may be after an audio track
// only consider the first track to represent the appended video for (trackIndex in 0 until extractor.trackCount) {
val trackIndex = 0
try { 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) { } 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() extractor.release()
pfd?.close() pfd?.close()
} }
return format return null
} }
fun getMotionPhotoVideoSizing(context: Context, uri: Uri, mimeType: String, sizeBytes: Long): Pair<Long, Long>? { fun getMotionPhotoVideoSizing(context: Context, uri: Uri, mimeType: String, sizeBytes: Long): Pair<Long, Long>? {