Documentation's Desktop Capture with Cancelation Token Example is not working.
GeraldEugenio opened this issue · comments
Hi,
I want to start and stop desktop screen recording programmatically and I tried this code from the documentation and put it in a Console App (.Net 5) but unfortunately, I haven't successfully executed the said code. The app is freezing and I have to manually stop the app and kill the ffmpeg.exe process in the Task Manager since it consumes large resources. Also, the output file was zero bytes.
using System.IO;
using System.Threading;
using System.Threading.Tasks;
using Xabe.FFmpeg;
namespace ScreenRecording
{
internal class Program
{
static async Task Main(string[] args)
{
string output = Path.Combine("C:", "Temp", "desktop_capture.mp4");
CancellationTokenSource cancellationTokenSource = new CancellationTokenSource();
await FFmpeg.Conversions.New()
.AddDesktopStream()
.SetOutput(output)
.SetOverwriteOutput(true)
.Start(cancellationTokenSource.Token);
await Task.Delay(5000);
cancellationTokenSource.Cancel();
}
}
}
Hello @GeraldEugenio
Awaiting conversion blocks your thread. You have to run it in separate task or use CancellationTokenSource with time limit