我的程序将MP4文件上传到blob然后将其修剪为10秒并重新上传到blob。我现在通过VS中的azure模拟器运行它时工作,但是当我将它部署到云时,输出文件有0个字节。
微调:
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);
}
}
Blob mover:
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 :(得分:0)
根据您的描述,我创建了我的项目来测试此问题。我可以使用存储模拟器在我身边按预期工作,并使用真实存储帐户部署到Azure。
我注意到您已使用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"));
}
}
此外,您可以按照此tutorial查看诊断数据,也可以利用Microsoft Azure Storage Explorer检查相关存储帐户的WADLogsTable
以检查应用程序日志。