php截取mp4作为封面,H5视频封面截取

部分html

controlslist="nodownload"

src="/xxx/xxx.mp4">您的浏览器不支持 video 标签。

获取视频封面

js$('#interception').on('click',function(){

var video = $('#ppVideo').get(0);

if (video.currentTime <= 0) {

alert('请播放视频,在合适的位置点击该按钮');

return;

}

var scale = 0.25;//比例

var canvas = document.createElement("canvas");//创建一个画布对象

canvas.width = video.videoWidth * scale;//封面图片的宽采用视频宽度的0.25倍

canvas.height = video.videoHeight * scale;//同上

canvas.getContext('2d').drawImage(video, 0, 0, canvas.width, canvas.height);//生成图片

$('#VideoPoster').attr('src', canvas.toDataURL());//设置图片的base64格式数据流

})

html的变化

string imgbase64 = base64.Substring(base64.IndexOf(",") + 1);//过滤掉逗号前面的部分,包括逗号

Guid guid = new Guid();

guid = Guid.NewGuid();

var imgName = guid.ToString();//用Guid当做图片文件的名称

string filename = "";

Bitmap bitmap = null;

try

{

byte[] arr = Convert.FromBase64String(imgbase64);

System.IO.MemoryStream ms = new System.IO.MemoryStream(arr);

Bitmap bmp = new Bitmap(ms);

ms.Close();//关闭当前流

bitmap = bmp;

filename = "Files/video/" + imgName + ".png";//所要保存的相对路径及名字

var path = Context.Server.MapPath("/");//获取项目的完整路径

string imgUrl = (path + filename).Replace("\\", "/"); //得到最终上传路径

bitmap.Save(imgUrl , System.Drawing.Imaging.ImageFormat.Png);//保存到服务器

}

catch (Exception e)

{

}

return filename;//返回相对路径

}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值