也许最简单的方法是使用容器 div 来“剪辑”视频元素:
使用 html Canvas 的替代方法
如果您对由纵横比差异引起的黑色边栏感到非常恼火,您可以在 html5 画布上绘制视频的每一帧,然后剪裁画布以仅显示非边栏区域。这是一个有用的链接:http://html5doctor.com/video-canvas-magic/
这是可能的,因为视频元素可以用作画布的图像源。
// get a reference to the video element
var videoElement=document.getElementById('#myVideo');
// draw the current frame of the video element onto canvas
context.drawImage(videoElement,0,0);
.drawImage 方法有一个重载,可以让您剪切源的一部分并在画布上绘制该剪切部分。 .drawImage 的剪辑版本如下所示:
context.drawImage(
sourceImage,
sourceX, sourceY, sourceWidthToClip, sourceHeightToClip,
canvasX, canvasY, scaledWidth, scaledHeight );
在之前的 Stackoverflow 帖子中提供了 .drawImage 剪辑版本的注释说明:
HTML / Java Script Canvas - how to draw an image between source and destination points?
使用 html 画布可以,但需要更多编码。如果您需要为视频添加文本注释或需要显示视频的非矩形部分,您可以考虑使用 html canvas。