video播放中页面上画线条-坐标点画图demo效果(整理)

简介: video播放中页面上画线条-坐标点画图demo效果(整理)


<template>
  <section class="video-box_wrapper">
    <div class="video">
      <div
        v-for="(v, idx) in position"
        :key="idx"
        class="box-line"
        :style="{
          width: `${v.x1 - v.x0}px`,
          height: `${v.y1 - v.y0}px`,
          left: `${v.x0}px`,
          top: `${v.y0}px`
        }">
        {{ v.scope }}
      </div>
      <video width="400" height="400" controls autoplay>
        <source src="https://www.runoob.com/try/demo_source/movie.ogg" type="video/ogg">
      </video>
    </div>
  </section>
</template>
<script>
const position0 = [
  { x0: 122, y0: 34, x1: 150, y1: 80, scope: 123 },
  { x0: 32, y0: 73, x1: 84, y1: 138, scope: 21 },
  { x0: 150, y0: 174, x1: 250, y1: 294, scope: 71 }
]; // 坐标数组
const position1 = [
  { x0: 211, y0: 134, x1: 259, y1: 243, scope: 81 },
  { x0: 12, y0: 75, x1: 84, y1: 138, scope: 31 },
  { x0: 150, y0: 43, x1: 185, y1: 104, scope: 21 }
]; // 坐标数组
const position2 = [
  { x0: 67, y0: 79, x1: 143, y1: 168, scope: 31 },
  { x0: 92, y0: 139, x1: 184, y1: 214, scope: 721 },
  { x0: 218, y0: 106, x1: 250, y1: 394, scope: 12 }
]; // 坐标数组
const obj = {
  position0,
  position1,
  position2
};
export default {
  name: 'App',
  data () {
    return {
      obj,
      freshTime: 0.6 * 1000, // 数据刷新时间
      position: [
        {x0: 122, y0: 34, x1: 150, y1: 80},
        {x0: 32, y0: 73, x1: 84, y1: 138},
        {x0: 150, y0: 174, x1: 250, y1: 294}
      ] // 坐标数组
    };
  },
  mounted () {
    this.int();
  },
  methods: {
    int () {
      // 定时获取后台返回的坐标数据
      this.time = setInterval(v => {
        const index = Math.floor(Math.random() * 2 + 0);
        this.position = this.obj[`position${index}`];
      }, this.freshTime);
      // 销毁定时任务
      this.$once('hook:beforeDestroy', () => {
        clearInterval(this.time);
      });
    }
  }
};
</script>
<style lang="less" scoped>
.video-box_wrapper {
  position: relative;
  .box-line {
    position: absolute;
    z-index: 2;
    border: 1px solid red;
    color: red;
  }
  .video {
    position: relative;
    z-index: 1;
    height: 402px;
    width: 402px;
    margin: 200px;
    border: 1px solid red;
    video {
      height: 400px;
      width: 400px;
    }
  }
}
</style>
<section class="video-box_wrapper">
  <divclass="video">
    <div v-for="(v, idx) in position" :key="idx" class="box-line" :style="{
        width: `${v.x1 - v.x0}px`,
        height: `${v.y1 - v.y0}px`,
        left: `${v.x0}px`,
        top: `${v.y0}px`
      }">
      {{ v.scores }}
    </div>
    <!-- autoplay -->
    <video ref="movie" :style="{ width: videoWidth+'px', height: videoHeight+'px' }" controls
      id="video" @play="handlePlay" @pause="handlePause">
      <source :src="videoSrc" type="video/ogg">
    </video>
  </div>
