Project status: maintenance mode (bug fixes only).
YoutubeExplode.Converter is an extension package for YoutubeExplode that provides an interface to download and mux videos directly using FFmpeg.
- NuGet:
dotnet add package YoutubeExplode.Converter
- Download adaptive videos directly to a file
- Choose specific streams to use
- Configure conversion settings
- Works with .NET Standard 2.0+ and .NET Framework 4.6.1+ (desktop only)
This library relies on FFmpeg, which you can download here. By default, YoutubeExplode.Converter
will look for the CLI it in the probe directory (where the dll
files are located), but you can also specify the exact location as well.
Resource usage and execution time depends mostly on whether transcoding between streams is required. When possible, use streams that have the same container as the output format (e.g. mp4
audio/video streams for mp4
output format). Currently, YouTube only provides adaptive streams in mp4
or webm
containers, with highest quality video streams (e.g. 4K) only available in webm
.
The following will automatically resolve and determine the most fitting set of streams for the specified format, download them, and process into a single file:
using YoutubeExplode;
using YoutubeExplode.Converter;
var youtube = new YoutubeClient();
await youtube.Videos.DownloadAsync("https://youtube.com/watch?v=u_yIGGhubZs", "video.mp4");
Audio streams are prioritized by format then by bitrate, while video streams are prioritized by video quality and framerate, then by format. Additionally, if the output format is a known audio-only format (e.g. mp3
or ogg
) then only the audio stream is downloaded.
You can use one of the overloads to configure different aspects of the conversion process:
var youtube = new YoutubeClient();
await youtube.Videos.DownloadAsync(
"https://youtube.com/watch?v=u_yIGGhubZs", "video.mp4",
o => o
.SetFormat("webm") // override format
.SetPreset(ConversionPreset.UltraFast) // change preset
.SetFFmpegPath("path/to/ffmpeg") // custom FFmpeg location
);
You can also skip the default strategy for determining most fitting streams and pass them directly:
var youtube = new YoutubeClient();
// Get stream manifest
var streamManifest = await youtube.Videos.Streams.GetManifestAsync("https://youtube.com/watch?v=u_yIGGhubZs");
// Select streams (1080p60 / highest bitrate audio)
var audioStreamInfo = streamManifest.GetAudio().WithHighestBitrate();
var videoStreamInfo = streamManifest.GetVideo().FirstOrDefault(s => s.VideoQualityLabel == "1080p60");
var streamInfos = new IStreamInfo[] { audioStreamInfo, videoStreamInfo };
// Download and process them into one file
await youtube.Videos.DownloadAsync(streamInfos, new ConversionRequestBuilder("video.mp4").Build());