azure - Windows Azure 媒体服务 Apple HLS 流媒体 - 不播放视频,仅播放音频

标签 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;
    }

最佳答案

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

  1. 将您的信号源转换为高品质 H.264 (MP4)
  2. 将步骤 (1) 的结果转换为 Microsoft Smooth Streaming
  3. 将步骤 (2) 的结果(平滑流)转换为 HLS

HLS 与 Microsoft Smooth Streaming 非常相似。因此它需要具有不同比特率的源 block 。通过 MP4 进行 HLS 转换不会起任何作用。

在我看来,微软在管理门户中提供这样的探索性功能是令人遗憾的。这会导致用户感到困惑。它在幕后的作用正是我向您建议的 - 首先获取高质量的 MP4,然后将其转换为 Microsoft Smooth 流,然后通过 Smooth Streaming 进行 HLS。但用户认为 HLS 是通过 MP4 执行的,这是完全错误的。

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

您可以尝试使用小工具 WaMediaWeb (来自 github 的源代码,持续交付到 Azure 网站),现场直播:http://wamediaweb.azurewebsites.net/ - 只需提供您的媒体帐户和 key 。看看readme on GitHub了解一些细节,例如什么来源产生什么结果。

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

关于azure - Windows Azure 媒体服务 Apple HLS 流媒体 - 不播放视频,仅播放音频,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13683940/

相关文章:

ffmpeg - JavaFX MediaPlayer 无法播放本地 m3u8 文件

bash - 加密的 HLS 可用作直播,不能用作 VOD

javascript - Smooth Streaming .ism 到 HTML5 视频标签

iis - 平滑流式传输 Apple URL 给出 404

azure - 使用 Azure Pipelines 部署和运行 .exe 文件

c# - 如何高性能存储地理散列数据

android - Google TV(或更普遍的 Android)的 HLS 播放器是否支持替代音频?

drm - 是否有可用的免费 PlayReady 服务器?

azure - 部署到 Azure,并将角色分配到不同配置中的不同实例?

Azure vm规模集、扩展配置文件最小实例限制含义