Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refactor/parse mp4 #291

Open
wants to merge 6 commits into
base: main
Choose a base branch
from
Open

Refactor/parse mp4 #291

wants to merge 6 commits into from

Conversation

hughfenghen
Copy link
Member

重构:基于文件读写的方式解析 mp4,替代以前基于流(ReadableStream)解析。
解决大体积 mp4 文件在解析阶段内存占用过大的问题。

Closes #129

Copy link

changeset-bot bot commented Oct 7, 2024

🦋 Changeset detected

Latest commit: ef8605b

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 3 packages
Name Type
@webav/av-cliper Patch
@webav/av-canvas Patch
@webav/av-recorder Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

if (box == null) break;

if (box.name === 'moof') isFMP4 = true;
if (box.name === 'mdat' && box.data == null) {
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

box.data 是什么情况下没有数据呢?

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

看了一下 getNextBox 返回的 mdat 类型 box 就是把 data 去掉的,那么下面的 if (box.data != null) 分支是不是永远不会执行?或者说 mp4boxFile 会重复解析?

let remainSize = box.size;
while (remainSize > 0) {
// 非 fMP4 文件的 mdat box 非常大,一次最多读取 30MB,避免内存占用过大
const chunkSize = Math.min(remainSize, 30 * 1024 * 1024);
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

这个 30MB 是 hard code,为什么不是 10M/20M?或许这个值可以开放给使用者控制?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

MP4Clip 大文件解析阶段内存优化
2 participants