CoreAnimation, AVFoundation and ability to make Video export

前端 未结 2 389
花落未央
花落未央 2021-01-30 12:23

I\'m looking for the correct way to export my pictures sequence into a quicktime video.

I know that AV Foundation have the ability to merge or recombine videos and also

相关标签:
2条回答
  • 2021-01-30 12:25

    I found the AVVideoCompositionCoreAnimationTool class that have the ability to take a CoreAnimation and reencode it as a video

    My understanding was that this instead was only able to take CoreAnimation and add it to an existing video. I just checked the docs, and the only methods available require a video layer too.

    EDIT: yep. Digging in docs and WWDC videos, I think you should be using AVAssetWriter instead, and appending images to the writer. Something like:

    AVAssetWriter *videoWriter = [[AVAssetWriter alloc] initWithURL:[NSURL fileURLWithPath:somePath] fileType:AVFileTypeQuickTimeMovie error:&error];
    
    NSDictionary *videoSettings = [NSDictionary dictionaryWithObjectsAndKeys:AVVideoCodecH264, AVVideoCodecKey, [NSNumber numberWithInt:320], AVVideoWidthKey, [NSNumber numberWithInt:480], AVVideoHeightKey, nil];
    AVAssetWriterInput* writerInput = [[AVAssetWriterInput assetWriterInputWithMediaType:AVMediaTypeVideo outputSettings:videoSettings] retain];
    
    [videoWriter addInput:writerInput];
    
    [videoWriter startWriting];
    [videoWriter startSessionAtSourceTime:CMTimeMakeWithSeconds(0, 30)]
    [writerInput appendSampleBuffer:sampleBuffer];
    [writerInput markAsFinished];
    [videoWriter endSessionAtSourceTime:CMTimeMakeWithSeconds(60, 30)];
    [videoWriter finishWriting];
    
    0 讨论(0)
  • 2021-01-30 12:29

    maybe you need a fake movie that contains totally black frame to fill the video layer, and then add a CALayer to manpiulate the images

    0 讨论(0)
提交回复
热议问题