Skip to content

Commit

Permalink
improve sar detection
Browse files Browse the repository at this point in the history
  • Loading branch information
kojirou1994 committed Nov 16, 2023
1 parent 65f116b commit 03496dc
Showing 1 changed file with 15 additions and 7 deletions.
22 changes: 15 additions & 7 deletions Sources/libChoco/ChocoMuxer.swift
Original file line number Diff line number Diff line change
Expand Up @@ -687,13 +687,21 @@ extension ChocoMuxer {
*/
let width = try! (videoTrack["Width"]?.string.flatMap(UInt.init)).unwrap("no width")
let height = try! (videoTrack["Height"]?.string.flatMap(UInt.init)).unwrap("no height")
let dar = try! {
let darString = try (videoTrack["DisplayAspectRatio_String"]?.string).unwrap("no dar")
let errInfo = "invalid dar format: \(darString)"
let parts = try darString.splitTwoPart(":").unwrap()
return try SampleAspectRatio(.init(parts.0).unwrap(errInfo), .init(parts.1).unwrap(errInfo))
}()
let sar = dar.divided(by: SampleAspectRatio(width, height))
let sar: SampleAspectRatio
if videoTrack["PixelAspectRatio"]?.string == "1.000" {
sar = .init(1)
} else {
do {
let darString = try (videoTrack["DisplayAspectRatio_String"]?.string).unwrap("no dar")
let errInfo = "invalid dar format: \(darString)"
let parts = try darString.splitTwoPart(":").unwrap()
let dar = try SampleAspectRatio(.init(parts.0).unwrap(errInfo), .init(parts.1).unwrap(errInfo))

sar = dar.divided(by: SampleAspectRatio(width, height))
} catch {
fatalError("cannot detect sar from dar! error: \(error)")
}
}
let fps = try! {
do {
let num = try (videoTrack["FrameRate_Original_Num"]?.string.flatMap(UInt.init)).unwrap("no framerate num origin")
Expand Down

0 comments on commit 03496dc

Please sign in to comment.