Ask your technical questions on forums or here :
ASP.NET or MVC | C# | Windows Phone
Microsoft Technology Journals by Abhimanyu K Vatsa
HOME ABOUT RAZOR BOOK SPEAKING MVC ASP.NET JQUERY VIDEOS EBOOK ARCHIVE
Showing posts with label Azure. Show all posts
Showing posts with label Azure. Show all posts

5 May 2017

Migrating Azure VMs on VNet from Azure Service Management (Classic or ASM) to Azure Resource Manager (Resource Manager or ARM)

In this post you will find code snippet to migrate your classic Azure VMs that is part of virtual networks. That is, you will learn Migrating Azure VMs on VNet from Azure Service Management (Classic or ASM) to Azure Resource Manager (Resource Manager or ARM). Without too much discussion, let's start step by step.

You need to have PowerShell installed. In the process of migration you first need to sign in your subscription using modern way that is ARM to prepare migration and then sign in your same subscription using classic approach that is ASM to perform migration and commit.

Step 1.
Let's login ARM

Login-AzureRmAccount

Step 2.
Store subscription id into a variable

$SubID = "1345e4-4561-1bd7-55c1-e3848012qw4r"

Step 3.
Select subscription using above variable

Select-AzureRmSubscription -SubscriptionID $SubID

Step 4.
Now, let's prepare the migration on ARM, this operation may take few minutes.

Register-AzureRmResourceProvider -ProviderNamespace Microsoft.ClassicInfrastructureMigrate

Step 5.
Now, in order to know the progress just use below command, you should see RegistrationState to Registered. Once you see Registered, you are good to go ahead.

Get-AzureRmResourceProvider -ProviderNamespace Microsoft.ClassicInfrastructureMigrate

Step 6.
Let's login ASM now

Add-AzureAccount

Step 7.
Then, select the subscription using subscription id that we stored in variable above.

Select-AzureSubscription -SubscriptionID $SubID

Step 8.
Now, let's get virtual network name that we will in next step.

Get-AzureVNetConfig -ExportToFile "C:\Users\Abhimanyu K Vatsa\Desktop\VNetConfig.xml"

Now you copy the value of VirtualNetworkSite name="demo-vnet-name"

Step 9.
Store the virtual network name in a variable. Remember, we are migrating virtual network that will automatically migration everything that is associated with this network, including network itself, vms, storage, load-balancer, subnet, nic etc.

$VNetName = "demo-vnet-name"

Step 10.
Let's run most powerful command that prepares the move and it may take few minutes.

Move-AzureVirtualNetwork -Prepare -VirtualNetworkName $VNetName

Step 11.
If you login to portal now, you will notice a new resource group is create with same name but -Migrated as post-fix. Don't worry, if you see everything doubled. Because these are exact same copy of your resources that was in classic. Once you run commit command (given below) your all classic resources will be removed and you will have migrated resources on ARM and every thing working as it was working earlier. Note, this operation may also take some time.

Move-AzureVirtualNetwork -Commit -VirtualNetworkName $VNetName

Or if you feel something going wrong, you can abort it using below command:

Move-AzureVirtualNetwork -Abort -VirtualNetworkName $VNetName

I used these commands several times and never faced any challenges, but still recommend you to run it yourself before your migrate production resources.

Hope this helps.

31 Aug 2016

Azure Media Service Encoding with custom presets

In this post you will learn how to use custom preset for Azure Media Service Encoding. But before that let's look at a case study or issue which I faced.

Introduction

When I uploaded a 55.5 MB mp4 file and encoded with "H264AdaptiveBitrateMP4Set720p" encoder preset, I received following output files:



















Look into green rectangular highlighted video files in the image, this looks good according to input file size. But if you look at red rectangular highlighted video files, these are *improved* files for adaptive streaming, which looks useless if you compare with my example "a dark line on my face in video can't be removed by system automatically...make sense". Here I'm trying to understand Azure Media Services encoding permutations but increasing file size 2-3 times larger than input file is never a acceptable deal.

Why I should pay more for bandwidth and storage on these large files, how I convince my clients?

On this issue I thought to understand this from community so I posted this here, but I'm still not convinced with answer.

Note: What are exact reasons encoder increases the file size, if you come to know please share with me too?

Is there any way I can define not to create such files when scheduling encoding?

Yes, we can use custom preset file and send it with encoding request to Azure Media Service. Let's see how it works in the code:

//// XML Preset
string name = "UploadedVideo-" + Guid.NewGuid().ToString();
IJob job = context.Jobs.Create(name);
IMediaProcessor processor = GetLatestMediaProcessorByName("Media Encoder Standard", context);
string configuration = System.IO.File.ReadAllText(HttpContext.Server.MapPath("~/MediaServicesCustomPreset.xml"));
ITask task = job.Tasks.AddNew(name + "- encoding task", processor, configuration, TaskOptions.None);
task.InputAssets.Add(inputAsset);
task.OutputAssets.AddNew(name + "-Adaptive-Bitrate-MP4", AssetCreationOptions.None);
job.Submit();
IAsset encodedOutputAsset = job.OutputMediaAssets[0];
string smoothStreamingUri = PublishAssetGetURLs(encodedOutputAsset, fileName);
string assetDetails = "MediaServiceFileName:" + encodedOutputAsset.Name + ", MediaServiceContainerUri:" + encodedOutputAsset.Uri + ", AssetId:" + encodedOutputAsset.Id;

Check code in repository here.

Notice blue highlighted code, that's what I added to send custom preset file with encoding request. I will be using xml preset file, you can use json file too. Let's look at the xml file now.

