如何在Delphi中使用FFMPEG

发布于 2025-01-01 15:16:10 字数 61 浏览 1 评论 0原文

我是delphi的初学者。我创建了一个示例应用程序,我需要一个帮助。如何在delphi内部使用FFMPEG?

Iam beginner in delphi.i create the one sample application i need one help.how to use FFMPEG in inside the delphi?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

深海蓝天 2025-01-08 15:16:10

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;

可以像这样调用它:

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

FFMPEG is a command line app, so you can easily call it using ShellExecute(), with some examples here.

First, however, you need to decide what command line switches to use.

I can post code tomorrow if you need further help.

EDIT:

Here is a more advanced method to run a command line application: It redirects the output to a memo for viewing:

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;

It can be called like so:

cmd := 'ffmpeg.exe -i "'+InFile+'" -vcodec copy -acodec copy "'+OutFile+'"';
GetDosOutput(cmd,FFMPEGDirectory,MemoLog);
我最亲爱的 2025-01-08 15:16:10

这是FFmpeg for Delphi的封装库。

http://www.delphiffmpeg.com/

您可以阅读文档并尝试构建示例。

Here is the encapsulated library of FFmpeg for Delphi.

http://www.delphiffmpeg.com/

You may read the documents and try to build the examples.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文