Streaming in PHP - php

I'm searching the best way to do what I'm trying to do, so I ask here... I have a webpage in PHP who's requesting a song by TCP to another server. The song is loaded into a temporary file on the server. While it's loading, I want to play it into the webpage OR into the user's favorite player. Is it possible to simply refer the file to the player, even if it's not fully loaded ?
Thanks !
EDIT:
I found a great open-source player named JW Player, seems to be able to do what I want, but I'm not sure how ...

its a little hard to understand what your asking.
PHP Does not have threads which will limit you in multiple tasks, but it is possible to do so
the problem is that if your fetching the file in the same php file that loads the player as a webpage then your going to have issues.
you will have to resort to several php pages to complete the task
Firstly the suer requests to the server the song he wishes to play, you will have to use ajax to infrom the server of the id, so you would ping a script on your server saying LOAD VIDEO ID XXXX in which that script starts downloading the video, you would then active the player to call another file that would read segments of the partially downloaded file and output it to the player.
it will get very complex and possibly very error prone, your best bet is to stream directly from server2

Yes possible but you should indicate size of file truely

Related

How do i get my file-sharing script to stream uploaded videos?

Let's say i have this file-sharing website script but you see, all it
does is share files, like PutLocker.com , i want it so that if a file
with an extension like ".mp4 or .mpeg etc" is uploaded, it uses your
player to stream the file instead of just having shared...
For example:
Jim's wants to start a website, but he is weak at coding. So he gets a
file sharing script.
But the file-sharing script does just that, share files! Jim wants
people to be able to stream their video files aswell, and if happy
worm's player allows him, stream just audio too!
So a user uploads to his website a regular folder, the link is shared,
the script is working fine. But then a user uploads a .mpeg video and
Jim does not want his website to just share the file, he wants his
script to allow users to automatically stream the video file using
Happy Worm's jPlayer and give users an option to download.
I hope you're not lost, believe me i've read the documentation. Should
i just slap the player's source code in there or is there some lines
of code needed to tell it that it needs to stream using that player?
The script i am talking about is X Filesharing pro
I can link you to the php code i have if it would help better...
Thanks...
PHP runs server-side, it won't play media. (Just like physics, you simply can't.)
There are various solutions to deliver media, but the most widely used is Flash.
JWPlayer from LongTailVideo is perfect for what you need, both audio and video.
The documentation is comprehensive and the player itself has lots and lots of cool extras, such as:
buffering
a JS API (for HTML styling)
For thumbnails from video files you'll need third party tools (ffmpeg) installed on the server, some degree of technical knowledge and access to the exec() function in PHP so you can run command-line tools via PHP and output results.

mp4 streaming with jwplayer and download speed limit

hi everyone i have a problem with my streaming. at the moment i have made jwplayer to open a php file (ex. movie2.php) and this php file gives to the jwplayer the movie file pice by pice by sleeping 1 second to limit the speed (this php file also checks referer and session and doesnt show the video path but that but these are not important for the problem) . until here everything is perfect but the problem is : I can not seek the video to a not loaded part and it is obvious the reason why . so can anyone tell me how should i do this ? i need to change this php file somehow to make it support the streaming or can anyone give me a script that supports the streaming and limit the download speed at the same time ??
Check the "start=" value passed to your php code. I've used the JW Player before, and it definitely supports seek. Apparently, a seek is more like a restart, and passes that 'start' to your php file. From there, your file just starts the playing at that point.
There's a couple other comments on that thread about handling the client side of the object to avoid a couple pitfalls. It may be a bit dated, but should be relevant.

Video Uploading: recommended process?

