0
votes

I am currently building an app and am trying to write a webjob to take an mp4file i have uploaded to blob storage and create an asset which i then can encode and prepare to stream using azure media services.

public class Functions
    {
        // This function will get triggered/executed when a new message is written 
        // on an Azure Queue called queue.
        static string accName = "copied from portal ";
        static string accKey = "as above";
        static CloudMediaContext context = new CloudMediaContext(accName,accName);
        // Use the cached credentials to create CloudMediaContext.
        //static CloudMediaContext context = new CloudMediaContext(accName,accKey);
        public static void ProcessVideo(
        [QueueTrigger("videorequest")] VideoBlobInformation blobInfo,
        [Blob("{ProfileId}/{BlobName}", FileAccess.Read)] Stream input,
        [Blob("{ProfileId}/{BlobNameWithoutExtension}_stream.mp4")] CloudBlockBlob outputBlob)
        {
            VideoBlobInformation b = blobInfo;
            using (Stream output = outputBlob.OpenWrite())
            {
                ConvertAndPrepareVideo(b,input, output);
            }
            // Entity Framework context class is not thread-safe, so it must
            // be instantiated and disposed within the function.
            using (impulsevidContext db = new impulsevidContext())
            {
                //var id = blobInfo.ProfileId;
                //Video ad = db.Videos.Find(id);
                //if (ad == null)
                //{
                  //  throw new Exception(String.Format("AdId {0} not found, can't create thumbnail", id.ToString()));
                //}
                //ad.StreamUrl = outputBlob.Uri.ToString();
                //db.SaveChanges();
            }
            
        }
        public static void ConvertAndPrepareVideo(VideoBlobInformation info,Stream input, Stream output)
        {
            var storageAccount = new CloudStorageAccount(new StorageCredentials("accnameofstorage", "storage account associated with azure media services"), true);
            //output all webjob input blobs into a container -mediacontroller- 
            var cloudBlobClient = storageAccount.CreateCloudBlobClient();
            var mediaBlobContainer = cloudBlobClient.GetContainerReference("impfile");
            mediaBlobContainer.CreateIfNotExists();
            IAsset sourceAsset = context.Assets.Where(a => a.Id == info.VideoId).First();
        }
I am using a single storage account that i upload to. i keep getting this error 400 no matter what i try caused by this line

IAsset sourceAsset = context.Assets.Where(a => a.Id == info.VideoId).First();

which causes this log error

Microsoft.Azure.WebJobs.Host.FunctionInvocationException: Exception while executing function: Functions.ProcessVideo ---> System.Net.WebException: The remote server returned an error: (400) Bad Request. at System.Net.WebClient.UploadValues(Uri address, String method, NameValueCollection data) at System.Net.WebClient.UploadValues(String address, String method, NameValueCollection data) at Microsoft.WindowsAzure.MediaServices.Client.AcsTokenProvider.<>c__DisplayClass47_2.b__0() at Microsoft.Practices.TransientFaultHandling.RetryPolicy.<>c__DisplayClass1.b__0() at Microsoft.Practices.TransientFaultHandling.RetryPolicy.ExecuteAction[TResult](Func1 func) at Microsoft.Practices.TransientFaultHandling.RetryPolicy.ExecuteAction(Action action) at Microsoft.WindowsAzure.MediaServices.Client.AcsTokenProvider.RefreshToken() at Microsoft.WindowsAzure.MediaServices.Client.AcsTokenProvider.GetAccessToken() at Microsoft.WindowsAzure.MediaServices.Client.AcsTokenProvider.GetAuthorizationHeader() at Microsoft.WindowsAzure.MediaServices.Client.OAuth.OAuthDataServiceAdapter.AddAccessTokenToRequest(WebRequest request) at Microsoft.WindowsAzure.MediaServices.Client.AzureMediaServicesClassFactory.<>c__DisplayClass21_0.<GetAccountApiEndpoint>b__0() at Microsoft.Practices.TransientFaultHandling.RetryPolicy.<>c__DisplayClass1.<ExecuteAction>b__0() at Microsoft.WindowsAzure.MediaServices.Client.TransientFaultHandling.MediaRetryPolicy.ExecuteAction[TResult](Func1 func) at Microsoft.Practices.TransientFaultHandling.RetryPolicy.ExecuteAction(Action action) at Microsoft.WindowsAzure.MediaServices.Client.AzureMediaServicesClassFactory.GetAccountApiEndpoint(OAuthDataServiceAdapter dataServiceAdapter, ServiceVersionAdapter versionAdapter, Uri apiServer, UserAgentAdapter userAgentAdapter, IWebRequestAdapter clientRequestIdAdapter) at Microsoft.WindowsAzure.MediaServices.Client.AzureMediaServicesClassFactory.<>c__DisplayClass24_0.b__0() at Microsoft.WindowsAzure.MediaServices.Client.Cache1.GetOrAdd(String key, Func1 valueFactory, Func1 expirationFactory) at Microsoft.WindowsAzure.MediaServices.Client.AzureMediaServicesClassFactory.CreateAzureMediaServicesEndPoint(Uri azureMediaServicesEndpoint, MediaContextBase mediaContext) at Microsoft.WindowsAzure.MediaServices.Client.AzureMediaServicesClassFactory..ctor(Uri azureMediaServicesEndpoint, CloudMediaContext mediaContext) at Microsoft.WindowsAzure.MediaServices.Client.CloudMediaContext.get_MediaServicesClassFactory() at Microsoft.WindowsAzure.MediaServices.Client.AssetCollection.<.ctor>b__2_0() at System.Lazy1.CreateValue() at System.Lazy1.LazyInitValue() at System.Lazy1.get_Value() at Microsoft.WindowsAzure.MediaServices.Client.AssetCollection.get_Queryable() at Microsoft.WindowsAzure.MediaServices.Client.BaseCollection1.get_Provider() at System.Linq.Queryable.Where[TSource](IQueryable1 source, Expression1 predicate) at VideoProcess.Functions.ConvertAndPrepareVideo(VideoBlobInformation info, Stream input, Stream output) at VideoProcess.Functions.ProcessVideo(VideoBlobInformation blobInfo, Stream input, CloudBlockBlob outputBlob) at lambda_method(Closure , Functions , Object[] ) at Microsoft.Azure.WebJobs.Host.Executors.VoidMethodInvoker1.InvokeAsync(TReflected instance, Object[] arguments) at Microsoft.Azure.WebJobs.Host.Executors.FunctionInvoker`1.d__8.MoveNext() --- End of stack trace from previous location where exception was thrown --- at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task) at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) at Microsoft.Azure.WebJobs.Host.Executors.FunctionExecutor.d__22.MoveNext() --- End of stack trace from previous location where exception was thrown --- at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task) at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) at System.Runtime.CompilerServices.TaskAwaiter.ValidateEnd(Task task) at Microsoft.Azure.WebJobs.Host.Executors.FunctionExecutor.d__21.MoveNext() --- End of stack trace from previous location where exception was thrown --- at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task) at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) at Microsoft.Azure.WebJobs.Host.Executors.FunctionExecutor.d__19.MoveNext() --- End of stack trace from previous location where exception was thrown --- at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task) at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) at System.Runtime.CompilerServices.TaskAwaiter.ValidateEnd(Task task) at Microsoft.Azure.WebJobs.Host.Executors.FunctionExecutor.d__13.MoveNext() --- End of inner exception stack trace --- at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw() at Microsoft.Azure.WebJobs.Host.Executors.FunctionExecutor.d__13.MoveNext() --- End of stack trace from previous location where exception was thrown --- at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task) at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) at Microsoft.Azure.WebJobs.Host.Executors.FunctionExecutor.d__10.MoveNext()

1
Are your file/container names too long?Mardoxx
nope the blob files are 8486c644-7ed7-4f63-bba2-a8dd60c10bb1.mp4 and the container names are id fields of this length f24d8371ef41e0b32ddc4da6f5aa84efTomMurphyDev
Did you get this solved?sabbour

1 Answers

0
votes

context = new CloudMediaContext(new MediaServicesCredentials( accName, accKey)); should be set within the ConvertAndPrepareVideo method not outside