Skip to content

Commit

Permalink
#579 解决 nominalFrameRate 不对的问题
Browse files Browse the repository at this point in the history
  • Loading branch information
kingslay committed Oct 6, 2023
1 parent 8701fe7 commit bd60377
Showing 1 changed file with 14 additions and 13 deletions.
27 changes: 14 additions & 13 deletions Sources/KSPlayer/MEPlayer/FFmpegAssetTrack.swift
Original file line number Diff line number Diff line change
Expand Up @@ -62,22 +62,23 @@ public class FFmpegAssetTrack: MediaPlayerTrack {
} else {
rotation = 0
}
let frameRate = stream.pointee.avg_frame_rate
if stream.pointee.duration > 0, stream.pointee.nb_frames > 0, stream.pointee.nb_frames != stream.pointee.duration {
nominalFrameRate = Float(stream.pointee.nb_frames) * Float(timebase.den) / Float(stream.pointee.duration) * Float(timebase.num)
} else if frameRate.den > 0, frameRate.num > 0 {
nominalFrameRate = Float(frameRate.num) / Float(frameRate.den)

if mediaType == .audio {
var frameSize = codecpar.frame_size
if frameSize < 1 {
frameSize = timebase.den / timebase.num
}
nominalFrameRate = max(Float(codecpar.sample_rate / frameSize), 44)
} else {
if mediaType == .audio {
var frameSize = codecpar.frame_size
if frameSize < 1 {
frameSize = timebase.den / timebase.num
}
nominalFrameRate = max(Float(codecpar.sample_rate / frameSize), 44)
} else {
nominalFrameRate = 24
let frameRate = stream.pointee.avg_frame_rate
if stream.pointee.duration > 0, stream.pointee.nb_frames > 0, stream.pointee.nb_frames != stream.pointee.duration {
nominalFrameRate = Float(stream.pointee.nb_frames) * Float(timebase.den) / Float(stream.pointee.duration) * Float(timebase.num)
} else if frameRate.den > 0, frameRate.num > 0 {
nominalFrameRate = Float(frameRate.num) / Float(frameRate.den)
}
nominalFrameRate = 24
}

if codecpar.codec_type == AVMEDIA_TYPE_VIDEO {
description += ", \(nominalFrameRate) fps"
}
Expand Down

0 comments on commit bd60377

Please sign in to comment.