Skip to content

Commit

Permalink
Fix: T2Je#12
Browse files Browse the repository at this point in the history
  • Loading branch information
soobeen27 committed Sep 10, 2024
1 parent 8504eb7 commit 3cc3dd2
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 8 deletions.
14 changes: 9 additions & 5 deletions Sources/FYVideoCompressor/FYVideoCompressor.swift
Original file line number Diff line number Diff line change
Expand Up @@ -183,7 +183,9 @@ public class FYVideoCompressor {

let videoSettings = createVideoSettingsWithBitrate(targetVideoBitrate,
maxKeyFrameInterval: 10,
size: scaleSize)
size: scaleSize,
targetFPS : quality.value.fps
)
#if DEBUG
print("************** Video info **************")
#endif
Expand Down Expand Up @@ -256,7 +258,9 @@ public class FYVideoCompressor {
let targetSize = calculateSizeWithScale(config.scale, originalSize: videoTrack.naturalSize)
let videoSettings = createVideoSettingsWithBitrate(targetVideoBitrate,
maxKeyFrameInterval: config.videomaxKeyFrameInterval,
size: targetSize)
size: targetSize,
targetFPS: config.fps
)

var audioTrack: AVAssetTrack?
var audioSettings: [String: Any]?
Expand Down Expand Up @@ -457,12 +461,12 @@ public class FYVideoCompressor {

}

private func createVideoSettingsWithBitrate(_ bitrate: Float, maxKeyFrameInterval: Int, size: CGSize) -> [String: Any] {
private func createVideoSettingsWithBitrate(_ bitrate: Float, maxKeyFrameInterval: Int, size: CGSize, targetFPS: Float = 30) -> [String: Any] {
return [AVVideoCodecKey: AVVideoCodecType.hevc,
AVVideoWidthKey: size.width,
AVVideoHeightKey: size.height,
// AVVideoScalingModeKey: AVVideoScalingModeResizeAspectFill,
AVVideoScalingModeKey: AVVideoScalingModeResizeAspect,
AVVideoScalingModeKey: AVVideoScalingModeResizeAspectFill,
AVVideoExpectedSourceFrameRateKey: targetFPS,
AVVideoCompressionPropertiesKey: [AVVideoAverageBitRateKey: bitrate,
// AVVideoProfileLevelKey: AVVideoProfileLevelH264HighAutoLevel,
// AVVideoH264EntropyModeKey: AVVideoH264EntropyModeCABAC,
Expand Down
10 changes: 7 additions & 3 deletions Sources/FYVideoCompressor/VideoFrameReducer.swift
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,14 @@ public struct ReduceFrameEvenlySpaced: VideoFrameReducer {

var res = [Int]()

while res.count < Int(targetFPS * videoDuration) {
while res.count < Int(originalFPS * videoDuration) && counter * stride < originalFrames.count {
let index = counter * stride
let frame = originalFrames[index]
res.append(frame)
// let frame = originalFrames[index]
// res.append(frame)
if index < originalFrames.count {
let frame = originalFrames[index]
res.append(frame)
}
counter += 1
}

Expand Down

0 comments on commit 3cc3dd2

Please sign in to comment.