Skip to content

Commit 03b9c27

Browse files
authored
Merge pull request #105411 from Juliako/download
started writing
2 parents a668397 + 320172e commit 03b9c27

File tree

4 files changed

+280
-77
lines changed

4 files changed

+280
-77
lines changed

articles/media-services/latest/TOC.yml

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -54,11 +54,13 @@
5454
- name: Storage account
5555
href: storage-account-concept.md
5656
displayName: Storage side encryption
57-
- name: Uploading
58-
items:
57+
- name: Assets
58+
items:
5959
- name: Assets
60-
href: assets-concept.md
61-
displayName: name, naming, file name
60+
href: assets-concept.md
61+
- name: Manage assets
62+
href: manage-asset-concept.md
63+
displayName: name, naming, file name, upload, output, download
6264
- name: Processing files
6365
items:
6466
- name: Transforms and Jobs
@@ -300,6 +302,8 @@
300302
items:
301303
- name: Publish an asset - CLI
302304
href: cli-publish-asset.md
305+
- name: Download results
306+
href: download-results-howto.md
303307
- name: Signal descriptive audio
304308
href: signal-descriptive-audio-howto.md
305309
- name: Reference

articles/media-services/latest/assets-concept.md

Lines changed: 11 additions & 73 deletions
Original file line numberDiff line numberDiff line change
@@ -20,84 +20,24 @@ ms.custom: seodec18
2020

2121
# Assets in Azure Media Services
2222

