如何在Delphi中使用FFMPEG

per*_*amy 3 delphi ffmpeg delphi-7

IAM的delphi.i初学者创建一个示例应用程序,我需要一个帮助。如何在delphi中使用FFMPEG?

Sim*_*mon 5

FFMPEG是一个命令行应用程序,因此您可以使用ShellExecute()在此处提供一些示例,轻松地调用它。

但是,首先,您需要确定要使用的命令行开关。

如果您需要进一步的帮助,我可以在明天发布代码。

编辑:

这是运行命令行应用程序的更高级的方法:它将输出重定向到备注以供查看:

procedure GetDosOutput(CommandLine, WorkDir: string;aMemo : TMemo);
var
  SA: TSecurityAttributes;
  SI: TStartupInfo;
  PI: TProcessInformation;
  StdOutPipeRead, StdOutPipeWrite: THandle;
  WasOK: Boolean;
  Buffer: array[0..255] of AnsiChar;
  BytesRead: Cardinal;
  Handle: Boolean;
begin
  AMemo.Lines.Add('Commencing processing...');
  with SA do begin
    nLength := SizeOf(SA);
    bInheritHandle := True;
    lpSecurityDescriptor := nil;
  end;
  CreatePipe(StdOutPipeRead, StdOutPipeWrite, @SA, 0);
  try
    with SI do
    begin
      FillChar(SI, SizeOf(SI), 0);
      cb := SizeOf(SI);
      dwFlags := STARTF_USESHOWWINDOW or STARTF_USESTDHANDLES;
      wShowWindow := SW_HIDE;
      hStdInput := GetStdHandle(STD_INPUT_HANDLE); // don't redirect stdin
      hStdOutput := StdOutPipeWrite;
      hStdError := StdOutPipeWrite;
    end;
    Handle := CreateProcess(nil, PChar('cmd.exe /C ' + CommandLine),
                            nil, nil, True, 0, nil,
                            PChar(WorkDir), SI, PI);
    CloseHandle(StdOutPipeWrite);
    if Handle then
      try
        repeat
          WasOK := ReadFile(StdOutPipeRead, Buffer, 255, BytesRead, nil);
          if BytesRead > 0 then
          begin
            Buffer[BytesRead] := #0;
            AMemo.Text := AMemo.Text + Buffer;
          end;
        until not WasOK or (BytesRead = 0);
        WaitForSingleObject(PI.hProcess, INFINITE);
      finally
        CloseHandle(PI.hThread);
        CloseHandle(PI.hProcess);
      end;
  finally
    CloseHandle(StdOutPipeRead);
    AMemo.Lines.Add('Processing completed successfully.');
    AMemo.Lines.Add('**********************************');
    AMemo.Lines.Add('');
  end;
end;
Run Code Online (Sandbox Code Playgroud)

可以这样称呼:

cmd := 'ffmpeg.exe -i "'+InFile+'" -vcodec copy -acodec copy "'+OutFile+'"';
GetDosOutput(cmd,FFMPEGDirectory,MemoLog);
Run Code Online (Sandbox Code Playgroud)