0

Windows Azure Media Services を使用して、ビデオ ファイルをアップロードし、エンコードしてから公開しています。Windows Azure Media Services サンプル コードを使用してファイルをエンコードしましたが、コードを使用して ".mp4" ファイルを Apple HLS に変換すると、iOS デバイスで正しく機能しないことがわかりました。オーディオのみが再生され、ビデオは表示されません。一方、Windows Azure Media Services Portal を使用して HLS でファイルをエンコードおよび公開すると、iOS デバイス (オーディオとビデオの両方の再生) で完全に正常に動作します。

私はこれについて何日も頭を悩ませてきましたが、誰かが(コードを介して)エンコードプロセスについて私を案内してくれることを本当に義務付けられていますか?

これは私が今まで持っているものです!

static IAsset CreateEncodingJob(IAsset asset)
    {


        // Declare a new job.
        IJob job = _context.Jobs.Create("My encoding job");
        // Get a media processor reference, and pass to it the name of the 
        // processor to use for the specific task.
        IMediaProcessor processor = GetLatestMediaProcessorByName("Windows Azure Media Encoder");
        // Create a task with the encoding details, using a string preset.
        ITask task = job.Tasks.AddNew("My encoding task",
            processor,
            "H264 Broadband SD 4x3", 
            TaskOptions.ProtectedConfiguration);
        // Specify the input asset to be encoded.
        task.InputAssets.Add(asset);
        // Add an output asset to contain the results of the job. 
        // This output is specified as AssetCreationOptions.None, which 
        // means the output asset is in the clear (unencrypted). 
        task.OutputAssets.AddNew("Output MP4 asset",
            true,
            AssetCreationOptions.None);

        // Launch the job. 
        job.Submit();

        // Checks job progress and prints to the console. 
        CheckJobProgress(job.Id);

        // Get an updated job reference, after waiting for the job 
        // on the thread in the CheckJobProgress method.
        job = GetJob(job.Id);

        // Get a reference to the output asset from the job.
        IAsset outputAsset = job.OutputMediaAssets[0];


        return outputAsset;


    }


 static IAsset CreateMp4ToSmoothJob(IAsset asset)
    {

        // Read the encryption configuration data into a string. 
        string configuration = File.ReadAllText(Path.GetFullPath(_configFilePath + @"\MediaPackager_MP4ToSmooth.xml"));



        //Publish the asset.
        //GetStreamingOriginLocatorformp4(asset.Id);


        // Declare a new job.
        IJob job = _context.Jobs.Create("My MP4 to Smooth job");
        // Get a media processor reference, and pass to it the name of the 
        // processor to use for the specific task.
        IMediaProcessor processor = GetLatestMediaProcessorByName("Windows Azure Media Packager");

        // Create a task with the encoding details, using a configuration file. Specify 
        // the use of protected configuration, which encrypts sensitive config data.
        ITask task = job.Tasks.AddNew("My Mp4 to Smooth Task",
            processor,
            configuration,
            TaskOptions.ProtectedConfiguration);
        // Specify the input asset to be encoded.
        task.InputAssets.Add(asset);
        // Add an output asset to contain the results of the job.
        task.OutputAssets.AddNew("Output Smooth asset",
            true,
            AssetCreationOptions.None);

        // Launch the job. 
        job.Submit();

        // Checks job progress and prints to the console. 
        CheckJobProgress(job.Id);


        job = GetJob(job.Id);
        IAsset outputAsset = job.OutputMediaAssets[0];

        // Optionally download the output to the local machine.
        //DownloadAssetToLocal(job.Id, _outputIsmFolder);

        return outputAsset;
    }

    // Shows how to encode from smooth streaming to Apple HLS format.
    static IAsset CreateSmoothToHlsJob(IAsset outputSmoothAsset)
    {
        // Read the encryption configuration data into a string. 
        string configuration = File.ReadAllText(Path.GetFullPath(_configFilePath + @"\MediaPackager_SmoothToHLS.xml"));


        //var getismfile = from p in outputSmoothAsset.Files
        //                 where p.Name.EndsWith(".ism")
        //                 select p;

        //IAssetFile manifestFile = getismfile.First();

        //manifestFile.IsPrimary = true;

        var ismAssetFiles = outputSmoothAsset.AssetFiles.ToList().Where(f => f.Name.EndsWith(".ism", StringComparison.OrdinalIgnoreCase)).ToArray();

        if (ismAssetFiles.Count() != 1)
            throw new ArgumentException("The asset should have only one, .ism file");

        ismAssetFiles.First().IsPrimary = true;
        ismAssetFiles.First().Update();




        //Use the smooth asset as input asset


        IAsset asset = outputSmoothAsset;



        // Declare a new job.
        IJob job = _context.Jobs.Create("My Smooth Streams to Apple HLS job");
        // Get a media processor reference, and pass to it the name of the 
        // processor to use for the specific task.
        IMediaProcessor processor = GetMediaProcessor("Smooth Streams to HLS Task");

        // Create a task with the encoding details, using a configuration file.
        ITask task = job.Tasks.AddNew("My Smooth to HLS Task", processor, configuration, TaskOptions.ProtectedConfiguration);

        // Specify the input asset to be encoded.
        task.InputAssets.Add(asset);

        // Add an output asset to contain the results of the job.
        task.OutputAssets.AddNew("Output HLS asset", true, AssetCreationOptions.None);

        // Launch the job. 
        job.Submit();

        // Checks job progress and prints to the console. 
        CheckJobProgress(job.Id);

        // Optionally download the output to the local machine.
        //DownloadAssetToLocal(job.Id, outputFolder);

        job = GetJob(job.Id);
        IAsset outputAsset = job.OutputMediaAssets[0];

        return outputAsset;
    }
