Iam初学者在delphi.i中创建一个示例应用程序我需要一个help.how在delphi中使用FFMPEG?
答案 0 :(得分:4)
FFMPEG是一个命令行应用,因此您可以使用ShellExecute()
轻松调用它,并提供一些示例here。
但是,首先,您需要确定要使用的命令行开关。
如果您需要进一步的帮助,我明天可以发布代码。
编辑:
以下是运行命令行应用程序的更高级方法:它将输出重定向到备忘录以供查看:
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);
答案 1 :(得分:0)