-
-
Save SlowLogicBoy/45f25b3711c341ba974fe22f04f71f4a to your computer and use it in GitHub Desktop.
This prototype pipes audio stream to ffmpeg and get result stream back.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#r "nuget: YoutubeExplode, *" | |
using YoutubeExplode; | |
using YoutubeExplode.Models.MediaStreams; | |
const string FFmpegPath = "./ffmpeg.exe"; | |
var youtubeClient = new YoutubeClient(); | |
var mediaStreamInfo = await youtubeClient.GetVideoMediaStreamInfosAsync("uBg-nNJCnmM"); | |
var audioStream = mediaStreamInfo.Audio.WithHighestBitrate(); | |
var processStartInfo = new ProcessStartInfo | |
{ | |
FileName = Path.GetFullPath(FFmpegPath), | |
Arguments = $"-i pipe:0 -vn -ar 44100 -ac 2 -ab 192k -f mp3 -", | |
RedirectStandardInput = true, | |
RedirectStandardOutput = true, | |
UseShellExecute = false | |
}; | |
using (var process = Process.Start(processStartInfo)) | |
{ | |
using (var fs = new FileStream("output.mp3", FileMode.CreateNew)) | |
{ | |
var downloadTask = youtubeClient.DownloadMediaStreamAsync(audioStream, process.StandardInput.BaseStream); | |
var outputTask = process.StandardOutput.BaseStream.CopyToAsync(fs); | |
await downloadTask; | |
process.StandardInput.Close(); | |
await outputTask; | |
process.StandardOutput.Close(); | |
} | |
process.WaitForExit(); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment