是否可以仅使用html5& amp;剪切视频的一部分并将其上传到服务器上? js [英] Is it possible to cut part of video and upload it on server only with html5 & js

查看:191
本文介绍了是否可以仅使用html5& amp;剪切视频的一部分并将其上传到服务器上? js的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用Filereader读取本地视频文件(mp4),因此可以在视频标签中显示它.

I use Filereader to read local video file (mp4), so I can display it in video tag.

我需要剪切mp4文件的一部分(即从5到10秒)并将其上传到服务器上.

I need to cut part of mp4 file (i.e. from 5 to 10 seconds) and upload it on server.

我当前的解决方案:我将整个视频文件上传到服务器上,并带有"from"和"to"参数,并在服务器上用ffmpeg对其进行剪切,然后上传到s3并返回url视频.

My current solution: I upload whole video file on server with "from" and "to" parameters, cut it with ffmpeg on server, upload to s3 and return the url video.

也许只有JS/HTML才可能吗?我找到了Blob.slice方法,但我不知道如何使用它来剪切视频部分.

Maybe is it possible only with JS/HTML? I found Blob.slice method but i didn't know how to use it to cut video parts.

谢谢!

推荐答案

一个mp4视频文件由原子"组成,这些原子类似于文件中的信息或数据块.

An mp4 video file is made up of 'atoms' which are like blocks of information or data within a file.

它们包含有关电影中的曲目的标题和元数据(音频,视频,字幕等)以及媒体数据本身.

They contain header and metadata about the tracks in the movie (Audio, video, subtitles etc) and also the media data itself.

概念很简单,但是当您查看一个mp4文件时就涉及很多-苹果开发人员网站(

The concepts are straightforward but an mp4 file is quite involved when you look at one - there is a good example here from the apple developers site (https://developer.apple.com/library/content/documentation/QuickTime/RM/Fundamentals/QTOverview/QTOverview_Document/QuickTimeOverview.html):

如果仅通过从文件中某个点到另一个点获取字节来获取mp4文件的切片",您会发现您将丢失头信息等,具体取决于您从哪里开始,并且大多数情况下可能始于原子"的中间.

If you take a 'slice' of the mp4 file by simply taking bytes from some point in the file to some other point, you can see that you will be missing header information etc depending where you start from, and will also most likely start in the middle of an 'atom'.

当您要剪切视频的一部分时,像ffmpeg这样的工具会费劲地提取和重组文件.

Tools like ffmpeg do the hard work to extract and restructure the file when you want to cut part of the video.

有些项目在Bowser中运行ffmpeg,但我不确定它们的实用性或采用性-无论如何,它似乎很受欢迎:

There are projects which run ffmpeg in the bowser, but I'm not sure how practical or adopted they are - the one seems pretty popular anyway:

这篇关于是否可以仅使用html5& amp;剪切视频的一部分并将其上传到服务器上? js的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