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?