コード例 #1
0
        private void AbortRecording(RecordingSession session)
        {
            Debug.LogError("FFmpeg has exited.");

            var videoError = CloseProcess(videoProcess);

            if (!string.IsNullOrEmpty(videoError))
            {
                Debug.LogError("Video encoding process: " + videoError);
            }

            videoProcess?.Dispose();
            videoProcess = null;

            var audioError = CloseProcess(videoProcess);

            if (!string.IsNullOrEmpty(videoError))
            {
                Debug.LogError("Video encoding process: " + audioError);
            }

            audioProcess?.Dispose();
            audioProcess = null;

            session.Dispose();
        }
コード例 #2
0
 private void CreateAudioProcess(string outputPath, int sampleRate, int channelCount)
 {
     audioProcess?.Dispose();
     audioProcess = new FFmpegHost(
         Settings.FFmpegExecutablePath,
         $"-y -f f32le -ar {sampleRate} -ac {channelCount}"
         + " -loglevel error -i - "
         + (string.IsNullOrEmpty(Settings.AudioCodec) ? "" : $" -acodec {Settings.AudioCodec}")
         + $" -ar {sampleRate} -ac {channelCount}"
         + $" {Settings.AudioArguments}"
         //+ $" -map 0:0 -f data"
         + $" \"{outputPath}_audio.{Settings.OutputExtension}\"");
 }
コード例 #3
0
 private void CreateVideoProcess(int width, int height, Rational frameRate, string outputPath,
                                 bool withoutMux = false)
 {
     videoProcess?.Dispose();
     videoProcess = new FFmpegHost(
         Settings.FFmpegExecutablePath,
         "-y -f rawvideo -vcodec rawvideo -pixel_format rgba"
         + " -video_size " + width + "x" + height
         + " -framerate " + frameRate.ToString()
         + " -loglevel error -i - " + "-pix_fmt yuv420p"
         + (Settings.VideoBitrate <= 0 ? "" : $" -b:v {Settings.VideoBitrate}")
         + (string.IsNullOrEmpty(Settings.VideoCodec) ? "" : $" -vcodec {Settings.VideoCodec}")
         + $" {Settings.VideoArguments}"
         + (withoutMux ? $" \"{outputPath}\"" : $" \"{outputPath}_video.{Settings.OutputExtension}\""));
 }
コード例 #4
0
        private string CloseProcess(FFmpegHost process)
        {
            if (process != null)
            {
                if (process.StdIn != null)
                {
                    process.StdIn.Close();
                }

                process.FFmpeg.WaitForExit();
                var outputReader = process.FFmpeg.StandardError;
                var error        = outputReader.ReadToEnd();
                return(error);
            }

            return(null);
        }
コード例 #5
0
        protected override void DisposeEncoder()
        {
            base.DisposeEncoder();

            Debug.Log("FFmpeg Recorder: End Encoder");

            bool mux = Settings.AudioInputSettings.PreserveAudio;

            if (audioProcess != null && videoProcess != null)
            {
                var videoError = CloseProcess(videoProcess);
                if (!string.IsNullOrEmpty(videoError))
                {
                    Debug.LogError("Video encoding process: " + videoError);
                }
                var audioError = CloseProcess(audioProcess);
                if (!string.IsNullOrEmpty(videoError))
                {
                    Debug.LogError("Audio encoding process: " + audioError);
                }

                if (mux)
                {
                    var muxProcess = new FFmpegHost(
                        Settings.FFmpegExecutablePath,
                        $"-y -loglevel error" +
                        $" -i \"{AbsoluteFilename}_audio.{Settings.OutputExtension}\" -i \"{AbsoluteFilename}_video.{Settings.OutputExtension}\"" +
                        $" -c:v copy -c:a copy" +
                        $" \"{AbsoluteFilename}\""
                        , true);
                    Debug.Log("FFmpeg Recorder: Start muxing");

                    muxProcess.FFmpeg.EnableRaisingEvents = true;
                    SynchronizationContext c = SynchronizationContext.Current;
                    muxProcess.FFmpeg.Exited += (obj, e) =>
                    {
                        c.Post((_) =>
                        {
                            muxProcess.FFmpeg.WaitForExit();
                            var outputReader = muxProcess.FFmpeg.StandardError;
                            var error        = outputReader.ReadToEnd();
                            if (!string.IsNullOrEmpty(error))
                            {
                                Debug.LogError("Muxing process: " + error);
                            }
                            else
                            {
                                File.Delete($"{AbsoluteFilename}_audio.{Settings.OutputExtension}");
                                File.Delete($"{AbsoluteFilename}_video.{Settings.OutputExtension}");
                            }

                            Debug.Log("FFmpeg Recorder: End muxing");
                        }, false);
                    };
                }

                videoProcess?.Dispose();
                audioProcess?.Dispose();
                videoProcess = null;
                audioProcess = null;
            }
        }