我是PHP的初学者,我不知道如何从PHP中的视频文件中获取缩略图。我没有找到帮助我的具体解决方案。我试过ffmpeg库。但现在我想要没有ffmpeg thumbnail.so请帮助我。这是我的codeigniter代码。请查阅。
<?php
$extension = pathinfo($_FILES["url"]["name"], PATHINFO_EXTENSION);/* Get file extension */
$filename = time() . '_' . mt_rand() . '.' . $extension;
move_uploaded_file($_FILES['url']['tmp_name'], $destinationPath . $filename);
$params['filename'] =$destinationPath.$filename;
$params['thumbImageName'] =$destinationPath.$thumbImageName;
$this->load->library('resize',$params);
$this->resize->resizeImage(WEIGHT, HEIGHT);
$this->resize->saveImage($destinationPath.$thumbImageName, 100);
?>
实际上有一种方法。
方法:用户选择要上传的视频。选择后,在弹出的div中显示加载消息或只使用警告框。然后,您要做的是将该视频文件加载到视频标记。最好显示视频标签:无。视频标记处于就绪状态后,跳至视频的50%。然后,获取视频标签的屏幕截图。您可以将图像作为base64,然后通过Ajax将其与视频一起发送到PHP。
(方法:用户选择要上传的视频。)选择后,在窗口中显示加载消息或使用警告框,然后将视频上传到视频剪辑。正在显示:none在视频处于就绪状态之前,以50%跳过视频,然后拍摄视频项屏幕截图。您可以在base64中获取图像然后发送使用Ajax进行PHP。)
包含base64脚本的输入标记。 (包括base64脚本的输入元素。)
<html>
<form action="" method="post" enctype="multipart/form-data" id="uploadvidform" accept="video/*">
<input type="file" name="file" id="file" />
<input type="text" name="screenshotbase64" id="screenshotbase64" value="" style="display: none;" />
</form>
<input type="button" value="Upload" id="uploadvidbut" />
和不可见的视频元素。 (和不可见的视频元素。)
<video width="400" id="videoelem" style="display: none;" controls>
<source src="" id="video_src">
Your browser does not support HTML5 video.
</video>
和脚本。首先,对选择文件时执行操作。确保已将头部元素中的Google Ajax文件链接起来。
(首先,执行选择文件的操作,确保在标题元素中链接了Google Ajax文件。)
<script>
var scalefac = 0.25;
// Scale of image;
// Echelle de l'image;
var screenshots = [];
// An array for multiple screenshots;
// Un tableau pour plusieurs captures d'écran;
// This function will create an image. It's not used now, it's used in the below action (when you change the file).
// Cette fonctionne créera une image. C'est pas pour maintenant c'est pour la fonctionne suivante (lorsqu'on change le fichier).
function capture(video, scalefac) {
if(scaleFactor == null){
scaleFactor = 1;
}
var w = video.videoWidth * scalefac;
var h = video.videoHeight * scalefac;
var canvas = document.createElement('canvas');
canvas.width = w;
canvas.height = h;
var ctx = canvas.getContext('2d');
ctx.drawImage(video, 0, 0, w, h);
return canvas;
}
$(document).ready(function(){
$(document).on("change", "#file", function(){
alert("Please wait while we verify your video. This will only take a couple of seconds.");
// The next 3 lines will load the video
// Les 3 lignes suivantes chargeront la vidéo
var lasource = $('#video_src');
lasource[0].src = URL.createObjectURL($('#file').prop("files")[0]);
lasource.parent()[0].load();
var video = document.getElementById("videoelem");
setTimeout(function(){
// Video needs to load then we check the state.
// Il faut que la vidéo charge puis nous vérifier l'état.
if (video.readyState == "4"){
var videoduration = $("#videoelem").get(0).duration;
var timetogoto = videodurationinseconds / 2;
$("#videoelem").get(0).currentTime = timetogoto;
setTimeout(function(){
// Video needs to load again
// Il faut que la vidéo charge de nouveau
var video = document.getElementById("videoelem");
// function the screen grab.
// fonctionne la capture d'écan.
var canvas = capture(video, scalefac);
screenshots.unshift(canvas);
for(var i=0; i<4; i++){
$("#screenshotbase64").val(screenshots[i].toDataURL());
}
}, 500);
}, 3000);
});
// Now that the form is filled, you can send your data to your PHP file.
// Maintenant que le formulaire est rempli vous pouvez envoyer les données à votre fichier de PHP.
$(document).on('click', '#uploadvidbut', function(){
var form = new FormData($("#uploadvidform")[0]);
$.ajax({
url: '/uploadvideodocument.php', // PHP file - Fichier de PHP
type: 'POST',
data: form,
cache: false,
contentType: false,
processData: false,
success: function (result){
if (result == 1){
alert("The video has been uploaded.");
}
}
}).fail(function(){
alert("Oh no, the video wasn't uploaded.");
});
});
});
</script>
现在是PHP文件。我只是将base64转换包含在图像中,我希望你知道如何做其余的事情。
(现在PHP文件,我只会在图像中包含base64转换,我希望你知道如何做其余的。)
<?php
$data = $_POST['screenshotbase64'];
list($type, $data) = explode(';', $data);
list(, $data) = explode(',', $data);
$data = base64_decode($data);
// The following 2 lines will create the time in microseconds which you can use as the name. Microseconds ensures an almost impossibility of two people uploading at the same time.
// Les 2 lignes suivantes créeront les temps dans microseconds, vous pouvez l'utiliser en tant que le nom. Utiliser les microseconds garantira une presque impossibilité de noms en double.
$mt = explode(' ', microtime());
$millies = ((int)$mt[1]) * 1000 + ((int)round($mt[0] * 1000));
$screenshotfilename = time(). $millies . '.png';
// In the next line, replace YOUR DIRECTORY with your home path and then include the folder of where you want to save the screenshot.
// Dans la ligne suivante, remplacez YOUR DIRECTORY par votre chemin d'accès, puis incluez le dossier dans lequel vous souhaitez sauvegarder la capture.
file_put_contents('YOUR DIRECTORY AND FOLDER' . $screenshotfilename, $data);
// Now, the screen shot has been saved to the server and the name of the file is $screenshotfilename.
// Maintenant la capure d'écran a été sauvegardée à votre serveur et le nom du fichier est $screenshotfilename.
?>
请注意:
某些浏览器可能不接受视频元素。如今,它几乎从未发生过。但请记住这一点。
请知道:
某些浏览器可能不接受视频元素。但现在几乎从未发生过。