@@ -32,11 +32,39 @@ public async Task RunAsync(
32
32
OnStreamProcessorEnded ? onEnded ,
33
33
CancellationToken cancellation )
34
34
{
35
- if ( ! Uri . IsWellFormedUriString ( inputPath , UriKind . Absolute ) )
36
- DirectoryUtility . CreateDirectoryIfNotExists ( Path . GetDirectoryName ( _config . OutputPath ) ) ;
35
+ EnsureOutputDirectoryExists ( _config . OutputPath ) ;
36
+ CleanOutputFile ( _config . OutputPath ) ;
37
+
37
38
await RunProcessAsync ( inputPath , _config . OutputPath , onStarted , onEnded , cancellation ) ;
38
39
}
39
40
41
+ private void EnsureOutputDirectoryExists ( string outputPath )
42
+ {
43
+ ErrorBoundary . Execute ( ( ) =>
44
+ {
45
+ if ( IsNonUriOutputPath ( outputPath ) )
46
+ {
47
+ DirectoryUtility . CreateDirectoryIfNotExists ( Path . GetDirectoryName ( _config . OutputPath ) ) ;
48
+ }
49
+ } ) ;
50
+ }
51
+
52
+ private static void CleanOutputFile ( string outputPath )
53
+ {
54
+ ErrorBoundary . Execute ( ( ) =>
55
+ {
56
+ if ( IsNonUriOutputPath ( outputPath ) )
57
+ {
58
+ File . Delete ( outputPath ) ;
59
+ }
60
+ } ) ;
61
+ }
62
+
63
+ private static bool IsNonUriOutputPath ( string outputPath )
64
+ {
65
+ return ! string . IsNullOrWhiteSpace ( outputPath ) && ! Uri . IsWellFormedUriString ( outputPath , UriKind . Absolute ) ;
66
+ }
67
+
40
68
private async Task RunProcessAsync ( string inputPath , string outputPath , OnStreamProcessorStarted ? onStarted , OnStreamProcessorEnded ? onEnded , CancellationToken cancellation )
41
69
{
42
70
var arguments = _config . Arguments
@@ -49,9 +77,6 @@ private async Task RunProcessAsync(string inputPath, string outputPath, OnStream
49
77
50
78
try
51
79
{
52
- if ( ! string . IsNullOrWhiteSpace ( outputPath ) )
53
- File . Delete ( outputPath ) ;
54
-
55
80
process . StartInfo = new ProcessStartInfo
56
81
{
57
82
FileName = _config . FFmpegPath ,
@@ -86,7 +111,6 @@ private async Task RunProcessAsync(string inputPath, string outputPath, OnStream
86
111
await onEnded . Invoke ( outputPath ) ;
87
112
}
88
113
}
89
-
90
114
private static async Task WaitForProcessTerminatingGracefully ( Process process , int gracefulPeriod )
91
115
{
92
116
if ( ! process . HasExited )
0 commit comments