4

1 に答える 1

2

iOS 互換の HLS に変換するには、HLS のベースとなるスムーズ ストリーミング ソースを使用する必要があります。したがって、あなたの手順は次のようになります。

  1. ソースを高品質の H.264 (MP4) に変換します
  2. 手順 (1) の結果を Microsoft Smooth Streaming に変換する
  3. ステップ (2) の結果 (スムーズ ストリーミング) を HLS に変換します。

HLS は、Microsoft Smooth Streaming と非常によく似ています。したがって、ビットレートが異なるソースのチャンクが必要です。MP4 で HLS 変換を行っても何も起こりません。

Microsoft がポータルexplorativeでそのような機能を提供しているのは悲しいことです。managementこれにより、ユーザーは混乱します。シーンの下でそれが何をするかは、まさに私があなたに提案することです-最初に高品質の MP4 を取得し、次にそれを Microsoft Smooth ストリーミングに変換し、次に Smooth Streaming で HLS を実行します。しかし、ユーザーは HLS が MP4 で実行されると考えていますが、これは完全に間違っています。

ここのオンライン ドキュメントを見ると、タスク プリセットの名前がConvert Smooth Streams to Apple HTTP Live Streams. HLS の正しいソースが Microsoft Smooth Stream であることを突き止める必要があります。私の経験からすると、優れたスムーズ ストリームは、優れた H.264 ソース (MP4) からのみ生成できます。H.264 以外のソースをスムーズ ストリームに変換しようとすると、ほとんどの場合エラーになります。

小さなツールWaMediaWeb (Azure Web サイトへの継続的な配信を備えた github のソース) を試すことができます。ここでは、ライブ: http://wamediaweb.azurewebsites.net/ - メディア アカウントとキーを提供するだけです。どのソースがどの結果を生成するかなど、いくつかの詳細については、GitHubの readme を参照してください。

ところで、タスクを 1 つのジョブにスタックして、常にジョブの結果を探すのを避けることができます。このメソッドtask.OutputAssets.AddNew(...)は実際に IAsset を返します。これを別のタスクの InputAsset として使用し、そのタスクを同じジョブに追加できます。例を見ると、ある時点でこれが行われます。また、iPad2 および iPhone 4 を搭載した iOS でテストされた HLS ストリームの作成でもうまく機能します。

于 2012-12-03T13:31:12.250 に答える