gpac / mp4box.js

JavaScript version of GPAC's MP4Box tool
https://gpac.github.io/mp4box.js/
BSD 3-Clause "New" or "Revised" License
1.92k stars 325 forks source link

How to delete video sample from MP4 #306

Open 1kilogram opened 1 year ago

1kilogram commented 1 year ago

How to delete video sample from MP4

At finish work mp4box.js we have:

hughfenghen commented 1 year ago

Try filtering the video tracks or audio tracks in the old mp4File's onSamples and adding them to the new mp4File. https://gpac.github.io/mp4box.js/#onsamplesid-user-samples

1kilogram commented 1 year ago

I found a way to solve this problem back in January. This is only the second time I came to this site, since I haven't found anything worthwhile, at least not that I needed. Even FFmpeg I found by chance through a search on duckduckgo. I suspect that gitHub is used more for advertising than for serious projects. At least about JavaScript projects.

The solution is made without using FFmpeg and doesn't require mp4box library, which depends on MSE API. And the direct dependence on MSE API makes the library - trash, in contrast to, for example FFmpeg, which depends on the technical data of the device. For example on iOS 4S full FFmpeg assembly can't be run due to memory shortage. At the same time build FFmpeg for mp4 - allows you to select audio from no more than 9 seconds of video. On iOS 13+ there is a time limit too, but not critical since there is more RAM in the new stump models. But the problem is that FFmpeg doesn't use BLOb API but reads whole file: hence memory leaks.

Anyway, the solution itself takes about 400 lines with size up to 20 Kb and uses just the BLOb API and some other standard APIs.

So we have compatibility since stumb 6+. I focused exactly on stumb, because at some point in the development of the program, I found that on stumbs, up to the latest versions of iOS, a commercial bug is embedded, which goes against the W3C specification.

This intentional commercial bug from Apple - does not allow the full use of the Web Audio API, according to the W3C. It does not allow to manipulate Audio data if it is Video and in .mp4 container.

I've tried 3 different ways to do this, including using a low-performance ScriptProcessorNode that only allows real-time rendering, but because of an Apple commercial bug - stumps just won't record audio, contrary to W3C spec. At the same time everything works fine on Gecko and Webkit from Google.

So the problem is solved, and full device support is as follows: iOS6+ Chrome20+ Firefox13+ Opera 12.1+ IE10+ Edge0+ Samsung0+ In terms of performance: it takes no more than 2.5 seconds to extract original audio quality from a half hour .MOV video on a regular 4S goggle.

This is an indicator, as the performance on more recent devices is an order of magnitude faster. There is also no limit on file size. For example Opera 32 browser: the process of extracting audio from 2+ gb of video takes no more than 9 seconds.

Such a thing.

If you have a desire to help with the following task:

Compressing video sizes. For example, from FHD to 240p.

From .mp4 to .mp4 is not suitable because it is too long process. Broadway.js may solve the problem, but it works through WASM, which is not suitable for all browsers.

I solve it with PLAYBox : Video API (

Maybe there is a solution, but I don't understand how to make my assembly based on FFmpeg sources to solve one single function : ".mp4 -> .gif" without extra libraries, the solution would be no more than 3-4 mb

This process works about as fast as PLAYBox, but without using Video API. Maybe there is an even easier way to extract frames from a video file.

I would like to know the opinion of people who will read my words.