Пример #1
0
        public void StartRecording()
        {
            // First make sure recording microphone is only on MP4
            recordMicrophone &= container == Container.MP4;
            // Create recording configurations // Clamp video width to 720
            var width       = 720;
            var height      = width * Screen.height / Screen.width;
            var framerate   = container == Container.GIF ? 10 : 30;
            var videoFormat = new VideoFormat(width, (int)height, framerate);
            var audioFormat = recordMicrophone ? AudioFormat.Unity: AudioFormat.None;

            // Start recording
            NatCorder.StartRecording(container, videoFormat, audioFormat, OnReplay);
            videoRecorder = CameraRecorder.Create(Camera.main);
            // If recording GIF, skip a few frames to give a real GIF look
            if (container == Container.GIF)
            {
                videoRecorder.recordEveryNthFrame = 5;
            }
            // Start microphone and create audio recorder
            if (recordMicrophone)
            {
                StartMicrophone();
                audioRecorder = AudioRecorder.Create(microphoneSource, true);
            }
        }
Пример #2
0
 public frmCamera()
 {
     InitializeComponent();
     //初始化录制器
     recorderPath = AppDomain.CurrentDomain.BaseDirectory + DateTime.Now.ToString("MMddHHmmss") + ".mp4";
     recorder     = new CameraRecorder(recorderPath, 10, true);
 }
Пример #3
0
        } //END CallStartRecordingBlockEventExternalCamera

        //-------------------------------//
        private void OnRecordingComplete( string path )
        //-------------------------------//
        {
            //If our PersistentDataPath/VideoRecordings path does not exist, create it now
            if( !Directory.Exists( DatabaseStringHelper.CreatePersistentDataPath("VideoRecordings") ) )
            {
                Directory.CreateDirectory( DatabaseStringHelper.CreatePersistentDataPath("VideoRecordings") );
            }

            //Move the recording into the PersistentData folder under the 'VideoRecordings' subfolder
            if ( File.Exists( path ) )
            {
                FileInfo fileInfo = new FileInfo( path );

                if( fileInfo != null )
                {
                    File.Move( path, DatabaseStringHelper.CreatePersistentDataPath("VideoRecordings/" + fileInfo.Name ) );
                    path = DatabaseStringHelper.CreatePersistentDataPath("VideoRecordings/" + fileInfo.Name );
                }
            }

            if( showDebug ) { Debug.Log( "BlockEventRecorder.cs OnRecordingComplete() adding path to list of captured videos = " + path ); }

            //Add our path to our list of recorded videos
            if( recordedVideos == null ) { recordedVideos = new List<string>(); }

            recordedVideos.Add( path );

#if NATCORDER
            //If we were capturing images from a passed in camera, dispose of the cameraRecorder at this time to free up memory
            if( cameraRecorder != null )
            {
                cameraRecorder.Dispose();
                cameraRecorder = null;
            }
#endif

            //If we were capturing audio samples from an AudioListener or AudioSource, destroy the AudioGetter.cs helper script attached to it
            if( audioGetter != null )
            {
                Destroy( audioGetter );
                audioGetter = null;
            }

#if NATCORDER
            //If we were capturing audio from the app, dispose of the audioRecorder at this time
            if( audioRecorder != null )
            {
                audioRecorder.Dispose();
                audioRecorder = null;
            }
#endif

            if( onRecordingCompleted != null ) { onRecordingCompleted.Invoke( path ); }

        } //END OnRecordingComplete
Пример #4
0
 void StartRecording()
 {
     Debug.Log("start recording method");
     // Start recording
     format = new VideoFormat(960, 540);
     NatCorder.StartRecording(Container.MP4, format, AudioFormat.None, OnReplay);
     // Create a camera recorder to record the main camera
     clock         = new RealtimeClock();
     videoRecorder = CameraRecorder.Create(mainCamera, clock);
     // audioRecorder = AudioRecorder.Create(sourceAudio);
 }
Пример #5
0
    private void Awake()
    {
        m_Rigidbody = GetComponent <Rigidbody>();
        recorder    = GetComponent <CameraRecorder>();
        backend     = GetComponent <BackendConnection>();
        freezer     = GetComponent <Freezer>();

        freezer.freeze = true; // freeze in space (undeployed)

        // Set up the axes
        m_MovementAxisName = "Vertical";
        m_TurnAxisName     = "Horizontal";
    }
