Skip to content

Commit 0009c2a

Browse files
authored
Merge pull request #908 from IgorFedorchuk/fix_infinity_crash
Fix crash in KSPlayer when reading video rotation from FFmpeg display matrix metadata.
2 parents 2c9d413 + 5324590 commit 0009c2a

1 file changed

Lines changed: 8 additions & 1 deletion

File tree

Sources/KSPlayer/MEPlayer/FFmpegAssetTrack.swift

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -168,7 +168,14 @@ public class FFmpegAssetTrack: MediaPlayerTrack {
168168
dovi = sideData.data.withMemoryRebound(to: DOVIDecoderConfigurationRecord.self, capacity: 1) { $0 }.pointee
169169
} else if sideData.type == AV_PKT_DATA_DISPLAYMATRIX {
170170
let matrix = sideData.data.withMemoryRebound(to: Int32.self, capacity: 1) { $0 }
171-
rotation = Int16(Int(-av_display_rotation_get(matrix)) % 360)
171+
let rawRotation = -av_display_rotation_get(matrix)
172+
if rawRotation.isFinite {
173+
let degrees = Int(rawRotation.rounded())
174+
let normalized = ((degrees % 360) + 360) % 360
175+
rotation = Int16(normalized)
176+
} else {
177+
rotation = 0
178+
}
172179
}
173180
}
174181
}

0 commit comments

Comments
 (0)