Cyf Posted November 19, 2008 Share Posted November 19, 2008 OK here goes, I basically have a video stream (internal ip) that i need to proxy via a php script (which will check the user is logged in) and then i will have a main page that streams from proxy.php. This is what i have so far: proxy.php <?php set_time_limit(0); $fp = fsockopen("server.domain.co.uk", 8000, $errno, $errstr, 30); if (!$fp) { echo "$errstr ($errno)<br />\n"; } else { $out = "GET /andi/news011008.wmv HTTP/1.1\r\n"; $out .= "Host: server.domain.co.uk\r\n"; $out .= "Connection: Close\r\n\r\n"; fwrite($fp, $out); while (!feof($fp)) { echo fgets($fp); } fclose($fp); } ?> viewvideo.html <object classid="clsid:22D6F312-B0F6-11D0-94AB-0080C74C7E95"> <param name="FileName" value="proxy.php" /> </object> If i view the proxy page directly i can see the header information and it does appear to spit out the data to the browser but when i load it through the html page is doesnt show anythign, do i need to stream this in a different way for it to work? Any help would be great im getting quite urgent for a solution! Thanks, Cyf Link to comment https://forums.phpfreaks.com/topic/133311-php-stream-video-file-using-fsockopen-wmf-acting-as-proxy/ Share on other sites More sharing options...
ratcateme Posted November 19, 2008 Share Posted November 19, 2008 $headers_complete = false; $headers = ""; while (!feof($fp)) { if($headers_complete){ echo fgets($fp); }else{ $headers .= fgets($fp); if(strpos($headers,"\r\n\r\n")!==false){ $headers_complete = true; } } } give that ago and you might want to look into a content-type header Scott. Link to comment https://forums.phpfreaks.com/topic/133311-php-stream-video-file-using-fsockopen-wmf-acting-as-proxy/#findComment-693310 Share on other sites More sharing options...
Cyf Posted November 19, 2008 Author Share Posted November 19, 2008 I tried setting: header('Content-type: video/x-ms-wmv'); at the very top but it didn't make a different, what does it know when the header data has ended using your method? does fgets only return data until a return character? \n\r\n\r? Link to comment https://forums.phpfreaks.com/topic/133311-php-stream-video-file-using-fsockopen-wmf-acting-as-proxy/#findComment-693316 Share on other sites More sharing options...
ratcateme Posted November 19, 2008 Share Posted November 19, 2008 fgets reads until new line of end of file(or stream in this case) a new line is a \r or \n or a \r immediately followed by a \n (so \r\n) the end of the headers is when \r\n\r\n is reached my code saves the data line by line adding it to $headers and after it saves each new line it check to see if it has a \r\n\r\n in it indicating that the headers are finished and the next line will be data so it sets $headers_complete to true so on the next loop the data will be echoed not saved. Scott. Link to comment https://forums.phpfreaks.com/topic/133311-php-stream-video-file-using-fsockopen-wmf-acting-as-proxy/#findComment-693320 Share on other sites More sharing options...
Cyf Posted November 19, 2008 Author Share Posted November 19, 2008 Tried that and it doesnt display anything through the <object>....</object> page. If i navigate directly it no longer outputs the data to the screen Code is now as follows: <?php header('Content-type: video/x-ms-wmv'); set_time_limit(0); $fp = fsockopen("source.site.gov.uk", 8000, $errno, $errstr, 30); if (!$fp) { echo "$errstr ($errno)<br />\n"; } else { $out = "GET /andi/news011008.wmv HTTP/1.1\r\n"; $out .= "Host: source.site.gov.uk\r\n"; fwrite($fp, $out); //while (!feof($fp)) { // echo fgets($fp); //} $headers_complete = false; $headers = ""; while (!feof($fp)) { if($headers_complete){ echo fgets($fp); }else{ $headers .= fgets($fp); if(strpos($headers,"\r\n\r\n")!==false){ $headers_complete = true; } } } fclose($fp); } ?> Thanks for your time! Link to comment https://forums.phpfreaks.com/topic/133311-php-stream-video-file-using-fsockopen-wmf-acting-as-proxy/#findComment-693324 Share on other sites More sharing options...
ratcateme Posted November 19, 2008 Share Posted November 19, 2008 you removed the connecion header re add this line $out .= "Connection: Close\r\n\r\n"; the server never thinks you have finished send your headers and to start sending it own. Scott. Link to comment https://forums.phpfreaks.com/topic/133311-php-stream-video-file-using-fsockopen-wmf-acting-as-proxy/#findComment-693342 Share on other sites More sharing options...
Cyf Posted November 19, 2008 Author Share Posted November 19, 2008 just noticed if i leave the webproxy loading for a while i get a message in a dialog box saying Title: Windows Media Player Details: The file youa re attempting to play has an extension (.wmv) that does not match the file format. Playing the file may result in unexpected behaviour" Do you want the player to try to play this content?" if i say yes it just opens windows media play, black screen shows and in the playlist it says no playing: webcamproxy but the play button is showing indicating its now playing? eventually says was unable to play :S Any more suggestions? thanks!! Link to comment https://forums.phpfreaks.com/topic/133311-php-stream-video-file-using-fsockopen-wmf-acting-as-proxy/#findComment-693343 Share on other sites More sharing options...
ratcateme Posted November 19, 2008 Share Posted November 19, 2008 is that with the connection close header back on? i can't see any other reason why it wouldn't work if you have that header i can use that script to load images on my server fine. Scott. Link to comment https://forums.phpfreaks.com/topic/133311-php-stream-video-file-using-fsockopen-wmf-acting-as-proxy/#findComment-693346 Share on other sites More sharing options...
Cyf Posted November 19, 2008 Author Share Posted November 19, 2008 OK thats working now!! I need to change the static video.wmv file i have in there for a .rm stream now which im trying to do with the following but real player object shows on the screen with a message saying it doesnt support the mimetype even though i got the mime type for video of there site? header("Content-Type: video/vnd.rn-realvideo"); ... $out = "GET /state07.rm RSTP/1.0\r\n"; //is this correct as my url has rtsp://? Link to comment https://forums.phpfreaks.com/topic/133311-php-stream-video-file-using-fsockopen-wmf-acting-as-proxy/#findComment-693363 Share on other sites More sharing options...
Cyf Posted November 19, 2008 Author Share Posted November 19, 2008 does anyone if this is possible? i need somethign like this: rstp://my.domain.com/video.rm to be streamed/proxied via my proxy php file in the same way that my wmv file did earlier in this post Link to comment https://forums.phpfreaks.com/topic/133311-php-stream-video-file-using-fsockopen-wmf-acting-as-proxy/#findComment-693473 Share on other sites More sharing options...
ratcateme Posted November 19, 2008 Share Posted November 19, 2008 i did a wire capture of a rstp video stream OPTIONS rtsp://rx-wes-sea69.rbn.com:554 RTSP/1.0 CSeq: 1 User-Agent: RealMedia Player HelixDNAClient/10.0.1.338 (win32) Supported: ABD-1.0 ClientChallenge: e584946913ee0e697ccaeebc94f6da33 ClientID: WinNT_5.1_6.0.14.835_RealPlayer_R41APR_en-us_686 CompanyID: Kl4ERtdV5/XRO1ZSJkHNeg== GUID: 00000000-0000-0000-0000-000000000000 PlayerStarttime: [20/11/2008:10:34:02 12:00] Pragma: initiate-session RegionData: 0600 RTSP/1.0 200 OK CSeq: 1 Date: Wed, 19 Nov 2008 21:34:02 GMT Session: 295275339-1;timeout=80 Server: Helix Mobile Server Version 11.1.7.3406 (linux-rhel4-i686) (RealServer compatible) Public: OPTIONS, DESCRIBE, ANNOUNCE, PLAY, PAUSE, SETUP, GET_PARAMETER, SET_PARAMETER, TEARDOWN TurboPlay: 1 RealChallenge1: 7349feaa11fcfac66f83e682109161e4 StatsMask: 0 DESCRIBE rtsp://rx-wes-sea69.rbn.com:554/farm/pull/tx-rbn-sea002:2459/farm/cspan/g2cspan/live/cspan2-g2.rm RTSP/1.0 CSeq: 2 Accept: application/sdp User-Agent: RealMedia Player HelixDNAClient/10.0.1.338 (win32) Session: 295275339-1;timeout=80 Bandwidth: 554327 ClientID: WinNT_5.1_6.0.14.835_RealPlayer_R41APR_en-us_686 GUID: 00000000-0000-0000-0000-000000000000 Language: en-us RegionData: 0600 Require: com.real.retain-entity-for-setup SupportsMaximumASMBandwidth: 1 RTSP/1.0 200 OK CSeq: 2 Date: Wed, 19 Nov 2008 21:34:04 GMT Session: 295275339-1;timeout=80 Set-Cookie: cbid=gkrgdmdlegfkeldmeoornpgqmrjrktlufkejkidlejdfklplqsnooppqlolnmtlugkhgohhl;path=/;expires=Thu,31-Dec-2037 23:59:59 GMT Content-base: rtsp://rx-wes-sea69.rbn.com:554/farm/pull/tx-rbn-sea002:2459/farm/cspan/g2cspan/live/cspan2-g2.rm/ ETag: 295275339-1 Session: 295275339-1;timeout=80 Vary: User-Agent, ClientID Content-type: application/sdp x-real-usestrackid: 1 Content-length: 3067 v=0 o=- 496376 496376 IN IP4 66.203.121.84 s=C-SPAN2 i=<No author> 2008 C-SPAN c=IN IP4 0.0.0.0 t=0 0 a=SdpplinVersion:1610641560 a=StreamCount:integer;3 a=control:* a=Clock Start Time:integer;1781384002 a=Flags:integer;9 a=IsRealDataType:integer;1 a=RP11DisableRecording:integer;1 a=LiveStream:integer;1 a=Copyright:buffer;"MjAwOCBDLVNQQU4A" a=Title:buffer;"Qy1TUEFOMgA=" a=ASMRuleBook:string;"#($Bandwidth >= 0),Stream1Bandwidth = 32041, Stream0Bandwidth = 167759;" a=Audiences:string;"CSPAN 200k;" a=audioMode:string;"voice" a=Creation Date:string;"7/28/2008 7:58:48" a=Description:string;"AutoGenerated EDF" a=Generated By:string;"Helix Producer SDK 10.0 for Windows, Build 10.0.1.1337" a=Modification Date:string;"7/28/2008 7:58:48" a=videoMode:string;"normal" m=video 0 RTP/AVP 101 b=AS:180 b=RR:6290 b=RS:2096 a=control:streamid=0 a=range:npt=0- a=length:npt=0 a=rtpmap:101 x-pn-realvideo/1000 a=fmtp:101 a=mimetype:string;"video/x-pn-realvideo" a=AvgBitRate:integer;167759 a=AvgPacketSize:integer;1000 a=EndTime:integer;0 a=MaxBitRate:integer;167759 a=MaxPacketSize:integer;1000 a=MinimumSwitchOverlap:integer;0 a=Preroll:integer;5024 a=SeekGreaterOnSwitch:integer;1 a=StartTime:integer;0 a=OpaqueData:buffer;"TUxUSQADAAAAAAAAAAEAAAAiAAAAIlZJRE9SVjQwAUAA8AAMAAAAAAAeAAAACBAgQACAAA==" a=RMFF 1.0 Flags:buffer;"AAMAAgAAAAI=" a=ASMRuleBook:string;"#($Bandwidth >= 167759),AverageBandwidth=167759,Priority=9;#($Bandwidth >= 167759),AverageBandwidth=0,Priority=5,OnDepend=\"0\";#($Bandwidth < 167759),TimestampDelivery=T,DropByN=T,priority=9;" a=StreamName:string;"Video Stream" m=audio 0 RTP/AVP 101 b=AS:34 b=RR:1201 b=RS:400 a=control:streamid=1 a=range:npt=0- a=length:npt=0 a=rtpmap:101 x-pn-realaudio/1000 a=fmtp:101 a=mimetype:string;"audio/x-pn-realaudio" a=ActualPreroll:integer;2229 a=AvgBitRate:integer;32041 a=AvgPacketSize:integer;1500 a=EndTime:integer;0 a=MaxBitRate:integer;32041 a=MaxPacketSize:integer;1500 a=MinimumSwitchOverlap:integer;200 a=Preroll:integer;2229 a=SeekGreaterOnSwitch:integer;0 a=StartTime:integer;0 a=OpaqueData:buffer;"TUxUSQACAAAAAAABAAAAVi5yYf0ABQAALnJhNQAAABAABQAAAEYABwAAAi4AAAAAAAOqtAAAAAAAEAIuAF0AAAAAViIAAFYiAAAAEAABZ2VucmNvb2sBBwAAAAAACAEAAAICAAAY" a=RMFF 1.0 Flags:buffer;"AAIAAgAA" a=ASMRuleBook:string;"AverageBandwidth=32041,Priority=5;AverageBandwidth=0,Priority=5,OnDepend=\"0\", OffDepend=\"0\";" a=StreamName:string;"Audio Stream" m=application 0 RTP/AVP 101 b=AS:0 b=RR:3 b=RS:1 a=control:streamid=2 a=range:npt=0- a=length:npt=0 a=rtpmap:101 x-pn-realevent/1000 a=fmtp:101 a=mimetype:string;"application/x-pn-realevent" a=AvgBitRate:integer;100 a=AvgPacketSize:integer;50 a=ContentVersion:integer;1048576 a=EndTime:integer;0 a=MaxBitRate:integer;100 a=MaxPacketSize:integer;500 a=Preroll:integer;1000 a=StartTime:integer;0 a=OpaqueData:buffer;"TUxUSQABAAAAAQAAAAA=" a=RMFF 1.0 Flags:buffer;"AAEAAg==" a=ASMRuleBook:string;"TimeStampDelivery=T,priority=10,PNMKeyframeRule=T;" a=StreamName:string;"Events Stream" SETUP rtsp://rx-wes-sea69.rbn.com:554/farm/pull/tx-rbn-sea002:2459/farm/cspan/g2cspan/live/cspan2-g2.rm/streamid=0 RTSP/1.0 CSeq: 3 RealChallenge2: ff05992e364aab3122b2579a050d575e01d0a8e3, sd=f93a2505 RDTFeatureLevel: 3 Transport: x-real-rdt/mcast;client_port=6970;mode=play,x-real-rdt/udp;client_port=6970;mode=play,x-pn-tng/udp;client_port=6970;mode=play,RTP/AVP;unicast;client_port=6970-6971;mode=play,x-pn-tng/tcp;mode=play,x-real-rdt/tcp;mode=play,RTP/AVP/TCP;unicast;mode=play User-Agent: RealMedia Player HelixDNAClient/10.0.1.338 (win32) If-Match: 295275339-1 RTSP/1.0 200 OK CSeq: 3 Date: Wed, 19 Nov 2008 21:34:05 GMT Session: 295275339-1;timeout=80 Reconnect: true RDTFeatureLevel: 3 StatsMask: 0 RealChallenge3: 3eaa38ffe1dafe42ddc7183ca83d80204f213d09,sdr=33efd1a8 Transport: x-real-rdt/udp;client_port=6970;server_port=25556 SETUP rtsp://rx-wes-sea69.rbn.com:554/farm/pull/tx-rbn-sea002:2459/farm/cspan/g2cspan/live/cspan2-g2.rm/streamid=1 RTSP/1.0 CSeq: 4 RDTFeatureLevel: 3 Transport: x-real-rdt/udp;client_port=6972;mode=play User-Agent: RealMedia Player HelixDNAClient/10.0.1.338 (win32) Session: 295275339-1 RTSP/1.0 200 OK CSeq: 4 Date: Wed, 19 Nov 2008 21:34:05 GMT Session: 295275339-1;timeout=80 RDTFeatureLevel: 3 StatsMask: 0 Transport: x-real-rdt/udp;client_port=6972;server_port=25556 SETUP rtsp://rx-wes-sea69.rbn.com:554/farm/pull/tx-rbn-sea002:2459/farm/cspan/g2cspan/live/cspan2-g2.rm/streamid=2 RTSP/1.0 CSeq: 5 RDTFeatureLevel: 3 Transport: x-real-rdt/udp;client_port=6974;mode=play User-Agent: RealMedia Player HelixDNAClient/10.0.1.338 (win32) Session: 295275339-1 RTSP/1.0 200 OK CSeq: 5 Date: Wed, 19 Nov 2008 21:34:05 GMT Session: 295275339-1;timeout=80 RDTFeatureLevel: 3 StatsMask: 0 Transport: x-real-rdt/udp;client_port=6974;server_port=25556 SET_PARAMETER rtsp://rx-wes-sea69.rbn.com:554/farm/pull/tx-rbn-sea002:2459/farm/cspan/g2cspan/live/cspan2-g2.rm RTSP/1.0 CSeq: 6 Subscribe: stream=0;rule=0,stream=0;rule=1,stream=1;rule=0,stream=1;rule=1,stream=2;rule=0 Session: 295275339-1 RTSP/1.0 200 OK CSeq: 6 Date: Wed, 19 Nov 2008 21:34:09 GMT Session: 295275339-1;timeout=80 SET_PARAMETER rtsp://rx-wes-sea69.rbn.com:554/farm/pull/tx-rbn-sea002:2459/farm/cspan/g2cspan/live/cspan2-g2.rm RTSP/1.0 CSeq: 7 SetDeliveryBandwidth: Bandwidth=498894;BackOff=0 Session: 295275339-1 PLAY rtsp://rx-wes-sea69.rbn.com:554/farm/pull/tx-rbn-sea002:2459/farm/cspan/g2cspan/live/cspan2-g2.rm RTSP/1.0 CSeq: 8 User-Agent: RealMedia Player HelixDNAClient/10.0.1.338 (win32) Session: 295275339-1 Range: npt=0- Bandwidth: 554327 RTSP/1.0 200 OK CSeq: 7 Date: Wed, 19 Nov 2008 21:34:10 GMT Session: 295275339-1;timeout=80 RTSP/1.0 200 OK CSeq: 8 Date: Wed, 19 Nov 2008 21:34:10 GMT Session: 295275339-1;timeout=80 RTP-Info: url=rtsp://rx-wes-sea69.rbn.com:554/farm/pull/tx-rbn-sea002:2459/farm/cspan/g2cspan/live/cspan2-g2.rm/streamid=0;seq=0;rtptime=0, url=rtsp://rx-wes-sea69.rbn.com:554/farm/pull/tx-rbn-sea002:2459/farm/cspan/g2cspan/live/cspan2-g2.rm/streamid=1;seq=0;rtptime=0, url=rtsp://rx-wes-sea69.rbn.com:554/farm/pull/tx-rbn-sea002:2459/farm/cspan/g2cspan/live/cspan2-g2.rm/streamid=2;seq=0;rtptime=0 RTCP-Interval: 250 this is from the stream at rtsp://rx-wes-sea69.rbn.com/farm/pull/tx-rbn-sea002:2459/farm/cspan/g2cspan/live/cspan2-g2.rm i think it is the US Senate. all the blocks starting in a command like SETUP or OPTIONS are sent by the client and all others are sent by the client. this looks like a very hard protocol to proxy in php. i is possible i guess but VERY hard. Scott. Link to comment https://forums.phpfreaks.com/topic/133311-php-stream-video-file-using-fsockopen-wmf-acting-as-proxy/#findComment-693834 Share on other sites More sharing options...
ratcateme Posted November 19, 2008 Share Posted November 19, 2008 just had a look at it runs the main data transfer over UDP not TCP and in my experience PHP is not very good with UDP Scott. Link to comment https://forums.phpfreaks.com/topic/133311-php-stream-video-file-using-fsockopen-wmf-acting-as-proxy/#findComment-693835 Share on other sites More sharing options...
Cyf Posted November 20, 2008 Author Share Posted November 20, 2008 i can do it in classic asp on a different server but i started with that and got stuck also :S what a nightmare!! you got any ideas in asp (classic)? Link to comment https://forums.phpfreaks.com/topic/133311-php-stream-video-file-using-fsockopen-wmf-acting-as-proxy/#findComment-694217 Share on other sites More sharing options...
ratcateme Posted November 20, 2008 Share Posted November 20, 2008 nah i have never learned asp. Scott. Link to comment https://forums.phpfreaks.com/topic/133311-php-stream-video-file-using-fsockopen-wmf-acting-as-proxy/#findComment-694219 Share on other sites More sharing options...
Cyf Posted November 20, 2008 Author Share Posted November 20, 2008 OK one other option i have... There is also a url video.cgi that i can use to access the stream the problem is that this requires authentication(box pops up asking for it) but because im trying to read the stream from my php file it doesnt give me the option to enter the details just gives me a 401 error 401 Unauthorized Your client does not have permission to get URL /mjpg/video.cgi from this server do you know how i can force the username and password when i try and retreive it via the socket in PHP? Link to comment https://forums.phpfreaks.com/topic/133311-php-stream-video-file-using-fsockopen-wmf-acting-as-proxy/#findComment-694233 Share on other sites More sharing options...
ratcateme Posted November 20, 2008 Share Posted November 20, 2008 this is the header you need to add for HTTP auth $out .= "Authorization: Basic " . base64_encode("Username:Password") . "\r\n"; Scott. Link to comment https://forums.phpfreaks.com/topic/133311-php-stream-video-file-using-fsockopen-wmf-acting-as-proxy/#findComment-694236 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.