Coder Social home page Coder Social logo

bitcodin-dotnet's Introduction

bitmovin

The bitcodin API for C# is a seamless integration with the bitmovin cloud transcoding service. It enables the generation of MPEG-DASH and HLS content in just some minutes.

#Preparations

Before you can use the bitcodin-c# API wrapper, you need a version of .NET that is compatible with that platform:

###Windows

###Linux

###OS X

#Usage

Before you can start using the api you need to set your API key.

Your API key can be found in the settings of your bitmovin user account, as shown in the figure below.

APIKey

An example how you can instantiate the bitcodin API is shown in the following:

using com.bitmovin.bitcodin.Api;
public static class BitcodinApiTest
{
  public static void Run()
  {
    const string apiKey = "YOUR_API_KEY";
    var bitApi = new BitcodinApi(apiKey);
  }
}

Example

The following example demonstrates how to create a simple transcoding job, generating MPEG-DASH and Apple HLS out of a single MP4.

 public static class CreateS3Job
  {
    public static void Run()
    {
      /* Create BitcodinApi */
      const string apiKey = "YOUR_API_KEY";
      var bitApi = new BitcodinApi(apiKey);

      /* Create URL Input */
      var s3InputConfig = new S3InputConfig
      {
        AccessKey = "ACCESSKEY",
        SecretKey = "SECRETKEY",
        Bucket = "BUCKET",
        Region = "REGION",
        ObjectKey = "path/to/file.ext"
      };

      Input input;
      try
      {
        input = bitApi.CreateInput(s3InputConfig);
      }
      catch (BitcodinApiException e)
      {
        Console.WriteLine("Could not create input: " + e);
        return;
      }

      Console.WriteLine("Created Input: " + input.Filename);

      /* Create EncodingProfile */
      var videoConfig1 = new VideoStreamConfig
      {
        Bitrate = 4800000,
        Width = 1920,
        Height = 1080,
        Profile = Profile.MAIN,
        Preset = Preset.PREMIUM
      };

      var videoConfig2 = new VideoStreamConfig
      {
        Bitrate = 2400000,
        Width = 1280,
        Height = 720,
        Profile = Profile.MAIN,
        Preset = Preset.PREMIUM
      };

      var videoConfig3 = new VideoStreamConfig
      {
        Bitrate = 1200000,
        Width = 854,
        Height = 480,
        Profile = Profile.MAIN,
        Preset = Preset.PREMIUM
      };

      var encodingProfileConfig = new EncodingProfileConfig { Name = "DotNetTestProfile" };

      encodingProfileConfig.VideoStreamConfigs.Add(videoConfig1);
      encodingProfileConfig.VideoStreamConfigs.Add(videoConfig2);
      encodingProfileConfig.VideoStreamConfigs.Add(videoConfig3);

      var audioStreamConfig = new AudioStreamConfig
      {
        DefaultStreamId = 0,
        Bitrate = 192000
      };
      encodingProfileConfig.AudioStreamConfigs.Add(audioStreamConfig);

      EncodingProfile encodingProfile;
      try
      {
        encodingProfile = bitApi.CreateEncodingProfile(encodingProfileConfig);
      }
      catch (BitcodinApiException e)
      {
        Console.WriteLine("Could not create encoding profile: " + e);
        return;
      }

      /* Create Job */
      var jobConfig = new JobConfig
      {
        EncodingProfileId = encodingProfile.EncodingProfileId,
        InputId = input.InputId
      };
      jobConfig.ManifestTypes.Add(ManifestType.MPEG_DASH_MPD);
      jobConfig.ManifestTypes.Add(ManifestType.HLS_M3U8);

      Job job;
      try
      {
        job = bitApi.CreateJob(jobConfig);
      }
      catch (BitcodinApiException e)
      {
        Console.WriteLine("Could not create job: " + e);
        return;
      }

      JobDetails jobDetails;

      do
      {
        try
        {
          jobDetails = bitApi.GetJobDetails(job.JobId);
          Console.WriteLine("Status: " + jobDetails.JobStatus +
                            " - Enqueued Duration: " + jobDetails.EnqueueDuration + "s" +
                            " - Realtime Factor: " + jobDetails.RealtimeFactor +
                            " - Encoded Duration: " + jobDetails.EncodedDuration + "s" +
                            " - Output: " + jobDetails.BytesWritten / (double)1024 / 1024 + "MB");
        }
        catch (BitcodinApiException)
        {
          Console.WriteLine("Could not get any job details");
          return;
        }

        if (jobDetails.JobStatus == JobStatus.ERROR)
        {
          Console.WriteLine("Error during transcoding");
          return;
        }

        Thread.Sleep(2000);
      } while (jobDetails.JobStatus != JobStatus.FINISHED);

      Console.WriteLine("Job with ID " + job.JobId + " finished successfully!");
    }
  }

#NuGet NuGet is a extension for Visual Studio which allows you to search for, install, uninstall and update external packages in your projects and solutions.

NuGet comes installed with the more recent versions of Visual Studio, but you can download it from [here] (https://docs.nuget.org/consume/installing-nuget) if you don’t already have it.

##Install bitcodin-dotnet via Package Manager Console To install bitcodin-dotnet, run the following command in the Package Manager Console:

    Install-Package bitcodin-dotnet -Version 1.0.0

##Managing NuGet Packages Using the Dialog Detailed information on how to find, install, remove, and update NuGet packages using the Manage NuGet Packages dialog box can be found at docs.nuget.org

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.