Skip to content

API for containers? #24

Closed
Closed

Description

@pthatcherg

It comes up as a common question: can we have an API for media containers? It's something that can be done JS/wasm and is arguably orthogonal to WebCodecs. But for some formats that you might consider video (GIF, (M)JPEG), the line is blurry between container and codec.

This is a tracking issue for a conversation around this topic. My current opinion is to leave it out of WebCodecs until it's more mature and then perhaps readdress it later.

Activity

  1. added
    maybe
    on Sep 18, 2019
  2. steveanton commented on Sep 18, 2019

    @steveanton
    Contributor

    The concern I have with containers is that it exposes a lot of API and specification surface but does not unlock anything new that can't already be done (pretty efficiently even) today.

    Following the principles of the Extensible Web Manifesto (https://extensiblewebmanifesto.org/), we should focus on delivering low-level codecs first. Only after that's done (or in parallel by a different group) consider tackling containers.

  3. pthatcherg commented on Sep 18, 2019

    @pthatcherg
    ContributorAuthor

    I agree completely. That's a great way to put it.

  4. guest271314 commented on Sep 18, 2019

    @guest271314
    Contributor

    Key use-cases

    • Non-realtime encoding/decoding/transcoding, such as for local file editing
    • Decoded and encoding images
    • Reencoding multiple input media streams in order to merge many encoded media streams into one encoded media stream.

    and potentially

    • Live stream uploading

    each could be considered an API that at least in part performed some form of code to edit a file. A file could be considered a "container" when technically compared to

    • Extremely low latency live streaming (<3s delay)
    • Cloud gaming
    • Advanced Real-time Communications:
      -- e2e encryption
      -- control over buffer behavior
      -- spatial and temporal scalability

    and potentially

    • Live stream uploading

    where any and all of the above is encompassed within the use case of recording media into a container whether that "container" be an array of images with an index element for "metadata", i.e., width, height, frame duration, or other adjustments made "mid-stream" or post-production ("codec" or instruction), to a .json (or, if preferred Matroska or WebM) "container", for download of both the entire procedure output by WebCodecs and specific time slices into a single "container" (file structure).

    Since the topic is at hand and the maintainers of this repository spans a wide range of topics it might be helpful to create a glossary to point to exactly what you (this repository) mean the definition of the term that you are using.

    Non-goal

    • Direct APIs for media containers (muxers/demuxers)

    indicates the technical proximity of "codecs" to "containers".

    Whether or not WebCodecs includes the reading, writing, editing, etc. of both "codecs" and "containers" that internal decision will not prevent nor preclude the fact of the actual use-case for a single API which is capable of both codec and container creation, extension, modification, etc., to avoid the necessity of attempting to utilizing what is available in different specifications that were not initially conceived as being interoperable with other APIs, both existing and proposed.

    One recent use case for not omitting to include the capability to perform the same procedures within the scope of "containers" the same as "codecs" is that the two are symbiotic and when a single API designed and maintained with that consideration at the forefront and throughout has the potential to solve more than one existing issue where separate portions of code in the same domain, for example, media, could have very different output due to different authors' intent at the time they wrote and merged the code: time passes, new technologies that the issue resolves are now an issue because the implementers may or may not be in accord with the various branches of "media". A single API from creation to editing to production of media streams and files is the explicit use case.

  5. guest271314 commented on Sep 18, 2019

    @guest271314
    Contributor

    Example use case: write audio to a WebM file https://plnkr.co/edit/Inb676?p=preview. Ideally, from a front-end perspective, this single API should be able to encode VP8 and Opus to a file, or if Opus is missing from an existing file, write the audio to the file.

  6. added
    probably not
    and removed
    maybe
    on Sep 18, 2019
  7. guest271314 commented on Sep 21, 2019

    @guest271314
    Contributor

    @steveanton

    (or in parallel by a different group)

    What is necessary to start such a group? Post the proposal at https://discourse.wicg.io? (Note, am not a member of W3C).

  8. guest271314 commented on Sep 21, 2019

    @guest271314
    Contributor

    @pthatcherg

    It's something that can be done JS/wasm

    While there does exist code which can write input images and output a WebM file (https://github.com/GoogleChromeLabs/webm-wasm; https://github.com/thenickdude/webm-writer-js) neither of the repository authors are interested in implementing writing audio to the same output file

    thenickdude/webm-writer-js#8 (comment)

    I don't have any plans to work on adding audio, sorry, and I'm not sure where best to begin either (it probably depends on what format you can capture the audio in and what environment you expect to run in, Chrome, arbitrary browser, Electron, etc).

    GoogleChromeLabs/webm-wasm#12

    It seems this project doesn't support encoding audio+video yet, just video-only? It this feasible, or would it be better to just use the more heavyweight ffmpeg.js project for this?

    GoogleChromeLabs/webm-wasm#12 (comment)

    Yeah, there’s no support for audio and I don’t have any plans to add it. This project was born out of the lackluster capabilities of MediaStreamRecorder.

    ffmpeg.js is definitely one choice. But if you already have an encoded audio and video stream, an mkv muxer might do. That would be a lot faster and smaller. Hope this helps!

    It seems this project doesn't support encoding audio+video yet, just video-only? It this feasible, or would it be better to just use the more heavyweight ffmpeg.js project for this?

    There is an implementation which is capable of writing audio as Opus to a WebM container https://github.com/kbumsik/opus-media-recorder/.

    Meaning this repository can reach maturity without a corresponding container writer being available and having proximal maturoty to write the output of WebCodecs to a file.

    Thus, simply because "JS/wasm" exists does not mean that implementations exist to meet the requirements described at Key use-cases, particuarly

    • Non-realtime encoding/decoding/transcoding, such as for local file editing.
  9. padenot commented on Oct 17, 2019

    @padenot
    Collaborator

    To write down what was said during TPAC, this might be very important to avoid the proliferation of badly muxed files. Muxing is rather hard to get right.

    A possible solution might be a vouched library, as noted above, but there is always the problem of updating it for bug fixes.

  10. chrisn commented on May 7, 2021

    @chrisn
    Member

    I've been following the general discussion around WebCodecs, and the need for a media container API seems to be recognised, but I thought I'd add my own use case as an example.

    I maintain a library waveform-data.js that produces data for waveform visualisation from audio.

    This uses Web Audio decodeAudioData() - but has the well-known problems: it runs on the main thread so UI updates stall during decoding, it requires the entire encoded audio to be held in memory, there's no indication of progress so I can't tell how long it will take to complete, and there's no way to cancel the decode.

    For this use case, the simplest solution would be to allow decodeAudioData() to run from a worker context, with an extended API to allow progress notifications and cancellation.

    WebCodecs also solves these issues, but introduces a new one. Because the library is generic, it will accept any audio format that decodeAudioData supports. So in order to use Web Codecs the library would have to include code to parse all the container formats, or define an API that moves container parsing to users of the library. Both options increase the amount of JavaScript that needs to be delivered, and unnecessarily so because parsing the container is a capability the browser already has. Also, leaving container parsing to library users would make the library much harder for people to use.

  11. chcunningham commented on May 12, 2021

    @chcunningham
    Collaborator

    Triage note: marking 'extension', as this would clearly be a new API.

  12. added
    extension
    on May 12, 2021
  13. chcunningham commented on May 17, 2021

    @chcunningham
    Collaborator

    @chrisn thanks for the use case.

    I'm a little torn. I find the argument about existing demuxers to be persuasive, but less so on the muxing side. Browsers have long compiled-in full featured demuxers for <video> and MSE, but for muxing I think the only example is MediaRecorder, and the files it produces are pretty basic. For example, I don't think we currently ship a muxer that could produce a fragmented MP4.

    We've found JS demuxing performance is quite good. Performance equal, there are some advantages to JS like rapid extensibility and perfect interoperability. My hope is that the download hit is largely amortized away by caching. WDYT?

    But the JS answer rings a little hollow because the available libraries for this are pretty limited right now. If folks like the idea, we could organize a community / WG effort to build / centralize.

  14. 9 remaining items

  15. KevinBoeing commented on Apr 11, 2023

    @KevinBoeing

    I am currently working on a video editor that runs entirely in the Chrome browser. I am currently struggling with the demuxing and muxing process. Mp4Box.js works great, but unfortunately it only allows .mp4 containers to be demuxed. Is there already a demuxer that allows you to demux any container type? I was thinking of ffmpeg.wasm (I saw clipchamp uses it too), but since it's a cli tool, I have no idea how to use it as an all-in-one demuxer in javascript. Is it even possible? The end result of the demuxing process should be to have all the EncodedVideoFrames in one array.

  16. dalecurtis commented on Apr 11, 2023

    @dalecurtis
    Contributor

    For all containers you'd definitely need something like ffmpeg.wasm #549 shows how this might work. Even if browsers had a containers API, it'd likely only support the formats they already parse (mp4, webm, ogg, etc)

  17. KevinBoeing commented on Apr 11, 2023

    @KevinBoeing

    Thats exactly what I needed. Thanks!

  18. bartadaniel commented on Jun 21, 2023

    @bartadaniel

    I also work on a fully in-browser video editing experience. While I made it work with ffmpeg+webcodecs, I can see massive value in adding something like the WebContainers API. Maybe my angle is a little different here; I had edge cases where I had to do workarounds and fixups on the demuxed streams before I could feed them to the VideoDecoder. Some examples:

    • I had to handle negative presentation timestamps in streams. The negative timestamp is not a problem for the VideoDecoder, but it results in the VideoFrame having a different timestamp than what I gave when calling decode.
    • For some videos, the extradata I receive from ffmpeg is missing some information that is available somewhere in the stream I guess. Without that, the VideoDecoder fails.

    Obviously, these things are out of the scope of WebCodecs. But I assume all these touches are already written somewhere in the major browsers because those problematic videos play just fine in Chrome. If I could have access to the video and audio stream in a way that the browser thinks it's appropriate for decoding, that would be a game-changer.

  19. dalecurtis commented on Jun 21, 2023

    @dalecurtis
    Contributor

    Maybe unsurprisingly, edge cases are one of the reasons we wouldn't want to do this. The argument being that containers are all edge cases and an external library meets needs the best. It's likely if we did undertake this the API would be limited to very common muxing and demuxing scenarios. E.g., playback w/ seeking and basic recording scenarios.

    IIRC, decoded timestamps should just pass through per spec: https://w3c.github.io/webcodecs/#output-videoframes -- If you're not seeing that, please file an issue with the respective UA. https://crbug.com/new for Chromium.

  20. aboba commented on May 2, 2024

    @aboba
    Collaborator

    Can we close this issue?

  21. padenot commented on May 2, 2024

    @padenot
    Collaborator

    I think so.

  22. chrisn commented on May 2, 2024

    @chrisn
    Member

    I think so too, but worth keeping track of developer interest, so have created w3c/media-and-entertainment#108 - anyone still interested is welcome to comment there.

  23. added
    won't fix
    and removed
    probably not
    on May 5, 2024
  24. ForeverSc commented on Aug 13, 2024

    @ForeverSc

    Recently I designed a WASM demuxer package specifically for WebCodecs, compared to ffmpeg.wasm, the size will be much smaller, and at the same time than mp4box.js support more formats such as like mkv, webm, flv, etc., I hope it can help people who need it! https://github.com/ForeverSc/web-demuxer

  25. ThioJoe commented on Nov 14, 2025

    @ThioJoe

    Seems like native support for such a basic functionality is a no-brainer. I don't want to use third party libraries for security and maintenance reasons. It doesn't have to be fancy.

  26. JonnyBurger commented on Nov 14, 2025

    @JonnyBurger
    Contributor

    I know it’s third party, but https://mediabunny.dev is really good.

    Can also be dropped in for example as a single-file script, there should not be any security concerns that apply

  27. ThioJoe commented on Nov 15, 2025

    @ThioJoe

    Can also be dropped in for example as a single-file script, there should not be any security concerns that apply

    It's not that I'm concerned the script itself is malicious or anything. It's more about having to add a dependency at all.

    Like if a vulnerability is discovered and patched at some point, then my local copy is vulnerable. For personal tools I make, I'm rarely going to check for dependency updates, if at all (so long as things keep working). For distributed projects, users might not stay up to date.

    Native browser support doesn't have this issue as browsers always keep themselves up to date.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    extensionwon't fix

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions