I use a PHP script to validate video requests before serving them. This script works as expected on the desktop, with Safari and Chrome. But on iOS, I get a broken play bu
As was stated above to stream or playback MP4 videos using PHP, you will need to handle byte ranges if you want proper playback on Safari and iOS.
rangeDownload() function mentioned in the previous answers does the job pretty well.
I want to mention another piece of this puzzle - make sure the source in the video ends with .mp4 as in . This makes browser thing that it is a video file, and it starts treating it as one.
Inside yourfile.php, you could grab the incoming reference for your file using $_SERVER['PATH_INFO'] or within REQUEST_URI. No need to pass it as a ?id=someId.mp4, direct slash approach looks more like a real file.
To sum up, from my experience to serve a video file from PHP correctly you will need:
moov atom at the beginning of the file (you could use ffmpeg's -movflags +faststart or MP4Box) Source attribute of video tag needs to look like an .mp4 file. Without this my videos were only playing in Chrome and not in Safari/iOS.videojsI wrote this based on my experience with serving thousands of videos on my music video website. While this might not be the case for all, but I found this cross-browser and cross-device setup work as expected.