3 ms·
It's not a great situation yeah - I'd heard there was some effort on Ocaml multimedia libraries but I don't know what's happened to that. Mozilla appear to have
by lmm 11y ago
It's not a great situation yeah - I'd heard there was some effort on Ocaml multimedia libraries but I don't know what's happened to that. Mozilla appear to have got some of their video stack implemented in rust but nowhere near the range of what ffmpeg supports. Hopefully in a few years we'll get there, but in the meantime there's no way around running some C code.
Even so, I would (and have) still use an FFI and put as much as possible in a safer language. You will get segfaults and memory leaks because you're still calling C code, but you won't be adding more, and IME that's well worth the overhead of an FFI. (Also ffmpeg has had quite a bit of attention from people using valgrind, afl-fuzz etc, so its defect rate is lower than your C code would likely have, unless you're also using those tools). Alternatively, depending on your use case you might be able to separate the decoding/encoding stages from the processing, in which case you can write the code without needing much in the way of libraries, and pipe to/from ffmpeg.
Write a quick prototype and see if you can get the performance you need within GC or a small amount of -XXasdf (you might be surprised, particularly with the state of Haskell and OCaml today. I've done literally this from Java, JNI-ing the ffmpeg libraries to do realtime streaming, and had it work fine, and that was five years ago). In the rare case something like that doesn't cut it Rust is what I'd use (there are other options but I know less about them).