我将视频上传到 azure,创建资产并对视频进行编码。编码完成后,我会在资产文件夹(.ism、.mp4、.xml、.xml)中获得四个文件以及指向每个源的链接。当我尝试在视频播放器中播放 .mp4 文件时,没有任何反应。但是,当我下载 .mp4 文件时,它工作正常。
<video id="video1" src="https://123media.blob.core.windows.net/asset-bf389cc4-8454-410a-9492-7acab59b2d25/Wildlife_H264_4500kbps_AAC_und_ch2_128kbps.mp4" autoplay="autoplay" height="400" width="600" />
CloudStorageAccount storageAccount1 = CloudStorageAccount.Parse(CloudConfigurationManager.GetSetting("StorageConnectionString"));
CloudBlobClient cloudBlobClient1 = storageAccount1.CreateCloudBlobClient();
var context = new CloudMediaContext("123media", "###############################");
var CreateAsset = context.Assets.Create(Path.GetFileNameWithoutExtension(fileName), AssetCreationOptions.None);
var assetFile = CreateAsset.AssetFiles.Create(fileName);
IAccessPolicy writePolicy = context.AccessPolicies.Create("Policy For Copying", TimeSpan.FromMinutes(30), AccessPermissions.Write | AccessPermissions.List);
ILocator assetLocator = context.Locators.CreateSasLocator(CreateAsset, writePolicy, DateTime.UtcNow.AddMinutes(-5));
string assetContainerName = (new Uri(assetLocator.Path)).Segments[1];
CloudBlobContainer assetContainer = cloudBlobClient1.GetContainerReference(assetContainerName);
CloudBlockBlob assetBlob = assetContainer.GetBlockBlobReference(blobName);
assetBlob.StartCopyFromBlob(blob);
var inputAsset = context.Assets.Where(a => a.Id == CreateAsset.Id).FirstOrDefault();
if (inputAsset == null)
throw new ArgumentException("Could not find assetId: " + CreateAsset.Id);
var encodingPreset = "H264 Broadband 720p"; // <a href="http://msdn.microsoft.com/en-us/library/windowsazure/jj129582.aspx#H264Encoding">http://msdn.microsoft.com/en-us/library/windowsazure/jj129582.aspx#H264Encoding</a>
IJob job = context.Jobs.Create("Encoding " + inputAsset.Name + " to " + encodingPreset);
IMediaProcessor latestWameMediaProcessor = (from p in context.MediaProcessors where p.Name == "Windows Azure Media Encoder" select p).ToList().OrderBy(wame => new Version(wame.Version)).LastOrDefault();
ITask encodeTask = job.Tasks.AddNew("Encoding", latestWameMediaProcessor, encodingPreset, TaskOptions.None);
encodeTask.InputAssets.Add(inputAsset);
encodeTask.OutputAssets.AddNew(inputAsset.Name + " as " + encodingPreset, AssetCreationOptions.None);
job.Submit();
job.GetExecutionProgressTask(CancellationToken.None).Wait();