7 ms·
I spend a ton of time in FFmpeg, and I’m still blown away by how it uses abstractions to stay modular—especially for a project that’s been around forever and st
by social_quotient 2y ago
I spend a ton of time in FFmpeg, and I’m still blown away by how it uses abstractions to stay modular—especially for a project that’s been around forever and still feels so relevant. Those filtergraphs pulling off polymorphism-like tricks in C? It’s such an elegant way to manage complex pipelines. e.g.
ffmpeg -i input.wav -filter_complex "
[0:a]asplit=2[a1][a2];
[a1]lowpass=f=500[a1_low];
[a2]highpass=f=500[a2_high];
[a1_low]volume=0.5[a1_low_vol];
[a2_high]volume=1.5[a2_high_vol];
[a1_low_vol][a2_high_vol]amix=inputs=2[a_mixed];
[a_mixed]aecho=0.8:0.9:1000:0.3[a_reverb]
" -map "[a_reverb]" output.wav
That said, keeping those interfaces clean and consistent as the codebase grows (and ages) takes some real dedication.
Also recently joined the mailing lists and it’s been awesome to get a step closer to the pulse of the project. I recommend if you want to casually get more exposure to the breadth of the project.
https://ffmpeg.org/mailman/listinfo https://ffmpeg.org/mailman/listinfo
- MuffinFlavored 2y agohow similar are the C abstractions in ffmpeg and qemu given they were started by the same person?
- variadix 2y agoI haven’t worked with ffmpeg’s code, but I have worked with QEMU. QEMU has a lot of OOP (implemented in C obviously) that is supported by macros and GCC extensions. I definitely think it would have been better (and the code would be easier to work with) to use C++ rather than roll your own object model in C, but QEMU is quite old so it’s somewhat understandable. I say that as someone who mostly writes C and generally doesn’t like using C++.
- shmerl 2y agoWhat's the reason for ffmpeg to use C, also historic?
- defrost 2y agoFabrice also wrote the Tiny C compiler, so very much his language of choice .. For those used to the language it was seen as "lighter" and easier to add OO like abstractions to your C usage than bog down in the weight and inconsistencies of (early) C++ https://bellard.org/ https://bellard.org/ https://en.wikipedia.org/wiki/Fabrice_Bellard https://en.wikipedia.org/wiki/Fabrice_Bellard
- lelanthran 2y ago> weight and inconsistencies of (early) C++ Since very little is ever removed from C++, all the inconsistencies in C++ are still there.
- maccard 2y agoEvery language has inconsistencies, and C is not stranger to that. Much of c++’s baggage is due to C and you carry the same weight. That’s not to say that initialization isn’t broken in C++, but just like many features in many languages (off the top of my head in C - strcpy, sprintf, ctime are like hand grenades with the pin pre pulled for you) don’t use them. There’s a subset of C++17 that to me solves so many issues with C and C++ that it just makes sense to use. An example from a codebase I spend a lot of time in is int val; bool valueSet = getFoo(&val); if (valueSet) {} printf(“%d”, val); // oops The bug can be avoided entirely with C++ if (int val; getFoo(&val)) // if you control getFoo this could be a reference which makes the null check in getFoo a compile time check {} printf(“%d”, val); // this doesn’t compile.
- ablob 2y agoYou could write this in C, no? { int val; if (getFoo(&val)) { ... }} Both ways of expressing this are weird, but stating that this can't be achieved with C is dishonest in my opinion.
- i_am_a_peasant 2y ago
- bonzini 2y agoQEMU's abstractions were added when Fabrice was almost completely inactive already (starting in 2008 for some command line support).