Example #1
0
        /// <summary>
        /// Stop capturing and produce the finalized video. Note that the video file may not be completely written when this method returns. In order to know when the video file is complete, register <c>OnComplete</c> delegate.
        /// </summary>
        public bool StopCapture()
        {
            if (status != CaptureStatus.STARTED)
            {
                Debug.LogWarningFormat(LOG_FORMAT, "Video capture session not start yet!");
                return(false);
            }

            if (offlineRender)
            {
                // Restore maximumDeltaTime states.
                Time.maximumDeltaTime = originalMaximumDeltaTime;
            }

            // pending for video encoding process
            status = CaptureStatus.STOPPED;

            if (hardwareEncoding && gpuEncoder.captureStarted)
            {
                gpuEncoder.StopCapture();
            }

            if (!hardwareEncoding && ffmpegEncoder.captureStarted)
            {
                ffmpegEncoder.StopCapture();

                if (captureAudio && FFmpegMuxer.singleton && FFmpegMuxer.singleton.captureStarted)
                {
                    FFmpegMuxer.singleton.StopCapture();
                }

                Debug.LogFormat(LOG_FORMAT, "Video capture session stopped, generating video...");
            }

            return(true);
        }
Example #2
0
        /// <summary>
        /// Stop capturing and produce the finalized video. Note that the video file may not be completely written when this method returns. In order to know when the video file is complete, register <c>OnComplete</c> delegate.
        /// </summary>
        public override bool StopCapture()
        {
            if (status != CaptureStatus.STARTED)
            {
                Debug.LogWarningFormat(LOG_FORMAT, "Video capture session not start yet!");
                return(false);
            }

            if (offlineRender)
            {
                // Restore captureFramerate states.
                Time.captureFramerate = 0;
            }

            // pending for video encoding process
            status = CaptureStatus.STOPPED;

            if (gpuEncoding)
            {
                if (nvidiaEncoding)
                {
                    if (nvidiaEncoder.captureStarted)
                    {
                        if (captureAudio)
                        {
                            if (audioRecorder.RecordStarted())
                            {
                                audioRecorder.StopRecord();
                            }

                            FFmpegMuxer.singleton.SetAudioFile(audioRecorder.GetRecordedAudio());

                            if (captureMicrophone)
                            {
                                if (microphoneRecorder.RecordStarted())
                                {
                                    microphoneRecorder.StopRecord();
                                }

                                FFmpegMuxer.singleton.SetAudioFile2(microphoneRecorder.GetRecordedAudio());
                            }

                            if (!FFmpegMuxer.singleton.muxInitiated)
                            {
                                FFmpegMuxer.singleton.InitMux();
                            }
                        }
                        else
                        {
                            if (!FFmpegTranscoder.singleton.transcodeInitiated)
                            {
                                FFmpegTranscoder.singleton.InitTranscode();
                            }
                        }

                        nvidiaEncoder.StopCapture();

                        Debug.LogFormat(LOG_FORMAT, "Video capture session stopped, generating video...");
                    }
                }
                else
                {
                    if (gpuEncoder.captureStarted)
                    {
                        gpuEncoder.StopCapture();
                    }
                }
            }
            else
            {
                if (ffmpegEncoder.captureStarted)
                {
                    ffmpegEncoder.StopCapture();

                    if (captureAudio)
                    {
                        if (audioRecorder.RecordStarted())
                        {
                            audioRecorder.StopRecord();
                        }

                        if (captureMicrophone)
                        {
                            if (microphoneRecorder.RecordStarted())
                            {
                                microphoneRecorder.StopRecord();
                            }
                        }
                    }

                    if (captureType == CaptureType.VOD)
                    {
                        if (captureAudio)
                        {
                            FFmpegMuxer.singleton.SetAudioFile(audioRecorder.GetRecordedAudio());

                            if (captureMicrophone)
                            {
                                FFmpegMuxer.singleton.SetAudioFile2(microphoneRecorder.GetRecordedAudio());
                            }

                            if (!FFmpegMuxer.singleton.muxInitiated)
                            {
                                FFmpegMuxer.singleton.InitMux();
                            }
                        }

                        Debug.LogFormat(LOG_FORMAT, "Video capture session stopped, generating video...");
                    }
                    else if (captureType == CaptureType.LIVE && FFmpegStreamer.singleton.streamStarted)
                    {
                        FFmpegStreamer.singleton.StopStream();
                    }
                }
            }

            // Reset camera settings.
            ResetCameraSettings();

            // Restore screen render.
            if (screenBlitter)
            {
                ClearBlitterInstance();
            }

            audioRecorder      = null;
            microphoneRecorder = null;

            return(true);
        }