ReadProgramData() Working Properly?

Linux specific forum
chris319
Enthusiast
Enthusiast
Posts: 782
Joined: Mon Oct 24, 2005 1:05 pm

ReadProgramData() Working Properly?

Post by chris319 »

I'm not sure ReadProgramData() is working properly under Linux. It keeps returning 0. Under Windows 10 it returns a non-zero number.

RunProgram() is being used to set up the pipe and readFrame is the result, which is non zero.

Code: Select all

count = ReadProgramData(readFrame, @frame(0), #H * #W * 3)
It works under Windows 10.
User avatar
NicTheQuick
Addict
Addict
Posts: 1224
Joined: Sun Jun 22, 2003 7:43 pm
Location: Germany, Saarbrücken
Contact:

Re: ReadProgramData() Working Properly?

Post by NicTheQuick »

It's working for me.

Code: Select all

*buf = AllocateMemory(1024 * 1024)

prog.i = RunProgram("/usr/bin/w", "", "", #PB_Program_Read | #PB_Program_UTF8 | #PB_Program_Open)

count.i = ReadProgramData(prog, *buf, 1024 * 1024)

Debug count

result.s = PeekS(*buf, -1, #PB_UTF8)

Debug result

CloseProgram(prog)
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.
chris319
Enthusiast
Enthusiast
Posts: 782
Joined: Mon Oct 24, 2005 1:05 pm

Re: ReadProgramData() Working Properly?

Post by chris319 »

You're using it to read UTF8 text. Try reading some data with ffmpeg from an mp4 file.
User avatar
NicTheQuick
Addict
Addict
Posts: 1224
Joined: Sun Jun 22, 2003 7:43 pm
Location: Germany, Saarbrücken
Contact:

Re: ReadProgramData() Working Properly?

Post by NicTheQuick »

This works also. I am using random data instead of a video file. That should not make any difference. Of course the PeekS() returns nonsense this way.

Code: Select all

*buf = AllocateMemory(1024 * 1024)

prog.i = RunProgram("/bin/cat", "/dev/urandom", "", #PB_Program_Read | #PB_Program_Open)

count.i = ReadProgramData(prog, *buf, 1024 * 1024)

Debug count

result.s = PeekS(*buf, -1, #PB_Ascii)

Debug result

CloseProgram(prog)
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.
chris319
Enthusiast
Enthusiast
Posts: 782
Joined: Mon Oct 24, 2005 1:05 pm

Re: ReadProgramData() Working Properly?

Post by chris319 »

The pipe opens successfully in Linux.

ReadProgramData() keeps returning 0.

It works in Windows.

Code: Select all

pipeIn$ = "-i " + filename$ + " -f image2pipe  -s 1280x720  -pix_fmt rgb24  -r 59.94  -vf zscale=in_range=limited:out_range=limited  -vcodec rawvideo -"

;readFrame = RunProgram("/usr/bin/ffmpeg", pipeIn$,"/home/chris/PureBasic/source/",#PB_Program_Open | #PB_Program_Read)
readFrame = RunProgram("ffmpeg", pipeIn$,"",#PB_Program_Open | #PB_Program_Read)
If readFrame = 0
  MessageRequester("Error", "unable to open pipe")
  End
Else
  MessageRequester("Success","Pipe opened")
EndIf

For ct = 1 To 30 ;READ FIRST 30 FRAMES
 
count = ReadProgramData(readFrame, @frame(0), #H * #W * 3)
Debug count
Next
User avatar
NicTheQuick
Addict
Addict
Posts: 1224
Joined: Sun Jun 22, 2003 7:43 pm
Location: Germany, Saarbrücken
Contact:

Re: ReadProgramData() Working Properly?

Post by NicTheQuick »

Maybe you have to wait until ffmpeg is returning the result. ReadProgramData() does not wait until the given buffer is full. You may have to read data until ProgramRunning() returns #False. Then you've got all the data you are looking for.
Maybe so:

Code: Select all

pipeIn$ = "-i " + filename$ + " -f image2pipe  -s 1280x720  -pix_fmt rgb24  -r 59.94  -vf zscale=in_range=limited:out_range=limited  -vcodec rawvideo -"

;readFrame = RunProgram("/usr/bin/ffmpeg", pipeIn$,"/home/chris/PureBasic/source/",#PB_Program_Open | #PB_Program_Read)
readFrame = RunProgram("ffmpeg", pipeIn$,"",#PB_Program_Open | #PB_Program_Read)
If readFrame = 0
	MessageRequester("Error", "unable to open pipe")
	End
Else
	MessageRequester("Success","Pipe opened")
EndIf

bytesReadSum.i = 0
bytesRead.i = 0
While ProgramRunning(readFrame)
	bytesRead = ReadProgramData(readFrame, @frame(0), #H * #W * 3)
	If bytesRead :
		bytesReadSum + bytesRead
		Debug bytesReadSum
	EndIf
Next
But of course this will not work together with your frame array. You have to change more than I did.
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.
chris319
Enthusiast
Enthusiast
Posts: 782
Joined: Mon Oct 24, 2005 1:05 pm

Re: ReadProgramData() Working Properly?

Post by chris319 »

Using AvailableProgramOutput() causes the program to wait forever for data which never arrives.

The program has to keep running to process subsequent frames.

This works in Windows and it works in Linux using the C language, so I have to conclude there is a problem with PB in Linux.
chris319
Enthusiast
Enthusiast
Posts: 782
Joined: Mon Oct 24, 2005 1:05 pm

Re: ReadProgramData() Working Properly?

Post by chris319 »

ReadProgramData() works OK on my big computer at home.

Here I sit in a hotel room using a tablet computer. Both machines are running Wndows 10. The tablet computer seems to have problems setting up pipes; the big computer does not.

Go figure.
Post Reply