Strange problem with FFMPEG's stdout

Windows specific forum
criobot
User
User
Posts: 10
Joined: Sat Dec 27, 2008 9:42 pm
Location: Bulgaria
Contact:

Strange problem with FFMPEG's stdout

Post by criobot »

I'm not sure if the problem is with PB's Process library or within FFMPEG itself. I am using the latest FFMPEG build. And it behaves very strange even with these simple parameters from the code below. It returns only exit code 1 and no output, but if I change the parameters to "-h", it behaves normally and outputs all the help with exit code 0. ReadProgramString does not read any program output, nor does ReadProgramData. My goal is to keep track on the conversion process through the console output, but no success so far... :(

Code: Select all

asdf = RunProgram("ffmpeg.exe", "-i test.mp4", "", #PB_Program_Open|#PB_Program_Read|#PB_Program_Hide|#PB_Program_Error)
If IsProgram(asdf)
  While ProgramRunning(asdf)
    If AvailableProgramOutput(asdf)
      Debug ReadProgramString(asdf)
    EndIf
  Wend
  Debug ProgramExitCode(asdf)
  CloseProgram(asdf)
EndIf
ricardo
Addict
Addict
Posts: 2402
Joined: Fri Apr 25, 2003 7:06 pm
Location: Argentina

Re: Strange problem with FFMPEG's stdout

Post by ricardo »

This coide (that i found somewhere) works with FFMPEG

Code: Select all

ProcedureDLL.s GetProgramResult(Command.s) 
  
  proc.PROCESS_INFORMATION ;Process info filled by CreateProcessA 
  ret.l ;long variable For get the Return value of the 
  start.MySTARTUPINFO ;StartUp Info passed To the CreateProceeeA 
  sa.SECURITY_ATTRIBUTES ;Security Attributes passeed To the 
  hReadPipe.l ;Read Pipe handle created by CreatePipe 
  hWritePipe.l ;Write Pite handle created by CreatePipe 
  lngBytesread.l ;Amount of byte Read from the Read Pipe handle 
  strBuff.s=Space(256) ;String buffer reading the Pipe 
  
  ;Consts For functions 
  #NORMAL_PRIORITY_CLASS = $20 
  #STARTF_USESTDHANDLES = $100 
  #STARTF_USESHOWWINDOW = $1 
  
  ;Create the Pipe 
  sa\nLength =SizeOf(SECURITY_ATTRIBUTES) ;Len(sa) 
  sa\bInheritHandle = 1 
  sa\lpSecurityDescriptor = 0 
  ret = CreatePipe_(@hReadPipe, @hWritePipe, @sa, 0) 
  If ret = 0 
    ;If an error occur during the Pipe creation exit 
    MessageRequester("info", "CreatePipe failed. Error: ",0) 
    End 
  EndIf 
  
  
  start\cb = SizeOf(MySTARTUPINFO) 
  start\dwFlags = #STARTF_USESHOWWINDOW | #STARTF_USESTDHANDLES 
  
  ;set the StdOutput And the StdError output To the same Write Pipe handle 
  start\hStdOutput = hWritePipe 
  start\hStdError = hWritePipe 
  
  ;Execute the command 
  ret = CreateProcess_(0, Command, sa, sa, 1, #NORMAL_PRIORITY_CLASS, 0, 0, @start, @proc) 
  
  If ret <> 1 
    retour.s="" 
  Else 
    
    ;Now We can ... must close the hWritePipe 
    ret = CloseHandle_(hWritePipe) 
    
    mOutputs.s = "" 
    
    ;Read the ReadPipe handle 
    While ret<>0 
      ret = ReadFile_(hReadPipe, strBuff, 255, @lngBytesread, 0) 
      If lngBytesread>0 
        mLine$ = Left(strBuff, lngBytesread)
        ;Debug mLine$
        ParseaData(mLine$)
        mOutputs = mOutputs + mLine$ 
      EndIf 
    Wend 
    
    ;Close the opened handles 
    ret = CloseHandle_(proc\hProcess) 
    ret = CloseHandle_(proc\hThread) 
    ret = CloseHandle_(hReadPipe) 
    ;ret=CloseHandle_(hWritePipe) 
    
    retour.s=mOutputs 
    
  EndIf 
  
  ProcedureReturn mOutputs ;ConformationAsciiEtenduVersAscii(mOutputs) 
EndProcedure 

bCommandLine$ = "FFmpeg -y -i abc.mp3 abc.flac"
  Datos$ = GetProgramResult(bCommandLine$)

ARGENTINA WORLD CHAMPION
DarkPlayer
Enthusiast
Enthusiast
Posts: 107
Joined: Thu May 06, 2010 11:36 pm

Re: Strange problem with FFMPEG's stdout

Post by DarkPlayer »

I think your problem is that FFMPEG can't find your input file.
Depeding on your compiler settings, the working directory might be C:\Program Files\Purebasic, if you start your program within the IDE. Just try an absolut path for the input file.
The reason why you can't see an error in the program output is that critical errors are written to STDERR and you are just collecting the output from STDOUT. You also have to use ReadProgramError() to collect all output messages from FFMPEG.
NY152
User
User
Posts: 29
Joined: Sun May 14, 2006 12:33 am

Re: Strange problem with FFMPEG's stdout

Post by NY152 »

i have a little question:

ParseaData is not function ! Where is this function ?
.:NY152:.
Bitblazer
Enthusiast
Enthusiast
Posts: 733
Joined: Mon Apr 10, 2017 6:17 pm
Location: Germany
Contact:

Re: Strange problem with FFMPEG's stdout

Post by Bitblazer »

read this
webpage - discord chat links -> purebasic GPT4All
NY152
User
User
Posts: 29
Joined: Sun May 14, 2006 12:33 am

Re: Strange problem with FFMPEG's stdout

Post by NY152 »

Thank you but this code does not work with the little test I made

I tested with a simple command

With the program and parameter : C:\Windows\System32\where.exe notepad

The program must return the notepad path, this is not the case, the output is empty.
.:NY152:.
Bitblazer
Enthusiast
Enthusiast
Posts: 733
Joined: Mon Apr 10, 2017 6:17 pm
Location: Germany
Contact:

Re: Strange problem with FFMPEG's stdout

Post by Bitblazer »

Just read what i linked to. ffmpeg is using STDOUT and STDERR in a non-standard way due to the way how ffmpeg is often used as a piping tool in *nix environments (for example 'cat inputfile.bin | ffmpeg -parameters >newvideo.mpg'). So they decided to use STDOUT for the output video stream and use STDERR for regular "STDOUT" output to achieve this kind of common usage in the *nix world work. That's why using other Programs to test your PB use with FFMPEG is a bit pointless. The code from ricardo assigns STDIN and STDERR into one pipe to work, i personally wouldn't do that as it makes it impossible to distinguish between STDIN and STDERR.
webpage - discord chat links -> purebasic GPT4All
NY152
User
User
Posts: 29
Joined: Sun May 14, 2006 12:33 am

Re: Strange problem with FFMPEG's stdout

Post by NY152 »

Whether in STDOUT or STDERR, I do not have the result, it's empty ...
.:NY152:.
Post Reply