Real-time streaming of an MP4 file - php

Is it possible to play the video (mp4) in real time using some flash player? What I mean by in real-time is that player would receive data on the fly, not from alredy saved file but e.g. php script (which sends appropriate content-type header) THAT IS DOWNLOADING AND 'ECHO-ing' THE FILE AT THE TIME PLAYER PLAYS IT - like e.g. some kind of live stream.

JW Player can play streaming video, and LongTail Video also has some good (practical) info on streaming in general:
http://www.longtailvideo.com/support/search/google_cse_adv/streaming
Edit: Maybe I didn't read the question quite as well as i ought to before I answered, but here is info on so called pseudo streaming that can be implemented in PHP:
http://www.longtailvideo.com/support/jw-player/jw-player-for-flash-v5/12534/video-delivery-http-pseudo-streaming

For instant playback using flash, you need to format your mp4 file to have the moov header box at the front of the file for playback to start right away. This can be done by the qt-faststart utility.
To allow for seeking in the file using flash (to a portion of the file not downloaded) you need to utilize pseudo streaming. (Since flash has disabled the partial bytes header). This needs to be implemented on the server side: http://h264.code-shop.com/trac as well as the flash side (both jwplayer and flowplayer supports this approach, and sends ?start=123 param on seek)
The other option is to use the html5 tag (but mp4 is only supported in a few browsers) - then you do not need the pseudostreaming backend.

You can use VLC media player from:
http://www.videolan.org/vlc/
After you successfully installed it, click on the menu Media->Open Network Stream and fill in the URL for the video.

Related

Uploading video, with PHP serverside formatting & encoding

