Skip to content
This repository has been archived by the owner. It is now read-only.
master
Switch branches/tags
Code

Latest commit

 

Git stats

Files

Permalink
Failed to load latest commit information.
Type
Name
Latest commit message
Commit time
 
 
 
 
 
 
 
 
 
 
 
 
 
 

YoutubeExplode.Converter

Build Coverage Version Downloads Discord Donate

⚠️ Project status: maintenance mode (bug fixes only).

The contents of this repository have been moved to YoutubeExplode.

YoutubeExplode.Converter is an extension package for YoutubeExplode that provides an interface to download and mux videos directly using FFmpeg.

Download

📦 NuGet: dotnet add package YoutubeExplode.Converter

Usage

Note that this library relies on FFmpeg binaries, which you can download here. By default, YoutubeExplode.Converter will look for FFmpeg in the probe directory (where the application's dll files are located), but you can also specify the exact location as well.

Downloading a video in highest quality

YoutubeExplode.Converter can be used through one of the extension methods provided on VideoClient. For example, to download a video in the best available quality, simply call DownloadAsync(...) with the video ID and the destination file path:

using YoutubeExplode;
using YoutubeExplode.Converter;

var youtube = new YoutubeClient();
await youtube.Videos.DownloadAsync("https://youtube.com/watch?v=u_yIGGhubZs", "video.mp4");

Under the hood, this resolves available media streams and selects the best candidates based on bitrate, quality, and framerate. If the specified output format is a known audio-only container (e.g. mp3 or ogg) then only the audio stream is downloaded.

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.

Custom conversion options

You can configure various aspects pertaining to the conversion process by using one of the overloads of DownloadAsync(...):

using YoutubeExplode;
using YoutubeExplode.Converter;

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
);

Specifying streams manually

If you need precise control over which streams are used for conversion, you can specify them directly as well:

using YoutubeExplode;
using YoutubeExplode.Videos.Streams;
using YoutubeExplode.Converter;

var youtube = new YoutubeClient();

// Get stream manifest
var streamManifest = await youtube.Videos.Streams.GetManifestAsync("u_yIGGhubZs");

// Select streams (1080p60 / highest bitrate audio)
var audioStreamInfo = streamManifest.GetAudioStreams().GetWithHighestBitrate();
var videoStreamInfo = streamManifest.GetVideoStreams().First(s => s.VideoQuality.Label == "1080p60");
var streamInfos = new IStreamInfo[] { audioStreamInfo, videoStreamInfo };

// Download and process them into one file
await youtube.Videos.DownloadAsync(streamInfos, new ConversionRequestBuilder("video.mp4").Build());