Why isn't .NET used for multimedia production? #121268
-
|
I've been wanting to implement some multimedia-related apps in C# recently, like video conferencing apps or video editors, but I ran into a problem: there's no library for that in the ecosystem. So I have a question: Why doesn't anyone implement video and audio libraries in .NET? How come .NET doesn't have any codecs for popular video and audio codecs H.264, AAC or MP3 in its entire ecosystem? In the entire .NET ecosystem (NuGet and GitHub), there's no codec for the aforementioned codecs/file formats that are used everywhere in the multimedia world, there are no such libraries. There are only the wrappers for native libraries (FFmpeg, OpenH264, Windows Media Foundation, ...) but no direct C# implementations. At first, I'd think it's because it's just too complex - but theoretically, it's more complex to implement such codecs in C than in C# because in C# there's less boilerplate code - and would you look at that, almost all implementations are written in C. Not to mention, there are more C# developers than there are C developers. Then I'd think performance, but C#/.NET is actually quite competitive to C in terms of performance when used correctly. It's sometimes even been proven to be faster, and generally speaking, it can be tuned further. You've got structs, parallelism, vectorization, intrinsics, threading - and you can even tune the performance of the application by putting it into release mode or using NativeAOT, ReadyToRun, or PGO. And it's also memory efficient thanks to the Garbage Collector. Also, there are even codec implementations in Java (mp4parser for MP4, jaad for AAC, jcodec for H.264) which actually isn't as fast as .NET, which makes this question even more interesting. Then, .NET developers actually seem to be interested in this happening. Take a look at libraries such as I'd then think licensing and patents, but:
.NET has also been cross-platform for a while now, which makes this question further more interesting. Let's also take a look at So, are there any factors that ultimately result in .NET not having any video/audio/multimedia libraries in its ecosystem (specifically NuGet, GitHub)? Developers seem to be interested, and .NET itself might actually be fast enough for writing this. Why even have a multimedia library in .NET in the first place?Theoretically, this is a must-have in many languages, but in .NET, it's especially a must-have rather than using native tools like FFmpeg. First of all, deployment and portability. If we use an FFmpeg binding, well, since FFmpeg is unmanaged, we will need binaries for all architectures (x64, ARM64, RISC-V, ...) and platforms (Windows, Linux, WebAssembly, ...) - not to mention, FFmpeg is a large binary (1xyMB where x >= 2) per platform and architecture. In .NET, it's one single binary. Also, if I want to use it in my application, I might also want to make a Blazor WebAssembly version (I do use it quite often, I like creating client-side websites), and there's no wasm version of FFmpeg or OpenH264, so if there's a C# library, it could be much more beneficial for deployment against both Desktop, Mobile, and Web versions. Next, integration. Writing a multimedia library in .NET means it integrates better with other .NET primitives like Finally, memory efficiency - since well, garbage collection. |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 5 replies
-
The short answer, for many languages, is because they were already implemented in C, and it's way easier/faster to call into the C library then re-implement it. This is especially true if the consuming language makes it difficult or dangerous to write a similarly performant version.
This is true, but often this is accomplished by building platform-specific binaries and only distributing the relevant platform-specific dependencies. This complicates build setup somewhat, but results in smaller output binaries.
The lack of interest in writing it, probably. That's why SixLabors has a commercial (split) license on their package, for instance. Note that this isn't something the BCL would implement, we would expect such a thing to be provided by the wider community.
GC doesn't make things more memory efficient (it often has at least a slight cost), it just often makes sure things get cleaned up. In fact, any performant implementation likely would internally be using techniques and patterns that rely on unmanaged (not handled by the GC) memory and other resources, or at least techniques that look closer to what the "C native" implementation does. The real benefit to GC isn't memory efficiency, it's developer efficiency due to not needing to worry about keeping track of object lifetimes. But there are ways it can be abused or misused, and for some situations you need techniques that essentially ignore or sidestep the existence of the GC. |
Beta Was this translation helpful? Give feedback.
The short answer, for many languages, is because they were already implemented in C, and it's way easier/faster to call into the C library then re-implement it. This is especially true if the consuming language makes it difficult or dangerous to write a similarly performant version.
This is true, but often this is accomplished by building platform-specific binaries and only distributing the relevant platform-specific dependencies. This complicates build setup somewhat, but results in smaller output binaries.