Unity3D windows平台视频录制录屏插件 UnityRecorder

1:Asset Store 搜索下载 :UnityRecorder

Unity3D windows平台视频录制录屏插件 UnityRecorder_第1张图片

2.打开 Window-> General-> Recorder -> Recorder Window

Unity3D windows平台视频录制录屏插件 UnityRecorder_第2张图片

3.添加新的录制 Movie  选择格式为 Mp4  选择录制分辩率为跟随系统 Custom  屏幕高宽比: 1920*1080 

1.exit play mode 退出播放模式

2.Record mode 记录模式  

      2.1 Manual 手动

      2.2 Single Frame 单帧记录 Frame 记录多少帧 

      2.3 Frame Interval 帧间隔,从开始到结束

      2.4 Time Interval 时间间隔 ,真实时间秒数录制

3. Frame Rate 帧速率 

     3.1 Playback  回放  -》 Constant  常数 

     3.2 Target    Custom  自定义  

4.Format : 输出模式 Mp4 

5.Capture : 录制  1.Game 视图  2. 自定义选择一个摄像机 3. 360视图  4.渲染纹理资源 5.纹理采样

6.output Resolution 分辨率 

7. Aspect  Ratio 屏幕宽度比 

8.Capture audio :是否录声音

9.Quality:录制质量  差 ,一般, 高

Unity3D windows平台视频录制录屏插件 UnityRecorder_第3张图片

4.点击START RECORDING 开始录制  ,点击 Stop 停止 ,输出文件夹自己选择 

Unity3D windows平台视频录制录屏插件 UnityRecorder_第4张图片

5.例子:从官方例子简单改了

using UnityEditor;
using UnityEditor.Recorder;
using UnityEditor.Recorder.Input;
using System;

namespace UnityEngine.Recorder.Examples
{
    public enum RecorderControllerState
    {
        Video,
        Animation,
        ImageSequence
    }

    /// 
    /// 录制
    /// 
    public class RecorderExammlpText : MonoBehaviour
    {
        RecorderController m_RecorderController;

        private RecorderControllerState controllerState = RecorderControllerState.Video;
        [Header("下面两个单纯观看数据,不用管")]
        public RecorderControllerSettings controllerSettings;
        public MovieRecorderSettings videoRecorder;

        private string animationOutputFolder;
        private string mediaOutputFolder;
        
        private void Start()
        {
            controllerSettings = ScriptableObject.CreateInstance();
            m_RecorderController = new RecorderController(controllerSettings);
            animationOutputFolder = Application.dataPath + "/SampleRecordings";
            mediaOutputFolder = Application.dataPath + "../SampleRecordings";

        }

        private void Update()
        {
            if (Input.GetKeyDown(KeyCode.A))
            {
                StartRecorder();
            }
            if (Input.GetKeyDown(KeyCode.D))
            {
                StopRecorder();
            }
        }

        #region 记录视频-结束视频 位置在项目根目录

        /// 
        /// 开始记录视频
        /// 
        /// 默认视频
        public void StartRecorder(RecorderControllerState state = RecorderControllerState.Video)
        {

            //var outputFolder = Application.dataPath + "/SampleRecordings";
            switch (state)
            {
                case RecorderControllerState.Video:

                    // Video
                    RecorderVideo();

                    break;
                case RecorderControllerState.Animation:

                    // Animation
                    RecorderAnimation();
                    break;
                case RecorderControllerState.ImageSequence:

                    // Image Sequence
                    RecorderImageSequence();
                    break;

                default:
                    break;
            }
            // Setup Recording

            controllerSettings.SetRecordModeToManual();
            controllerSettings.frameRate = 60.0f;

            Options.verboseMode = false;
            m_RecorderController.StartRecording();
        }

        /// 
        /// 录制视频
        /// 
        private void RecorderVideo()
        {
            videoRecorder = ScriptableObject.CreateInstance();
            videoRecorder.name = "My Video Recorder";
            videoRecorder.enabled = true;

            videoRecorder.outputFormat = VideoRecorderOutputFormat.MP4;
            videoRecorder.videoBitRateMode = VideoBitrateMode.Low;

            // videoRecorder.SetOutput_720p_HD(); GameViewInputSettings 修改屏幕分辨率
            videoRecorder.imageInputSettings = new GameViewInputSettings
            {
                outputWidth = 1920,
                outputHeight = 1080
            };

            videoRecorder.audioInputSettings.preserveAudio = true;
            string str = DateTime.Now.Year.ToString()+"_" + DateTime.Now.Month + "_" + DateTime.Now.Day + "_" + DateTime.Now.Hour + "_" + DateTime.Now.Minute + "_" + DateTime.Now.Second;
            videoRecorder.outputFile = mediaOutputFolder + "/Magic_" + str;
            controllerSettings.AddRecorderSettings(videoRecorder);
        }

        /// 
        /// 动画
        /// 
        private void RecorderAnimation()
        {
            var animationRecorder = ScriptableObject.CreateInstance();
            animationRecorder.name = "My Animation Recorder";
            animationRecorder.enabled = true;

            var sphere = GameObject.CreatePrimitive(PrimitiveType.Sphere);

            animationRecorder.animationInputSettings = new AnimationInputSettings
            {
                gameObject = sphere,
                recursive = true,
            };

            animationRecorder.animationInputSettings.AddComponentToRecord(typeof(Transform));

            animationRecorder.outputFile = animationOutputFolder + "/animation_" + DefaultWildcard.GeneratePattern("GameObject") + "_" + DefaultWildcard.Take;

            controllerSettings.AddRecorderSettings(animationRecorder);
        }

        /// 
        /// 图像序列
        /// 
        private void RecorderImageSequence()
        {
            var imageRecorder = ScriptableObject.CreateInstance();
            imageRecorder.name = "My Image Recorder";
            imageRecorder.enabled = true;

            imageRecorder.outputFormat = ImageRecorderOutputFormat.PNG;
            imageRecorder.captureAlpha = true;

            imageRecorder.outputFile = mediaOutputFolder + "/image_" + DefaultWildcard.Frame + "_" + DefaultWildcard.Take;

            imageRecorder.imageInputSettings = new CameraInputSettings
            {
                source = ImageSource.MainCamera,
                outputWidth = 1920,
                outputHeight = 1080,
                captureUI = true
            };

            controllerSettings.AddRecorderSettings(imageRecorder);
        }

        /// 
        /// 停止录制
        /// 
        public void StopRecorder()
        {
            Debug.Log("停止录制");
            m_RecorderController.StopRecording();
            controllerSettings.RemoveRecorder(videoRecorder);
        }

        #endregion


        void OnDisable()
        {
            StopRecorder();
           
        }
    }
}

 

你可能感兴趣的:(学习优化)