예제 #1
0
        public static void Run(
            [QueueTrigger(QueueNames.MediaToEncode)] MediaMetadata mediaMetadataFromQueue,
            [Queue(QueueNames.MediaToPublish)] out MediaMetadata mediaMetadataToPublish,
            TraceWriter log)
        {
            log.Info($"{nameof(EncodeMediaAsset)} triggered");

            IAsset asset = null;

            try
            {
                asset = AzureMediaServices.GetAsset(mediaMetadataFromQueue);
                var newAsset = AzureMediaServices.EncodeToAdaptiveBitrateMP4Set(asset, mediaMetadataFromQueue.Title);

                mediaMetadataToPublish = new MediaMetadata
                {
                    FileName             = newAsset.Name,
                    MediaServicesAssetId = newAsset.Id,
                    MediaAssetUri        = newAsset.Uri,
                    Title      = mediaMetadataFromQueue.Title,
                    UploadedAt = mediaMetadataFromQueue.UploadedAt,
                };
            }
            catch (Exception e)
            {
                log.Info($"Error {e.Message}");
                throw e;
            }
            finally
            {
                asset?.Delete(false);
                log.Info($"{nameof(EncodeMediaAsset)} completed");
            }
        }
예제 #2
0
        public static void Run(
            [QueueTrigger(QueueNames.MediaToPublish)] MediaMetadata mediaMetadataFromQueue,
            [Queue(QueueNames.MediaToAddToCosmosDb)] out MediaMetadata mediaMetadataToAddToCosmosDb,
            TraceWriter log)
        {
            log.Info($"{nameof(PublishMediaAsset)} triggered");

            IAsset asset = null;

            try
            {
                mediaMetadataToAddToCosmosDb = mediaMetadataFromQueue;

                asset = AzureMediaServices.GetAsset(mediaMetadataFromQueue);

                log.Info($"Publishing Media");
                var locator = AzureMediaServices.PublishMedia(asset, TimeSpan.FromDays(999));

                log.Info($"Generating Streaming Endpoint");
                AzureMediaServices.CreateStreamingEndpoint();

                log.Info($"Generating Urls");
                var(manifestUri, hlsUri, mpegDashUri) = AzureMediaServices.BuildStreamingURLs(asset, locator);

                mediaMetadataToAddToCosmosDb.BlobStorageMediaUrl = $"{mediaMetadataToAddToCosmosDb.MediaAssetUri}/{AzureMediaServices.GetMP4FileName(asset)}";
                mediaMetadataToAddToCosmosDb.ManifestUrl         = manifestUri;
                mediaMetadataToAddToCosmosDb.HLSUrl      = hlsUri;
                mediaMetadataToAddToCosmosDb.MPEGDashUrl = mpegDashUri;
            }
            catch (Exception e)
            {
                log.Info($"Error: {e.Message}");
                asset?.Delete();

                throw e;
            }
            finally
            {
                log.Info($"{nameof(PublishMediaAsset)} completed");
            }
        }