0

I have a site that uses multiple servers - main, database, images, ffmpeg/video files.

The main server uses wordpress that has a front end form which users use to create posts. They can choose a combination of options and upload pictures to create a mp4 video using my php ffmpeg script.

I am using an ajax script to do things dynamically without reloading the page.

success: function(data) {
            $("#video-preview")[0].pause();
            $("#video-preview")[0].load();
        },

to show the video on my php page I have --

 <video id="video-preview" class="video-element" preload="metadata"><source src="video.mp4"></video>

The php script from my main server executes ffmpeg commands on the video server.

$cmd = '/usr/local/bin/ffmpeg -threads 1 -i '.$musicpath .'/'.$music.'.mp3 -y '.$output.' 2>&1';

Then ffmpeg creates the mp4 files and saves it to the video server.

The page on my main server then tries to load the mp4 file from the video server when the ajax callback is successful.

Half of the time everything works fine. Then the other half of the time, I have to reload the page several times before the correct file loads.

When this happens I am getting either -

GET https://myvideoserver.com/videoposts/772/9900/output-9900.mp4 416 (Requested Range Not Satisfiable) errors

and/or

GET https://myvideoserver.com/videoposts/772/9900/output-9900.mp4 net::ERR_CONNECTION_RESET 206 (Partial Content) errors. Which is weird cause when I check the files created, they all are fine.

I think it has something do with latency or because the mp4 file is constantly edited and recreated any time a user runs the script for that file/post. Which may cause some delay reading the file when trying to use ajax to load the new file again.

Im not sure but I've searched for the 416 error and followed some suggestions by using

Header set Accept-Ranges none
RequestHeader unset Range

in my htaccess file but it makes my site crash.

How can I prevent from running into 416/206 when constantly making changes to mp4 file and then loading it dynamically?

730wavy
  • 101
  • 4
  • 416 and 206 are not errors when serving streaming media. They are normal operation. – Michael Hampton Dec 29 '18 at 18:56
  • when my php script creates the file and tries loading it using ajax, I end up with one of those errors and it doesnt go away until I refresh the page several times. @MichaelHampton – 730wavy Dec 29 '18 at 19:48
  • Don't overwrite the same file, edit a temporary file and then rename it when done editing. better yet, don't edit the file at all, use a new name for every file. – Michael Hampton Dec 29 '18 at 20:05
  • @MichaelHampton but that would create thousands of mp4's in a short amount of time if I have multiple users on the site. – 730wavy Dec 30 '18 at 01:55
  • Are these files temporary? So far you haven't really described what is going on here or why you need to change a file so frequently that video players can't play the whole thing. – Michael Hampton Dec 30 '18 at 02:29
  • I updated my question with more context. The files are currently not temporary files. There's one final mp4 per post. But a user can edit it by running the script from the front end form. @MichaelHampton – 730wavy Dec 30 '18 at 03:14

0 Answers0