首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >使用ProgressiveDownload流媒体格式在媒体服务上发布视频

使用ProgressiveDownload流媒体格式在媒体服务上发布视频
EN

Stack Overflow用户
提问于 2017-12-15 10:47:52
回答 1查看 299关注 0票数 0

我需要实现一个应用程序,能够上传一个.mp4视频在上。视频应该以ProgressiveDownload流格式发布,并在rest上进行加密。

研究Media文档后,我尝试实现一个控制台应用程序。

代码语言:javascript
复制
static void Main(string[] args)
    {
        try
        {
            var tokenCredentials = new AzureAdTokenCredentials(_AADTenantDomain, AzureEnvironments.AzureCloudEnvironment);
            var tokenProvider = new AzureAdTokenProvider(tokenCredentials);

            _context = new CloudMediaContext(new Uri(_RESTAPIEndpoint), tokenProvider);

            // Add calls to methods defined in this section.
            // Make sure to update the file name and path to where you have your media file.
            IAsset inputAsset =
            UploadFile(_videoPath, AssetCreationOptions.StorageEncrypted);

            IAsset encodedAsset =
            EncodeToAdaptiveBitrateMP4s(inputAsset, AssetCreationOptions.StorageEncrypted);

            PublishAssetGetURLs(encodedAsset);
        }
        catch (Exception exception)
        {
            // Parse the XML error message in the Media Services response and create a new
            // exception with its content.
            exception = MediaServicesExceptionParser.Parse(exception);

            Console.Error.WriteLine(exception.Message);
        }
        finally
        {
            Console.ReadLine();
        }
    }       

    static public IAsset EncodeToAdaptiveBitrateMP4s(IAsset asset, AssetCreationOptions options)
    {

        // Prepare a job with a single task to transcode the specified asset
        // into a multi-bitrate asset.

        IJob job = _context.Jobs.CreateWithSingleTask(
            "Media Encoder Standard",
            "Adaptive Streaming",
            asset,
            "Adaptive Bitrate MP4",
            options);

        Console.WriteLine("Submitting transcoding job...");


        // Submit the job and wait until it is completed.
        job.Submit();

        job = job.StartExecutionProgressTask(
            j =>
            {
                Console.WriteLine("Job state: {0}", j.State);
                Console.WriteLine("Job progress: {0:0.##}%", j.GetOverallProgress());
            },
            CancellationToken.None).Result;

        Console.WriteLine("Transcoding job finished.");

        IAsset outputAsset = job.OutputMediaAssets[0];

        return outputAsset;
    }

    static public void PublishAssetGetURLs(IAsset asset)
    {
        // Publish the output asset by creating an Origin locator for adaptive streaming,
        // and a SAS locator for progressive download.

        IAssetDeliveryPolicy policy =
            _context.AssetDeliveryPolicies.Create("Clear Policy",
            AssetDeliveryPolicyType.NoDynamicEncryption,
            AssetDeliveryProtocol.ProgressiveDownload | AssetDeliveryProtocol.HLS | AssetDeliveryProtocol.SmoothStreaming | AssetDeliveryProtocol.Dash, 
            null);

        asset.DeliveryPolicies.Add(policy);

        _context.Locators.Create(
            LocatorType.OnDemandOrigin,
            asset,
            AccessPermissions.Read,
            TimeSpan.FromDays(30));

        _context.Locators.Create(
            LocatorType.Sas,
            asset,
            AccessPermissions.Read,
            TimeSpan.FromDays(30));


        IEnumerable<IAssetFile> mp4AssetFiles = asset
                .AssetFiles
                .ToList()
                .Where(af => af.Name.EndsWith(".mp4", StringComparison.OrdinalIgnoreCase));

        // Get the Smooth Streaming, HLS and MPEG-DASH URLs for adaptive streaming,
        // and the Progressive Download URL.
        Uri smoothStreamingUri = asset.GetSmoothStreamingUri();
        Uri hlsUri = asset.GetHlsUri();
        Uri mpegDashUri = asset.GetMpegDashUri();

        // Get the URls for progressive download for each MP4 file that was generated as a result
        // of encoding.
        List<Uri> mp4ProgressiveDownloadUris = mp4AssetFiles.Select(af => af.GetSasUri()).ToList();                       
    }

当我添加该部分以在rest中管理加密时,此代码停止工作。更确切地说,当我:

  • UploadFile(_videoPath, AssetCreationOptions.None);替换为UploadFile(_videoPath, AssetCreationOptions.StorageEncrypted);
  • EncodeToAdaptiveBitrateMP4s(inputAsset, AssetCreationOptions.None);替换为EncodeToAdaptiveBitrateMP4s(inputAsset, AssetCreationOptions.StorageEncrypted);
  • PublishAssetGetURLs方法中添加了以下代码 IAssetDeliveryPolicy policy =_context.AssetDeliveryPolicies.Create(“清除策略”,AssetDeliveryPolicyType.NoDynamicEncryption,AssetDeliveryProtocol.ProgressiveDownload AssetDeliveryProtocol.HLS x AssetDeliveryProtocol.SmoothStreaming AssetDeliveryProtocol.Dash,null); Asset.DeliveryPolicies.Add(政策);

问题是视频被正确上传,但是当我试图在Azure Portal中播放视频时,我会得到一个通用的0x0错误。

EN

Stack Overflow用户

发布于 2018-01-20 21:40:55

Id避免渐进下载,如果您需要它的保护。除非您正在构建脱机保护下载解决方案。如果是这样的话,我们只是在我们的文档中添加了一些新的文章,这些文章展示了如何进行Play战备、Widevine和Fairpoay离线DRM。请查看文档的内容保护部分以获取这些文章。

票数 0
EN
查看全部 1 条回答
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/47830711

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档