We've currently developed an ExpressionEngine site (php), and are using a paid JWPlayer to display video uploaded by the client.
At present we're running into a number of issues, as the client is:
Uploading video at the wrong size
Uploading video randomly in both flv or mp4 format
And the player is chugging along terribly with multiple pauses throughout the video - sometimes buffering the entire clip before it is played.
I know FFMPEG can be installed serverside, but I'm not sure of the way in which to go about this, and how it might interact between ExpressionEngine and JWPlayer. I'm also not sure about the formatting - the ability for this automated encoding process to also crop/resize the video to suit the player dimensions on the site.
We would really like to have the videos playable on all browsers & iOS devices.
A HQ option would also be great where applicable, but it's just a nice to have - as we're struggling with the formatting / encoding issues first and foremost.
Any help figuring out the best process, and what tools I might need would be greatly appreciated.
I'd reccomend using a service like zencoder
I've used them in the past and no matter what video format I've thrown at them it works great. (PS. I'm not affiliated with them at all)
There is a PHP API with a whole lot of resizing, quality and format options. After you've uploaded your video you can send it to zencoder and they'll send you a response some time later with success or fail.
They can put the processed video on Amazon S3 or FTP it to a server.
You'll need a HTML5 player for iOS devices though, unless JWPlayer has come a long way since I used it last.
You could get zencoder to output in mp4. and then you still only need mp4 for JWPlayer/flash and the HTML5 version for iOS, as long as your happy to use flash for all desktop browsers there's no problem.
As far as the buffering issues you are having - I have found that using a CDN version of the swf for JWPlayer (or whatever player you are using) has caused it to load the entire video file before playing. Easily fixed by hosting it yourself.
I have found many times the video conversion capabilities of different CMS to be limited, and often restricting video formats to what the developers thought was appropriate, such as FLV, which nowadays is turning obsolete for video delivery.
One of the ways you can approach it is by creating a custom script to process the videos uploaded by your client using FFmpeg, which in fact can accept almost any video format, and generate the correct output formats and dimensions, ensuring that the resulting videos will be suitable for web playback using your player.
The problem with the video buffering you are facing is because the video file is not prepared for progressive download or pseudo-streaming, so your browser needs to download the whole video before starting to play. This can be solved with programs like qt-faststart for MP4 and MOV video files, and flvtool2 for FLV files. So your script would need to also optimize the encoded videos using these tools.
Also note that if you use an HTML5 video player (browser native or recent JWPlayer), then you can enjoy from random seeking the video files without buffering them.
If starting from scratch is not an option, you can look into a commercial solution like tremendum transcoder which also uses FFmpeg and is quite simple to use, yet it does all you need in regards to dealing with different input formats and aspect ratios automatically.
I have done a few setups this way, separating the CMS part from the video processing part, and it saved me some headaches.

How can I stream a video from a torrent using HTML 5?

I have an HTML 5 website where I want to stream videos from a torrent server. I don't know which Linux torrent client to use. Can I use PHP as a torrent client?
Example:
<video src="downloder.php?file=movie.mp4"
downloader.php would then return an mp4 file from the .torrent file.
You can use #feross' fantastic library, webtorrent. This works in both Node.js and the browser.
HTML5/javascript can't do the bittorrent protocol. Java applets can, but few browsers support java applets out of the box these days. https://webtorrent.io/ is an alternate protocol that works in the browser. It can't communicate via the bittorrent protocol though, so only works with webtorrent trackers (and piers that speak webtorrent.)
I don't think it is even possible to stream from torrent. Files from torrent are separated into small chunks that are obtained unordered, when/if you will get them from other clients, when/if other clients decide to send them to you.
The torrent file doesn't contain any data to stream. Your PHP server would have to start receiving the torrent data from other peers (that is how torrents work).
MP4 is not a format that needs every byte to play - that is why QuickTime can start playing before completely downloading (hence streaming), but the bytes to play need to be at the start (or at the end, but in any case) - torrents do not 'load' in 'byte order'. As the above user says, torrents load data in chunks. You'd need at least the header.
It's just not realistic.

HTML5 Audio Streaming

There has been some talk of this around stackoverflow before, but nothing really answered this question from what I have seen.
I am trying to implement a streaming audio web application. Almost identical to what WFMU has done with their player (http://wfmu.org/html5/player.php).
All I have been able to figure out from their stream is they are piping the stream into PHP, don't know in what format, and then feeding this to jPlayer for HTML5 presentation to the client.
They have this working awesome, but I am just unsure how they are feeding the audio into PHP and what they are doing within their PHP to present it in an acceptable format for HTML5.
Any ideas would be greatly appreciated.
It looks like the PHP script just echos out an audio file (http://blogfiles.wfmu.org/DG/stream3.php).
There is no requirement to use PHP. For the client, all that matters is you send the appropriate content type, and actual content. In this case, audio/mpeg (MP3), or OGG for Firefox (which, isn't working for them right now, but it definitely can).
I suspect the reason that they are using PHP to relay the stream, is that they are using SHOUTcast as the streaming server. Doing some poking around, I found this: http://mp3stream.wfmu.org:8000/
Note that when you hit that URL in your browser, you get the basic information page. However, if you hit this with an audio player, you get the stream. The SHOUTcast server decides this based on the User-Agent string. If it contains "Mozilla" anywhere in the User-Agent, then it returns this page. If it doesn't, then it returns the stream. So, for an HTML5 audio player, it would use the browser's User-Agent (which contains Mozilla) and would be unable to access the stream. I suspect their PHP script is what gets around the problem.
The PHP script would use cURL, connect to the streaming server with its own User-Agent (can be anything, as long as it isn't "Mozilla"), and relay chunk by chunk to the browser that hit the PHP script. Piece of key-lime-pie.

how to save an image from video/quicktime video?

Hello is there a way in PHP to save an image from video/quicktime video ?
It's not possible in pure PHP. You would have to use an external command line tool like ffmpeg - but that makes the script less portable to other servers.
The only other idea that comes to mind is the Snapshot plugin to the LongTail Video player. With that, you can manually send snapshots of a video playing in the video player (an embeddable Flash player) to a server side script. The process can't be automated, though, and the video will need to be a FLV or MP4 one for this to work.

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