HTML5 video 提交预览照片视頻怎样设定、预览视頻

2021-02-23 02:10 jianzhan

当1收到提交照片视頻并能够动态性设定视頻显示信息的海报帧的要求时,关键想的是如何分析视頻并获得储存每帧的照片,百度搜索出来的大多数是相近下面这类必须播发video并点一下截图的,或是用php ffmpeg拓展,跟要求不1致,有点抓狂了,随后就先做了视頻照片的预览作用,进而对设定海报帧换了种思路,根据键入设定video刚开始播发的時间,撤销全自动播发和操纵条,这样客户看到的便是1张照片

/*预览*/
              $('.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 = '<div class="qtuploader__view"><div class="qtuploader__mask"></div><div class="qtuploader__thumb" style="width:' + thumbWidth + 'px;height:' + thumbHeight + 'px;margin:0 auto;"><video controls width="' + thumbWidth + '" height="' + thumbHeight + '" src="' + srcStr + '">您的访问器不适用 video 标识</video></div></div>';
    }
    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⑼]*$/.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 video 提交预览照片视頻怎样设定、预览视頻某秒的海报帧,期待对大伙儿有一定的协助,假如大伙儿有任何疑惑请给我留言,网编会立即回应大伙儿的。在此也十分谢谢大伙儿对脚本制作之家网站的适用!