How to develop web streaming in php?

Dani AI

Generated

asked about video streaming and rightly pointed out that server-side prep plus a player are required. A concise, modern approach: prepare video for HTTP delivery (adaptive streaming or plain progressive download), serve correct HTTP headers for seeking, and use an HTML5-capable player or a small JS fallback where native support is missing. HTTP Live Streaming (HLS) and MPEG‑DASH remain the standard adaptive formats. (RFC 8216 — HLS, DASH‑IF overview). (datatracker.ietf.org)

For basic needs, deliver files to an HTML5 <video> element and support byte ranges so the browser can seek and resume downloads; this is the simplest “stream-like” behaviour. For adaptive bitrate, package multi-bitrate manifests and segments and use a JS player that implements MSE/EME when native HLS/DASH is not available. See the HTML5 video element and HTTP range request docs for the required headers and behaviour. (MDN: <video>, MDN: Range requests, hls.js player). (developer.mozilla.org)

Small, practical PHP pattern (byte-range support) — use this only for access control or small traffic; avoid using PHP to serve every segment at scale (use a CDN and signed URLs instead):

<?php
$file = '/path/to/video.mp4';
$size = filesize($file);
$start = 0; $end = $size - 1;
if (!empty($_SERVER['HTTP_RANGE'])) {
  if (preg_match('/bytes=(\d+)-(\d+)?/', $_SERVER['HTTP_RANGE'], $m)) {
    $start = intval($m[1]);
    if ($m[2] !== '') $end = intval($m[2]);
    header('HTTP/1.1 206 Partial Content');
    header("Content-Range: bytes $start-$end/$size");
  }
}
header('Accept-Ranges: bytes');
header('Content-Length: ' . ($end - $start + 1));
header('Content-Type: video/mp4');
$fp = fopen($file, 'rb'); fseek($fp, $start);
while (!feof($fp) && ftell($fp) <= $end) echo fread($fp, 8192);
fclose($fp);
exit;

For production, package HLS/DASH on the origin, push delivery to a CDN, and use short‑lived signed URLs or a managed encoder/packager (for example, API-first platforms) to reduce operational overhead and improve scale and security. (aws.amazon.com)

Recommended Answers

All 3 Replies

Hi,

You mean video and audio streaming?

You will need to have an ffmpeg, mp4 box, flvtool2,mencoder and mplayer, ffmpeg-php capable server. You can also look into red5 media server as an option.

Additional items you would need is a reliable flash player like the ones offered by jwplayer and flowmotion.

If you have a limited bandwidth on your hosting account, make sure to have your video metadata injected with flvtool2 (flv files only), for the h264 and mp4 you can move the moov atom in the front of the video, by using mp4box. These tools will allow you to pseudo-stream your contents without translating all the media file size into bandwidth consumptions.

Lastly, you will need to know all of the basics of ffmpeg-php and the basics ffmpeg encoding commands.

video streaming

You will need to look for a reliable hosting company. This is the hosting company I used for developing video streaming applications.

I think they also have a ready to install FREE video streaming applications e.g. phpmotion, clic bucket, vidiscript and many others.

MORE INFO. NOT RELATED TO YOUR QUESTION
I was one of the developer of the vidiscript open-source version 1.0 to version 1.3, but that is the old version we wrote that is still being distributed by most ffmpeg hosting companies. I was able to released all the bug fixes two years ago 2010 and then it was followed by major fix for php 5.3+ in my last year release.

I wrote version 3.7 of the open source, but got really busy at my schooling, and then I have to trashed bin all of the 3.7 version because I want to write it as a video content management using my own mvc framework with an option of smarty, twig and tinybutstrong template engines. I am still on track for my projected release date by mid 2013. This will be called veedeoo scripts which is an open source.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.