2017-03-07 4 views
0

私のプログラムはMP4ファイルをブロブにアップロードしてから10秒間トリミングし、ブロブに再アップロードします。私は現在、VSのAzureエミュレータを使って実行しているときにこれを動作させていますが、クラウドにデプロイすると出力ファイルのサイズは0バイトになります。Azureにデプロイされたときにファイルがストリームにコピーされず、VSエミュレータを使用しています

トリマー:

public static void Trimmer(string localStoragePath, Stream output) 
{ 
    string path2= localStoragePath.Remove(localStoragePath.Length-4)+ "_trimmed.mp4"; 
    string ffmpeg = "ffmpeg.exe"; 
    bool success = false; 
    string ExeArguments; 

    try 
    { 

     Process proc; 
     proc = new Process(); 
     proc.StartInfo.FileName = ffmpeg; 
     ExeArguments = @" -t 10 -i " + localStoragePath + " -map_metadata 0 -acodec copy " 
            + path2 + " -y"; 
     //ExeArguments = @"–t 10 -i -acodec" + localStoragePath + path2 ; 
     Trace.TraceInformation(ExeArguments); 
     proc.StartInfo.Arguments = ExeArguments; 
     proc.StartInfo.CreateNoWindow = true; 
     proc.StartInfo.UseShellExecute = false; 
     proc.StartInfo.ErrorDialog = false; 
     proc.Start(); 
     proc.WaitForExit(); 
     success = true; 
    } 

    catch { } 

    Trace.TraceInformation(string.Format("Video has been trimmed")); 

    using (Stream file = File.OpenRead(path2)) 
    { 
     Trace.TraceInformation(string.Format("Video moving to CopyStream")); 
     copyStream(file, output); 
    } 
} 

コピーストリーム:

public static void copyStream(Stream input, Stream output) 
{ 
    Trace.TraceInformation(string.Format("Video has been trimmed and now sent to be copied to stream")); 
    byte[] buffer = new byte[8 * 1024]; 
    int len; 
    while ((len = input.Read(buffer, 0, buffer.Length)) > 0) 
    { 
     output.Write(buffer, 0, len); 
    } 
} 

ブロブムーバー:

public static void fileMover (CloudBlob mover, string filePath, Stream input, Stream output) 
     { 


      string localStoragePath; 
      //start string from 7th letter, eg, images 
      string link = filePath.Substring(7); 


       LocalResource locRes; 
       locRes = RoleEnvironment.GetLocalResource("WorkerRoleLocalStorage"); 

       //To determine the path to the local storage resource's directory 

       localStoragePath = string.Format(locRes.RootPath); 

      //Moving file to local storage 
      try 
      { 
       mover.DownloadToFile(localStoragePath + link, FileMode.OpenOrCreate); 
       Trace.TraceInformation("file mover has been called " + localStoragePath + link); 
       //add meta data 
      } 
      catch(Exception e) { } 

      try 
      { 
       Trimmer(localStoragePath + link, output); 
      } 
      catch(Exception e) {} 
     } 

ありがとうございました。

+0

読み書きのためにBLOBを開く部分を追加できますか? – juunas

+0

@juunasメインポストに追加されました。 – user3107448

+0

空のキャッチブロックにいくつかのログを追加することをお勧めします。発生する可能性のある例外から役立つ情報を捨ててしまいます。 – stuartd

答えて

0

あなたの説明によると、私はこの問題をテストするプロジェクトを作成しました。私はストレージエミュレータと一緒に私の側でそれを期待どおりに動作させることができ、実際のストレージアカウントでAzureに配備しました。

enter image description here

私はあなたがこの問題を見つけ、解決するためのいくつかの提案があり、ここで、あなたはtry-catchでコードをラップしていることに気づい:

  • あなたがあなたのクラウドサービスプロジェクトのための診断を可能にすることができますAzureにデプロイする前にアプリケーションログを記録してください。 System.Diagnostics.Traceを使用して、例外をキャプチャするときに詳細なエラーをログに記録することができます。詳細は、tutorialに従ってください。

  • Trimmerの方法では、path2ファイルが存在するかどうかを確認する必要があります。私は、ファイルが生成されない場合、出力blobファイルのサイズが0になることをテストしました。私はTrimmerメソッドを変更しました。それを参照することができます。

public static void Trimmer(string localStoragePath, CloudBlockBlob outPutBlob) 
{ 
    string path2 = localStoragePath.Remove(localStoragePath.Length - 4) + "_trimmed.mp4"; 
    string ffmpeg = "ffmpeg.exe"; 
    bool success = false; 
    string ExeArguments; 
    try 
    { 
     Process proc; 
     proc = new Process(); 
     proc.StartInfo.FileName = ffmpeg; 
     ExeArguments = @" -t 10 -i " + localStoragePath + " -map_metadata 0 -acodec copy " 
             + path2 + " -y"; 
     Trace.TraceInformation(ExeArguments); 
     proc.StartInfo.Arguments = ExeArguments; 
     proc.StartInfo.CreateNoWindow = true; 
     proc.StartInfo.UseShellExecute = false; 
     proc.StartInfo.ErrorDialog = false; 
     proc.Start(); 
     proc.WaitForExit(); 
    } 
    catch(Exception ex) 
    { 
     Trace.TraceError($"Trimmer exception:{ex.Message}\r\nStackTrace:{ex.StackTrace}"); 
    } 

    var fi = new FileInfo(path2); 
    if (fi.Exists) 
    { 
     success = true; 
     Trace.TraceInformation(string.Format("Video has been trimmed")); 
     using (Stream file = File.OpenRead(path2)) 
     { 
      Trace.TraceInformation(string.Format("Video moving to CopyStream")); 
      Trace.TraceInformation(string.Format("Video has been trimmed and now sent to be copied to stream")); 
      byte[] buffer = new byte[8 * 1024]; 
      int len; 
      using (Stream outpuStream = outPutBlob.OpenWrite()) 
      { 
       while ((len = file.Read(buffer, 0, buffer.Length)) > 0) 
       { 
        outpuStream.Write(buffer, 0, len); 
       } 
      }  
     } 
    } 
    else 
    { 
     Trace.TraceWarning(string.Format("Video has not been trimmed")); 
    } 
} 

また、あなたは、診断データを表示したり、あなたのアプリケーションログを確認するように、関連するストレージアカウントのWADLogsTableをチェックするMicrosoft Azure Storage Explorerを活用することができ、このtutorialに従うことができます。

関連する問題