Iam beginner in delphi.i create the one sample application i need one help.how to use FFMPEG in inside the delphi?
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试):
问题:
回答1:
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);
回答2:
Here is the encapsulated library of FFmpeg for Delphi.
http://www.delphiffmpeg.com/
You may read the documents and try to build the examples.