static void Main(string[] args) { string folder = $"C:\\Users\\{Environment.UserName}\\Downloads\\Nuclear"; foreach (var file in Directory.GetFiles(folder).Where(f => f.EndsWith(".webm"))) { Console.WriteLine(file); var outputStream = File.OpenWrite(file.Replace(".webm", ".opus")); MatroskaDemuxer.ExtractOggOpusAudio(File.OpenRead(file), outputStream); outputStream.Close(); } }
public async Task <Stream> GetOggOpusAudioStreamAsync([HttpTrigger(AuthorizationLevel.Function, "post")] HttpRequest req) { _logger.LogInformation("HttpTrigger - GetOggOpusAudioStreamAsync"); var streamInfo = await _serializer.DeserializeAsync <AudioOnlyStreamInfo>(req.Body); var destinationStream = new MemoryStream(); await _client.Videos.Streams.CopyToAsync(streamInfo, destinationStream); destinationStream.Position = 0; var oggOpusStream = new MemoryStream(); MatroskaDemuxer.ExtractOggOpusAudio(destinationStream, oggOpusStream); oggOpusStream.Position = 0; return(oggOpusStream); }
static void Main(string[] args) { string downloads = $"C:\\Users\\{Environment.UserName}\\Downloads\\"; //var orgStream = File.OpenRead(downloads + "Estas Tonne - Internal Flight Experience (Live in Cluj Napoca)_org.opus"); //var oggHeader1 = new OggHeader(); //var source = new BinaryReader(orgStream); //oggHeader1.ReadFromStream(source); //var orgData = File.ReadAllBytes(downloads + "Estas Tonne - Internal Flight Experience (Live in Cluj Napoca)_org.opus"); var f = "Estas Tonne - Internal Flight Experience (Live in Cluj Napoca).webm"; var dataStream = new FileStream(downloads + f, FileMode.Open, FileAccess.Read); //var doc1 = MatroskaSerializer.Deserialize(new FileStream(downloads + @"matroska_test_w1_1\test1.mkv", FileMode.Open, FileAccess.Read)); //var doc2 = MatroskaSerializer.Deserialize(new FileStream(downloads + @"matroska_test_w1_1\test2.mkv", FileMode.Open, FileAccess.Read)); //var doc3 = MatroskaSerializer.Deserialize(new FileStream(downloads + @"matroska_test_w1_1\test3.mkv", FileMode.Open, FileAccess.Read)); //var doc5 = MatroskaSerializer.Deserialize(new FileStream(downloads + @"matroska_test_w1_1\test5.mkv", FileMode.Open, FileAccess.Read)); //var doc6 = MatroskaSerializer.Deserialize(new FileStream(downloads + @"matroska_test_w1_1\test6.mkv", FileMode.Open, FileAccess.Read)); //var doc8 = MatroskaSerializer.Deserialize(new FileStream(downloads + @"matroska_test_w1_1\test8.mkv", FileMode.Open, FileAccess.Read)); var doc = MatroskaSerializer.Deserialize(dataStream); Console.WriteLine(JsonSerializer.Serialize(doc.Segment.Info, jsonOptions)); Console.WriteLine(JsonSerializer.Serialize(doc.Segment.Tracks, jsonOptions)); var fileStream = File.OpenWrite(downloads + "Estas Tonne - Internal Flight Experience (Live in Cluj Napoca).opus"); MatroskaDemuxer.ExtractOggOpusAudio(doc, fileStream); var stream = new MemoryStream(); MatroskaDemuxer.ExtractOggOpusAudio(doc, stream); ISoundOut soundOut; if (WasapiOut.IsSupportedOnCurrentPlatform) { soundOut = new WasapiOut(); } else { soundOut = new DirectSoundOut(); } stream.Position = 0; var track = new Track(stream, ".opus"); Console.WriteLine(JsonSerializer.Serialize(track, new JsonSerializerOptions { WriteIndented = true })); var waveSource = new OpusSource(stream, (int)track.SampleRate, 2); Console.WriteLine("len = {0} {1}", waveSource.Length, waveSource.GetLength()); soundOut.Initialize(waveSource); waveSource.SetPosition(TimeSpan.FromMinutes(6)); soundOut.Play(); }