Latest 1.0.1
Homepage https://github.com/TintGit/MediaComposition
License MIT
Platforms ios 8.0, requires ARC
Frameworks AVFoundation
Authors

功能:多张图片合成视频、音视频合成、多段音频合成、多段视频合成、修改音视频音量

预览

效果

效果

使用 Cocoapods 导入

MediaComposition is available on CocoaPods. Add the following to your Podfile:

pod 'MediaComposition'

目录

  • 实现原理
  • 配置
  • 基本用法

实现原理

图片合成方案一

基于AVFoundation
将图片转换CVPixelBufferRef 通过AVAssetWriter写入AVAssetWriterInput/AVAssetWriterInputPixelBufferAdaptor

图片合成方案二

基于AVFoundation Core Animation
将图片添加到layer上 通过AVMutableComposition合成视频
可以Core Animation 添加动画

音视频合成

基于AVFoundation

配置

  • 视频分辨率 naturalSize
  • 每张图片展示的时间 picTime
  • frameNumber 帧率
  • 动画效果 可修改图片 CALayerContentsGravity
  • 方案一 需要自适配图片 否则 图片会被压缩 默认提供了一种方案(scaleAspectFit)
  • 多段音频合成
  • 音视频合成
  • 添加背景音乐
  • 设置音频音量 背景音乐音量

基本用法

let composition = MediaComposition()
//有动画
composition.imagesVideoAnimation(with: images, progress: { (progress) in
    print("合成进度",progress)
}, success: {[weak self] (path) in
    guard let `self` = self else {return}
    print("合成后地址",path)
}) { (errMessage) in
    print("合成失败",errMessage ?? "")
}

//音视频合成 添加背景音乐 修改音量
composition.bgMusicVideo(audioPath: audioPath, videoPath: videoPath, durationType: .audio_loopVideo, audioVolume: 0.1, musicPath: audioPath1, musicVolume: 1, progress: { (progress) in
    print("合成进度",progress)
}, success: {[weak self] (path) in
    guard let `self` = self else {return}
    print("合成后地址",path)
    self.path = path
}) { (errMessage) in
    print("合成失败",errMessage ?? "")
}

Latest podspec

{
    "name": "MediaComposition",
    "version": "1.0.1",
    "summary": "u56feu7247u5408u6210u89c6u9891u7279u6548 u97f3u89c6u9891u5408u6210",
    "description": "MediaComposition u97f3u89c6u9891u5408u6210",
    "homepage": "https://github.com/TintGit/MediaComposition",
    "license": {
        "type": "MIT",
        "file": "LICENSE"
    },
    "authors": {
        "u95ebu660e": "[email protected]"
    },
    "platforms": {
        "ios": "8.0"
    },
    "source": {
        "git": "https://github.com/TintGit/MediaComposition.git",
        "branch": "master"
    },
    "source_files": "MediaComposition/Source/*.swift",
    "swift_version": "4.2",
    "frameworks": "AVFoundation",
    "resources": [
        "MediaComposition/Resource/black.mp4",
        "MediaComposition/Resource/canvas.png"
    ],
    "static_framework": true,
    "requires_arc": true
}

Pin It on Pinterest

Share This