Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: direct audio proxy file writing #25

Merged
merged 1 commit into from
Jan 26, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 16 additions & 17 deletions src/Aurio.FFmpeg/FFmpegSourceStream.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
using System.IO;
using System.Security.Cryptography;
using System.Text;
using System.Threading.Tasks;
using Aurio.Streams;

namespace Aurio.FFmpeg
Expand Down Expand Up @@ -301,17 +302,20 @@ public static FileInfo CreateWaveProxy(FileInfo fileInfo, FileInfo proxyFileInfo
}

var reader = new FFmpegReader(fileInfo, FFmpeg.Type.Audio);

var writer = new MemoryWriterStream(
new AudioProperties(
reader.AudioOutputConfig.format.channels,
reader.AudioOutputConfig.format.sample_rate,
reader.AudioOutputConfig.format.sample_size * 8,
reader.AudioOutputConfig.format.sample_size == 4
? AudioFormat.IEEE
: AudioFormat.LPCM
)
var properties = new AudioProperties(
reader.AudioOutputConfig.format.channels,
reader.AudioOutputConfig.format.sample_rate,
reader.AudioOutputConfig.format.sample_size * 8,
reader.AudioOutputConfig.format.sample_size == 4
? AudioFormat.IEEE
: AudioFormat.LPCM
);
var writer = new BlockingFixedLengthFifoStream(properties, 1024 * 1024 * 16);

var writerTask = Task.Run(() =>
{
AudioStreamFactory.WriteToFile(writer, proxyFileInfo.FullName);
});

int output_buffer_size = reader.AudioOutputConfig.frame_size * writer.SampleBlockSize;
byte[] output_buffer = new byte[output_buffer_size];
Expand All @@ -334,13 +338,8 @@ out Type type
writer.Write(output_buffer, 0, bytesRead);
}

reader.Dispose();

writer.Position = 0;

AudioStreamFactory.WriteToFile(writer, proxyFileInfo.FullName);

writer.Close();
writer.SignalEndOfInput();
writerTask.Wait();

return proxyFileInfo;
}
Expand Down
Loading