當(dāng)一收到上傳圖片視頻并可以動(dòng)態(tài)設(shè)置視頻顯示的海報(bào)幀的需求時(shí),主要想的是怎么樣解析視頻并獲取保存每幀的圖片,百度出來(lái)的大多是類(lèi)似下面這種需要播放video并點(diǎn)擊截圖的,或者是用php ffmpeg擴(kuò)展,跟需求不一致,有點(diǎn)抓狂了,然后就先做了視頻圖片的預(yù)覽功能,進(jìn)而對(duì)設(shè)置海報(bào)幀換了種思路,通過(guò)輸入設(shè)置video開(kāi)始播放的時(shí)間,取消自動(dòng)播放和控制條,這樣用戶(hù)看到的就是一張圖片
/*預(yù)覽*/ $('.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': '請(qǐng)?jiān)O(shè)置正確范圍的海報(bào)幀', '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 標(biāo)簽</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(); }); /*設(shè)置海報(bào)幀預(yù)覽時(shí)間*/ $('.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('請(qǐng)?jiān)O(shè)置海報(bào)幀'); } else if (!(/^[0-9]*$/.test(strVal))) { parent.addClass('is-error'); parent.find('.qverify__font').text('請(qǐng)輸入數(shù)字'); } else if (video.length > 0 && strVal > video[0].duration) { parent.addClass('is-error'); parent.find('.qverify__font').text('不超過(guò)(' + video[0].duration + ')'); console.log('111---' + video[0].duration) } else { parent.removeClass('is-error'); parent.find('.qverify__font').text('請(qǐng)?jiān)O(shè)置海報(bào)幀'); } }) /*關(guān)閉預(yù)覽*/ $(document).undelegate('.qtuploader__mask', 'click'); $(document).delegate('.qtuploader__mask', 'click', function() { $(this).closest('.qtuploader__view').fadeOut('normal', function() { $(this).closest('.qtuploader__view').remove(); }) }) /*設(shè)置預(yù)覽大小*/ 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; }
總結(jié)
以上所述是小編給大家介紹的HTML5 video 上傳預(yù)覽圖片視頻如何設(shè)置、預(yù)覽視頻某秒的海報(bào)幀,希望對(duì)大家有所幫助,如果大家有任何疑問(wèn)請(qǐng)給我留言,小編會(huì)及時(shí)回復(fù)大家的。在此也非常感謝大家對(duì)腳本之家網(wǎng)站的支持!
標(biāo)簽:西寧 南京 酒泉 佳木斯 淮安 廣西 十堰 咸寧
巨人網(wǎng)絡(luò)通訊聲明:本文標(biāo)題《HTML5 video 上傳預(yù)覽圖片視頻如何設(shè)置、預(yù)覽視頻某秒的海報(bào)幀》,本文關(guān)鍵詞 HTML5,video,上傳,預(yù)覽,圖片,;如發(fā)現(xiàn)本文內(nèi)容存在版權(quán)問(wèn)題,煩請(qǐng)?zhí)峁┫嚓P(guān)信息告之我們,我們將及時(shí)溝通與處理。本站內(nèi)容系統(tǒng)采集于網(wǎng)絡(luò),涉及言論、版權(quán)與本站無(wú)關(guān)。