1
votes

I am trying to make a video from list of bmp images, when I execute from command line ffmpeg -i img%5d.bmp -r 20 -c:v libx264 -preset slow -crf 22 output.mkv everything is ok, but when I try to execute from delphi project, it doesn't work. I've tried:

parameters := '-i img%5d.bmp -r 20 -c:v libx264 -preset slow -crf 22  output.mkv';
ShellExecute(0, nil, PChar('c:\videos\ffmpeg.exe'), PChar(parameters), nil, SW_NORMAL); 

I can't use TProcess, it has to be done with ShellExecute Please help me with this one, tnx in advance :)

1
You reap what you sow when you call ShellExecute. It does not support sane error handling. Use ShellExecuteEx and get a proper error code. Then take it from there. However, ShellExecuteEx is still the wrong function. You need to call CreateProcess to do this right.David Heffernan
I am very new at this, I don't know how to handle parameters and special characters :(hudy boy
I stand by what I said in my comment.David Heffernan
When i use ShellExecuteEx i get Too many actual parameters and there is a fiew arguments in CreateProcess which i don't understandhudy boy
@hudyboy There's only one way to interpret "too many actual parameters". The reason why you aren't understanding any of this is that you are running around like a headless chicken. The only way you can call a function and pass too many arguments is by failing to read the documentation. How can you expect anything other than failure if you won't read documentation?David Heffernan

1 Answers

1
votes

Here is a nice little piece of code I use. I am giving you this code but expect you to NOT just copy and paste. Please go through it to understand what it does.

The CreateProcess is what David spoke about. It is the best way to create and handle a process in Windows. Also note the WaitForSingleObject. That causes your execution to wait for Windows to finish before it returns after creating the process. You may of course remove the wait part. Also note the create flags.

It is called ExecuteAndWait. When you call it it will create a process and wait for it to finish:

function ExecuteAndWait(AFilename : String; AParameter : string;
                        ACmdShow : Integer; var AErrorOrExitCode : Cardinal): Boolean;
var
  StartupInfo: TStartupInfo;
  ProcessInfo: TProcessInformation;
  S : String;
begin
  FillChar(StartupInfo,Sizeof(StartupInfo),0);
  StartupInfo.cb := Sizeof(StartupInfo);
  StartupInfo.dwFlags := STARTF_USESHOWWINDOW;
  StartupInfo.wShowWindow := ACmdShow;
  S := AParameter;
  UniqueString(S);
  if not CreateProcess(PChar(AFilename),PChar(S),nil,nil,False,
                       CREATE_NEW_CONSOLE or NORMAL_PRIORITY_CLASS,nil,nil,
                       StartupInfo,ProcessInfo) then
    begin
      Result := False;
      AErrorOrExitCode := GetLastError;
    end
  else
    begin
      Result := True;
      WaitforSingleObject(ProcessInfo.hProcess,INFINITE);
      GetExitCodeProcess(ProcessInfo.hProcess,AErrorOrExitCode);
      CloseHandle(ProcessInfo.hProcess);
      CloseHandle(ProcessInfo.hThread);
    end;
end;

Example:

var
  ErrorOrExitCode : Cardinal;
begin
  If not ExecuteAndWait('c:\windows\regedit.exe','"c:\windows\regedit.exe" "c:\test.reg"',SW_SHOWDEFAULT,ErrorOrExitCode) then
    Showmessage(Inttostr(ErrorOrExitCode));

Here I tell regedit to load a exported reg file. Note the double-quotes and also note that I specify the executable as the filename and as part of the parameter.

Adapt it to your needs.