Streaming with MPlayer using stdin?

Everything else that doesn't fall into one of the other PB categories.
User avatar
Joakim Christiansen
Addict
Addict
Posts: 2452
Joined: Wed Dec 22, 2004 4:12 pm
Location: Norway
Contact:

Streaming with MPlayer using stdin?

Post by Joakim Christiansen »

EDIT: Ok, got it working, see my second post. :)

I've been trying to understand this, but it seems I can't get the hang of it... sometimes it just hangs (WriteProgramData freezes?!) and I have to close the console window to get rest of the strings from mplayer. :S I know I must somehow read the feedback and not send mplayer more data than it wants.

If you want to test just get the mplayer files, which for example is included in this player:
http://smplayer.sourceforge.net/

Code: Select all

movie$ = "C:\Downloads\Californication\Californication.S01E01.avi";OpenFileRequester("","","",0)

If movie$
  handle = RunProgram("C:\Program Files\SMPlayer\mplayer\mplayer.exe","-cache 1192 -","",#PB_Program_Open|#PB_Program_Write|#PB_Program_Read)
  ReadFile(0,movie$)
  *buffer = AllocateMemory(1192000)
  While Not Eof(0) And ProgramRunning(handle)
    If AvailableProgramOutput(handle)
      result$ = Trim(ReadProgramString(handle))
      Debug result$
      If LCase(Left(result$,Len("Cache fill"))) = "cache fill" Or Left(result$,2) = "A:"
        dataRead = ReadData(0,*buffer,1192000)
        WriteProgramData(handle,*buffer,dataRead)
        Debug "read"
      EndIf
    EndIf
    ;Debug "read"

    Delay(100)
  Wend
  Debug "closed"
EndIf
lol, this is so weird...
Last edited by Joakim Christiansen on Sun May 10, 2009 8:26 pm, edited 1 time in total.
I like logic, hence I dislike humans but love computers.
User avatar
Joakim Christiansen
Addict
Addict
Posts: 2452
Joined: Wed Dec 22, 2004 4:12 pm
Location: Norway
Contact:

Post by Joakim Christiansen »

This seems to work.
I just had to remove the read flag. And now it wont make WriteProgramData() return before it needs more data, so I can't flood it now.

Code: Select all

movie$ = OpenFileRequester("Open a avi file","","avi|*.avi",0)
If movie$ And ReadFile(0,movie$)
  handle = RunProgram("C:\Program Files\SMPlayer\mplayer\mplayer.exe"," -","",#PB_Program_Open|#PB_Program_Write)
  If IsProgram(handle)
    *buffer = AllocateMemory(1192000)
    While Eof(0)=#False And ProgramRunning(handle)
      dataRead = ReadData(0,*buffer,1192000)
      If ProgramRunning(handle) And WriteProgramData(handle,*buffer,dataRead) ;this halts until a new piece is needed btw
        Debug "Whole piece read"
      EndIf
    Wend
    Debug "Closed"
  Else
    Debug "Unable to start MPlayer"
  EndIf
  CloseFile(0)
EndIf
Last edited by Joakim Christiansen on Sun May 10, 2009 8:25 pm, edited 1 time in total.
I like logic, hence I dislike humans but love computers.
User avatar
utopiomania
Addict
Addict
Posts: 1655
Joined: Tue May 10, 2005 10:00 pm
Location: Norway

Post by utopiomania »

What are you trying to do here?
User avatar
Joakim Christiansen
Addict
Addict
Posts: 2452
Joined: Wed Dec 22, 2004 4:12 pm
Location: Norway
Contact:

Post by Joakim Christiansen »

utopiomania wrote:What are you trying to do here?
Sending a buffer containing a part of the video file to MPlayer and repeating the process until is has streamed the whole video.

And in the last snippet I managed to do just that, I was just very confused first about MPlayer's behavior when using the #PB_Program_Read flag. But I guess I don't care too much about that now since I got it working.
I like logic, hence I dislike humans but love computers.
User avatar
utopiomania
Addict
Addict
Posts: 1655
Joined: Tue May 10, 2005 10:00 pm
Location: Norway

Post by utopiomania »

Ok, I don't want to talk about this anymore! Your programming skills far superceedes mine
so please go away. :shock: :)
User avatar
Joakim Christiansen
Addict
Addict
Posts: 2452
Joined: Wed Dec 22, 2004 4:12 pm
Location: Norway
Contact:

Post by Joakim Christiansen »

utopiomania wrote:Ok, I don't want to talk about this anymore! Your programming skills far superceedes mine
so please go away. :shock: :)
:lol:
I like logic, hence I dislike humans but love computers.
AND51
Addict
Addict
Posts: 1040
Joined: Sun Oct 15, 2006 8:56 pm
Location: Germany
Contact:

Re: Streaming with MPlayer using stdin?

Post by AND51 »

Joakim Christiansen wrote:sometimes it just hangs (WriteProgramData freezes?!)
I found this bug on Linux, maybe the bug also affects the windows version. Could you have a look, JLC ?
http://www.purebasic.fr/english/viewtopic.php?t=37364

// edit:
My personal test on windows is negative, this bug is only on Linux.

// edit 2:
Well, did you consider writing an EOF into the stdin? Can't see it. Please read the manual at WriteProgramData() and write a #PB_Program_EOF into the input.
PB 4.30

Code: Select all

onErrorGoto(?Fred)
Post Reply