工具
1.視訊編碼器。下載下傳後輕按兩下安裝。
連結:https://pan.baidu.com/s/1iTcLu8RiTqDNXlnj5NdnFQ
提取碼:yih9
2.AVProMovieCapture,下載下傳後導入Unity工程。
連結:https://pan.baidu.com/s/11r5SE4fLKxwcgqHSGuCsqg
提取碼:t7ln
步驟
1.使用AVProMovieCapture錄制視訊并且含外音即CaptureAudio為ture,需設定CaptureMode:ReadltimeCapture,Source:System Recoding Device。

2.使用預設編碼格式錄屏會占用大量的記憶體。使用h.264錄屏會卡頓。是以自己安裝了一種編碼格式:x264vfw - H.264/MPEG-4 AVC codec,錄制時Code設定為它即可。其他設定如圖:
3.修改CaptureBase.cs
4.添加RecordVidioButton.cs
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using RenderHeads.Media.AVProMovieCapture;
using UnityEngine.UI;
public class RecordVidioButton : MonoBehaviour
{
public CaptureBase m_MovieCapture;
[HideInInspector]
public int OnClickCount = 0;
public Button m_RecordButton;
private float m_Shake;
private Image m_RecordBg;
// Use this for initialization
void Start()
{
m_RecordButton.onClick.AddListener(StartRecord);
}
// Update is called once per frame
void Update()
{
閃爍效果
//if (m_RecordBg != null)
//{
// m_Shake += Time.deltaTime;
// if (m_Shake % 1 > 0.5f)
// {
// m_RecordBg.enabled = true;
// }
// else
// {
// m_RecordBg.enabled = false;
// }
//}
}
public void StartRecord()
{
if (OnClickCount == 0)
{
m_MovieCapture.index++;
m_MovieCapture.StartCapture();
//Tip.m_TipStatic.m_RecordImg.gameObject.SetActive(true);
OnClickCount = 1;
//m_RecordBg = Tip.m_TipStatic.m_RecordImg.gameObject.GetComponent<Image>();
}
else
{
m_MovieCapture.StopCapture();
//Tip.m_TipStatic.m_RecordImg.gameObject.SetActive(false);
m_RecordBg = null;
OnClickCount = 0;
}
}
}
5.參考場景Demo:ScreenCaptureDemo。
6.最後效果: