简体   繁体   English

在javascript中修剪视频Blob(webm)的开头

[英]Trim the beginning of a video Blob (webm) in javascript

I have a video Blob array in Javascript;我在 Javascript 中有一个视频 Blob 数组; the array is segmented into 1 second intervals.该阵列被分割成 1 秒的间隔。 I want to trim from the beginning and end of the video.我想从视频的开头和结尾修剪。

I found this post ( how-to-edit-trim-a-video-in-the-browser ) describing how to trim my blob, but it only works for the end of the video.我发现这篇文章 ( how-to-edit-trim-a-video-in-the-browser ) 描述了如何修剪我的斑点,但它只适用于视频的结尾。

I suspect that removing the beginning of the blob removes the header information and makes the webm invalid.我怀疑删除 blob 的开头会删除标头信息并使 webm 无效。

This works:这有效:
// remove 2 seconds from the end of the video const trimmedVideo = blobArray.slice(0, blobArray.length - 2);

This does not work:这不起作用:
// remove 1 second from the start of the video const trimmedVideo = blobArray.slice(1, blobArray.length);

How can I trim from the beginning of my video blob?如何从视频 blob 的开头开始修剪?

A hacky and sub-optimal solution, you could set your blob as the source of a video element, then seek to the timestamp where you want to start trimming (could even do this through the uri using #t=[starttime][,endtime] syntax), stream that video element to a new recorder, and play it until the timestamp you want to trim.一个 hacky 和次优的解决方案,你可以将你的 blob 设置为视频元素的来源,然后寻找你想要开始修剪的时间戳(甚至可以通过 uri 使用#t=[starttime][,endtime]语法),将该视频元素流式传输到新的录像机,并播放它直到您想要修剪的时间戳。

You can simplify this a bit by trimming the end by discarding blob chunks, but as @Nuthinking said, you'd lose precision (even the video player won't be 100% precise though, I believe firefox works with 2ms precision).您可以通过丢弃 blob 块来修剪结尾来稍微简化一下,但是正如@Nuthinking 所说,您会失去精度(即使视频播放器也不会 100% 精确,我相信 firefox 的精度为 2ms)。

While I believe this would work, and the video doesn't need to be in the DOM, you'd be encoding at 1:1 time.虽然我相信这会起作用,并且视频不需要在 DOM 中,但您会以 1:1 的时间进行编码。

I'm not aware of any other answers to this that would involve just HTML5.我不知道任何其他只涉及 HTML5 的答案。 This question is tricky because the MediaRecorder API explicitly says blob chunks produced need not be playable by themselves.这个问题很棘手,因为MediaRecorder API 明确表示生成的 blob 块不需要自己播放。

The mediarecorder object that the original solution uses has a method called requestData() , which apparently continues recording in a new Blob after it is called.原始解决方案使用的mediarecorder对象有一个名为requestData()的方法,该方法显然会在调用后继续记录在新的 Blob 中。

Maybe you can use this to continue to record in a new Blob after you find the start point of your edited footage.找到编辑素材的起点后,也许您可以使用它在新的 Blob 中继续录制。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM