I tried to port a .net console application to a docker container. The application tries to call ffmpeg.exe, I get an error? Is it possible that I can't run an exe in this container?
static void encoder(string inputFile, string outputFolder, string outputFileName)
{
if (!Directory.Exists(outputFolder))
{
Directory.CreateDirectory(outputFolder);
}
var GetDirectory = Path.GetDirectoryName(System.Reflection.Assembly.GetExecutingAssembly().Location);
// Part 1: use ProcessStartInfo class.
ProcessStartInfo startInfo = new ProcessStartInfo();
startInfo.CreateNoWindow = false;
startInfo.UseShellExecute = false;
startInfo.RedirectStandardInput = true;
startInfo.FileName = GetDirectory @"/ffmpeg.exe";
startInfo.WindowStyle = ProcessWindowStyle.Hidden;
// Part 2: set arguments.
startInfo.Arguments = "-i " inputFile " -q:a 8 -filter:a loudnorm " outputFolder outputFileName;
// Part 3: start with the info we specified.
// ... Call WaitForExit.
using (Process exeProcess = Process.Start(startInfo))
{
exeProcess.StandardInput.WriteLine("y");
exeProcess.WaitForExit();
}
}
Error
OPUS-Encoder System.ComponentModel.Win32Exception (8): An error occurred trying to start process '/App/ffmpeg.exe' with working directory '/App'. Exec format error
at System.Diagnostics.Process.ForkAndExecProcess(ProcessStartInfo startInfo, String resolvedFilename, String[] argv, String[] envp, String cwd, Boolean setCredentials, UInt32 userId, UInt32 groupId, UInt32[] groups, Int32& stdinFd, Int32& stdoutFd, Int32& stderrFd, Boolean usesTerminal, Boolean throwOnNoExec)
at System.Diagnostics.Process.StartCore(ProcessStartInfo startInfo)
at System.Diagnostics.Process.Start()
at System.Diagnostics.Process.Start(ProcessStartInfo startInfo)
at Program.<<Main>$>g__encoder|0_0(String inputFile, String outputFolder, String outputFileName) in /App/Program.cs:line 77
at Program.<Main>$(String[] args) in /App/Program.cs:line 34
thx
CodePudding user response:
Looks like your docker container running Linux, but executable is Windows PE.
If your container is running Linux you need Linux binary not Windows ".exe". You can get one here
API for call will be same.
If you want to support Linux and Windows you will need to change path parameter according to current OS. Here is the question about how to do it on runtime.