4

With the new video features in AVFoundation that are included with iOS4, it is possible to access the raw video frames as they are captured by the camera by using AVCaptureVideoDataOutput.

I would like to overlay text and other information on top of these frames, then output them to a movie file which at some point will be saved to the asset library.

Unfortunately it doesn't appear that Apple has given us an easy way to save these frames to a movie file.

What are my options for saving the frames to a movie file that will be compatible with the asset library?

Is there any way to accomplish this using only the iPhone SDK?

If not, what third party libraries exist that are iPhone compatible and could be utilized to accomplish this?

4

4 回答 4

1

您现在可以使用AVAssetWriter将帧保存在您的AVCaptureVideoDataOutput

AVAssetWriter以下是如何在 Swift 4中使用的示例:

assetWriter = AVAssetWriter()
let documentsPath = NSSearchPathForDirectoriesInDomains(.documentDirectory, .userDomainMask, true).first
let outputURL = URL(fileURLWithPath: documentsPath!).appendingPathComponent("test.m4v")
assetWriter = try! AVAssetWriter(outputURL: outputURL, fileType: .mp4)
assetWriterInput = AVAssetWriterInput(mediaType: .video, outputSettings: videoOutput.recommendedVideoSettingsForAssetWriter(writingTo: .mp4))
assetWriterInput.expectsMediaDataInRealTime = true

if assetWriter.canAdd(assetWriterInput) {
    assetWriter.add(assetWriterInput)
    } else {
        print("no input added")
    }
assetWriter.startWriting()

参考文档在这里:AVAssetWriter

我希望这对某人有所帮助,我现在也在经历 AVFoundation 的斗争。

于 2019-01-02T19:11:49.097 回答
0

AVCaptureMovieFileOutput让您将数据捕获到 QuickTime 电影中,也许这会有所帮助...

于 2010-07-15T23:06:41.133 回答
0

我发现没有任何方法可以对捕获的帧进行编码AVCaptureVideoDataOutput或将它们写入 Quicktime .mov 文件。

您可能想查看ffmpeg以了解它是否满足您的需求——它可以处理容器格式和编码。

于 2010-07-13T17:24:45.370 回答
0

嘿!如果您只需要在视频上添加某种水印,那么只需使用相机拍摄电影然后使用 AVVideoComposition 的 AVVideoCompositionCoreAnimationTool 就很容易了。您可以添加任何类型的动画、文本作为视频的叠加层。

于 2010-10-07T09:45:16.593 回答