Advertisement
Guest User

Untitled

a guest
Feb 25th, 2017
90
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.06 KB | None | 0 0
  1. #r "Microsoft.WindowsAzure.Storage"
  2.  
  3. using Microsoft.WindowsAzure.Storage.Blob;
  4.  
  5. using System.Diagnostics;
  6. using System.IO;
  7.  
  8. public static async Task Run(Stream myBlob, string name, Binder binder, TraceWriter log)
  9. {
  10. log.Info($"Jordan C# Blob trigger function Processed blob\n Name:{name} \n Size: {myBlob.Length} Bytes");
  11.  
  12. byte[] bytes = null;
  13.  
  14. using(var ms = new MemoryStream()){
  15. myBlob.CopyTo(ms);
  16. bytes = ms.ToArray();
  17. }
  18.  
  19. var f = @"D:\home\site\wwwroot\Timelapser\ffmpeg.exe";
  20.  
  21. var temp = Path.GetTempFileName();
  22. var tempOut = Path.GetTempFileName() + ".mpg";
  23.  
  24. var tempPath = Path.Combine(Path.GetTempPath(), Guid.NewGuid().ToString());
  25.  
  26. Directory.CreateDirectory(tempPath);
  27.  
  28. File.WriteAllBytes(temp, bytes);
  29.  
  30. log.Info($"Exists: {File.Exists(temp)}");
  31.  
  32. var readBack = File.ReadAllBytes(temp);
  33.  
  34. log.Info($"ReadBack: {readBack.Length}, {temp}");
  35.  
  36. var psi = new ProcessStartInfo();
  37.  
  38. psi.FileName = f;
  39. psi.Arguments = $"-i \"{temp}\" -y -s 640x360 -b:v 1024k -r 29.7 -movflags faststart -pix_fmt yuv420p \"{tempOut}\"";
  40. psi.RedirectStandardOutput = true;
  41. psi.RedirectStandardError = true;
  42. psi.UseShellExecute = false;
  43.  
  44. log.Info($"Args: {psi.Arguments}");
  45.  
  46. var process = Process.Start(psi);
  47. //string output = process.StandardOutput.ReadToEnd();
  48. //string err = process.StandardError.ReadToEnd();
  49. process.WaitForExit((int)TimeSpan.FromSeconds(60).TotalMilliseconds);
  50.  
  51. // log.Info(output);
  52. // log.Info(err);
  53.  
  54. log.Info($"Output: {process.ExitCode}");
  55.  
  56.  
  57. log.Info($"Temp Out Exists: {File.Exists(tempOut)}");
  58.  
  59. var attributes = new Attribute[]
  60. {
  61. new BlobAttribute("renc/" + name + "_reenc.mpg"),
  62. new StorageAccountAttribute("jortana_STORAGE")
  63. };
  64.  
  65.  
  66. var renc = File.ReadAllBytes(tempOut);
  67. log.Info($"Renc Length: {renc.Length}");
  68. var writer = await binder.BindAsync<CloudBlockBlob>(attributes);
  69.  
  70. // await writer.UploadFromByteArrayAsync(renc, 0, renc.Length);
  71.  
  72. File.Delete(tempOut);
  73. File.Delete(temp);
  74. Directory.Delete(tempPath, true);
  75. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement