Subclip a video when encoding with Media Services - .NET
You can trim or subclip a video when encoding it using a Job. This functionality works with any Transform that is built using either the BuiltInStandardEncoderPreset presets, or the StandardEncoderPreset presets.
The following C# example creates a job that trims a video in an Asset as it submits an encoding job.
Prerequisites
To complete the steps described in this topic, you have to:
- Create an Azure Media Services account
- Create a Transform and an input and output Assets. You can see how to create a Transform and input and output Assets in the Upload, encode, and stream videos using .NET tutorial.
- Review the Encoding concept topic.
Example
/// <summary>
/// Submits a request to Media Services to apply the specified Transform to a given input video.
/// </summary>
/// <param name="client">The Media Services client.</param>
/// <param name="resourceGroupName">The name of the resource group within the Azure subscription.</param>
/// <param name="accountName"> The Media Services account name.</param>
/// <param name="transformName">The name of the transform.</param>
/// <param name="jobName">The (unique) name of the job.</param>
/// <param name="inputAssetName">The name of the input asset.</param>
/// <param name="outputAssetName">The (unique) name of the output asset that will store the result of the encoding job. </param>
// <SubmitJob>
private static async Task<Job> JobWithBuiltInStandardEncoderWithSingleClipAsync(
IAzureMediaServicesClient client,
string resourceGroupName,
string accountName,
string transformName,
string jobName,
string inputAssetName,
string outputAssetName)
{
var jobOutputs = new List<JobOutputAsset>
{
new JobOutputAsset(state: JobState.Queued, progress: 0, assetName: outputAssetName)
};
var clipStart = new AbsoluteClipTime()
{
Time = new TimeSpan(0, 0, 20)
};
var clipEnd = new AbsoluteClipTime()
{
Time = new TimeSpan(0, 0, 30)
};
var jobInput = new JobInputAsset(assetName: inputAssetName, start: clipStart, end: clipEnd);
Job job = await client.Jobs.CreateAsync(
resourceGroupName,
accountName,
transformName,
jobName,
new Job(input: jobInput, outputs: jobOutputs.ToArray(), name: jobName)
{
Description = $"A Job with transform {transformName} and single clip.",
Priority = Priority.Normal,
});
return job;
}