private void StartFfmpegProcess(VideoRecordingOptions videoRecordingOptions) { var inputArgs = $"-thread_queue_size 512 -use_wallclock_as_timestamps 1 -f rawvideo -pix_fmt rgb32 -video_size {videoRecordingOptions.Width}x{videoRecordingOptions.Height} -i {pipePrefix}{pipeName}"; //$"-framerate {videoRecordingOptions.FrameRate} -f rawvideo -pix_fmt rgb32 -video_size {videoRecordingOptions.Width}x{videoRecordingOptions.Height} -i {pipePrefix}{pipeName}"; var outputArgs = $"-vcodec libx264 -crf 15 -pix_fmt yuv420p -preset ultrafast -r {videoRecordingOptions.FrameRate} -y {Path.Combine(videoRecordingOptions.Path, videoRecordingOptions.FileName)}"; //$"-vcodec libx264 -crf 17 -pix_fmt yuv420p -preset ultrafast -r {videoRecordingOptions.FrameRate} -y {Path.Combine(videoRecordingOptions.Path, videoRecordingOptions.FileName)}"; var ffmpegPath = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "ffmpeg.exe"); _ffmpegProcess = new Process { StartInfo = { FileName = ffmpegPath, Arguments = $"{inputArgs} {outputArgs}", UseShellExecute = false, CreateNoWindow = true, RedirectStandardError = true, RedirectStandardInput = true }, EnableRaisingEvents = true }; _ffmpegProcess.ErrorDataReceived += (s, e) => ProcessTheErrorData(s, e); _ffmpegProcess.Start(); _ffmpegProcess.BeginErrorReadLine(); }
public MainWindow() { InitializeComponent(); _timer = new Timer((TimeSpan time) => { TimerLbl.Content = time.ToString(); }); _videoRecordingOptions = new VideoRecordingOptions { FrameRate = 10, Height = 900, Width = 900, X = 300, Y = 300, Path = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "videos"), FileName = "out.mp4" }; }
public VideoWriter(VideoRecordingOptions videoRecordingOptions) { _videoBuffer = new byte[videoRecordingOptions.Width * videoRecordingOptions.Height * 4]; _ffmpegStream = new NamedPipeServerStream(pipeName, PipeDirection.Out, 1, PipeTransmissionMode.Byte, PipeOptions.Asynchronous, 0, _videoBuffer.Length); StartFfmpegProcess(videoRecordingOptions); }
public VideoRecording(VideoRecordingOptions videoRecordingOptions) { _frames = new BlockingCollection <Bitmap>(); _writer = new VideoWriter(videoRecordingOptions); _videoRecordingOptions = videoRecordingOptions; }