0

The following Powershell script only executes the first ffmpeg call, no matter which one is first. Both the ffmpeg and the powershell processes never finish. Stopping the server, however, leads to the processes finishing and suddenly the second picture also appears.

Param($InputFile, $OutputFile, $Thumbnail, $Sprites)

$ThumbnailWidth = 120
$ThumbnailHeight = 120

# Thumbnail
ffmpeg -i $InputFile -f image2 -vframes 1 -filter:v "crop=min(iw\,ih):min(iw\,ih), scale=$($ThumbnailWidth):$($ThumbnailHeight)" -crf 18 "$($Thumbnail)\150x150.png"

# Poster
ffmpeg -i $InputFile -f image2 -vframes 1 -filter:v "crop=min(iw\,ih):min(iw\,ih), scale=$($PosterWidth):$($PosterHeight)" -crf 18 "$($Thumbnail)\1000x1000.png"

The script gets called within an ASP.NET application as follows:

ProcessStartInfo startInfo = new ProcessStartInfo();
startInfo.FileName = "powershell.exe";
startInfo.Arguments = String.Format("-executionpolicy RemoteSigned -file \"{0}\" \"{1}\" \"{2}\" \"{3}\" \"{4}\"", scriptPath, fullPath, videoPath, thumbnailPath, sprites);
startInfo.RedirectStandardOutput = true;
startInfo.RedirectStandardError = true;
startInfo.UseShellExecute = false;
startInfo.CreateNoWindow = true;
Process process = new Process();
process.StartInfo = startInfo;

process.EnableRaisingEvents = true;
process.Exited += delegate
{
     // Do some cleaning up
};

process.Start();

Does anyone have a clue, why only the first the two ffmpeg calls is working, while each call seems to be correct?

Adding process.StandardError.ReadToEnd(); makes the script finish as expected, but also makes it block, which is not acceptable.

sk904861
  • 1,247
  • 1
  • 14
  • 31
  • Do you see any error message or anything else? Or ps script just waits for the first call to be completed? – lavrik Mar 24 '14 at 15:38
  • 1
    May be script calls ffmpeg twice and doesn't wait before first will end. [Look at this](http://stackoverflow.com/questions/1741490/how-to-tell-powershell-to-wait-for-each-command-to-end-before-starting-the-next). – lavrik Mar 24 '14 at 15:42
  • Could this also be the problem, if the script runs correctly when run from cmd? Visual Studio doen't show any errors. The ffmpeg and the powershell processes stay alive and never finish. – sk904861 Mar 24 '14 at 16:11
  • Strange. Try to use cmd only if it runs correctly. – lavrik Mar 24 '14 at 16:17
  • What happens if you put in a process.WaitForExit() right after the process.Start()? Normally you wouldn't want to block the ASP.NET thread but this is for troubleshooting purposes. – Keith Hill Mar 24 '14 at 17:19
  • `process.WaitForExit()` doesn't seem to change anything. Concerning cmd: By cmd I meant the actual Windows command line. – sk904861 Mar 24 '14 at 18:45
  • I can add one additional discovery: When I stop the server, both processes are stopping as well and the second image actually appears in the folder. – sk904861 Mar 24 '14 at 18:51
  • Adding `process.StandardError.ReadToEnd();` makes the script finish as expected, but also makes it block, which is not acceptable. – sk904861 Mar 25 '14 at 13:44

0 Answers0