It is currently Sun Dec 16, 2018 4:36 pm

All times are UTC + 1 hour




Post new topic Reply to topic  [ 8 posts ] 
Author Message
 Post subject: ReadProgramData() Working Properly?
PostPosted: Wed Dec 05, 2018 11:08 am 
Offline
Enthusiast
Enthusiast

Joined: Mon Oct 24, 2005 1:05 pm
Posts: 693
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:
count = ReadProgramData(readFrame, @frame(0), #H * #W * 3)


It works under Windows 10.


Top
 Profile  
Reply with quote  
 Post subject: Re: ReadProgramData() Working Properly?
PostPosted: Wed Dec 05, 2018 11:45 am 
Offline
Enthusiast
Enthusiast
User avatar

Joined: Sun Jun 22, 2003 7:43 pm
Posts: 293
Location: Germany, Homburg (Saar)
It's working for me.
Code:
*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)

_________________
Electronics, Crazy & Interesting Stuff, all that with text, image and sound? Click here!

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.


Top
 Profile  
Reply with quote  
 Post subject: Re: ReadProgramData() Working Properly?
PostPosted: Wed Dec 05, 2018 12:23 pm 
Offline
Enthusiast
Enthusiast

Joined: Mon Oct 24, 2005 1:05 pm
Posts: 693
You're using it to read UTF8 text. Try reading some data with ffmpeg from an mp4 file.


Top
 Profile  
Reply with quote  
 Post subject: Re: ReadProgramData() Working Properly?
PostPosted: Wed Dec 05, 2018 3:15 pm 
Offline
Enthusiast
Enthusiast
User avatar

Joined: Sun Jun 22, 2003 7:43 pm
Posts: 293
Location: Germany, Homburg (Saar)
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:
*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)

_________________
Electronics, Crazy & Interesting Stuff, all that with text, image and sound? Click here!

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.


Top
 Profile  
Reply with quote  
 Post subject: Re: ReadProgramData() Working Properly?
PostPosted: Wed Dec 05, 2018 6:11 pm 
Offline
Enthusiast
Enthusiast

Joined: Mon Oct 24, 2005 1:05 pm
Posts: 693
The pipe opens successfully in Linux.

ReadProgramData() keeps returning 0.

It works in Windows.

Code:
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


Top
 Profile  
Reply with quote  
 Post subject: Re: ReadProgramData() Working Properly?
PostPosted: Wed Dec 05, 2018 7:29 pm 
Offline
Enthusiast
Enthusiast
User avatar

Joined: Sun Jun 22, 2003 7:43 pm
Posts: 293
Location: Germany, Homburg (Saar)
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:
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.

_________________
Electronics, Crazy & Interesting Stuff, all that with text, image and sound? Click here!

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.


Top
 Profile  
Reply with quote  
 Post subject: Re: ReadProgramData() Working Properly?
PostPosted: Wed Dec 05, 2018 8:18 pm 
Offline
Enthusiast
Enthusiast

Joined: Mon Oct 24, 2005 1:05 pm
Posts: 693
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.


Top
 Profile  
Reply with quote  
 Post subject: Re: ReadProgramData() Working Properly?
PostPosted: Thu Dec 06, 2018 8:30 pm 
Offline
Enthusiast
Enthusiast

Joined: Mon Oct 24, 2005 1:05 pm
Posts: 693
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.


Top
 Profile  
Reply with quote  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 8 posts ] 

All times are UTC + 1 hour


Who is online

Users browsing this forum: No registered users and 1 guest


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
Jump to:  

 


Powered by phpBB © 2008 phpBB Group
subSilver+ theme by Canver Software, sponsor Sanal Modifiye