Html5 video 上传预览图片视频,设置、预览视频某秒的海报帧

这篇文章主要介绍了Html5 video 上传预览图片视频,设置、预览视频某秒的海报帧的相关资料,有一定的参考价值,有需要的朋友可以参考一下,希望对你们有所帮助。

本文介绍了Html5 video 上传预览图片视频,设置、预览视频某秒的海报帧,分享给大家,具体如下:

1.jpg

当一收到上传图片视频并可以动态设置视频显示的海报帧的需求时,主要想的是怎么样解析视频并获取保存每帧的图片,百度出来的大多是类似下面这种需要播放video并点击截图的,或者是用php ffmpeg扩展,跟需求不一致,有点抓狂了,然后就先做了视频图片的预览功能,进而对设置海报帧换了种思路,通过输入设置video开始播放的时间,取消自动播放和控制条,这样用户看到的就是一张图片

 /*预览*/
              
$('.qtuploader__items').on('click', '[name="viewVideoPicBtn"]', function() {
    var parent = $(this).closest('.qtab__page');
    var video = $(this).closest('.qtuploader__itemsbd').find('video');
    var srcStr = '', htmlStr = '';
    if($(this).siblings('.qtuploader__picinputbox').hasClass('is-error')){
      $.fn.toast({
        'parentDom': parent,
        'classes': 'isorange',
        'top': '0',
        'spacing': 0,
        'toastContent': '请设置正确范围的海报帧',
        'autoHide': 3000,
        'position': {
          'top': '5px',
          'left': '50%'
        }
      });
      return;
    }
    if (video.length > 0) {
      var thumbHeight = setSize(video)[0];
      var thumbWidth = setSize(video)[1];
      srcStr = video.attr('src');
      htmlStr = '<p class="qtuploader__view"><p class="qtuploader__mask"></p><p class="qtuploader__thumb" style="width:' + thumbWidth + 'px;height:' + thumbHeight + 'px;margin:0 auto;"><video controls width="' + thumbWidth + '" height="' + thumbHeight + '" src="' + srcStr + '">您的浏览器不支持 video 标签</video></p></p>';
    }
    parent.append(htmlStr);
    parent.find('.qtuploader__view video')[0].currentTime = $(this).siblings('.qtuploader__picinputbox').find('.qtuploader__picinput').val();
    parent.find('.qtuploader__view').fadeIn();
  });
  
  /*设置海报帧预览时间*/
  $('.qtuploader__items').on('keyup', '.qtuploader__picinput', function() {
    var parent = $(this).closest('.qtuploader__picinputbox');
    var video = $(this).closest('.qtuploader__itemsbd').find('video');
    var strVal = $.trim($(this).val());
    console.log(strVal)
    if (strVal == '') {
      parent.addClass('is-error');
      parent.find('.qverify__font').text('请设置海报帧');
    } else if (!(/^[0-9]*$/.test(strVal))) {
      parent.addClass('is-error');
      parent.find('.qverify__font').text('请输入数字');
    } else if (video.length > 0 && strVal > video[0].duration) {
      parent.addClass('is-error');
      parent.find('.qverify__font').text('不超过(' + video[0].duration + ')');
      console.log('111---' + video[0].duration)
    } else {
      parent.removeClass('is-error');
      parent.find('.qverify__font').text('请设置海报帧');
    }
  })
  /*关闭预览*/
  $(document).undelegate('.qtuploader__mask', 'click');
  $(document).delegate('.qtuploader__mask', 'click', function() {
    $(this).closest('.qtuploader__view').fadeOut('normal', function() {
      $(this).closest('.qtuploader__view').remove();
    })
  })
  /*设置预览大小*/
  function setSize(element) {
    var thumbWidth = 0, thumbHeight = 0, arr = [];
    var winWidth = $(window).width(), winHeight = $(window).height();
    var imgWidth = element.width(), imgHeight = element.height();
    if (imgWidth > imgHeight) {
      thumbHeight = parseInt(winHeight - 200);
      thumbWidth = parseInt((1920 * thumbHeight) / 1080);
    } else {
      thumbHeight = parseInt(winHeight - 200);
      thumbWidth = parseInt((1080 * thumbHeight) / 1920);
    }
    arr.push(thumbHeight, thumbWidth)
    return arr;
  }

总结:以上就是本篇文的全部内容,希望能对大家的学习有所帮助。更多相关教程请访问Html5视频教程

相关推荐:

php公益培训视频教程

HTML5图文教程

HTML5在线手册

以上就是Html5 video 上传预览图片视频,设置、预览视频某秒的海报帧的详细内容,更多请关注编程之家其它相关文章!

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。

相关推荐


HTML5和CSS3实现3D展示商品信息的代码
利用HTML5中的Canvas绘制笑脸的代码
Html5剪切板功能的实现
如何通过HTML5触摸事件实现移动端简易进度条
Html5移动端获奖无缝滚动动画实现
关于HTML5和CSS3实现机器猫的代码
HTML5使用DOM进行自定义控制
使用HTML5 Canvas绘制阴影效果的方法
使用PHP和HTML5 FormData实现无刷新文件上传
如何解决HTML5 虚拟键盘出现挡住输入框的问题
HTML5中div和section以及article的区别分析
html5和CSS 实现禁止IOS长按复制粘贴功能
html5 touch事件实现触屏页面上下滑动
canvas 模拟实现电子彩票刮刮乐的代码
HTML5 Plus 实现手机APP拍照或相册选择图片上传的功能
Android自定义环形LoadingView效果
HTML5 canvas绘制五角星的方法
html5使用html2canvas实现浏览器截图
使用Canvas处理图片的方法介绍
利用Canvas模仿百度贴吧客户端loading小球的方法