Thanks Geepster,
I check that but the problem seems in the ffmpeg part so there will never be a output although I checked my command and it works.
Yep, I see the issue. FFmpeg needs you to read from both StdErr and Ouput, otherwise it locks up. I modified my generic TProcess piper (see below).
And then after reading some forums, this seems to work:
procedure FFmpegGetVideoFrame(const APicture: TPicture; const AFileName: String; const ASeconds: Double);
var
LMemoryStream: TMemoryStream;
begin
LMemoryStream := TMemoryStream.Create;
try
ProcessExecute('ffmpeg.exe', '-ss,' + FloatToStr(ASeconds) + ',-i,' + AnsiQuotedStr(AFileName, '"') +
',-f,mjpeg,-vframes,1,pipe:1',
nil, LMemoryStream, nil);
LMemoryStream.Position := 0;
APicture.LoadFromStream(LMemoryStream);
finally
FreeAndNil(LMemoryStream);
end;
end;
I tested it with this:
FFmpegGetVideoFrame(Image1.Picture, 'Resolution (2012).mp4', 60 * 10);
Here is my current generic TProcess function. Now includes 3 streams, which can be nil if not used. (It may need more testing)
procedure ProcessExecute(const AExecutable, AParameters: String; const AInput, AOutput, AStderr: TStream);
var
LBuffer: array[word] of byte;
LCount: longint;
begin
with TProcess.Create(nil) do begin
try
Options := [poUsePipes];
ShowWindow := swoHIDE;
Executable := AExecutable;
Parameters.CommaText := AParameters;
Execute;
if Assigned(AInput) then begin
while Running and (Input.Write(LBuffer, AInput.Read(LBuffer, SizeOf(LBuffer))) > 0) do begin
Sleep(10);
end;
end;
CloseInput;
while Running or (Output.NumBytesAvailable > 0) or (Stderr.NumBytesAvailable > 0) do begin
if Stderr.NumBytesAvailable > 0 then begin
LCount := Stderr.Read(LBuffer, SizeOf(LBuffer));
if Assigned(AStderr) then begin
AStderr.Write(LBuffer, LCount);
end;
end;
if Output.NumBytesAvailable > 0 then begin
LCount := Output.Read(LBuffer, SizeOf(LBuffer));
if Assigned(AOutput) then begin
AOutput.Write(LBuffer, LCount);
end;
end;
Sleep(10);
end;
finally
Free;
end;
end;
end;
** EDIT ** Small bug fix. Added "or (Stderr.NumBytesAvailable > 0)"