【问题标题】:Windows Azure Media Services Apple HLS Streaming - No video plays only audio playsWindows Azure 媒体服务 Apple HLS 流媒体 - 不播放视频,只播放音频
【发布时间】:2012-11-20 23:01:42
【问题描述】:

我正在使用 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;
    }

【问题讨论】:

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


    【解决方案1】:

    为了转换为与 iOS 兼容的 HLS,您必须使用 Smooth Streaming Source,它是 HLS 的基础。所以你的步骤是:

    1. 将您的源转换为高质量的 H.264 (MP4)
    2. 将步骤 (1) 的结果转换为 Microsoft Smooth Streaming
    3. 将第 (2) 步(平滑流式处理)的结果转换为 HLS

    HLS 与 Microsoft Smooth Streaming 非常相似。因此,它需要具有不同比特率的源块。通过 MP4 进行 HLS 转换将无济于事。

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

    如果我们看一下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 流方面也做得很好,在 iOS 上使用 iPad2 和 iPhone 4 进行了测试。

    【讨论】:

    • 感谢您的回答!但我已经为自己找到了解决方案。我没有使用 Windows Azure 媒体编码器将我的 mp4 文件转换为各种比特率以实现流畅的流传输。我宁愿使用 Windows Azure Media Packager 将我的 mp4 转换为流畅的流媒体,该流媒体正在转换为其原生比特率格式(而不是各种其他比特率)。而且我会根据你的建议堆叠我的任务!
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-11-09
    • 2016-09-07
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多