Hey just a quick question for anyone who has done this. I want to create a video tube site. I have done file uploads before but was wondering if anyone could give me suggestions on what I am planning to do.
The way I am planning is to have a folder in my web directory and to upload videos into the folder after virus scanning and checking mime. The video will then be converted and compressed using FFMPEG into flv.
I will change the name and store the video reference id in mysql so the file name can be fetched and served.
I will serve the files using HTTP_Download to a flash player
$dl = new HTTP_Download();
$dl->setFile("$path");
$dl->setContentDisposition(HTTP_DOWNLOAD_ATTACHMENT, "$path");
$dl->setContentType('video/flv');
$dl->send();
Anyone have any suggestions? Is it a good idea to put all videos in one directory?
You may want to consider a Java based uploader as PHP can run into timeout problems on large uploads.
Also do you FFMPEG processing as a CRON job not at upload as it takes a long time.
Look in something like Wowza Streaming Server to serve the videos. Allows streaming and everything is above the root. I name each video with a UID and send a parameter to the Flash video player to decide which one to play.
Where and how you store them will largely depend on how secure they need to be (i.e. should people be able to access the files in the directory directly? or should it be stored more securely than that?)
If direct access is fine, then putting them all in one folder is okay. If not, then you may want to obscure folder names, store them in a secure Database, or in a folder that is not accessible outside of the server.
Also, I'm hoping you're aware of the massive amounts of storage space and bandwidth such a service will consume? I hope you have a scaled solution ready to deploy if you're really serious about this..

What's the logic i need to make this work? PHP Video manipulation with third party control functionality

I am a php newbie so i may be completely off here. But this is what i want to do.
Have a user upload a video to my site.
This then has a 30 second clip from our database added to it.
Which can be downloaded by the user for upload on any third party websites. Essentially the video is a flv or mpeg4, etc. But now with the 30 second clip added on.
These are the key point that make this difficult though.
I would want for certain links that are attached to the video file that is downloaded to be clickable from whereever it is uploaded to.
I would want for the 30 second slot to not be fast-forwardable. (Like on the youtube ads). <- I know they use FLASH for that./ But i would need my videos to be functional anywhere and youtube videos cant do that without attachment to youtube.
(This is something i intend to build myself. I just need your help in figuring out HOW to do it.)
All answers are GREATLY appreciated.
Thanks Alot!!
The challenges you bring up are not something you would ideally fix with PHP knowledge per se. PHP doesn't offer any video editing capabilities of its own, so you would effectively have to use PHP to run some other utilities.
The only PHP aspect here, really, is receiving an upload from the user, executing an external command on the uploaded file, and providing it as a download again. Those are the only parts of this process that I think you can realistically do with PHP alone, and they are quite easy. If you want to figure those out before you figure out the video editing aspect, then find information about making PHP receive a file from the user, how to make a PHP script downloadable instead of a page, and how to execute external commands.
That said, there are command-line utilities out there which you can use PHP to run on the file. I suggest you check out 'mencoder'. I've only used it a couple of times myself to do some video encoding conversions, but that's the first thing that comes to mind. It doesn't matter what you find... provided that it's a command-line utility, you can make PHP use it, even if you're running Windows as a server (imagine that!).
In short; I recommend trying to find command-line utilities that support video manipulation first, forgetting about PHP for a while, then figuring out how to use them, and only then figuring out how to make PHP do what you have to do.
The part with links in the video + no fastforward is not possible in my experience with php or anything else if this is only a video file.
If you go for a full embeded player or at least youtube, then it's possible.

Streaming video file?

I need to stream an flv file.
Streaming should look like live streaming,
and I there should be a way to change the target file.
Sorry for my poor English.
If by "streaming" you mean "showing a flash-video clip", flv-streaming isn't really streaming, but it's a normal file transfer, with the flash player starting playback even if the file isn't completely downloaded to the client. Time seeking is implemented in a standard HTTP way, with a file download offset - if you scroll the video halfway on the timeline and it hasn't downloaded yet, the current download is (most often) aborted, and restarted with an offset of filesize/2 bytes.
So, you could be fine with just using plain old readfile() and fixing the HTTP mime-type headers appropriately with header(). But, since you'd need seeking, you need to parse the HTTP request and instead of readfile(), use fpassthru(), seeking the right place, instead.
tl;dr: Avoid handling this on the PHP side, and let Apache (or the httpd of your choice) handle this instead.
I'm not quite sure what you're asking about, but if you have a bunch of media files and want to play them with a Youtube-esque media player on your website, I suggest checking out Flowplayer - It has an amazing Javascript API that lets you do all kinds of cool stuff to the player, including handling stuff like playlists and programmatically changing the current video.
I recently used it on a project with great results.

Categories