ReadProgramError()

Linux specific forum
Inf0Byt3
PureBasic Fanatic
PureBasic Fanatic
Posts: 2236
Joined: Fri Dec 09, 2005 12:15 pm
Location: Elbonia

ReadProgramError()

Post by Inf0Byt3 »

Hi,

I have a little problem with ReadProgramError(). I am running FFMpeg like this:

Code: Select all

FFHandle = RunProgram(FFMPEG,CmdLine,CurrentDir,#PB_Program_Error|#PB_Program_Open|#PB_Program_Hide)
and i need to collect the output and parse it. FFMpeg doesn't write on stdout, only on stderr. All is ok so far. Then, i use this in my code:

Code: Select all

   While ProgramRunning(FFHandle)
     Event = WaitWindowEvent() 
     ;
     Err.s = ReadProgramError(FFHandle)
     If Err <> ""
      ;
      Debug Err
      ;
      ;AddStatusLine("FFMpeg -> "+Err)
      
     EndIf
   Wend
The code works, with the exception that ReadProgramError freezes the window (like it never had a message loop) and it returns nothing! After the program ends, it returns all the output in just one string. This is wrong, since i need to read the output in realtime so I can calculate the progress and show it, but all i get is "" and at the end I get all the lines concatenated in only 1 string. Something makes ReadProgramError not to return after it reads the output.

Is there any way of fixing this?

[Edit]
On windows, the above lines work perfectly.

[Later edit]
I changed a bit the progrm flow and now it seems to work. I had to remove the resizing code, otherwise it won't process the window messages.
None are more hopelessly enslaved than those who falsely believe they are free. (Goethe)
User avatar
DannyWeijermans
User
User
Posts: 26
Joined: Thu Aug 25, 2022 10:10 pm
Contact:

Re: ReadProgramError()

Post by DannyWeijermans »

Hi Inf0Byt3,
I'm running in the same problem on OSX using ffmpeg:
what did you mean by 'I had to remove the resizing code' ?
Maybe that's also what I have to do..
Thanks for any insights!
Regards,
Danny Weijermans
User avatar
NicTheQuick
Addict
Addict
Posts: 1519
Joined: Sun Jun 22, 2003 7:43 pm
Location: Germany, Saarbrücken
Contact:

Re: ReadProgramError()

Post by NicTheQuick »

Well, if there are no window messages coming, `WaitWindowEvent()` will block the loop until there is an event. So you either have to use the timeout option in `WaitWindowEvent()` or you need to use `WindowEvent()` together with a small `Delay(1)` if the event is 0 and `ReadProgramError()` returns an empty string.
The english grammar is freeware, you can use it freely - But it's not Open Source, i.e. you can not change it or publish it in altered way.
User avatar
DannyWeijermans
User
User
Posts: 26
Joined: Thu Aug 25, 2022 10:10 pm
Contact:

Re: ReadProgramError()

Post by DannyWeijermans »

Hi NicTheQuick! ;)
Thanks for your explanation!
Yes, I was exactly doing that
(WindowEvent() and Delay(1) )
but even then ReadProgramError() doesn't return the output from ffmpeg
(or what I'm after: ffplay)
I think it has to do something with HOW ffmpeg (and ffplay) are 'piping' that in OSX..
Tried several ways to tell ffmpeg to 'pipe' differently, to no avail..
Anyone knows about this?
Regards + much thanks for all insights!!
Danny
User avatar
NicTheQuick
Addict
Addict
Posts: 1519
Joined: Sun Jun 22, 2003 7:43 pm
Location: Germany, Saarbrücken
Contact:

Re: ReadProgramError()

Post by NicTheQuick »

Under Linux you could try the `stdbuf` tool which allows you to modify the buffer size of programs that output stuff to stderr or stdout.
Here's just a simple example call.

Code: Select all

stdbuf -o0 -e0 ffmpeg -i input.mp4 -c:v libx264 -f null -
Here's a snippet from the man page:

Code: Select all

       -i, --input=MODE
              adjust standard input stream buffering

       -o, --output=MODE
              adjust standard output stream buffering

       -e, --error=MODE
              adjust standard error stream buffering

       If MODE is 'L' the corresponding stream will be line buffered.  This option is invalid with standard input.

       If MODE is '0' the corresponding stream will be unbuffered.
I don't know if this helps in any way, I did not try it out myself.

Other programming languages give you more options to connect to the output streams of other processes where you then can exactly define the buffer size that should be used or disable the buffer altogether. But Purebasic does not have this option unfortunately.
The english grammar is freeware, you can use it freely - But it's not Open Source, i.e. you can not change it or publish it in altered way.
Post Reply