Coder Social home page Coder Social logo

youtubeexplode.converter's Introduction

YoutubeExplode.Converter

Build Coverage Version Downloads Donate

YoutubeExplode.Converter is a helper library for YoutubeExplode that provides an interface to download videos directly, without having to multiplex or convert streams yourself.

Download

  • NuGet: dotnet add package YoutubeExplode.Converter

Features

  • Download and multiplex videos directly to a file
  • Manually specify output format
  • Select specific streams to download
  • Progress reporting and cancellation
  • Fully asynchronous API
  • Targets .NET Framework 4.5+ and .NET Standard 2.0+ (only Desktop OS)

Usage

The library uses FFmpeg under the hood and thus requires the static link binaries in order to work (only ffmpeg.exe, the rest are not needed). The default YoutubeConverter constructor will look for it in the same directory but you can also specify the exact location.

If you don't want to add FFmpeg to your git repository, check out how it's downloaded in the test project.

Note: the resource usage and execution time mostly depends on whether transcoding 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.

Download video

This will automatically determine the most fitting audio and video streams, download them, and process them into a single file. Audio streams are prioritized by format then by bitrate. Video streams are prioritized by video quality and framerate, then by format. If the output format is audio-only (e.g. mp3) then the video stream is skipped entirely.

The approach above will try to select streams to achieve the fastest execution speed while not sacrificing video quality.

It's recommended to use mp4 as output format where possible, because most videos provide highest quality streams in mp4 and, when the former is not the case, transcoding to mp4 is the fastest compared to other formats.

var converter = new YoutubeConverter();
await converter.DownloadVideoAsync("-qmBhoeQgv8", "video.mp4"); // output format inferred from file extension

Download and mux specific streams

If you want a more fine-grained control over which streams are processed, you can select them yourself and pass them as a parameter to a different method. This lets you specify exact streams you want to use (e.g. for specific quality) while still benefiting from FFmpeg abstraction, progress reporting and cancellation support.

var youtube = new YoutubeClient();
var converter = new YoutubeConverter(youtube); // re-using the same client instance for efficiency, not required

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

// Select audio stream
var audioStreamInfo = streamManifest.GetAudio().WithHighestBitrate();

// Select video stream
var videoStreamInfo = streamManifest.GetVideo().FirstOrDefault(s => s.VideoQualityLabel == "1080p60");

// Combine them into a collection
var streamInfos = new IStreamInfo[] { audioStreamInfo, videoStreamInfo };

// Download and process them into one file
await converter.DownloadAndProcessMediaStreamsAsync(streamInfos, "video.mp4", "mp4");

youtubeexplode.converter's People

Contributors

tyrrrz avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.