Пример #6
0
    public void StartRecording()
    {
        // Start the microphone
        var microphoneFormat = Format.Default;

        NatMic.StartRecording(microphoneFormat, OnSampleBuffer);
        // Start recording
        recordingClock = new RealtimeClock();
        var audioFormat = new AudioFormat(microphoneFormat.sampleRate, microphoneFormat.channelCount);

        NatCorder.StartRecording(Container.MP4, VideoFormat.Screen, audioFormat, OnRecording);
        // Create a camera recorder for the main cam
        cameraRecorder = CameraRecorder.Create(recordingCamera, recordingClock);
    }
Пример #7
0
 /// <summary>
 /// Start recording a replay with no audio
 /// </summary>
 /// <param name="recordingCamera">Source camera for recording replay</param>
 /// <param name="configuration">Configuration for recording</param>
 /// <param name="saveCallback">Callback to be invoked when the video is saved</param>
 public static void StartRecording(Camera recordingCamera, Configuration configuration, SaveCallback saveCallback)
 {
     if (!recordingCamera)
     {
         Util.LogError("Cannot record replay without source camera");
         return;
     }
     if (saveCallback == null)
     {
         Util.LogError("Cannot record replay without callback");
         return;
     }
     NatCorder.StartRecording(configuration, saveCallback);
     camera = recordingCamera.gameObject.AddComponent <CameraRecorder>();
 }
Пример #8
0
        public static void Renew(object s)
        {
            if (rec != null)
            {
                rec.StopRecording();
            }

            var configuration = new CameraRecorderConfiguration()
            {
                VideosFolderPath = Directory.GetCurrentDirectory() + @"\Camera\",
                VideoFormat      = ".mpeg4"
            };

            rec = new CameraRecorder(cam, configuration);
            rec.StartRecording();
        }
Пример #9
0
        private void InitCamera()
        {
            recorder          = new CameraRecorder();
            recorder.NewFrame = frame =>
            {
                this.picVideo.Image = (Bitmap)frame.Clone();
            };

            recorder.RecorderTimer = (seconds, timerString) =>
            {
                //10分钟自动保存一次
                if (seconds > (60 * 60))
                {
                    StopRecorder();
                    StartRecorder();
                }

                this.lblTimer.Invoke(new Action(() =>
                {
                    this.lblTimer.Text = timerString;
                }));
            };
        }
Пример #10
0
        public FrmMain()
        {
            InitializeComponent();
            for (int i = 1; i <= 30; i++)
            {
                this.cboFrameRate.Items.Add(i);
            }
            this.cboFrameRate.Text             = "15";
            this.FormClosing                  += FrmMain_FormClosing;
            this.cboDevs.SelectedIndexChanged += CboDevs_SelectedIndexChanged;
            recorder          = new CameraRecorder();
            recorder.NewFrame = frame =>
            {
                this.picVideo.Image = (Bitmap)frame.Clone();
            };

            recorder.RecorderTimer = (seconds, timerString) =>
            {
                this.lblTimer.Invoke(new Action(() =>
                {
                    this.lblTimer.Text = timerString;
                }));
            };
        }
Пример #11
0
 /// <summary>
 /// 开始录像
 /// </summary>
 public void StartRecorder()
 {
     videoRecorder.StartRecording();
     cameraRecorder = Camera.main.gameObject.AddComponent <CameraRecorder>();
     cameraRecorder.Setup(videoRecorder, null);
 }
Пример #12
0
 /// <summary>
 /// Stop recording a replay
 /// </summary>
 public static void StopRecording()
 {
     CameraRecorder.Destroy(camera);
     NatCorder.StopRecording();
 }
Пример #13
0
 // Start is called before the first frame update
 void Start()
 {
     characterInput = GetComponent <Character_Input>();
     recorder       = GetComponent <CameraRecorder>();
     UpdateCameraView(); // Initialize (make sure only one camera is active and appropriate wheels are hidden)
 }
