The blog post explores how C, despite lacking built-in object-oriented features like polymorphism, achieves similar functionality through clever struct design and function pointers. It uses examples from the Linux kernel and FFmpeg to demonstrate this. Specifically, it showcases how defining structs with common initial members (akin to base classes) and using function pointers within these structs allows different "derived" structs to implement their own versions of specific operations, effectively mimicking virtual methods. This enables flexible and extensible code that can handle various data types or operations without needing to know the specific concrete type at compile time, achieving runtime polymorphism.
Taner Şener, the creator of FFmpegKit, a commercial wrapper around FFmpeg for mobile development, announced that he's ceasing development and support. Due to complexities in maintaining FFmpeg across various architectures and operating systems, increasing maintenance burden, and inadequate revenue to justify continued development, he's chosen to shut down. Existing clients can continue using their purchased licenses, but future updates and support are discontinued. The core issue is the difficulty of sustainably supporting a complex project like FFmpegKit, even as a paid product, given the rapid pace of mobile development and the substantial engineering effort required for compatibility. While acknowledging the disappointment this will cause some users, Şener emphasizes the unsustainable nature of the project's current trajectory and thanks users for their support over the years.
Hacker News users discuss the author's decision to discontinue FFmpegKit, an iOS/Android FFmpeg library. Several commenters express disappointment, highlighting FFmpegKit's ease of use compared to alternatives like MobileFFmpeg. Some suggest the decision stems from the difficulty of maintaining cross-platform compatibility and the complex build process involved with FFmpeg. Others speculate about the author's motivation, including burnout or lack of financial viability. A few offer alternative solutions or express hope for a successor project. The lack of clear documentation for building FFmpeg directly is also a recurring concern, reinforcing the value of projects like FFmpegKit.
This blog post details the author's process of creating "guitaraoke" videos: karaoke videos with automated chord diagrams. Using the Vamp plugin Chordino to analyze audio and extract chord information, the author then leverages ImageSharp (a C# image processing library) to generate chord diagram images. Finally, FFmpeg combines these generated images with the original music video to produce the final guitaraoke video. The post focuses primarily on the technical challenges and solutions encountered while integrating these different tools, especially handling timestamps and ensuring smooth transitions between chords.
The Hacker News comments generally praise the author's clear writing style and interesting project. Several users discuss their own experiences with similar audio analysis tools, mentioning alternatives like LibChord and Madmom. Some express interest in the underlying algorithms and the potential for real-time performance. One commenter points out the challenge of accurately transcribing complex chords, while another highlights the project's educational value in understanding audio processing. There's a brief discussion on the limitations of relying solely on frequency analysis for chord recognition and the need for rhythmic context. Finally, a few users share their excitement for the upcoming parts of the series.
FFmpeg by Example provides practical, copy-pasteable command-line examples for common FFmpeg tasks. The site organizes examples by specific goals, such as converting between formats, manipulating audio and video streams, applying filters, and working with subtitles. It emphasizes concise, easily understood commands and explains the function of each parameter, making it a valuable resource for both beginners learning FFmpeg and experienced users seeking quick solutions to everyday encoding and processing challenges.
Hacker News users generally praised "FFmpeg by Example" for its clear explanations and practical approach. Several commenters pointed out its usefulness for beginners, highlighting the simple, reproducible examples and the focus on solving specific problems rather than exhaustive documentation. Some suggested additional topics, like hardware acceleration and subtitles, while others shared their own FFmpeg struggles and appreciated the resource. One commenter specifically praised the explanation of filters, a notoriously complex aspect of FFmpeg. The overall sentiment was positive, with many finding the resource valuable and readily applicable to their own projects.
Summary of Comments ( 67 )
https://news.ycombinator.com/item?id=43280517
Hacker News users generally praised the article for its clear explanation of polymorphism in C, particularly how FFmpeg and the Linux kernel utilize function pointers and structs to achieve object-oriented-like designs. Several commenters pointed out the trade-offs of this approach, highlighting the increased complexity for debugging and the potential performance overhead compared to simpler C code or using C++. One commenter shared personal experience working with FFmpeg's codebase, confirming the article's description of its design. Another noted the value in understanding these techniques even if using higher-level languages, as it helps with interacting with C libraries and understanding lower-level system design. Some discussion focused on the benefits and drawbacks of C++'s object model compared to C's approach, with some suggesting modern C++ offers a more manageable way to achieve polymorphism. A few commenters mentioned other examples of similar techniques in different C projects, broadening the context of the article.
The Hacker News post "Exploring Polymorphism in C: Lessons from Linux and FFmpeg's Code Design (2019)" has a modest number of comments, generating a brief discussion around the topic of object-oriented programming (OOP) in C. While not a large or particularly contentious debate, several commenters offer their perspectives on the merits and drawbacks of the approaches discussed in the article.
One commenter points out that leveraging function pointers for dynamic dispatch, a common technique for implementing polymorphism in C, often leads to a "bloated" vtable. They argue that this can negatively impact performance due to increased code size and indirect function calls. This commenter contrasts this approach with a "switch dispatch," where a switch statement is used to select the appropriate function based on a type identifier. They suggest that this approach can often be more efficient, especially in scenarios with a limited number of types.
Another commenter emphasizes the potential maintenance challenges associated with complex function pointer structures. They propose that, while powerful, this level of indirection can make the code harder to reason about and debug, especially for developers unfamiliar with the project's specific design choices. This echoes the general sentiment that achieving polymorphism in C can sometimes introduce complexity that might be more easily managed in languages with built-in OOP features.
Further discussion revolves around alternative approaches to polymorphism in C, with one commenter mentioning the use of tagged unions and generic programming techniques. This suggestion moves beyond the article's primary focus on function pointers, highlighting the variety of strategies available to C developers for achieving similar results. However, the commenter also acknowledges that these alternatives may introduce their own set of trade-offs in terms of performance and code readability.
Finally, there's a brief exchange about the trade-offs between code complexity and performance. One commenter suggests that the added complexity of OOP-style techniques in C can be justified by the performance benefits, particularly in scenarios where dynamic dispatch is crucial. Another commenter counters this, arguing that the performance gains are often negligible and not worth the increased difficulty in maintaining the codebase.
In summary, the comments section on Hacker News provides a concise but insightful discussion on the complexities and trade-offs involved in implementing polymorphism in C. The commenters touch upon performance considerations, code maintainability, and alternative approaches, offering a balanced perspective on the topic without delving into highly technical or lengthy debates.