23-
In Azure Media Services, an [Asset](https://docs.microsoft.com/rest/api/media/assets) contains information about digital files stored in Azure Storage (including video, audio, images, thumbnail collections, text tracks, and closed caption files).
23+
In Azure Media Services, an [Asset](https://docs.microsoft.com/rest/api/media/assets) is a core concept. It is where you input media (for example, through upload or live ingest), output media (from a job output), and publish media from (for streaming).
2424

25-
An Asset is mapped to a blob container in the [Azure Storage account](storage-account-concept.md) and the files in the Asset are stored as block blobs in that container. Media Services supports Blob tiers when the account uses General-purpose v2 (GPv2) storage. With GPv2, you can move files to [Cool or Archive storage](https://docs.microsoft.com/azure/storage/blobs/storage-blob-storage-tiers). **Archive** storage is suitable for archiving source files when no longer needed (for example, after they've been encoded).
25+
An Asset is mapped to a blob container in the [Azure Storage account](storage-account-concept.md) and the files in the Asset are stored as block blobs in that container. Assets contain information about digital files stored in Azure Storage (including video, audio, images, thumbnail collections, text tracks, and closed caption files).
26+
27+
Media Services supports Blob tiers when the account uses General-purpose v2 (GPv2) storage. With GPv2, you can move files to [Cool or Archive storage](https://docs.microsoft.com/azure/storage/blobs/storage-blob-storage-tiers). **Archive** storage is suitable for archiving source files when no longer needed (for example, after they've been encoded).
2628

2729
The **Archive** storage tier is only recommended for very large source files that have already been encoded and the encoding Job output was put in an output blob container. The blobs in the output container that you want to associate with an Asset and use to stream or analyze your content must exist in a **Hot** or **Cool** storage tier.
2830

29-
### Naming
31+
## Naming
3032

31-
#### Assets
33+
### Assets
3234

3335
Asset's names must be unique. Media Services v3 resource names (for example, Assets, Jobs, Transforms) are subject to Azure Resource Manager naming constraints. For more information, see [Naming conventions](media-services-apis-overview.md#naming-conventions).
3436

35-
#### Blobs
37+
### Blobs
3638

3739
The names of files/blobs within an asset must follow both the [blob name requirements](https://docs.microsoft.com/rest/api/storageservices/Naming-and-Referencing-Containers--Blobs--and-Metadata) and the [NTFS name requirements](https://docs.microsoft.com/windows/win32/fileio/naming-a-file). The reason for these requirements is the files can get copied from blob storage to a local NTFS disk for processing.
3840

39-
## Upload digital files into Assets
40-
41-
After the digital files are uploaded into storage and associated with an Asset, they can be used in the Media Services encoding, streaming, and analyzing content workflows. One of the common Media Services workflows is to upload, encode, and stream a file. This section outlines the general steps.
42-
43-
> [!TIP]
44-
> Before you start developing, review [Developing with Media Services v3 APIs](media-services-apis-overview.md) (includes information on accessing APIs, naming conventions, and so on).
45-
46-
1. Use the Media Services v3 API to create a new "input" Asset. This operation creates a container in the storage account associated with your Media Services account. The API returns the container name (for example, `"container": "asset-b8d8b68a-2d7f-4d8c-81bb-8c7bbbe67ee4"`).
47-
48-
If you already have a blob container that you want to associate with an Asset, you can specify the container name when you create the Asset. Media Services currently only supports blobs in the container root and not with paths in the file name. Thus, a container with the "input.mp4" file name will work. However, a container with the "videos/inputs/input.mp4" file name won't work.
49-
50-
You can use the Azure CLI to upload directly to any storage account and container that you have rights to in your subscription.
51-
52-
The container name must be unique and follow storage naming guidelines. The name doesn't have to follow the Media Services Asset container name (Asset-GUID) formatting.
53-
54-
```azurecli
55-
az storage blob upload -f /path/to/file -c MyContainer -n MyBlob
56-
```
57-
2. Get a SAS URL with read-write permissions that will be used to upload digital files into the Asset container. You can use the Media Services API to [list the asset container URLs](https://docs.microsoft.com/rest/api/media/assets/listcontainersas).
58-
3. Use the Azure Storage APIs or SDKs (for example, the [Storage REST API](../../storage/common/storage-rest-api-auth.md) or [.NET SDK](../../storage/blobs/storage-quickstart-blobs-dotnet.md)) to upload files into the Asset container.
59-
4. Use Media Services v3 APIs to create a Transform and a Job to process your "input" Asset. For more information, see [Transforms and Jobs](transform-concept.md).
60-
5. Stream the content from the "output" asset.
61-
62-
For a full .NET example that shows how to create the Asset, get a writable SAS URL to the Asset’s container in storage, and upload the file into the container in storage using the SAS URL, see [Create a job input from a local file](job-input-from-local-file-how-to.md).
63-
64-
### Create a new asset
65-
66-
> [!NOTE]
67-
> An Asset's properties of the Datetime type are always in UTC format.
68-
69-
#### REST
70-
71-
```
72-
PUT https://management.azure.com/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Media/mediaServices/{amsAccountName}/assets/{assetName}?api-version=2018-07-01
73-
```
74-
75-
For a REST example, see the [Create an Asset with REST](https://docs.microsoft.com/rest/api/media/assets/createorupdate#examples) example.
76-
77-
The example shows how to create the **Request Body** where you can specify description, container name, storage account, and other useful info.
78-
79-
#### cURL
80-
81-
```cURL
82-
curl -X PUT \
83-
'https://management.azure.com/subscriptions/00000000-0000-0000-000000000000/resourceGroups/resourceGroupName/providers/Microsoft.Media/mediaServices/amsAccountName/assets/myOutputAsset?api-version=2018-07-01' \
84-
-H 'Accept: application/json' \
85-
-H 'Content-Type: application/json' \
86-
-d '{
87-
"properties": {
88-
"description": "",
89-
}
90-
}'
91-
```
92-
93-
#### .NET
94-
95-
```csharp
96-
Asset asset = await client.Assets.CreateOrUpdateAsync(resourceGroupName, accountName, assetName, new Asset());
97-
```
98-
99-
For a full example, see [Create a job input from a local file](job-input-from-local-file-how-to.md). In Media Services v3, a job's input can also be created from HTTPS URLs (see [Create a job input from an HTTPS URL](job-input-from-http-how-to.md)).
100-
10141
## Map v3 asset properties to v2
10242

10343
The following table shows how the [Asset](https://docs.microsoft.com/rest/api/media/assets/createorupdate#asset)'s properties in v3 map to Asset's properties in v2.
@@ -129,12 +69,10 @@ To protect your Assets at rest, the assets should be encrypted by the storage si
12969

13070
<sup>2</sup> In Media Services v3, storage encryption (AES-256 encryption) is only supported for backwards compatibility when your Assets were created with Media Services v2. Meaning v3 works with existing storage encrypted assets but won't allow creation of new ones.
13171

132-
## Filtering, ordering, paging
72+
## Next steps
13373

134-
See [Filtering, ordering, paging of Media Services entities](entities-overview.md).
74+
[Manage assets in Media Services](manage-asset-concept.md)
13575

136-
## Next steps
76+
## Also see
13777

138-
* [Stream a file](stream-files-dotnet-quickstart.md)
139-
* [Using a cloud DVR](live-event-cloud-dvr.md)
140-
* [Differences between Media Services v2 and v3](migrate-from-v2-to-v3.md)
78+
[Differences between Media Services v2 and v3](migrate-from-v2-to-v3.md)
Lines changed: 119 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,119 @@
1+
---
2+
title: Download the results of a job - Azure Media Services
3+
description: This article demonstrates how to download the results of a job.
4+
services: media-services
5+
documentationcenter: ''
6+
author: Juliako
7+
manager: femila
8+
editor: ''
9+
10+
ms.service: media-services
11+
ms.workload:
12+
ms.topic: article
13+
ms.date: 02/18/2019
14+
ms.author: juliako
15+
---
16+
17+
# Download the results of a job
18+
19+
In Azure Media Services, when processing your videos (for example, encoding or analyzing) you need to create an output [asset](assets-concept.md) to store the result of your [job](transforms-jobs-concept.md). You can then download these results to a local folder using Media Service and Storage APIs.
20+
21+
This article demonstrates how to download the results using Java and .NET SDKs.
22+
23+
## Java
24+
25+
```java
26+
/**
27+
* Use Media Service and Storage APIs to download the output files to a local folder
28+
* @param manager The entry point of Azure Media resource management
29+
* @param resourceGroup The name of the resource group within the Azure subscription
30+
* @param accountName The Media Services account name
31+
* @param assetName The asset name
32+
* @param outputFolder The output folder for downloaded files.
33+
* @throws StorageException
34+
* @throws URISyntaxException
35+
* @throws IOException
36+
*/
37+
private static void downloadResults(MediaManager manager, String resourceGroup, String accountName,
38+
String assetName, File outputFolder) throws StorageException, URISyntaxException, IOException {
39+
ListContainerSasInput parameters = new ListContainerSasInput()
40+
.withPermissions(AssetContainerPermission.READ)
41+
.withExpiryTime(DateTime.now().plusHours(1));
42+
AssetContainerSas assetContainerSas = manager.assets()
43+
.listContainerSasAsync(resourceGroup, accountName, assetName, parameters).toBlocking().first();
44+
45+
String strSas = assetContainerSas.assetContainerSasUrls().get(0);
46+
CloudBlobContainer container = new CloudBlobContainer(new URI(strSas));
47+
48+
File directory = new File(outputFolder, assetName);
49+
directory.mkdir();
50+
51+
ArrayList<ListBlobItem> blobs = container.listBlobsSegmented(null, true, EnumSet.noneOf(BlobListingDetails.class), 200, null, null, null).getResults();
52+
53+
for (ListBlobItem blobItem: blobs) {
54+
if (blobItem instanceof CloudBlockBlob) {
55+
CloudBlockBlob blob = (CloudBlockBlob)blobItem;
56+
File downloadTo = new File(directory, blob.getName());
57+
58+
blob.downloadToFile(downloadTo.getPath());
59+
}
60+
}
61+
62+
System.out.println("Download complete.");
63+
}
64+
```
65+
66+
See the full code sample: [EncodingWithMESPredefinedPreset](https://github.com/Azure-Samples/media-services-v3-java/blob/master/VideoEncoding/EncodingWithMESPredefinedPreset/src/main/java/sample/EncodingWithMESPredefinedPreset.java)
67+
68+
## .NET
69+
70+
```csharp
71+
/// <summary>
72+
/// Use Media Service and Storage APIs to download the output files to a local folder
73+
/// </summary>
74+
/// <param name="client">The Media Services client.</param>
75+
/// <param name="resourceGroupName">The name of the resource group within the Azure subscription.</param>
76+
/// <param name="accountName">The Media Services account name.</param>
77+
/// <param name="assetName">The asset name.</param>
78+
/// <param name="resultsFolder">The output folder name for downloaded files.</param>
79+
/// <returns>A task.</returns>
80+
private async static Task DownloadResults(IAzureMediaServicesClient client, string resourceGroupName, string accountName, string assetName, string resultsFolder)
81+
{
82+
AssetContainerSas assetContainerSas = client.Assets.ListContainerSas(
83+
resourceGroupName,
84+
accountName,
85+
assetName,
86+
permissions: AssetContainerPermission.Read,
87+
expiryTime: DateTime.UtcNow.AddHours(1).ToUniversalTime()
88+
);
89+
90+
Uri containerSasUrl = new Uri(assetContainerSas.AssetContainerSasUrls.FirstOrDefault());
91+
CloudBlobContainer container = new CloudBlobContainer(containerSasUrl);
92+
93+
string directory = Path.Combine(resultsFolder, assetName);
94+
Directory.CreateDirectory(directory);
95+
96+
Console.WriteLine("Downloading results to {0}.", directory);
97+
98+
var blobs = container.ListBlobsSegmentedAsync(null,true, BlobListingDetails.None,200,null,null,null).Result;
99+
100+
foreach (var blobItem in blobs.Results)
101+
{
102+
if (blobItem is CloudBlockBlob)
103+
{
104+
CloudBlockBlob blob = blobItem as CloudBlockBlob;
105+
string filename = Path.Combine(directory, blob.Name);
106+
107+
await blob.DownloadToFileAsync(filename, FileMode.Create);
108+
}
109+
}
110+
111+
Console.WriteLine("Download complete.");
112+
}
113+
```
114+
115+
See the full code sample: [EncodingWithMESPredefinedPreset](https://github.com/Azure-Samples/media-services-v3-dotnet/blob/master/VideoEncoding/EncodingWithMESPredefinedPreset/Program.cs)
116+
117+
## Next steps
118+
119+
[Create a job input from an HTTPS URL](job-input-from-http-how-to.md).

0 commit comments

Comments
 (0)