swift-video-generator:图片加音频生成视频及多视频合并库及演示
来源:互联网 发布:搜狐动态ip软件 编辑:程序博客网 时间:2024/05/22 12:28
This library provides an easy way to combine images and audio into a video or merge multiple videos into one.
Features
- create a video from a single image and audio file
- create a video from multiple image/audio pairs
- merge multiple videos into one
Supported video formats
- mov (only when merging videos)
- m4v
- mp4 (only when merging videos)
Requirements
- iOS 9.0 or later
- Xcode 8.3 or later
- Swift 3.2 or later
Communication
- If you need help or want to ask a general question, you can find me @guardians_devil or @devlabsbg. Or tag #swift-video-generator on Twitter
- If you found a bug, open an issue
- If you have a feature request, open an issue
- If you want to contribute, submit a pull request
Installation
CocoaPods
CocoaPods is a dependancy manager for Xcode. You can install it by running the following command in the Terminal:
$ gem install cocoapods
To use Swift Video Generator in your Xcode project using CocoaPods, add it in the Podfile
:
platform :ios, '10.0'use_frameworks!target '<Your Target Name>' do pod 'SwiftVideoGenrator'end
Manually
If you don't want to use a dependency manager, you can integrate SwiftVideoGenerator manually.
Download the following .swift files:
VideoGenerator
ImageExtension
Add files to project:
- Open your project in Xcode
- Select your project target, right-click and create two New Groups: VideoGenerator and ImageExtension (you can also create a group Extensions and add a subgroup Image)
- Now add the files you downloaded to their respective groups
- And you're done. You're now ready to make some video magic.
Usage
If you used Cocoapods to install SwiftVideoGenerator, you need to import the module:
import SwiftVideoGenerator
For both the .single and .multiple types of video generation the output video file format is m4v.
Create a video from a single audio and image file
if let audioURL = Bundle.main.url(forResource: "audio", withExtension: "mp3"), let _image = UIImage(named: "image") { VideoGenerator.current.fileName = "singleMovie" VideoGenerator.current.generate(withImages: [_image], andAudios: [audioURL], andType: .single, { (progress) in print(progress) }, success: { (url) in print(url) self.createAlertView(message: "Finished single type video generation") }, failure: { (error) in print(error) self.createAlertView(message: error.localizedDescription) })}
With the generator type .single you can create a video from a single pair of audio and an image.
Exmaple video
The scaleWidth property scales the image to a desired size. Only used in a .single type of video.
The fileName property sets the output file's name.
The videoBackgroundColor property is used when scaling the image. When an image is scaled to a smaller frame then the video's it leaves empty spaces around the image. You can set the background color of that space with the videoBackgroundColorproperty. If you don't specify a scaleWidth the image is scaled (keeping the aspect ration) to fill the entire video frame.
Create a video from multiple image/audio pairs
if let audioURL1 = Bundle.main.url(forResource: "audio1", withExtension: "mp3"), let audioURL2 = Bundle.main.url(forResource: "audio2", withExtension: "mp3"), let audioURL3 = Bundle.main.url(forResource: "audio3", withExtension: "mp3") { if let _image1 = UIImage(named: "image1"), let _image2 = UIImage(named: "image2"), let _image3 = UIImage(named: "image3") { VideoGenerator.current.fileName = "multipleVideo" VideoGenerator.current.videoBackgroundColor = .red VideoGenerator.current.scaleWidth = 700 VideoGenerator.current.generate(withImages: [_image1, _image2, _image3], andAudios: [audioURL1, audioURL2, audioURL3], andType: .multiple, { (progress) in print(progress) }, success: { (url) in print(url) self.createAlertView(message: "Finished single type video generation") }, failure: { (error) in print(error) self.createAlertView(message: error.localizedDescription) }) }}
With the type .multiple you can create a video that combines multiple image/audio pairs. The finished video will queue up multiple videos created by taking one image from the array and it's corresponding index element from the audio array, creating a video from it and then appending it to the finished video. Then the next pair of audio and image will be made into a video and appended after the first one. This will continue untill all image/audio pairs have been appended. If the image/audio pairs are not the same count, the extra audio(s)/image(s) is not used.
The fileName and videoBackgroundColor properties are used in the same way as in the .single type.
Exmaple video
Merging multiple videos into one
if let videoURL1 = Bundle.main.url(forResource: "video1", withExtension: "mov"), let videoURL2 = Bundle.main.url(forResource: "video2", withExtension: "mov") { VideoGenerator.mergeMovies(videoURLs: [videoURL1, videoURL2], andFileName: "mergedMovie", success: { (videoURL) in print(videoURL) }) { (error) in print(error) }}
You can provide URLs both for local resource files as well as those stored on the device (i.e. in the Documents folder).
Exmaple video
- swift-video-generator:图片加音频生成视频及多视频合并库及演示
- 音频及视频端子
- 视频<video>音频<audio>
- Trufun UML工具代码生成及代码同步视频演示
- 视频截取合并及切割
- [HTML5] Video 标签播放及控制视频
- 【video】视频编码标准汇总及比较
- video.js 视频播放插件及常见问题
- 免费Web视频及音频播放器
- 免费Web视频及音频播放器
- android视频和音频采集及预览
- FFmpeg提取第一个视频合并第二个视频的音频同时加2个水印
- 图片合并及生成二维码
- 图片+音频->视频
- 获取图片,视频,音频
- 数据库存放图片及视频
- 视频合并及添加字幕 back音乐
- HTML5-音频audio和视频video标签
- 访问远程服务器Redis失败解决方法
- 为什么分类里的属性没有成员变量
- Math类与BigDecimal类
- OpenVPN下载、安装、配置及使用详解 OpenVPN简介 OpenVPN是一个用于创建虚拟专用网络(Virtual Private Network)加密通道的免费开源软件。使用OpenVPN可以方
- vmware Workstation下安装redhat linux+oracle12c 之一 创建虚拟机
- swift-video-generator:图片加音频生成视频及多视频合并库及演示
- tomcat时,一直卡在Deploying web application directory这块的解决方案
- Fragment的show,add,hide使用
- Admin-0013.doc
- java中关于用\t格式输出
- iOS 使用lame库进行音频转mp3(一)
- java 环形阻塞队列简单实现
- bzoj1612 [Usaco2008 Jan]Cow Contest奶牛的比赛
- kubeadm快速部署kubernetes1.7.6