So I'm trying to play videos that are hosted on a remote server, the problem I'm encountering is that it takes a VERY long time for large videos to start playing. It seems that the entire video needs to be downloaded before the video starts playing (by comparing the time it takes for the video to start playing with the time it takes to download it). Does anyone have any advice on how to set up the videos to start showing as soon as even a small amount of it has downloaded.
-
you'll want to move the metadata to the beginning of the file which helps the browser make better decisions about how much it needs to stream correctly. See this answer - https://stackoverflow.com/questions/27351136/preparing-mp4-file-for-html-5/27362604#27362604 - forhow to do that – Offbeatmammal Oct 04 '15 at 22:35
-
I've those suggestions in my research, the problem is that the website allows users to upload their own videos for later viewing. Is there a way to run something like that in a php backend or on the website itself? – user3194367 Oct 05 '15 at 13:13
-
you could have a script running on the server that watches the upload folder and triggers ffmpeg to process any new files. Because there is a delay though users will have to wait until their video is available... have a look at http://stackoverflow.com/questions/2504842/ffmpeg-running-in-command-line-but-not-php?rq=1 – Offbeatmammal Oct 05 '15 at 23:13
-
This will take some time to investigate if you post it as a separate answer I'll mark it as the answer. – user3194367 Oct 05 '15 at 23:40
1 Answers
to process individual uploads you'll want to use something like ffmpeg to move the meta data (MOOV atom) to the front of the video file:
./ffmpeg -y -i SourceFile.mp4 -s 1280x720 -c:v libx264 -b 3M -strict -2 -movflags faststart DestFile.mp4
The above will give you a 1280x720 output, at 3Mbps using h264 in an mp4 container, and will also do a second pass to move the moov element to the front of the file enabling it to start streaming faster. It will not re-encode the audio so will keep whatever quality you started with
You may want to play around with the framesize and the bitrate to get the filesize to match what you like/need.
to do this in the background you'll want to review something like this to call ffmpeg from PHP, or to make use of http://ffmpeg-php.sourceforge.net/ to call it, or if easier use a remote transcode service such as http://ffmpegasaservice.com/

- 1
- 1

- 7,970
- 2
- 33
- 52