Update audio extraction to use file-based streaming instead of in-memory buffers to support processing video files larger than 2GB. **Changes:** - Modified `IAudioExtractor.ExtractMp3FromMp4Async()` to accept an output audio stream parameter instead of creating a MemoryStream internally - Updated `AudioExtractor` to write directly to the provided audio stream, eliminating the need to load entire video into memory - Enhanced `FFMpegService` to detect FileStream inputs and use direct file-to-file processing when possible, falling back to pipe-based streaming for other stream types - Refactored `DefaultCommand` to create output directory and audio file stream before extraction, enabling direct file-based audio extraction - Updated all unit and integration tests to accommodate the new audio stream parameter This change prevents `OutOfMemoryException` errors when processing large video files by streaming data directly to disk rather than buffering in memory. Additionally, it removes the possibility of overflowing the 2GB size limit that `MemoryStream` has, which would result in `IOException` errors when trying to write or copy to it.
29 lines
885 B
C#
29 lines
885 B
C#
namespace StreamShorts.Library.Tests.Integration.Media.Audio;
|
|
|
|
public class AudioExtractorTests
|
|
{
|
|
private readonly AudioExtractor _sut = new();
|
|
|
|
[Fact]
|
|
public async Task ExtractMp3FromMp4Async_WhenCalled_ItShouldExtractAudio()
|
|
{
|
|
using var testVideo = TestData.GetTestVideo();
|
|
using var extractedAudio = TestData.GetExtractedAudio();
|
|
using var audioStream = new MemoryStream();
|
|
|
|
var result = await _sut.ExtractMp3FromMp4Async(testVideo, audioStream);
|
|
|
|
var audioBytes = await ConvertStreamToBytesAsync(extractedAudio);
|
|
var resultBytes = await ConvertStreamToBytesAsync(result);
|
|
|
|
resultBytes.Should().Equal(audioBytes);
|
|
result.Should().BeSameAs(audioStream);
|
|
}
|
|
|
|
private static async Task<byte[]> ConvertStreamToBytesAsync(Stream stream)
|
|
{
|
|
using var ms = new MemoryStream();
|
|
await stream.CopyToAsync(ms);
|
|
return ms.ToArray();
|
|
}
|
|
} |