Skip to content

Commit

Permalink
Support --output-manifest-name option for "assets" and "storage" command
Browse files Browse the repository at this point in the history
Description:

   When --output-manifet-name option is set, it will be used as the file name for DASh mpd file and top-level HLS m3u8 file.

   If it is not set, the input asset's manifest file name is used as usual.

   Update AssetDetails to include OutputManifest which is a nullable string,
   Consume the OutputManifest in packager and related places.

   Once "assets" command is completed, the matching outputManifest name is reported together with the OutputPath metadata in the input asset container.
  • Loading branch information
weibz committed Jul 8, 2023
1 parent 663c7ab commit 4e12bb3
Show file tree
Hide file tree
Showing 14 changed files with 44 additions and 15 deletions.
10 changes: 10 additions & 0 deletions AssetOptionsBinder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,14 @@ This is specific to the cloud you are migrating to.
{
Arity = ArgumentArity.ZeroOrOne
};

private readonly Option<string?> _outputManifest = new Option<string?>(
aliases: new[] { "--output-manifest-name", "-m" },
description: @"The output manifest name without extension,
if it is not set, use input asset's manifest name.")
{
Arity = ArgumentArity.ZeroOrOne
};

private readonly Option<DateTimeOffset?> _creationTimeStart = new Option<DateTimeOffset?>(
aliases: new[] { "--creation-time-start", "-cs" },
Expand Down Expand Up @@ -135,6 +143,7 @@ public Command GetCommand(string name, string description)
command.AddOption(_sourceAccount);
command.AddOption(_storageAccount);
command.AddOption(_pathTemplate);
command.AddOption(_outputManifest);
command.AddOption(_creationTimeStart);
command.AddOption(_creationTimeEnd);
command.AddOption(_filter);
Expand All @@ -156,6 +165,7 @@ protected override AssetOptions GetBoundValue(BindingContext bindingContext)
bindingContext.ParseResult.GetValueForOption(_storageAccount)!,
bindingContext.ParseResult.GetValueForOption(_packagerType),
bindingContext.ParseResult.GetValueForOption(_pathTemplate)!,
bindingContext.ParseResult.GetValueForOption(_outputManifest)!,
bindingContext.ParseResult.GetValueForOption(_creationTimeStart),
bindingContext.ParseResult.GetValueForOption(_creationTimeEnd),
bindingContext.ParseResult.GetValueForOption(_filter),
Expand Down
10 changes: 10 additions & 0 deletions StorageOptionsBinder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,14 @@ This is specific to the cloud you are migrating to.
Arity = ArgumentArity.ZeroOrOne
};

private readonly Option<string?> _outputManifest = new Option<string?>(
aliases: new[] { "--output-manifest-name", "-m" },
description: @"The output manifest name without extension,
if it is not set, use input asset's manifest name.")
{
Arity = ArgumentArity.ZeroOrOne
};

private readonly Option<string?> _prefix = new Option<string?>(
aliases: new[] { "--prefix", "-p" },
description: @"")
Expand Down Expand Up @@ -113,6 +121,7 @@ public Command GetCommand(string name, string description)
command.AddOption(_sourceAccount);
command.AddOption(_storageAccount);
command.AddOption(_pathTemplate);
command.AddOption(_outputManifest);
command.AddOption(_prefix);
command.AddOption(_overwrite);
command.AddOption(_skipMigrated);
Expand All @@ -132,6 +141,7 @@ protected override StorageOptions GetBoundValue(BindingContext bindingContext)
bindingContext.ParseResult.GetValueForOption(_storageAccount)!,
bindingContext.ParseResult.GetValueForOption(_packagerType),
bindingContext.ParseResult.GetValueForOption(_pathTemplate)!,
bindingContext.ParseResult.GetValueForOption(_outputManifest)!,
bindingContext.ParseResult.GetValueForOption(_prefix),
workingDirectory,
bindingContext.ParseResult.GetValueForOption(_copyNonStreamable),
Expand Down
2 changes: 1 addition & 1 deletion ams/AssetAnalyzer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ private async Task<AnalysisResult> AnalyzeAsync(MediaAssetResource asset, BlobSe
}
else
{
var assetDetails = await container.GetDetailsAsync(_logger, cancellationToken, asset.Data.Name, false);
var assetDetails = await container.GetDetailsAsync(_logger, cancellationToken, null, asset.Data.Name, false);

if (assetDetails.Manifest == null)
{
Expand Down
4 changes: 2 additions & 2 deletions ams/AssetMigrator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -174,15 +174,15 @@ public async Task<MigrationResult> MigrateAsync(
}
else
{
var details = await asset.GetDetailsAsync(_logger, cancellationToken);
var details = await asset.GetDetailsAsync(_logger, cancellationToken, _options.OutputManifest);
var record = new AssetRecord(account, asset, details);

// AssetType and ManifestName are not supposed to change for a specific input asset,
// Set AssetType and manifest from the asset container before doing the actual transforming.
if (details.Manifest != null)
{
result.AssetType = details.Manifest.Format;
result.ManifestName = details.Manifest.FileName?.Replace(".ism", "");
result.ManifestName = _options.OutputManifest ?? details.Manifest.FileName?.Replace(".ism", "");
}
else
{
Expand Down
4 changes: 2 additions & 2 deletions ams/StorageMigrator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -138,14 +138,14 @@ private async Task<MigrationResult> MigrateAsync(
return result;
}

var assetDetails = await containerClient.GetDetailsAsync(_logger, cancellationToken);
var assetDetails = await containerClient.GetDetailsAsync(_logger, cancellationToken, _storageOptions.OutputManifest);

// AssetType and ManifestName are not supposed to change for a specific input asset,
// Set AssetType and manifest from the input container before doing the actual transforming.
if (assetDetails.Manifest != null)
{
result.AssetType = assetDetails.Manifest.Format;
result.ManifestName = assetDetails.Manifest.FileName?.Replace(".ism", "");
result.ManifestName = _storageOptions.OutputManifest ?? assetDetails.Manifest.FileName?.Replace(".ism", "");
}
else
{
Expand Down
2 changes: 2 additions & 0 deletions contracts/AssetOptions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ public record AssetOptions(
string StoragePath,
Packager Packager,
string PathTemplate,
string OutputManifest,
DateTimeOffset? CreationTimeStart,
DateTimeOffset? CreationTimeEnd,
string? ResourceFilter,
Expand All @@ -19,6 +20,7 @@ public record AssetOptions(
StoragePath,
Packager,
PathTemplate,
OutputManifest,
WorkingDirectory,
CopyNonStreamable,
OverWrite,
Expand Down
1 change: 1 addition & 0 deletions contracts/MigratorOptions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ public record MigratorOptions(
string StoragePath,
Packager Packager,
string PathTemplate,
string OutputManifest,
string WorkingDirectory,
bool CopyNonStreamable,
bool OverWrite,
Expand Down
2 changes: 2 additions & 0 deletions contracts/StorageOptions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ public record StorageOptions(
string StoragePath,
Packager Packager,
string PathTemplate,
string OutputManifest,
string? Prefix,
string WorkingDirectory,
bool CopyNonStreamable,
Expand All @@ -17,6 +18,7 @@ public record StorageOptions(
StoragePath,
Packager,
PathTemplate,
OutputManifest,
WorkingDirectory,
CopyNonStreamable,
OverWrite,
Expand Down
6 changes: 3 additions & 3 deletions transform/AssetTransform.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,11 @@

namespace AMSMigrate.Transform
{
public record AssetRecord(MediaServicesAccountResource Account, MediaAssetResource Asset, string AssetName, BlobContainerClient Container, Manifest? Manifest, ClientManifest? ClientManifest)
: AssetDetails(AssetName, Container, Manifest, ClientManifest)
public record AssetRecord(MediaServicesAccountResource Account, MediaAssetResource Asset, string AssetName, BlobContainerClient Container, Manifest? Manifest, ClientManifest? ClientManifest, string? OutputManifest)
: AssetDetails(AssetName, Container, Manifest, ClientManifest, OutputManifest)
{
public AssetRecord(MediaServicesAccountResource account, MediaAssetResource asset, AssetDetails details):
this(account, asset, details.AssetName, details.Container, details.Manifest, details.ClientManifest)
this(account, asset, details.AssetName, details.Container, details.Manifest, details.ClientManifest, details.OutputManifest)
{
}
}
Expand Down
2 changes: 1 addition & 1 deletion transform/PackageTransform.cs
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ protected override async Task<string> TransformAsync(
(string Container, string Prefix) outputPath,
CancellationToken cancellationToken = default)
{
var (assetName, container, manifest, clientManifest) = details;
var (assetName, container, manifest, clientManifest, outputManifest) = details;
if (manifest == null) throw new ArgumentNullException(nameof(manifest));

// create a linked source which when disposed cancels all tasks.
Expand Down
6 changes: 4 additions & 2 deletions transform/ShakaPackager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,10 @@ public ShakaPackager(AssetDetails assetDetails, TransMuxer transMuxer, ILogger<S
var manifests = SelectedTracks
.Select((t, i) => $"{baseName}_{i}{HLS_MANIFEST}")
.ToList();
manifests.Add($"{baseName}{HLS_MANIFEST}");
manifests.Add($"{baseName}{DASH_MANIFEST}");

var outputManifest = assetDetails.OutputManifest ?? baseName;
manifests.Add($"{outputManifest}{HLS_MANIFEST}");
manifests.Add($"{outputManifest}{DASH_MANIFEST}");
Manifests = manifests;

// Shaka packager cannot handle smooth input.
Expand Down
6 changes: 4 additions & 2 deletions transform/StorageExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -138,16 +138,18 @@ public static async Task<AssetDetails> GetDetailsAsync(
this MediaAssetResource asset,
ILogger logger,
CancellationToken cancellationToken,
string? outputManifestname,
bool includeClientManifest = true)
{
var container = await asset.GetContainerAsync(cancellationToken);
return await container.GetDetailsAsync(logger, cancellationToken, asset.Data.Name, includeClientManifest);
return await container.GetDetailsAsync(logger, cancellationToken, outputManifestname, asset.Data.Name, includeClientManifest);
}

public static async Task<AssetDetails> GetDetailsAsync(
this BlobContainerClient container,
ILogger logger,
CancellationToken cancellationToken,
string? outputManifestname,
string? name = null,
bool includeClientManifest = true)
{
Expand All @@ -158,7 +160,7 @@ public static async Task<AssetDetails> GetDetailsAsync(
{
clientManifest = await container.GetClientManifestAsync(manifest, logger, cancellationToken);
}
return new AssetDetails(name, container, manifest, clientManifest);
return new AssetDetails(name, container, manifest, clientManifest, outputManifestname);
}
}
}
2 changes: 1 addition & 1 deletion transform/StorageTransform.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

namespace AMSMigrate.Transform
{
public record AssetDetails(string AssetName, BlobContainerClient Container, Manifest? Manifest, ClientManifest? ClientManifest);
public record AssetDetails(string AssetName, BlobContainerClient Container, Manifest? Manifest, ClientManifest? ClientManifest, string? OutputManifest);

internal abstract class StorageTransform : ITransform<AssetDetails, AssetMigrationResult>
{
Expand Down
2 changes: 1 addition & 1 deletion transform/UploadTransform.cs
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ protected override async Task<string> TransformAsync(
(string Container, string Prefix) outputPath,
CancellationToken cancellationToken = default)
{
var (assetName, inputContainer, manifest, _) = details;
var (assetName, inputContainer, manifest, _, _) = details;
var inputBlobs = await inputContainer.GetListOfBlobsAsync(cancellationToken, manifest);
var uploads = inputBlobs.Select(blob => UploadBlobAsync(blob, outputPath, cancellationToken));
await Task.WhenAll(uploads);
Expand Down

0 comments on commit 4e12bb3

Please sign in to comment.