Regarding the speed, it affects hosting. Is it normal, even if the video is less than 1 megabyte, also affected by the speed of hosting because I have slow speed in all sizes, whether I upload a video of 1 megabyte or 1 Giga.
I use laravel-ffmpeg and through laravel queue I am cutting the video into several qualities I will attach the code to you below.
public function handle()
{
//180p
$lowBitrate1 = (new X264('aac'))->setKiloBitrate(613);
//270p
$lowBitrate2 = (new X264('aac'))->setKiloBitrate(906);
//360p
$midBitrate1 = (new X264('aac'))->setKiloBitrate(1687);
//540p
$midBitrate2 = (new X264('aac'))->setKiloBitrate(2227);
//720p
$highBitrate1 = (new X264('aac'))->setKiloBitrate(4300);
//1080
$highBitrate2 = (new X264('aac'))->setKiloBitrate(7917);
FFMpeg::fromDisk('s3')
->open($this->movie->path)
->exportForHLS()
->onProgress(function ($percent) {
$this->movie->update([
'percent' => $percent
]);
})
->setSegmentLength(10)// optional
->addFormat($lowBitrate1)
->addFormat($lowBitrate2)
->addFormat($midBitrate1)
->addFormat($midBitrate2)
->addFormat($highBitrate1)
->addFormat($highBitrate2)
->toDisk('s3')
->save("public/Movies/{$this->movie->id}/{$this->movie->id}.m3u8");
}//end of handle
This special code in the process of raising and processing in Java script will be attached below.
$('#movie__file-input').on('change',function() {
$('#movie__upload-wrapper').css('display' , 'none');
$('#movie__properties').css('display' , 'block');
var url = $(this).data('url');
var movie = this.files[0];
var movieId = $(this).data('movie-id');
var movieName = movie.name.split('.').slice(0, -1).join('.');
$('#movie__name').val(movieName);
var formData = new FormData();
formData.append('movie_id', movieId);
// formData.append('name', movieName);
formData.append('movie', movie);
$.ajax({
url: url,
data: formData,
method: 'POST',
processData: false,
contentType: false,
cache: false,
success: function (movieBeforeProcessing) {
var interval = setInterval (function () {
$.ajax({
url: `/ATeChatH/posts/${movieBeforeProcessing.id}`,
method: 'GET',
success: function (movieWhileProcessing) {
$('#movie__upload-status').html('Processing');
$('#movie__upload-progress').css('width', movieWhileProcessing.percent + '%');
$('#movie__upload-progress').html(movieWhileProcessing.percent + '%');
if (movieWhileProcessing.percent == 100) {
clearInterval(interval); //break interval
$('#movie__upload-status').html('Done Processing');
$('#movie__upload-progress').parent().css('display', 'none');
$('#movie__submit-btn').css('display', 'block');
}
},
});//end of ajax call
}, 3000);
},
xhr: function () {
var xhr = new window.XMLHttpRequest();
xhr.upload.addEventListener("progress", function (evt) {
if (evt.lengthComputable) {
var percentComplete = Math.round(evt.loaded / evt.total * 100) + "%";
$('#movie__upload-progress').css('width', percentComplete).html(percentComplete);
}
}, false);
return xhr;
},
}); // end of ajax call
}); // end of file input