Skip to content

Commit

Permalink
analizators/s4457
Browse files Browse the repository at this point in the history
  • Loading branch information
SuhorukovAnton committed Dec 28, 2021
1 parent c332120 commit ee79cec
Showing 1 changed file with 16 additions and 6 deletions.
22 changes: 16 additions & 6 deletions products/ASC.Files/Core/Services/FFmpegService/FFmpeg.cs
Original file line number Diff line number Diff line change
Expand Up @@ -33,11 +33,16 @@ public bool IsConvertable(string extension)
return MustConvertable.Contains(extension.TrimStart('.'));
}

public async Task<Stream> Convert(Stream inputStream, string inputFormat)
public Task<Stream> Convert(Stream inputStream, string inputFormat)
{
if (inputStream == null) throw new ArgumentException();
if (string.IsNullOrEmpty(inputFormat)) throw new ArgumentException();

return ConvertInternal(inputStream, inputFormat);
}

private async Task<Stream> ConvertInternal(Stream inputStream, string inputFormat)
{
var startInfo = PrepareFFmpeg(inputFormat);

Process process;
Expand All @@ -50,7 +55,7 @@ public async Task<Stream> Convert(Stream inputStream, string inputFormat)
await ProcessLog(process.StandardError.BaseStream);

return process.StandardOutput.BaseStream;
}
}
}

public FFmpegService(IOptionsMonitor<ILog> optionsMonitor, IConfiguration configuration)
Expand Down Expand Up @@ -116,13 +121,18 @@ private ProcessStartInfo PrepareFFmpeg(string inputFormat)
return startInfo;
}

private static async Task<int> StreamCopyToAsync(Stream srcStream, Stream dstStream, bool closeSrc = false, bool closeDst = false)
private static Task<int> StreamCopyToAsync(Stream srcStream, Stream dstStream, bool closeSrc = false, bool closeDst = false)
{
const int bufs = 2048 * 4;

if (srcStream == null) throw new ArgumentNullException("srcStream");
if (dstStream == null) throw new ArgumentNullException("dstStream");

return StreamCopyToAsyncInternal(srcStream, dstStream, closeSrc, closeDst);
}

private static async Task<int> StreamCopyToAsyncInternal(Stream srcStream, Stream dstStream, bool closeSrc, bool closeDst)
{
const int bufs = 2048 * 4;

var buffer = new byte[bufs];
int readed;
var total = 0;
Expand All @@ -146,7 +156,7 @@ private static async Task<int> StreamCopyToAsync(Stream srcStream, Stream dstStr
dstStream.Close();
}

return total;
return total;
}

private async Task ProcessLog(Stream stream)
Expand Down

0 comments on commit ee79cec

Please sign in to comment.