从 JobId 或 SmoothStreamingUrl 获取输入资产或输出资产 - Azure 媒体服务

问题描述 投票:0回答:1

在我们的数据库中,我们有一个 JobId 列表(来自 Azure 媒体服务编码)和 SmoothStreamingUrl,如下所示:

职位ID SmoothSteamingURL
nb:jid:UUID:xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx http://testvideo-euno.streaming.media.azure.net/xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx/xxxxxxxx-xxxx-xxxx-xxxx-xxxx.ism/manifest|

我想要的是使用这些信息之一来获取输入/输出资产名称,以便我可以记录视频文件在存储帐户中的存储位置。

目前我一直在使用 Azure.ResourceManager.Media nuget 包并尝试尝试获取此信息,但到目前为止尚未成功。

有人可以提供任何帮助或建议吗?

azure azure-resource-manager azure-media-services
1个回答
0
投票

所以我想出了如何主要使用 Azure.ResourceManager.Media Nuget 来获取输出资源。不确定这是否是最好的方法,但对我有用。仅适用于在 V2 中创建的流媒体 URL,对于在 V3 中创建的流媒体 URL,它提供输出资源名称,然后您可以使用资源管理器 nuget 中的 .GetMediaAsset() 来获取容器。

    var mediaServiceAccountId = MediaServicesAccountResource.CreateResourceIdentifier(
        subscriptionId: {subscriptionId},
        resourceGroupName: {resourceGroupName},
        accountName: {accountName});
    
    var credential = new ClientSecretCredential({tenant}, {clientId}, {clientSecret});
    var armClient = new ArmClient(credential);
    
    var mediaServicesAccount = armClient.GetMediaServicesAccountResource(mediaServiceAccountId);
    
    //Gets results from table
    var videosOldEncoding = Repository.GetAllVideosOldEncoding();
    
    var locators = mediaServicesAccount.GetStreamingLocators();
    
    foreach (var locator in locators)
    {
        var streamingEndpoint = (mediaServicesAccount.GetStreamingEndpoints().Get("default")).Value;
    
        var streamingName = PrintStreamingUrlsAsync(locator, streamingEndpoint);
    
        foreach (var video in videosOldEncoding)
        {
            if (video.SmoothStreamingUrl != null)
            {
                string[] items = video.SmoothStreamingUrl.Split("/", StringSplitOptions.RemoveEmptyEntries);
                string[] idStrings = { items[2], items[3] };
                var streamingId = String.Join("/", idStrings);
    
                if (streamingName.Contains(streamingId))
                {
                    Repository.UpdateAsset(video.VideoId, String.Concat("asset-", locator.Data.AssetName));
                }
            }
        }
    }

static string PrintStreamingUrlsAsync(
           StreamingLocatorResource locator,
           StreamingEndpointResource streamingEndpoint)
{
    var paths = locator.GetStreamingPaths();

    foreach (StreamingPath path in paths.Value.StreamingPaths)
    {
        //Console.WriteLine($"The following formats are available for {path.StreamingProtocol.ToString().ToUpper()}:");

        if (path.StreamingProtocol == StreamingPolicyStreamingProtocol.SmoothStreaming)
        {
            string streamingFormatPath = path.Paths.FirstOrDefault();

            var uriBuilder = new UriBuilder()
            {
                Scheme = "https",
                Host = streamingEndpoint.Data.HostName,
                Path = streamingFormatPath
            };

            return uriBuilder.ToString();
        }
    }

    return null;
}
© www.soinside.com 2019 - 2024. All rights reserved.