fix(iOS): replace FileHandle(forWritingTo:) with Data concatenation for TS merge
FileHandle(forWritingTo:) throws when file doesn't exist — it opens, not creates. Changed to Data.append + Data.write which creates the file automatically.
This commit is contained in:
parent
f73bc4532e
commit
1f8ecb9bcb
@ -216,15 +216,14 @@ final class HLSRecorder: ObservableObject {
|
||||
|
||||
NSLog("[MiniPlayer] Recording loop exited: %d segments downloaded", downloadedSegments.count)
|
||||
|
||||
// 4. 合并所有 TS 片段
|
||||
// 4. 合并所有 TS 片段(用 Data 拼接,避免 FileHandle(forWritingTo:) 不会创建文件的坑)
|
||||
let mergedTS = tempDir.appendingPathComponent("merged.ts")
|
||||
let output = try FileHandle(forWritingTo: mergedTS)
|
||||
var mergedData = Data()
|
||||
for segFile in downloadedSegments {
|
||||
let segData = try Data(contentsOf: segFile)
|
||||
output.write(segData)
|
||||
mergedData.append(try Data(contentsOf: segFile))
|
||||
}
|
||||
output.closeFile()
|
||||
NSLog("[MiniPlayer] Merged %d segments → %@", downloadedSegments.count, mergedTS.path)
|
||||
try mergedData.write(to: mergedTS)
|
||||
NSLog("[MiniPlayer] Merged %d segments → %@ (%d bytes)", downloadedSegments.count, mergedTS.path, mergedData.count)
|
||||
|
||||
// 5. TS → MP4(内部有超时保护)
|
||||
let outputURL = try await remuxToMP4(tsURL: mergedTS)
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user