Unity3D 如何做视频(Mac)

-2018年5月30日,收到一个新任务:做1个3D的操作视频,

经过昨天一下午的研究,需要用到工具如下:

Unity3D_5.4版本以上

FFmpeg(期间需要安装homebrow)


步骤一:Unity3D生成录屏图片,用到UnityREC图片,代码如下;

步骤二:先安装Homebrow,然后安装FFmpeg

步骤三:生成视频。



步骤一:先测试系统_建立截屏代码

(截取的图片保存在Asset下面的REC文件夹中)

using UnityEngine;
using System.Collections;

public class UnityREC : MonoBehaviour {

	public int 渲染时长 = 30;
	public float 时间流逝 = 0.08f;
	public string 输出路径;
	public int 帧率 = 30;
	private int 帧=1;
	private bool 停止 = false;

	void Start ()
	{
		Invoke ("停止渲染", 渲染时长);
		Time.timeScale = 0;
		if (帧 < 10) {文件名称 = "0000" + 帧.ToString () + ".jpg";} 
		else if (帧 < 100) {文件名称 = "000" + 帧.ToString () + ".jpg";} 
		else if (帧 < 1000) {文件名称 = "00" + 帧.ToString () + ".jpg";} 
		else if (帧 < 10000) {文件名称 = "0" + 帧.ToString () + ".jpg";} 
		else {文件名称 = 帧.ToString () + ".jpg";} 
		Application.CaptureScreenshot (Application.dataPath + "/REC/"+文件名称);
		帧++;
		Time.timeScale = 时间流逝;
		InvokeRepeating ("渲染截图", 1f / (float)帧率, 1f / (float)帧率);
	}

	void Awake()
	{
		Application.targetFrameRate=帧率;
	}


	void 渲染截图 () {
		if (!停止) 
		{
			Time.timeScale = 0;
			if (帧 < 10) {文件名称 = "0000" + 帧.ToString () + ".png";} 
			else if (帧 < 100) {文件名称 = "000" + 帧.ToString () + ".png";} 
			else if (帧 < 1000) {文件名称 = "00" + 帧.ToString () + ".png";} 
			else if (帧 < 10000) {文件名称 = "0" + 帧.ToString () + ".png";} 
			else {文件名称 = 帧.ToString () + ".png";} 
			Application.CaptureScreenshot (Application.dataPath + "/REC/"+文件名称);
			帧++;
			Time.timeScale = 时间流逝;
		}
	}

	void 停止渲染 () {
		停止 = true;
		Time.timeScale = 0;
		CancelInvoke ("渲染截图");
		Debug.Log ("渲染完毕");
	}
}


步骤二:a.安装Homebrow,打开“终端”,输入

/usr/bin/ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"

安装开始图片


安装结束图片


步骤二:b.安装FFmpeg,打开“终端”,输入


注意:用这个代码的前提,必须Xcode 9.2版本,mac的系统必须在10.03以上


安装完毕截图


使用代码:

ffmpeg -loop 1 -f image2 -i /Users/encore/Desktop/REC/%05d.png -vcodec libx264 -r 10 -t 10 /Users/encore/Desktop/REC/test.mp4

如果退出了ffmepg,可以重新进入,mac上的路径:

cd /usr/local/Cellar/ffmpeg/4.0/bin

视频就制作完成了



猜你喜欢

转载自blog.csdn.net/SAP_Support/article/details/80519289
今日推荐