Page 1 of 1
ReadProgramData() Working Properly?
Posted: Wed Dec 05, 2018 11:08 am
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.
Re: ReadProgramData() Working Properly?
Posted: Wed Dec 05, 2018 11:45 am
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)
Re: ReadProgramData() Working Properly?
Posted: Wed Dec 05, 2018 12:23 pm
by chris319
You're using it to read UTF8 text. Try reading some data with ffmpeg from an mp4 file.
Re: ReadProgramData() Working Properly?
Posted: Wed Dec 05, 2018 3:15 pm
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)
Re: ReadProgramData() Working Properly?
Posted: Wed Dec 05, 2018 6:11 pm
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
Re: ReadProgramData() Working Properly?
Posted: Wed Dec 05, 2018 7:29 pm
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.
Re: ReadProgramData() Working Properly?
Posted: Wed Dec 05, 2018 8:18 pm
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.
Re: ReadProgramData() Working Properly?
Posted: Thu Dec 06, 2018 8:30 pm
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.