Blogger Information
Blog 43
fans 0
comment 3
visits 26825
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
js 转视频第一帧为base64图片,用php转为图片文件
Time
Original
667 people have browsed it

js代码:视频文件和js代码最好为同一服务器下,不然容易出错

  1. <!DOCTYPE html>
  2. <html>
  3. <head>
  4. <meta charset="utf-8">
  5. <title></title>
  6. </head>
  7. <body>
  8. <video id="video" controls="controls" width="400" height="300" preload="auto">
  9. <source src="./upload/63534e2688f81.mp4">
  10. </video>
  11. <br>
  12. <br> 视频第一帧图片:
  13. <div id="output"></div>
  14. <script type="text/javascript">
  15. (function() {
  16. var video, output;
  17. var scale = 0.8;
  18. var initialize = function() {
  19. output = document.getElementById("output");
  20. video = document.getElementById("video");
  21. video.addEventListener('loadeddata', captureImage);
  22. };
  23. var captureImage = function() {
  24. var canvas = document.createElement("canvas");
  25. canvas.width = video.videoWidth * scale;
  26. canvas.height = video.videoHeight * scale;
  27. canvas.getContext('2d').drawImage(video, 0, 0, canvas.width,canvas.height);
  28. var img = document.createElement("img");
  29. img.src = canvas.toDataURL("image/png");
  30. img.width = 400;
  31. img.height = 300;
  32. console.log(img);
  33. output.appendChild(img);
  34. };
  35. initialize();
  36. })();
  37. </script>
  38. </body>
  39. </html>

php代码:将js获取到的base64数据转为文件

  1. file_put_contents('./aa.jpg',base64_decode(explode(',',$base64)[1]));
Statement of this Website
The copyright of this blog article belongs to the blogger. Please specify the address when reprinting! If there is any infringement or violation of the law, please contact admin@php.cn Report processing!
All comments Speak rationally on civilized internet, please comply with News Comment Service Agreement
0 comments
Author's latest blog post