</section>
data(){
  num: 0,
  // freshTime: 0.6 * 1000, // 数据刷新时间
  freshTime: '', // 数据刷新时间--动态计算
  position: [], // 坐标数组
}
var framesNum = 100; //返回帧数
this.freshTime= (10 / framesNum * 1000).toFixed(3);
var width1 = 1920; //返回原宽度1920-计算缩放后的坐标--500是定义视频大小
for (var i = 0; i < jsarr2.length; i++) {
  for (var k = 0; k < jsarr2[i].videoCalculateResult.length; k++) {
    jsarr2[i].videoCalculateResult[k].x0 = 500 / width1 * jsarr2[i].videoCalculateResult[k].x0;
    jsarr2[i].videoCalculateResult[k].x1 = 500 / width1 * jsarr2[i].videoCalculateResult[k].x1;
    jsarr2[i].videoCalculateResult[k].y0 = 500 / width1 * jsarr2[i].videoCalculateResult[k].y0;
    jsarr2[i].videoCalculateResult[k].y1 = 500 / width1 * jsarr2[i].videoCalculateResult[k].y1;
  }
}
this.jsarr2 = jsarr2;
handlePlay() {
  console.log('视频已开始播放');
  this.int(); //执行-画的框框事件
},
handlePause() {
  clearInterval(this.time);
  console.log('视频已暂停');
  // 销毁定时任务
},
onVideoEnded() {
  console.log('视频播放完成');
  clearInterval(this.time);
  this.int(); //执行-画的框框事件
  this.$forceUpdate();
},
int() {
  // 定时获取后台返回的坐标数据
  this.time = setInterval(v => {
    if (this.num < this.jsarr2.length) {
      this.position = this.jsarr2[this.num].videoCalculateResult;
      this.num++;
    } else {
      this.num = 0;
      clearInterval(this.time);
    }
  }, this.freshTime);
  // 销毁定时任务
  this.$once('hook:beforeDestroy', () => {
    clearInterval(this.time);
  });
},
.video-box_wrapper {
  position:relative;
  .box-line {
    position: absolute;
    z-index: 2;
    border: 1px solid red;
    color: red;
  }
  .video {
    position: relative;
    z-index: 1;
    width: 502px;
    height: 502px;
    // margin: 200px;
    // border: 1px solid red;
    video {
      margin: 0 auto;
      width: 500px;
      height: 500px;
    }
  }
}
/* 隐藏全屏按钮 */
video::-webkit-media-controls-fullscreen-button {
  display: none !important;
}
video::-webkit-media-controls-overlay-play-button {
  display: none !important;
}
相关文章
|
7月前
[笔记]音视频学习之SDL篇《二》 绘制平铺的背景图并居中放置另一图片
[笔记]音视频学习之SDL篇《二》 绘制平铺的背景图并居中放置另一图片
|
7月前
[笔记]音视频学习之SDL篇《五》裁剪图片成子图片(裁剪精灵表)
[笔记]音视频学习之SDL篇《五》裁剪图片成子图片(裁剪精灵表)
|
6天前
|
前端开发 小程序
微信小程序canvas画布绘制base64图片并保存图片到相册中
微信小程序canvas画布绘制base64图片并保存图片到相册中
|
图形学
unity3d UI特效处理,image置灰shader
新建材质,材质指定该shader,然后将材质球拖拽到image上面,效果就显示出来了 图片.png Shader "UI/ImageGreyShader" { Properties { [PerRendere...
3144 0
|
6天前
|
监控 API 计算机视觉
OpenCV这么简单为啥不学——1.4、基础标识绘制(绘制线line函数、rectangle函数绘制四边形、circle函数绘制圆形、putText函数绘制文字、putText绘制中文文字)
OpenCV这么简单为啥不学——1.4、基础标识绘制(绘制线line函数、rectangle函数绘制四边形、circle函数绘制圆形、putText函数绘制文字、putText绘制中文文字)
32 0
|
6天前
|
前端开发 小程序
微信小程序canvas画布绘制;canvas画布图片保存
微信小程序canvas画布绘制;canvas画布图片保存
46 0
|
7月前
|
异构计算
[笔记]音视频学习之SDL篇《十》绘制矩形,线条
[笔记]音视频学习之SDL篇《十》绘制矩形,线条
|
7月前
[笔记]音视频学习之SDL篇《十一》图片 缩放 旋转
[笔记]音视频学习之SDL篇《十一》图片 缩放 旋转
|
8月前
|
JavaScript
文字、图片左右无缝滚动效果--支持拖拽js效果demo效果示例(整理)
文字、图片左右无缝滚动效果--支持拖拽js效果demo效果示例(整理)
|
9月前
|
前端开发
前端 SVG 与 Canvas 框架案例 (画线、矩形、箭头、文字 ....)
前端 SVG 与 Canvas 框架案例 (画线、矩形、箭头、文字 ....)
111 0