当前位置: 首页 > 编程日记 > 正文

swift-video-generator:图片加音频生成视频及多视频合并库及演示

阅读 80
收藏 9
2017-11-07
原文链接:github.com
腾讯云学生优惠套餐,985高校学习云计算的主力机型,2G2核,1M带宽系统盘(Linux 50G/Windows 50G)免费赠送50GB对象存储空间还有.cn域名一年使用权!不要犹豫了,立即来腾讯云抢购!https://cloud.tencent.com/act/campus

swift-video-generator-logo

Platform CocoaPods License Twitter URL Website

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>' dopod '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) inprint(progress)}, success: { (url) inprint(url)self.createAlertView(message: "Finished single type video generation")}, failure: { (error) inprint(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 = .redVideoGenerator.current.scaleWidth = 700VideoGenerator.current.generate(withImages: [_image1, _image2, _image3], andAudios: [audioURL1, audioURL2, audioURL3], andType: .multiple, { (progress) inprint(progress)}, success: { (url) inprint(url)self.createAlertView(message: "Finished single type video generation")}, failure: { (error) inprint(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) inprint(videoURL)}) { (error) inprint(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

相关文章:

Hadoop集群搭建(八:Hive的安装配置)

实验 目的 要求 目的&#xff1a; &#xff08;1&#xff09;掌握数据仓库工具Hive的安装和配置&#xff1b; 要求&#xff1a; 完成Hive工具的安装和配置&#xff1b;Hive工具能够正常启动运行&#xff1b;Hive控制台命令能够正常使用&#xff1b;能够正常操作数据库、表、…

iOS 富文本编辑工厂, 让书写更简便.

由于最近常用富文本, 在编辑一个富文本时需要操作很多的属性, 书写起来很不方便. 所以我将这些相关属性整理并使用链式方式将它简化了一下. 效果请看下面Demo. 项目工程 实现很简单, 我嘴太笨, 这里就不介绍了, 如有兴趣直接看源码吧. 同时可以通过cocoapods来使用它. pod SJAt…

ORACLE 数据的逻辑组成

数据块&#xff08;block&#xff09;Oracle数据块&#xff08;Data Block&#xff09;是一组连续的操作系统块。分配数据库块大小是在Oracle数据库创建时设置的&#xff0c;数据块是Oracle读写的基本单位。数据块的大小一般是操作系统块大小的整数倍&#xff0c;这样可以避免不…

Java 的zip压缩和解压缩

Java 的zip压缩和解压缩好久没有来这写东西了&#xff0c;今天中秋节&#xff0c;有个东西想拿出来分享&#xff0c;一来是工作中遇到的问题&#xff0c;一来是和csdn问候一下&#xff0c;下面就分享一个Java中的zip压缩技术&#xff0c;代码实现比较简单,代码如下&#xff1a;…

Hadoop集群搭建(九:各服务的启动)

1、查看Zookeeper服务状态&#xff0c;若集群中只有一个"leader"节点&#xff0c; 其余的均为"follower"节点&#xff0c;则集群的工作状态正常 $zkServer.sh status 2、在集群中所有主机上使用此命令&#xff0c;启动Zookeeper服务 $zkServer.sh start…

iOS 后台下载及管理库

说起下载第一个想起的就是ASI。一年前接手的新项目是核心功能是视频相关业务&#xff0c;在修改和解决视频下载相关的问题的时候让我体会到了ASI的下载的强大。后来新需求需要视频后台下载&#xff0c;使用NSURLSession的时候&#xff0c;更加深刻的体会到了ASI的强大好用。后来…

(转) 使用Speech SDK 5.1文字转音频

下载地址&#xff1a; http://www.microsoft.com/en-us/download/details.aspx?id10121 SeppchSDK51.exe 语音合成引擎 SpeechSDK51LangPack.exe 支持日语和简体中文需要这个支持。 SpeechSDK51MSM.exe 如果要将引擎作为产品的一部分发布需要这个。 Sp5TTintXP.exe XP下Mike和…

IE8下面的line-height的bug

当line-height小于正常值时&#xff0c;超出的部分将被剪裁掉转载于:https://www.cnblogs.com/jsingleegg/p/js_ie8.html

Hadoop集群的基本操作(一:HDFS操作及MapReduce程序练习)

实验 目的 要求 目的&#xff1a; 理解HDFS在Hadoop体系结构中的角色&#xff1b;熟练使用HDFS操作常用的Shell命令&#xff1b;了解Hadoop集群MapReduce程序的简单使用&#xff1b;&#xff08;上传WordCount的jar执行程序&#xff1b;使用WordCount进行MapReduce计算&#x…

iOS实现动态区域裁剪图片

阅读 249收藏 322017-11-29原文链接&#xff1a;github.com想自己动手搭建一个 Discuz 论坛&#xff1f;试试腾讯云上实验室吧https://cloud.tencent.com/developer/labs 裁剪图片功能在很多上传图片的场景里都需要用到&#xff0c;一方面应用服务器可能对图片的尺寸大小有限制…

每天CookBook之JavaScript-062

鼠标进入事件鼠标离开事件<!DOCTYPE html> <html lang"en"> <head><meta charset"UTF-8"><title>062</title> </head> <body> <div><img src"001" alt"001"><img src…

spring + Quartz定时任务配置

<bean id"exportBatchFileTask" class"com.ydcn.pts.task.ExportBatchFileTask"></bean><bean id"readBatchFileTask" class"com.ydcn.pts.task.ReadBatchFileResultTask"></bean><!-- 生成开卡档&#xf…

Hadoop集群的基本操作(二:HBase的基本操作)

实验 目的 要求 目的&#xff1a; 1、HBase的基本应用 要求&#xff1a; 完成HBase的高可用完全分布模式的安装&#xff1b;HBase的相关服务进程能够正常的启动&#xff1b;HBase控制台能够正常使用&#xff1b;表创建、数据查询等数据库操作能够正常进行&#xff1b; …

Abaqus用户子程序umat的学习

Abaqus用户子程序umat的学习 说明&#xff1a;在文件中&#xff0c;&#xff01;后面的内容为注释内容。本文为学习心得&#xff0c;很多注释是自己摸索得到。如有不正确的地方&#xff0c;敬请指正。 ! —————————————————————————— ! 1、为何需要…

PHP:isset()-检测变量是否被设置

isset()-检测变量是否被设置 bool isset(mixed $var [, mixed $...])&#xff0c;检查变量是否被设置&#xff0c;并且不是NULL。var,要检测的变量&#xff0c;...其他变量&#xff0c;允许有多个变量。 返回值&#xff1a;如果var存在并且不是NULL&#xff0c;则返回TRUE&…

Android通过ShareSDK实现新浪微博分享

ShareSDK社会化分享的官方说明&#xff1a;是中国最大的APP内分享服务提供商&#xff0c;ShareSDK社会化分享&#xff0c;全面支持微信&#xff0c;微博&#xff0c;QQ空间&#xff0c;来往&#xff0c;易信&#xff0c;Facebook等国内外40个平台。 ShareSDK官方网站&#xff…

Hadoop集群的基本操作(三:HBase的基本操作)

实验 目的 要求 目的&#xff1a; MySQL数据库的基本命令&#xff1b;MySQL数据库中使用SQL语句&#xff1b;MySQL数据库中数据库&#xff0c;表&#xff0c;数据的操作&#xff1b;要求&#xff1a; 完成MySQL的集群版的安装&#xff1b;MySQL集群的相关服务进程能够正常启…

iOS通过Plist保存离线调试日志

最近需要测试APP在iPhone没连接USB情况下定位时间间隔的情况&#xff0c;固把nslog的日志信息保存成本地Plist文件&#xff0c;以便测试结束后查阅运行时的日志。 一、新建一个保存日志的方法&#xff0c;参数为每次定位成功的时间&#xff08;作为key&#xff09;&#xff0c…

关于变量名前面加m的问题

为什么很多人写代码会在变量名前面加一个小写的m&#xff1f; 上大学那会儿就对这个问题感到很好奇。于是网上到处搜&#xff0c;有人说是member的意思。于是后来一直就这么认为。 最近在读Android源码&#xff0c;发现很多系统变量命名时都加了m&#xff0c;而有的变量又没有加…

谷歌推出情境感知API

在 Google I/O 2016 大会上&#xff0c;我们宣布推出新的 Google Awareness API&#xff0c;让您的应用可以利用快照和围栏智能应对用户情境&#xff0c;并且仅需占用极少量的系统资源。 所有开发者均可以通过 Google Play 服务获取 Google Awareness API。 利用 7 种不同类型的…

Hadoop集群的基本操作(四:Hive的基本操作)

实验 目的 要求 目的&#xff1a; &#xff08;1&#xff09;掌握数据仓库工具Hive的使用&#xff1b; 要求&#xff1a; 掌握数据仓库Hive的使用&#xff1b;能够正常操作数据库、表、数据&#xff1b; 实 验 环 境 五台独立PC式虚…

【转】通过Hibernate将数据 存入oracle数据库例子

一、 Hibernate介绍 Hibernate是基于对象/关系映射&#xff08;ORM&#xff0c;Object/Relational Mapping&#xff09;的一个解决方案。ORM方案的思想是将对象模型表示的对象映射到关系型数据库中&#xff0c;或者反之。Hibernate目前是ORM思想在Java中最成功、最强大的实现。…

自动布局按钮排列平均分布

需要实现如下图所示的主页面布局&#xff0c;需要两排按钮&#xff0c;每一排都自动平均分布&#xff0c;Android的话直接用LinearLayout水平布局&#xff0c;并设置layout_weight即可&#xff0c;对于iOS&#xff0c;网上有使用代码实现&#xff0c;感觉略麻烦&#xff0c;我直…

maven3 手动安装本地jar到仓库

安装命令&#xff1a; mvn install:install-file -Dfile{Path/to/your/ojdbc.jar} -DgroupIdcom.oracle -DartifactIdojdbc6 -Dversion11.2.0 -Dpackagingjar我自己安装oracle14.jar 时命令如下&#xff1a;mvn install:install-file -DgroupIdcom.oracle -DartifactIdojdbc14 …

Hadoop集群的基本操作(五:Sqoop的基本操作)

实验 目的 要求 目的&#xff1a; 掌握ETL工具Sqoop的使用&#xff1b;掌握MySQL和HDFS之间的数据转换&#xff1b;要求&#xff1a; 掌握ETL工具Sqoop的使用&#xff1b;能够正常操作数据库、表、数据&#xff1b; 实 验 环 境 五台…

NEWS - InstallShield 2013 SP1发布

2013的这个国庆假期期间&#xff0c;InstallShield厂商Flexerasoftware&#xff08;中文名&#xff1a;福莱睿&#xff09;发布了最新版本InstallShield 2013的SP1&#xff0c;由于这个升级包带来一些新的技术支持和变化&#xff0c;所以特地给大家介绍一下&#xff1a; 1. 支持…

iOS 高德导航按返回后报错 解决

最近项目要添加导航功能&#xff0c;用了高德导航SDK&#xff0c;很郁闷每次从地图界面返回前一页面都报错&#xff0c;弄了很久&#xff0c;最终从高德开发者论坛找到一解决方法&#xff0c;可以试一下。 在导航的ViewController的viewWillDisappear中调用如下方法&#xff0…

Oracle的基本操作(一:子查询与常用函数)

1、描述TO_CHAR和TO_DATE函数的用法。 TO_CHAR&#xff08;d|n[,fmt]):把日期和数字转换为指定格式(fmt)的字符串; TO_DATE(x[,fmt]):把一个字符串一fmt格式转换为一个日期类型&#xff1b; 举例&#xff1a;select to_char(sysdate,yyyy-mm-dd) "char", to_date(…

易买网的一些增删改查

正如题目所说的一样,今天就来说说易买网中的一些增删改查,主要的功能有注册、用户管理以及商品分类等&#xff01; 1.注册 1.1 注册涉及到了一个ajax远端技术,主要是用来控制注册用户在数据库中是否存在&#xff1a; <script>$(function(){//焦点移出表单时$("#user…

iOS后台持续定位并定时上传

最近做一个考勤APP&#xff0c;功能很简单&#xff0c;就是一直在后台运行&#xff0c;每隔固定时间向服务器上传一次位置信息。持续运行24小时测试&#xff0c;功能实现。 1.ViewController.h文件&#xff1a; #import <CoreLocation/CoreLocation.h>并实现CLLocationMa…