Recent

Author Topic: Running ffmpeg from lazarus  (Read 2490 times)

gozo97

  • Newbie
  • Posts: 5
Running ffmpeg from lazarus
« on: November 10, 2019, 03:38:56 pm »
Hello!
I am trying to run an ffmpeg command from within a lazarus program on Linux.  It should take a radio stream, extract the metadata and write to a file.  I know the command works because if I type into a terminal (using http://c2.auracast.net:8048/stream as an example)

/usr/bin/ffmpeg -i http://c2.auracast.net:8048/stream -f ffmetadata FFMETADATAFILE -y

it saves metadata info in my home directory with a text file FFMETADATAFILE. 

I have searched for various ways of doing this from a pascal program, based on "executing an external program"  but none of them seems to work.  The latest effort runs without an error, but the output file never appears:

 procedure TForm1.Button9Click(Sender: TObject);

// run ffmpeg

  var AProcess : TProcess;
   
    begin
     
     AProcess:= TProcess.Create(nil);
     Aprocess.Executable:='/usr/bin/ffmpeg';
     Aprocess.Parameters.Add(' -i');
     Aprocess.Parameters.Add(' http://c2.auracast.net:8048/stream');
     Aprocess.Parameters.Add(' -f ffmetadata');
     Aprocess.Parameters.Add(' FFMETADATAFILE');
     Aprocess.Parameters.Add(' -y');
     AProcess.Execute;
     AProcess.Free;
   
end;             

What am I doing wrong, please?                 

lucamar

  • Hero Member
  • *****
  • Posts: 4219
Re: Running ffmpeg from lazarus
« Reply #1 on: November 10, 2019, 04:16:13 pm »
Try this:

Code: Pascal  [Select][+][-]
  1.  procedure TForm1.Button9Click(Sender: TObject);
  2.  
  3. // run ffmpeg
  4.  
  5.   var AProcess : TProcess;
  6.    
  7.     begin
  8.      
  9.      AProcess:= TProcess.Create(nil);
  10.      Aprocess.Executable:='/usr/bin/ffmpeg';
  11.      Aprocess.Options := Aprocess.Options + [poWaitOnExit];
  12.      Aprocess.Parameters.Add(' -i http://c2.auracast.net:8048/stream');
  13.      Aprocess.Parameters.Add(' -f ffmetadata');
  14.      Aprocess.Parameters.Add(' FFMETADATAFILE');
  15.      Aprocess.Parameters.Add(' -y');
  16.      AProcess.Execute;
  17.      AProcess.Free;
  18. end;
Turbo Pascal 3 CP/M - Amstrad PCW 8256 (512 KB !!!) :P
Lazarus/FPC 2.0.8/3.0.4 & 2.0.12/3.2.0 - 32/64 bits on:
(K|L|X)Ubuntu 12..18, Windows XP, 7, 10 and various DOSes.

fred

  • Full Member
  • ***
  • Posts: 201
Re: Running ffmpeg from lazarus
« Reply #2 on: November 10, 2019, 06:34:28 pm »
With the spaces it will be quoted as a single parameter so I guess it should be like this:

Code: Pascal  [Select][+][-]
  1.      Aprocess.Parameters.Add('-i');
  2.      Aprocess.Parameters.Add('http://c2.auracast.net:8048/stream');
  3.      Aprocess.Parameters.Add('-f');
  4.      Aprocess.Parameters.Add('ffmetadata');
  5.      Aprocess.Parameters.Add('FFMETADATAFILE');
  6.      Aprocess.Parameters.Add('-y');

https://www.freepascal.org/docs-html/current/fcl/process/tprocess.parameters.html

gozo97

  • Newbie
  • Posts: 5
Re: Running ffmpeg from lazarus
« Reply #3 on: November 11, 2019, 03:13:53 pm »
Thank you both fred and lucamar.  I have tried both, but no success. 
The only thing I can think of, is that the script runs o.k. but for some reason the output file is not saved.

sstvmaster

  • Sr. Member
  • ****
  • Posts: 299
Re: Running ffmpeg from lazarus
« Reply #4 on: November 11, 2019, 04:15:41 pm »
Maybe a write access problem?

Try to add a path before FFMETADATAFILE!
Code: Pascal  [Select][+][-]
  1.      Aprocess.Parameters.Add('-i');
  2.      Aprocess.Parameters.Add('http://c2.auracast.net:8048/stream');
  3.      Aprocess.Parameters.Add('-f');
  4.      Aprocess.Parameters.Add('ffmetadata');
  5.      Aprocess.Parameters.Add('/home/username/Desktop/FFMETADATAFILE'); // or something else, where the user have write access!
  6.      Aprocess.Parameters.Add('-y');



greetings Maik

Windows 10,
- Lazarus 2.2.6 (stable) + fpc 3.2.2 (stable)
- Lazarus 2.2.7 (fixes) + fpc 3.3.1 (main/trunk)

gozo97

  • Newbie
  • Posts: 5
Re: Running ffmpeg from lazarus
« Reply #5 on: November 11, 2019, 04:30:38 pm »
I think I have found the answer!  The FFMETADATAFILE was possibly being saved somewhere, but not in the home directory where the terminal output saved it.
When I changed
Aprocess.Parameters.Add('FFMETADATAFILE');     to  Aprocess.Parameters.Add('/home/bob/FFMETADATAFILE');
everything worked!  Seems that you have to be specific in the full path.

Thank you again.

P.S  Just read sstvmaster's reply as I was typing!   Many thanks!  Didn't think of access rights.

metis

  • Sr. Member
  • ****
  • Posts: 300
Re: Running ffmpeg from lazarus
« Reply #6 on: November 14, 2019, 05:41:33 pm »
Hi gozo97,

if You'd like to run the three FFmpeg-CLIs ('ffmpeg.exe', 'ffprobe.exe' and 'ffplay.exe') with
CommandLine-Arguments and read out their Outputs, You might be also interested in 'RunFFmpeg':
http://forum.lazarus.freepascal.org/index.php/topic,43411.0.html -> GoTo "RunFFmpeg".

For now, the RunFFmpeg-GUI is Win32, only - You may adapt the SourceCode to Your Needs and extend it for Linux.  :)
Life could be so easy, if there weren't those f*** Details.
My FFmpeg4Lazarus = FFPlay4Laz + FFGrab4Laz + FFInfo4Laz

 

TinyPortal © 2005-2018