Özel bir dönüşümle kodlama-.NET

media services logosu v3


v2 Media Services mı arayabilirsiniz?

Azure Media Services ile kodlarken, akış dosyaları öğreticisinde gösterildiği gibi, sektörde en iyi uygulamaları temel alan önerilen yerleşik ön ayarlardan biriyle hızlı bir şekilde çalışmaya başlayın. Ayrıca, belirli bir senaryoyu veya cihaz gereksinimlerinizi hedeflemek için özel bir ön ayar oluşturabilirsiniz.

Dikkat edilmesi gerekenler

Özel ön ayarlar oluşturulurken aşağıdaki noktalar geçerlidir:

  • AVC içeriğinde yükseklik ve genişlik değerlerinin tümü 4 ' ün katı olmalıdır.
  • Azure Media Services v3 'de, tüm kodlama bit fiyatları bit/saniye cinsinden. Bu, birim olarak kilobit/saniye kullanan v2 API 'lerimiz olan ön ayarlardan farklıdır. Örneğin, v2 'deki bit hızı 128 (kilobit/saniye) olarak belirtilmişse, v3 'de 128000 (bit/saniye) olarak ayarlanır.

Önkoşullar

Media Services hesabı oluşturma

Örneği indirme

Aşağıdaki komutu kullanarak makinenize tam .NET Core örneği içeren bir GitHub deposunu kopyalayın:

git clone https://github.com/Azure-Samples/media-services-v3-dotnet.git

Özel önceden ayarlanmış örnek, .NET klasörü kullanan özel bir önayar Ile Encoding içinde bulunur.

Özel önayar olan bir dönüşüm oluşturma

Yeni bir dönüşümoluştururken, ne zaman çıkış olarak üretmek istediğinizi belirtmeniz gerekir. Gerekli parametre, aşağıdaki kodda gösterildiği gibi bir TransformOutput nesnesidir. Her TransformOutput bir Ön ayar içerir. Önceden belirlenmiş , Istenen Transformoutput oluşturmak için kullanılacak video ve/veya ses işleme işlemlerinin adım adım talimatlarını açıklar. Aşağıdaki Transformoutput , özel codec ve katman çıkış ayarları oluşturur.

Bir Dönüşüm oluştururken ilk olarak aşağıdaki kodda gösterildiği gibi Get yöntemi ile bir dönüşümün zaten var olup olmadığını denetlemeniz gerekir. Media Services v3 'de varlık mevcut değilse (ad üzerinde büyük/küçük harfe duyarsız bir denetim), varlıklarda yöntemleri Al null değeri döndürür.

Örnek özel dönüşüm

Aşağıdaki örnek, bu dönüşüm kullanıldığında oluşturulmasını istediğimiz bir çıktı kümesi tanımlar. İlk olarak, video kodlaması için ses kodlaması ve iki H264Video katmanı için bir AacAudio katmanı ekleyeceğiz. Video katmanlarında, çıkış dosyası adlarında kullanılamaları için etiketler atariz. Ardından çıkışın küçük resimleri de içermesi gerekir. Aşağıdaki örnekte, giriş videosunu çözünürlüğün %50'sinde oluşturulan PNG biçiminde ve üç zaman damgasında oluşturulan görüntüleri belirtiriz: giriş video uzunluğu {%25, %50, %75}} . Son olarak, çıkış dosyalarının biçimini (biri video + ses, diğeri küçük resimler için) belirtiriz. Birden çok H264Layers'ımız olduğu için katman başına benzersiz ad üreten makrolar kullanmamız gerekir. Bir veya makrosu {Label} {Bitrate} kullanabiliriz; örnekte öncekiler de gösterir.

/// <summary>
/// If the specified transform exists, return that transform. If the it does not
/// exist, creates a new transform with the specified output. In this case, the
/// output is set to encode a video using a custom preset.
/// </summary>
/// <param name="client">The Media Services client.</param>
/// <param name="resourceGroupName">The name of the resource group within the Azure subscription.</param>
/// <param name="accountName"> The Media Services account name.</param>
/// <param name="transformName">The transform name.</param>
/// <returns></returns>
private static async Task<Transform> CreateCustomTransform(IAzureMediaServicesClient client, string resourceGroupName, string accountName, string transformName)
{

    Console.WriteLine("Creating a custom transform...");

    // Create a new Transform Outputs array - this defines the set of outputs for the Transform
    TransformOutput[] outputs = new TransformOutput[]
    {
            // Create a new TransformOutput with a custom Standard Encoder Preset
            // This demonstrates how to create custom codec and layer output settings

          new TransformOutput(
                new StandardEncoderPreset(
                    codecs: new Codec[]
                    {
                        // Add an AAC Audio layer for the audio encoding
                        new AacAudio(
                            channels: 2,
                            samplingRate: 48000,
                            bitrate: 128000,
                            profile: AacAudioProfile.AacLc
                        ),
                        // Next, add a H264Video for the video encoding
                       new H264Video (
                            // Set the GOP interval to 2 seconds for all H264Layers
                            keyFrameInterval:TimeSpan.FromSeconds(2),
                             // Add H264Layers. Assign a label that you can use for the output filename
                            layers:  new H264Layer[]
                            {
                                new H264Layer (
                                    bitrate: 3600000, // Units are in bits per second and not kbps or Mbps - 3.6 Mbps or 3,600 kbps
                                    width: "1280",
                                    height: "720",
                                    label: "HD-3600kbps" // This label is used to modify the file name in the output formats
                                ),
                                new H264Layer (
                                    bitrate: 1600000, // Units are in bits per second and not kbps or Mbps - 1.6 Mbps or 1600 kbps
                                    width: "960",
                                    height: "540",
                                    label: "SD-1600kbps" // This label is used to modify the file name in the output formats
                                ),
                                new H264Layer (
                                    bitrate: 600000, // Units are in bits per second and not kbps or Mbps - 0.6 Mbps or 600 kbps
                                    width: "640",
                                    height: "360",
                                    label: "SD-600kbps" // This label is used to modify the file name in the output formats
                                ),
                            }
                        ),
                        // Also generate a set of PNG thumbnails
                        new PngImage(
                            start: "25%",
                            step: "25%",
                            range: "80%",
                            layers: new PngLayer[]{
                                new PngLayer(
                                    width: "50%",
                                    height: "50%"
                                )
                            }
                        )
                    },
                    // Specify the format for the output files - one for video+audio, and another for the thumbnails
                    formats: new Format[]
                    {
                        // Mux the H.264 video and AAC audio into MP4 files, using basename, label, bitrate and extension macros
                        // Note that since you have multiple H264Layers defined above, you have to use a macro that produces unique names per H264Layer
                        // Either {Label} or {Bitrate} should suffice
                         
                        new Mp4Format(
                            filenamePattern:"Video-{Basename}-{Label}-{Bitrate}{Extension}"
                        ),
                        new PngFormat(
                            filenamePattern:"Thumbnail-{Basename}-{Index}{Extension}"
                        )
                    }
                ),
                onError: OnErrorType.StopProcessingJob,
                relativePriority: Priority.Normal
            )
    };

    string description = "A simple custom encoding transform with 2 MP4 bitrates";

    // Does a Transform already exist with the desired name? This method will just overwrite (Update) the Transform if it exists already. 
    // In production code, you may want to be cautious about that. It really depends on your scenario.
    Transform transform = await client.Transforms.CreateOrUpdateAsync(resourceGroupName, accountName, transformName, outputs, description);

    return transform;
}

Sonraki adımlar

Akış dosyaları