I am trying to save a video in my photo library. But sometimes I get an error: The operation couldn’t be completed. (PHPhotosErrorDomain error -1.)
This is my code:
PHPhotoLibrary.shared().performChanges({
PHAssetChangeRequest.creationRequestForAssetFromVideo(atFileURL: exporter!.outputURL!)
}) { saved, error in
if saved {
print("video saved to camera roll")
} else {
print(error?.localizedDescription)
}
}
I was able to resolve this by removing the AVVideoQualityKey within AVVideoCompressionPropertiesKey in my video output settings for AVAssetWriter.
Related
We have successfully integrated video DRM logic using AVAssetResourceLoaderDelegate.
It worked well. But lately, after playing the same movie several times in a row, we started getting this error when trying to get SPC.
do {
let spcData = try loadingRequest.streamingContentKeyRequestData(forApp: certificateData, contentIdentifier: assetIDData, options: [AVAssetResourceLoadingRequestStreamingContentKeyRequestRequiresPersistentKey: true as AnyObject])
return spcData
} catch {
print(error)
return nil
}
Error:
Domain=AVFoundationErrorDomain Code=-11879 "(null)" UserInfo={NSUnderlyingError=0x2805f9980 {Error Domain=NSOSStatusErrorDomain Code=-15841 "(null)"}}
I found that this code -11879 means that the request has been canceled.
I don't know what the second code means.
Why is the device not issuing more SPCs for content?
Maybe it's cached and needs to be updated somehow.
Using SwiftyDropbox download method to download all files. But, i found progress block showing data all together of different files, not downloading files in a way that downloading of one file start after completing the previous one.
Here, is the code used :
DropboxClientsManager.authorizedClient?.files
.download(path: entry.pathLower!, overwrite: true, destination: destination)
.response { response, error in
if let response = response {
print(response)
}
else if let error = error {
print(error)
}
}
.progress { progressData in
print(progressData)
}
I am trying to record screen with audio in OSX with AVFoundation, When i record video is working perfectly. But when adding audio input and appending it to AVAssetWriterInput, the asset writer status changes to .failed.
if let sampleBuffer = sampleBuffer {
if CMSampleBufferDataIsReady(sampleBuffer) {
if assetWriter.status == .unknown {
let startTime = CMSampleBufferGetPresentationTimeStamp(sampleBuffer)
assetWriter.startWriting()
assetWriter.startSession(atSourceTime: startTime)
}
if assetWriter.status == .failed {
print("writer error \(String(describing: assetWriter.error?.localizedDescription))")
return false
}
if isVideo {
if videoInputWriter.isReadyForMoreMediaData {
videoInputWriter.append(sampleBuffer)
return true
}
} else {
if audioInputWriter.isReadyForMoreMediaData {
audioInputWriter.append(sampleBuffer)
return true
}
}
}
}
The error message is
Error Domain=AVFoundationErrorDomain Code=-11800 "The operation could not be completed" UserInfo={NSLocalizedFailureReason=An unknown error occurred (-12780), NSLocalizedDescription=The operation could not be completed, NSUnderlyingError=0x600002841320 {Error Domain=NSOSStatusErrorDomain Code=-12780 "(null)"}}
Welcome!
I'm guessing, but it seems you are using the same callback for processing the audio and video samples. The problem might be that audio and video samples will be delivered concurrently in different queues (threads), which means that assetWriter.startSession(atSourceTime: startTime) could be accidentally executed multiple times in different threads—which is not allowed.
You need to somehow (atomically) protect that call, for instance by using a separate synchronization queue. Alternatively, you could only start the session with the first video buffer that arrives and ignore any audio buffer that comes before that (which would also prevent accidental black frames at the beginning of the video).
Can't load video from a UIImagePickerController using WebRTC.
With saved in-app Bundle file, it works, but if I use UIImagePickerController
UIImagePickerControllerDelegate.imagePickerController(_:didFinishPickingMediaWithInfo:))
so I use mediaInfo like this:
(info[.mediaURL] as! URL).path
This code I use to start capturing a video file
public func startCaptureLocalVideoFile(name: String, renderer: RTCVideoRenderer) {
print("startCaptureLocalVideoFile")
stopLocalCapture()
localRenderer = renderer
videoCapturer = RTCFileVideoCapturer(delegate: videoSource)
guard let capturer = videoCapturer as? RTCFileVideoCapturer else {
print("WebRTCService can't get capturer")
return
}
capturer.startCapturing(fromFileNamed: name) { error in
print("startCapturing error ", error)
return
}
localVideoTrack?.add(renderer)
}
so I get this media info:
info [__C.UIImagePickerControllerInfoKey(_rawValue: UIImagePickerControllerMediaURL): file:///private/var/mobile/Containers/Data/PluginKitPlugin/5F7A4469-5006-4590-8F59-396CD86A083B/tmp/trim.B46C5878-BAF2-432B-B627-9787D74CE7B0.MOV, __C.UIImagePickerControllerInfoKey(_rawValue: UIImagePickerControllerMediaType): public.movie, __C.UIImagePickerControllerInfoKey(_rawValue: UIImagePickerControllerReferenceURL): assets-library://asset/asset.MOV?id=33EECFB7-514A-435A-AA19-26A055FB9F06&ext=MOV]
and this error:
startCapturing error Error Domain=org.webrtc.RTCFileVideoCapturer Code=2001 "(null)" UserInfo={NSUnderlyingError=File /private/var/mobile/Containers/Data/PluginKitPlugin/5F7A4469-5006-4590-8F59-396CD86A083B/tmp/trim.B46C5878-BAF2-432B-B627-9787D74CE7B0.MOV not found in bundle}
Seems like it works with Bundle.main only, but we can't write to it.
Am I doing it right? Maybe there is another way to accomplish this?
Thanks for the help!
The below swift code is written to upload an image to firebase storage. Earlier it was working fine. But now onwards it works randomly. I waited 30mins to upload an image but didn't reach to success nor even in error.
I have tried different code to upload an image. Also, search a lot to analyze the problem. But sometimes it works randomly. I am not able to identify why this is happening.
To check if the image is uploading or not, I just put an observer to check the progress of an upload task, uploading works perfectly, but it didn't reach to completion block. I tried to generate download URL too after upload task done but it also didn't reach to completion block.
let storageRef = Storage.storage().reference().child("abc").child("myImage1234")
storageRef.putData(imageData, metadata: nil, completion: { (storageMetaData, error) in
if let error = error {
print(error.localizedDescription)
} else {
storageRef.downloadURL(completion: { (url, error) in
if error != nil {
print(error?.localizedDescription as Any)
return
}
if let photoUrl = url?.absoluteString {
self.imageUpload()
}
})
}
})
I am really stuck at this point. Any help would be appreciated.