Recent

Author Topic: Run ffmpeg via TProcess  (Read 551 times)

HobbyDev

  • New Member
  • *
  • Posts: 32
Run ffmpeg via TProcess
« on: January 21, 2025, 08:51:52 pm »
Hi there, I am searching now for a while already but may be I am a kind of blind and don't see it:

I want to run ffmpeg using TProcess but don't get it done. That's the code:
Code: Pascal  [Select][+][-]
  1. procedure TForm1.Button2Click(Sender: TObject);
  2. var AProcess : TProcess;
  3.     cmdStr : String;
  4.  
  5. begin
  6.   LogMeldungen.Clear; // LogMeldungen : TMemo
  7.   AProcess:= TProcess.Create(nil);
  8.   // Aprocess.Executable:='/usr/bin/sh';
  9.   // Aprocess.Parameters.Add('-c');
  10.  
  11.   Aprocess.Executable:='/usr/bin/ffmpeg';
  12.   cmdStr             := CommandLine.Text;
  13.   Aprocess.Parameters.Add(cmdStr);
  14.   Aprocess.Options   := Aprocess.Options + [poWaitOnExit];
  15.   {
  16.   Aprocess.Parameters.Add('-y');
  17.   Aprocess.Parameters.Add('-i');
  18.   Aprocess.Parameters.Add(srcPath+Dateiname);
  19.   Aprocess.Parameters.Add('-c');
  20.   Aprocess.Parameters.Add('copy');
  21.   Aprocess.Parameters.Add('-map');
  22.   Aprocess.Parameters.Add('0');
  23.   Aprocess.Parameters.Add('-metadata');
  24.   Aprocess.Parameters.Add(creationTimeStr);
  25.   Aprocess.Parameters.Add('-metadata');
  26.   Aprocess.Parameters.Add(metadescStr);
  27.   Aprocess.Parameters.Add(dstPath + Dateiname);
  28.   }
  29.   AProcess.Execute;
  30.   LogMeldungen.Append('ExitCode ist: ' + IntTostr(AProcess.ExitCode));
  31.   //LogMeldungen.Lines.LoadFromStream(AProcess.Output);
  32.   AProcess.Free;
  33. end;
If I open a terminal and put in /usr/bin/ffmpeg followed by the cmdStr it works perfect. If I use /usr/bin/sh as TProcess.Executable and add "-c" as the first parameter and than either all of all uncommented lines or the /usr/bin/ffmpeg + cmdStr as one TProcess.Parameter that all works fine but not the way I like it.
The cmdStr could be:
Code: Pascal  [Select][+][-]
  1.  -y -i /mnt/Media-Store/Videos/MKVs/Band31/2006-01-08_09-38_uhr_0.mkv -codec copy -map 0 -metadata creation_time="2006-01-08 09:38:00" -metadata description="My Test Description" /home/hobbydev/Videos/2006-01-08_09-38_uhr_0.mkv
  2.  

Do you see what's wrong? Many thanks!

TRon

  • Hero Member
  • *****
  • Posts: 3925
Re: Run ffmpeg via TProcess
« Reply #1 on: January 22, 2025, 01:07:59 am »
I want to run ffmpeg using TProcess but don't get it done.
What does that actually mean ? Do you get an error, is the command not processed at all, does it not do what you want ti do do or ....  what ?


Quote
Do you see what's wrong? Many thanks!
What I can see is that you seem to be using metadata tags that are not supported by the mkv container format (as per ffpmeg documentation).

That you are able to run the command using cmdstr and/or using sh doe not mean anything in that regards. I am able to run the command using tprocess and adding individual parameters just fine. The posted example code is missing some vital information.


Code: Pascal  [Select][+][-]
  1. procedure ProcessVideoFile(Filename, SrcPath, DstPath:string);
  2. var
  3.   Proc            : TProcess;
  4.   CreationTimeStr : string = '2006-01-08 09:38:00';
  5.   MetadescStr     : string = 'My Test Description';
  6. begin
  7.   Proc:= TProcess.Create(nil);
  8.   try
  9.     Proc.Options := Proc.Options + [poStderrToOutPut,poWaitOnExit];
  10.     Proc.Executable:='ffmpeg';
  11.  
  12.     Proc.Parameters.Add('-y');
  13.     Proc.Parameters.Add('-i');
  14.     Proc.Parameters.Add(srcPath + Filename);
  15.     Proc.Parameters.Add('-codec');
  16.     Proc.Parameters.Add('copy');
  17.     Proc.Parameters.Add('-map');
  18.     Proc.Parameters.Add('0');
  19.     Proc.Parameters.Add('-metadata');
  20.     Proc.Parameters.Add('creation_time=' + creationTimeStr);  // MP3 only
  21.     Proc.Parameters.Add('-metadata');
  22.     Proc.Parameters.Add('description=' + metadescStr);  // Shows up in comment
  23.  
  24.     Proc.Parameters.Add('-metadata');
  25.     Proc.Parameters.Add('author=free pascal');  // This is an actual by mkv supported meta-tag
  26.  
  27.     Proc.Parameters.Add(dstPath + Filename);
  28.  
  29.     Proc.Execute;
  30.   finally
  31.     Proc.Free;
  32.   end;
  33. end;
  34.  
I do not have to remember anything anymore thanks to total-recall.

HobbyDev

  • New Member
  • *
  • Posts: 32
[solved] Run ffmpeg via TProcess
« Reply #2 on: January 22, 2025, 09:25:39 pm »
 :) Thx TRon! Yes indeed, this code is working. But I don't see the difference! :'(
Beside that - the time_creation tag and the description tag are supported and do work with mkv's. At least Digikam does recognize it and puts it in the right data fields.
Many thanks again!

TRon

  • Hero Member
  • *****
  • Posts: 3925
Re: Run ffmpeg via TProcess
« Reply #3 on: January 22, 2025, 10:52:55 pm »
You're welcome HobbyDev.

The only difference I can spot (that is why is called your posted example incomplete) is that I explicitly and literally use the name of the tag. That is the part that we are unable to see from your example code. You might perhaps added the name of the tag in the strings as well as their value but it is impossible to tell from the example.

Note that ffpmpeg is (or can be in my experience) very finicky when supplying tags as parameters. F.e. when you quote the whole meta-tag option, e.g. '"creation_time=' + creationTimeStr + '"') it will add the tag as a custom tag. At least, that is what VLC is telling me.

I admit to not know the details about the mkv container format and its support tags so have to rely on what ffmpeg is documenting. Ofc any program can do as it wishes  :)

At least you got it solved. thx for reporting back  👍
I do not have to remember anything anymore thanks to total-recall.

 

TinyPortal © 2005-2018