Пример #14
0
    // Use this for initialization
    void Start()
    {
        float targetaspect = 1f;

        // determine the game window's current aspect ratio
        float windowaspect = (float)Screen.width / (float)Screen.height;

        // current viewport height should be scaled by this amount
        float scaleheight = windowaspect / targetaspect;

        // obtain camera component so we can modify its viewport
        Camera camera = GetComponent <Camera>();

        Debug.Log(Screen.height + " " + camera.orthographicSize);

        //camera.orthographicSize = Screen.height / 2f;

        float width = camera.orthographicSize * 2f * camera.aspect;

        camera.aspect = 1;

        camera.orthographicSize = width / 2f;

        //camera.pixelRect = new Rect(0, 0, Screen.width, Screen.width);

        // if scaled height is less than current height, add letterbox
        //if (scaleheight < 1.0f)
        //{
        //    Rect rect = camera.rect;

        //    rect.width = scaleheight;
        //    rect.height = 1.0f;
        //    rect.x = 0;
        //    rect.y = (1.0f - scaleheight) / 2.0f;

        //    camera.rect = rect;
        //}
        //else // add pillarbox
        //{
        //    float scalewidth = 1.0f / scaleheight;

        //    Rect rect = camera.rect;

        //    rect.width = scalewidth;
        //    rect.height = 1.0f;
        //    rect.x = (1.0f - scalewidth) / 2.0f;
        //    rect.y = 0;

        //    camera.rect = rect;
        //}

        VideoFormat videoFormat = new VideoFormat(GetComponent <Camera>().pixelWidth, GetComponent <Camera>().pixelWidth, 60);

        NatCorder.StartRecording(Container.MP4, videoFormat, AudioFormat.Unity, OnRecording);
        var videoRecorder = CameraRecorder.Create(GetComponent <Camera>());

        videoRecorder.recordEveryNthFrame = 4;
        var audioRecorder = AudioRecorder.Create(GetComponent <AudioListener>());

        timeLeft = 20f;
        StartCoroutine(startWait());
    }
Пример #15
0
        } //END CallEvent

        //------------------------------//
        private void CallStartRecordingUnityCameraEvent()
        //------------------------------//
        {

#if NATCORDER
            //We can only record one source at a time
            if( NatCorder.IsRecording ) { return; }

            if( useDefaultSettings )
            {
                if( showDebug ) { Debug.Log( "BlockEventRecorder.cs Calling StartRecording() for default Unity Camera" ); }
                NatCorder.StartRecording( Container.MP4, VideoFormat.Screen, AudioFormat.Unity, OnRecordingComplete );
            }
            else
            {
                
                //Set our AudioFormat to the defaults
                int _sampleRate = AudioFormat.Unity.sampleRate;
                int _channelCount = AudioFormat.Unity.channelCount;

                //Check if we need to override our default AudioFormat
                if( IsUseDefaultAudioSettingsFalse() )
                {
                    _sampleRate = sampleRate;
                    _channelCount = channelCount;
                }

                //If our Video Container format is GIF, we cannot allow any kind of audio recording
                if( IsVideoContainerGIF() )
                {
                    NatCorder.StartRecording(
                    container,
                    GetVideoFormatForUnityCamera(),
                    AudioFormat.None,
                    OnRecordingComplete );
                }

                //Otherwise our audio should be based on the settings we selected
                else
                {
                    //Use the customized audio settings
                    if( IsUseDefaultAudioSettingsFalse() )
                    {
                        NatCorder.StartRecording(
                        container,
                        GetVideoFormatForUnityCamera(),
                        new AudioFormat( _sampleRate, _channelCount ),
                        OnRecordingComplete );
                    }

                    //Use the default audio settings
                    else
                    {
                        if( audioFormat == AudioRecordFormat.None )
                        {
                            NatCorder.StartRecording(
                            container,
                            GetVideoFormatForUnityCamera(),
                            AudioFormat.None,
                            OnRecordingComplete );
                        }
                        else if( audioFormat == AudioRecordFormat.Unity )
                        {
                            NatCorder.StartRecording(
                            container,
                            GetVideoFormatForUnityCamera(),
                            AudioFormat.Unity,
                            OnRecordingComplete );
                        }
                        
                    }
                }
            }

            //Start sending the texture data from the passed in camera to the recorder
            if( cameraToRecord != null )
            {
                cameraRecorder = null;
                cameraRecorder = CameraRecorder.Create( cameraToRecord );
            }

            //Start sending the audio data from the scene's AudioListener to the recorder
            if( audioListener != null )
            {
                audioRecorder = null;
                audioRecorder = AudioRecorder.Create( audioListener );
            }

            if( onRecordingStarted != null ) { onRecordingStarted.Invoke(); }
#else
            Debug.LogError( "BlockEventRecorder.cs CallStartRecordingUnityCameraEvent() missing NATCORDER scripting define symbol under project settings" );
#endif

        } //END CallStartRecordingUnityCameraEvent