Windows Azure媒体服务Apple HLS流媒体 - 没有视频只播放音频播放

时间:2012-12-03 13:09:59

标签: azure http-live-streaming smooth-streaming

我正在使用Windows Azure媒体服务上传视频文件,进行编码,然后发布它们。 我使用Windows Azure媒体服务示例代码对文件进行编码,我发现当我使用代码将“.mp4”文件转换为Apple HLS时,它在iOS设备中无法正常运行。只播放音频,没有视频。然而,如果我使用Windows Azure媒体服务门户在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;
    }

1 个答案:

答案 0 :(得分:2)

要转换为iOS兼容的HLS,您必须使用平滑流媒体源,它将成为HLS的基础。所以你的步骤将是:

  1. 将您的信号源转换为高质量的H.264(MP4)
  2. 将步骤(1)的结果转换为Microsoft Smooth Streaming
  3. 将步骤(2)(Smooth Streaming)的结果转换为HLS
  4. HLS与Microsoft Smooth Streaming非常相似。因此,它需要具有不同比特率的源块。通过MP4进行HLS转换将不起作用。

    微软在explorative门户网站中提供此类management功能,这是令人遗憾的。这会导致用户感到困惑。它在场景下的作用正是我建议的 - 首先获得高质量的MP4,然后将其转换为Microsoft Smooth流,然后通过Smooth Streaming进行HLS。但是用户通过MP4执行HLS的事情是完全错误的。

    如果我们查看online documentation here,我们会看到任务预设名为Convert Smooth Streams to Apple HTTP Live Streams。从中我们必须弄清楚HLS的正确来源是Microsoft Smooth Stream。根据我的经验,良好的平滑流只能通过良好的H.264源(MP4)生成。如果您尝试将非H.264源转换为平滑流,则结果很可能是错误。

    您可以尝试使用小工具WaMediaWeb(github上的源码以及向Azure网站的持续传递),现场直播:http://wamediaweb.azurewebsites.net/ - 只需提供您的媒体帐户和密钥。请查看readme on GitHub的某些细节,例如哪些来源会产生什么结果。

    顺便说一句,您可以在一个作业中堆叠任务,以避免不断寻找工作结果。方法task.OutputAssets.AddNew(...)实际上返回一个IAsset,您可以将其用作另一个任务的InputAsset,并将该任务添加到同一个作业中。如果你看一下这个例子,它会在某些时候这样做。它在创建HLS流方面也做得很好,在iOS2上使用iPad2和iPhone 4进行了测试。