小编Tom*_*rth的帖子

使用AVFoundation混合图像和视频

我正在尝试将图像拼接成预先存在的视频,以便在Mac上使用AVFoundation创建新的视频文件.

到目前为止,我已经阅读了Apple文档示例,

ASSETWriterInput用于在Iphone问题上从UIImages制作视频

使用AVVideoCompositionCoreAnimationTool在CALayer中将视频与静态图像混合

AVFoundation教程:为视频和其他一些SO链接添加叠加和动画

现在这些已经被证明是非常有用的,但我的问题是我没有创建一个静态水印或覆盖,我想在视频的各个部分之间插入图像.到目前为止,我已经设法获取视频并创建空白部分以插入这些图像并将其导出.

我的问题是让图像在这些空白部分插入自己.我可以看到可行的唯一方法是创建一系列动画层,以便在正确的时间改变它们的不透明度,但我似乎无法让动画工作.

下面的代码是我用来创建视频片段和图层动画的代码.

    //https://developer.apple.com/library/ios/documentation/AudioVideo/Conceptual/AVFoundationPG/Articles/03_Editing.html#//apple_ref/doc/uid/TP40010188-CH8-SW7

    // let's start by making our video composition
    AVMutableComposition* mutableComposition = [AVMutableComposition composition];
    AVMutableCompositionTrack* mutableCompositionTrack = [mutableComposition addMutableTrackWithMediaType:AVMediaTypeVideo preferredTrackID:kCMPersistentTrackID_Invalid];

    AVMutableVideoComposition* mutableVideoComposition = [AVMutableVideoComposition videoCompositionWithPropertiesOfAsset:gVideoAsset];

    // if the first point's frame doesn't start on 0
    if (gFrames[0].startTime.value != 0)
    {
        DebugLog("Inserting vid at 0");
        // then add the video track to the composition track with a time range from 0 to the first point's startTime
        [mutableCompositionTrack insertTimeRange:CMTimeRangeMake(kCMTimeZero, gFrames[0].startTime) ofTrack:gVideoTrack atTime:kCMTimeZero …
Run Code Online (Sandbox Code Playgroud)

macos avfoundation cgimage caanimation ios

6
推荐指数
1
解决办法
3238
查看次数

标签 统计

avfoundation ×1

caanimation ×1

cgimage ×1

ios ×1

macos ×1