Skip to content

Commit

Permalink
outputURL
Browse files Browse the repository at this point in the history
  • Loading branch information
juliangerhards committed Apr 5, 2022
1 parent ca9ab65 commit 338a016
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 6 deletions.
2 changes: 1 addition & 1 deletion Sources/VideoKit/Compressor.swift
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ internal class Compressor {
let audioInputQueue = DispatchQueue(label: "audioQueue")

do {
assetWriter = try AVAssetWriter(outputURL: URL(fileURLWithPath: VideoKit.getOutputPath(UUID().uuidString)), fileType: AVFileType.mp4)
assetWriter = try AVAssetWriter(outputURL: VideoKit.outputURL(), fileType: AVFileType.mp4)

} catch {
assetWriter = nil
Expand Down
35 changes: 35 additions & 0 deletions Sources/VideoKit/Extensions/FileManager.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
// Copyright © 2022 - present Julian Gerhards
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
//
// GitHub https://github.com/knoggl/VideoKit
//

import Foundation

public extension FileManager {

/// Clears the temporary directory
func clearTmpDirectory() {
do {
let tmpDirURL = FileManager.default.temporaryDirectory
let tmpDirectory = try contentsOfDirectory(atPath: tmpDirURL.path)
try tmpDirectory.forEach { file in
let fileUrl = tmpDirURL.appendingPathComponent(file)
try removeItem(atPath: fileUrl.path)
}
} catch {
print("Could not clear tmp directory")
}
}
}
10 changes: 5 additions & 5 deletions Sources/VideoKit/VideoKit.swift
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ public class VideoKit {
instruction.layerInstructions = [transformer]
videoComposition.instructions = [instruction]

let outputVideoUrl = URL(fileURLWithPath: getOutputPath(UUID().uuidString))
let outputVideoUrl = outputURL()
let exporter = AVAssetExportSession(asset: asset, presetName: config.quality.value)

if let exporter = exporter {
Expand Down Expand Up @@ -152,10 +152,10 @@ public class VideoKit {
}
}

public static func getOutputPath(_ name: String) -> String {
let documentPath = NSSearchPathForDirectoriesInDomains(.documentDirectory, .userDomainMask, true )[0] as NSString
let outputPath = "\(documentPath)/\(name).mp4"
return outputPath
public static func outputURL() -> URL {
let documentsPath = NSTemporaryDirectory()
let outputPath = "\(documentsPath)/\(UUID().uuidString).mp4"
return URL(fileURLWithPath: outputPath)
}

/// Converts degrees to radians
Expand Down

0 comments on commit 338a016

Please sign in to comment.