<?xml version="1.0" encoding="utf-16"?>
<Preset xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" Version="1.0" xmlns="http://www.windowsazure.com/media/encoding/Preset/2014/03">
  <Encoding>
    <H264Video>
      <KeyFrameInterval>00:00:02</KeyFrameInterval>
      <H264Layers>
        <H264Layer>
          <Bitrate>1500</Bitrate>
          <Width>960</Width>
          <Height>540</Height>
          <FrameRate>0/1</FrameRate>
          <Profile>Auto</Profile>
          <Level>auto</Level>
          <BFrames>3</BFrames>
          <ReferenceFrames>3</ReferenceFrames>
          <Slices>0</Slices>
          <AdaptiveBFrame>true</AdaptiveBFrame>
          <EntropyMode>Cabac</EntropyMode>
          <BufferWindow>00:00:05</BufferWindow>
          <MaxBitrate>1500</MaxBitrate>
        </H264Layer>
        <H264Layer>
          <Bitrate>1000</Bitrate>
          <Width>640</Width>
          <Height>360</Height>
          <FrameRate>0/1</FrameRate>
          <Profile>Auto</Profile>
          <Level>auto</Level>
          <BFrames>3</BFrames>
          <ReferenceFrames>3</ReferenceFrames>
          <Slices>0</Slices>
          <AdaptiveBFrame>true</AdaptiveBFrame>
          <EntropyMode>Cabac</EntropyMode>
          <BufferWindow>00:00:05</BufferWindow>
          <MaxBitrate>1000</MaxBitrate>
        </H264Layer>
        <H264Layer>
          <Bitrate>650</Bitrate>
          <Width>640</Width>
          <Height>360</Height>
          <FrameRate>0/1</FrameRate>
          <Profile>Auto</Profile>
          <Level>auto</Level>
          <BFrames>3</BFrames>
          <ReferenceFrames>3</ReferenceFrames>
          <Slices>0</Slices>
          <AdaptiveBFrame>true</AdaptiveBFrame>
          <EntropyMode>Cabac</EntropyMode>
          <BufferWindow>00:00:05</BufferWindow>
          <MaxBitrate>650</MaxBitrate>
        </H264Layer>
        <H264Layer>
          <Bitrate>400</Bitrate>
          <Width>320</Width>
          <Height>180</Height>
          <FrameRate>0/1</FrameRate>
          <Profile>Auto</Profile>
          <Level>auto</Level>
          <BFrames>3</BFrames>
          <ReferenceFrames>3</ReferenceFrames>
          <Slices>0</Slices>
          <AdaptiveBFrame>true</AdaptiveBFrame>
          <EntropyMode>Cabac</EntropyMode>
          <BufferWindow>00:00:05</BufferWindow>
          <MaxBitrate>400</MaxBitrate>
        </H264Layer>
      </H264Layers>
      <Chapters />
    </H264Video>
    <AACAudio>
      <Profile>AACLC</Profile>
      <Channels>2</Channels>
      <SamplingRate>48000</SamplingRate>
      <Bitrate>128</Bitrate>
    </AACAudio>
  </Encoding>
  <Outputs>
    <Output FileName="{Basename}_{Width}x{Height}_{VideoBitrate}.mp4">
      <MP4Format />
    </Output>
  </Outputs>
</Preset>

Check code in repository here.

If we do not pass custom preset file to Azure Media Service, then they use their default preset file which has higher bitrates and they don't have better logic to check input file bitrate and based on this decide new bitrates, this is what I understood.

So, I removed higher bitrate encoding from my preset file and this does the work. This has one disadvantage is that, any superb video quality will be loosed because preset is hardcoded for every video file. But, at-least now I have opportunity to write this bitrate dynamically based on video being uploaded through our service. And then send this new bitrate to Azure Media Services. Check the issue log here.

Hope this helps.

26 Apr 2016

Credential parameter can only be used with Organization ID credentials - Azure Deployment or Continuous Deployment Error

I faced this error while Azure Web App Deployment starts in after Continuous Integration. Here's the detailed information you see in the error:

-Credential parameter can only be used with Organization ID credentials. For more information, please refer to http://go.microsoft.com/fwlink/?linkid=331007&clcid=0x409 for more information about the difference between an organizational account and a Microsoft account. There was an error with the Azure credentials used for deployment.

 Error Screenshot:


If you face this issue, here's quick way:

Step 1

Edit existing build definition and select "Azure Web App Deployment" and then click on "Manage".


Now you will be redirect on new tab.

Step 2

On new tab click on "Update service configuration" and this will open a dialog box where you need to select "Certificate Based" option and then fill up the details. You can click on "Publish settings file" to download, this file will have everything you need to fill here.


Now click on "ok" button to save changes and then fire another build and this will work now.

Hope this helps.

28 Jul 2013

Working with Azure BLOB Storage in MVC

In this post you will learn following things:

i) Introduction to BLOB Storage
ii) Installing the Azure SDK
iii) Creating MVC Application (Web Role) to upload BLOBs (for example, images) and delete BLOBs
iv) Publishing to Windows Azure (Storage and Web Role)

16 Apr 2013

Using Microsoft SQL Server Management Studio to connect SQL Azure databases

In this article you will learn how to connect SQL Azure database from SQL Server Management Studio.

17 Dec 2012

Deploying an ASP.NET MVC 4 Web Application on Windows Azure

In this video you will learn how to deploy ASP.NET MVC 4 Web Application on Windows Azure environment. Sorry for the noisy video.