LaiFengiOS / LFLiveKit

LaiFeng IOS Live Kit,H264 and AAC Hard coding,support GPUImage Beauty, rtmp transmission,weak network lost frame,Dynamic switching rate
MIT License
4.39k stars 1.11k forks source link

Saving video to device, Couldn't write a frame #353

Open tomihr opened 3 years ago

tomihr commented 3 years ago

I am tring to save the video to the device, but I didn't succeed yet. I am setting session property session?.saveLocalVideo = true and providing file name and path, here is my code:

session?.saveLocalVideo = true
let now = NSDate()
let nowTimeStamp = self.getCurrentTimeStampWOMiliseconds(dateToConvert: now)
pathToMovie = (NSSearchPathForDirectoriesInDomains(.documentDirectory, .userDomainMask, true)[0] as NSString).appendingPathComponent(nowTimeStamp + "_UMOO.mp4")
print("pathToMovie: " + pathToMovie)
let movieURL:NSURL = NSURL(fileURLWithPath: pathToMovie)
print("movieURL: " + movieURL.absoluteString!)
session?.saveLocalVideoPath = movieURL as URL

Do I have to do something else?

Thanks

harsh12312 commented 3 years ago
   `session?.saveLocalVideo = true
    let cachesDir = FileManager.default.urls(for: .cachesDirectory, in: .userDomainMask).map(\.path)[0]
    let movieName = "\(UUID().uuidString).mp4"
    let pathToMovie = URL(fileURLWithPath: cachesDir).appendingPathComponent(movieName).path
    session?.saveLocalVideoPath = URL(fileURLWithPath: pathToMovie)`

Then in liveStateDidChange, case stop

` if let videoURL = self.session.saveLocalVideoPath{ UISaveVideoAtPathToSavedPhotosAlbum(videoURL.relativePath, self, #selector(self.image(_:didFinishSavingWithError:contextInfo:)), nil) }

//MARK: - Save Video callback
@objc func image(_ image: UIImage, didFinishSavingWithError error: Error?, contextInfo: UnsafeRawPointer) {
    if let error = error {
        print(error.localizedDescription)
    } else {
        print("Success")
    }

}`

tomihr commented 3 years ago

Thanks, will try.

tomihr commented 3 years ago

Is it possible to save the video without streaming it to the RMTP server, just to have a save mode that will not relay on RMTP streaming?

Thanks

tomihr commented 3 years ago

I stumbled on one issue, if I put the app in the background ad then activate it again and move it to the foreground, I got this message:

Couldn't write a frame

No matter am I recording or not, and streaming is broken. How do I fix this?

Thanks