Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Swift 5 Support #56

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion SceneKitVideoRecorder/Classes/Options.swift
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ extension SceneKitVideoRecorder {
outputUrl: URL(fileURLWithPath: NSTemporaryDirectory() + "output.mp4"),
audioOnlyUrl: URL(fileURLWithPath: NSTemporaryDirectory() + "audio.m4a"),
videoOnlyUrl: URL(fileURLWithPath: NSTemporaryDirectory() + "video.mp4"),
fileType: AVFileTypeAppleM4V,
fileType: AVFileType.m4v.rawValue,
codec: AVVideoCodecH264,
deleteFileIfExists: true,
useMicrophone: true,
Expand Down
24 changes: 14 additions & 10 deletions SceneKitVideoRecorder/Classes/SceneKitVideoRecorder.swift
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ public class SceneKitVideoRecorder: NSObject, AVAudioRecorderDelegate {

self.options.videoSize = options.videoSize

writer = try! AVAssetWriter(outputURL: self.options.videoOnlyUrl, fileType: self.options.fileType)
writer = try! AVAssetWriter(outputURL: self.options.videoOnlyUrl, fileType: AVFileType(rawValue: self.options.fileType))

self.setupVideo()
}
Expand Down Expand Up @@ -161,7 +161,7 @@ public class SceneKitVideoRecorder: NSObject, AVAudioRecorderDelegate {

private func setupVideo() {

self.videoInput = AVAssetWriterInput(mediaType: AVMediaTypeVideo,
self.videoInput = AVAssetWriterInput(mediaType: AVMediaType.video,
outputSettings: self.options.assetWriterVideoInputSettings)

self.videoInput.mediaTimeScale = self.options.timeScale
Expand All @@ -188,7 +188,7 @@ public class SceneKitVideoRecorder: NSObject, AVAudioRecorderDelegate {
return promise.future
}

promise.success()
promise.success(())
return promise.future
}

Expand Down Expand Up @@ -333,17 +333,21 @@ public class SceneKitVideoRecorder: NSObject, AVAudioRecorderDelegate {
let aVideoAsset : AVAsset = AVAsset(url: videoUrl)
let aAudioAsset : AVAsset = AVAsset(url: audioUrl)

mutableCompositionVideoTrack.append(mixComposition.addMutableTrack(withMediaType: AVMediaTypeVideo, preferredTrackID: kCMPersistentTrackID_Invalid))
mutableCompositionAudioTrack.append(mixComposition.addMutableTrack(withMediaType: AVMediaTypeAudio, preferredTrackID: kCMPersistentTrackID_Invalid))
//<<<<<<< HEAD
// mutableCompositionVideoTrack.append(mixComposition.addMutableTrack(withMediaType: AVMediaType.video, preferredTrackID: kCMPersistentTrackID_Invalid)!)
// mutableCompositionAudioTrack.append( mixComposition.addMutableTrack(withMediaType: AVMediaType.audio, preferredTrackID: kCMPersistentTrackID_Invalid)!)
//=======
mutableCompositionVideoTrack.append(mixComposition.addMutableTrack(withMediaType: AVMediaType.video, preferredTrackID: kCMPersistentTrackID_Invalid)!)
mutableCompositionAudioTrack.append(mixComposition.addMutableTrack(withMediaType: AVMediaType.audio, preferredTrackID: kCMPersistentTrackID_Invalid)!)

guard !aVideoAsset.tracks.isEmpty, !aAudioAsset.tracks.isEmpty else {
let error = NSError(domain: errorDomain, code: ErrorCode.zeroFrames.rawValue, userInfo: nil)
promise.failure(error)
return promise.future
}

let aVideoAssetTrack : AVAssetTrack = aVideoAsset.tracks(withMediaType: AVMediaTypeVideo)[0]
let aAudioAssetTrack : AVAssetTrack = aAudioAsset.tracks(withMediaType: AVMediaTypeAudio)[0]
let aVideoAssetTrack : AVAssetTrack = aVideoAsset.tracks(withMediaType: AVMediaType.video)[0]
let aAudioAssetTrack : AVAssetTrack = aAudioAsset.tracks(withMediaType: AVMediaType.audio)[0]

do {
try mutableCompositionVideoTrack[0].insertTimeRange(CMTimeRangeMake(kCMTimeZero, aVideoAssetTrack.timeRange.duration), of: aVideoAssetTrack, at: kCMTimeZero)
Expand All @@ -362,15 +366,15 @@ public class SceneKitVideoRecorder: NSObject, AVAudioRecorderDelegate {
let savePathUrl : URL = self.options.outputUrl

let assetExport: AVAssetExportSession = AVAssetExportSession(asset: mixComposition, presetName: AVAssetExportPresetHighestQuality)!
assetExport.outputFileType = AVFileTypeMPEG4
assetExport.outputFileType = AVFileType.mp4
assetExport.outputURL = savePathUrl
assetExport.shouldOptimizeForNetworkUse = true

assetExport.exportAsynchronously { () -> Void in
switch assetExport.status {

case AVAssetExportSessionStatus.completed:
promise.success()
promise.success(())
case AVAssetExportSessionStatus.failed:
let assetExportErrorMessage = "failed \(String(describing: assetExport.error))"
let error = NSError(domain: self.errorDomain, code: ErrorCode.assetExport.rawValue, userInfo: ["Reason": assetExportErrorMessage])
Expand All @@ -380,7 +384,7 @@ public class SceneKitVideoRecorder: NSObject, AVAudioRecorderDelegate {
let error = NSError(domain: self.errorDomain, code: ErrorCode.assetExport.rawValue, userInfo: ["Reason": assetExportErrorMessage])
promise.failure(error)
default:
promise.success()
promise.success(())
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -176,6 +176,7 @@
TargetAttributes = {
2C1EA3781F6281C200E97D5E = {
CreatedOnToolsVersion = 9.0;
LastSwiftMigration = 0910;
ProvisioningStyle = Automatic;
};
2C3EB9571F9A580000AA77B4 = {
Expand Down Expand Up @@ -453,7 +454,8 @@
PRODUCT_BUNDLE_IDENTIFIER = com.okaris.SceneKitVideoRecorderDemo;
PRODUCT_NAME = "$(TARGET_NAME)";
PROVISIONING_PROFILE_SPECIFIER = "";
SWIFT_VERSION = 3.0;
SWIFT_SWIFT3_OBJC_INFERENCE = Default;
SWIFT_VERSION = 4.0;
TARGETED_DEVICE_FAMILY = "1,2";
};
name = Debug;
Expand All @@ -471,7 +473,8 @@
PRODUCT_BUNDLE_IDENTIFIER = com.okaris.SceneKitVideoRecorderDemo;
PRODUCT_NAME = "$(TARGET_NAME)";
PROVISIONING_PROFILE_SPECIFIER = "";
SWIFT_VERSION = 3.0;
SWIFT_SWIFT3_OBJC_INFERENCE = Default;
SWIFT_VERSION = 4.0;
TARGETED_DEVICE_FAMILY = "1,2";
};
name = Release;
Expand Down