Skip to content

Commit 6911d6a

Browse files
committed
fix: avoid throwing exception when trying to create an output directory for ffmpeg process
1 parent ca0cd79 commit 6911d6a

File tree

1 file changed

+12
-5
lines changed

1 file changed

+12
-5
lines changed

src/LiveStreamingServerNet.StreamProcessor/Internal/FFmpeg/FFmpegProcess.cs

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -32,11 +32,21 @@ public async Task RunAsync(
3232
OnStreamProcessorEnded? onEnded,
3333
CancellationToken cancellation)
3434
{
35-
if (!Uri.IsWellFormedUriString(inputPath, UriKind.Absolute))
36-
DirectoryUtility.CreateDirectoryIfNotExists(Path.GetDirectoryName(_config.OutputPath));
35+
EnsureOutputDirectoryExists(_config.OutputPath);
3736
await RunProcessAsync(inputPath, _config.OutputPath, onStarted, onEnded, cancellation);
3837
}
3938

39+
private void EnsureOutputDirectoryExists(string outputPath)
40+
{
41+
ErrorBoundary.Execute(() =>
42+
{
43+
if (!Uri.IsWellFormedUriString(outputPath, UriKind.Absolute))
44+
{
45+
DirectoryUtility.CreateDirectoryIfNotExists(Path.GetDirectoryName(_config.OutputPath));
46+
}
47+
});
48+
}
49+
4050
private async Task RunProcessAsync(string inputPath, string outputPath, OnStreamProcessorStarted? onStarted, OnStreamProcessorEnded? onEnded, CancellationToken cancellation)
4151
{
4252
var arguments = _config.Arguments
@@ -49,9 +59,6 @@ private async Task RunProcessAsync(string inputPath, string outputPath, OnStream
4959

5060
try
5161
{
52-
if (!string.IsNullOrWhiteSpace(outputPath))
53-
File.Delete(outputPath);
54-
5562
process.StartInfo = new ProcessStartInfo
5663
{
5764
FileName = _config.FFmpegPath,

0 commit comments

Comments
 (0)