# Run command didn't work [closed]

I am trying to use external ffmpeg.exe to convert list of image files into mp4

a = Table[Plot[Sin[ω t], {t, 0, 10}, PlotRange -> {-1, 1}, ImageMargins -> .4],
{ω, .1, 2, .1}];

Export["movie01.png", a, "VideoFrames"];
Run["ffmpeg -f image2 -framerate 12 -i movie%02d.png -c:v libx264  movie.mp4"]


But the conversion is not done. If I run the exactly same ffmpeg code in windows CMD, it works. What is wrong with the above Run command?

solution

It turns out that after adding new exe to the windows environment(in this case, ffmpeg.exe), we have to restart mathematica, or this new exe will not be recognized by mathematica.

• Do your paths / \$Paths match? – Yves Klett Nov 15 '15 at 16:17
• @Yves Klett yeah. Run["del file"] works well – matheorem Nov 15 '15 at 16:27
• ass @YvesKlett points out, you need to make sure that you reference the absolute path. – elbOlita Nov 15 '15 at 19:39
• Why do you refer to the movie file as "movie01.png" in Export and as "movie%02d.png" in Run? – m_goldberg Nov 15 '15 at 23:02
• @m_goldberg This is the command of ffmpeg. see "ffmpeg.org/ffmpeg.html#Options" search "image2" you will find this. – matheorem Nov 16 '15 at 0:33

Let's override the Run so it stops acting up.

Needs["NETLink"];
InstallNET[];
Unprotect[Run];
Run[x___] := Module[{t, p},
DirectorySetCurrentDirectory[Directory[]];
t = NETNew["System.Diagnostics.Process"];
t@StartInfo@FileName = "C:\\Windows\\System32\\cmd.exe";
t@StartInfo@Arguments = "/c " <> StringJoin@Riffle[{x}, " "];
t@Start[];
t@WaitForExit[];
t@ExitCode];
Protect[Run];
Run["ffmpeg -f image2 -framerate 12 -i movie%02d.png -c:v libx264 movie.mp4"]


Someone is welcome to convert this to .NET link but as it stands the following works for me. This is the old code.

using System;
using System.Diagnostics;

public class Run{
public static void Main(String[] arg) {
string command = @"C:\Windows\System32\cmd.exe";
Process process = new Process();
process.StartInfo.FileName = command;
process.StartInfo.Arguments = "/c " + string.Join(" ",arg);
process.Start();
}
}


Compile it like so.

C:\Windows\Microsoft.NET\Framework\v4.0.30319\csc.exe Run.cs


and run it like so in Mathematica

Run["Run.exe ffmpeg -f image2 -framerate 12 -i movie%02d.png -c:v libx264  movie.mp4"]

• compile shows cannot find “Wolfram.NETLink.dll”? – matheorem Nov 16 '15 at 2:37
• @matheorem Now try it. Sorry it is how I compile .NET links when starting a kernel from .net – William Nov 16 '15 at 2:50
• This is great ! Thank you! upvoted. But still wish mma could fix this annoying bug – matheorem Nov 16 '15 at 2:53
• @matheorem I think it is a speed trade of(notice mathematica doesn't display a cmd window) maybe or at least they way they currently have it. I'm not really sure though. If I have time I'll try to convert it to a .NET link. – William Nov 16 '15 at 2:54
• I don't understand. You mean it has something to do the disappearance of the cmd window? – matheorem Nov 16 '15 at 2:56