FFmpeg: The Incredible Technology Behind Video on the Internet | Lex Fridman Podcast #496
Watch on YouTube →
Overview
Jean-Baptiste Kempf and Kieran Kunhya discuss FFmpeg and VLC, the foundational open-source multimedia technologies powering much of the internet. They highlight the extreme complexity and optimization required for video codecs, the collaborative spirit of open-source development, and the philosophical commitment to user freedom and accessibility that drives these projects, contrasting it with proprietary models and patent-laden standards.
Key takeaways
- FFmpeg and VLC are foundational open-source multimedia technologies, built by a small core team and thousands of global volunteers, powering much of the internet's video and audio.
- The extreme optimization required for video codecs necessitates extensive use of handwritten assembly, achieving performance gains orders of magnitude beyond compiler optimizations.
- Open-source projects like FFmpeg and VLC thrive on a philosophy of technical excellence and accessibility, refusing lucrative offers that would compromise their user-centric, ad-free, and privacy-respecting principles.
- The development of codecs involves a constant battle against patent minefields, driving the creation of royalty-free alternatives like AV1 and AV2.
- The open-source community faces significant challenges, including maintainer burnout, security threats, and the need to educate large corporations about the value and limitations of volunteer-driven projects.
- The future of multimedia extends beyond audio and video, with FFmpeg and VLC poised to handle new data types like haptics, volumetric video, and potentially even brain-computer interface data.
Chapters
- FFmpeg prioritizes code quality over contributor identity or background.
- Community values excellent code as the defining characteristic.
- Contributors come from diverse, often introverted, backgrounds.
- FFmpeg is a major global CPU user.
- Every sentence in its documentation represents a lifetime of work.
- Complexity is inordinate, with 100,000 lines of assembly for codecs.
- Video codecs are heavily optimized with 79.9% assembly.
- Every CPU cycle is critical for performance.
- Billions of devices decode video constantly, with AV1 usage at 30% for Netflix and 50% for YouTube.
- The FFmpeg Twitter account celebrates open source and low-level engineering.
- It provides unapologetic commentary on software development practices.
- Kieran Kunhya manages the account, known for its 'spicy' opinions.
- VLC is used to record VHS tapes via capture cards.
- It supports obscure formats like DVD-Audio and game codecs.
- A competition was held to create the most 'horrible' file VLC could play.
- The VLC traffic cone logo is globally recognized, even in remote areas.
- Many users search for 'cone player' and download VLC.
- An April Fool's joke to change the logo resulted in 10,000 emails of protest.
- Stage 1: Fetching data from a URL (HTTP, file, DVD) to a byte stream.
- Stage 2: Demultiplexing (demuxing) to separate audio, video, and subtitle tracks.
- Stage 3: Decoding compressed data, potentially using GPU hardware acceleration.
- Up to 45% of files may not be GPU-decodable.
- These require software fallback for de-entropy coding (e.g., Huffman, arithmetic coding).
- Process involves spatial domain intra-prediction and frequency domain transforms (DCT).
- Video compression achieves 100x-200x reduction by removing details humans don't perceive.
- Codecs mimic human ear and eye responses.
- YUV color space (luminance and chrominance) is used instead of RGB.
- Compression degrades the signal, unlike ZIP's lossless data retrieval.
- Degradation must match human perception for optimal results.
- Techniques include scaling down color resolution and using frequency domain transforms (DCT).
- Each codec generation offers ~30% better compression for the same quality.
- This requires immense computational power.
- Optimization is done at the lowest possible stack level: C and assembly.
- Containers (muxers) like MP4, MOV, MKV, AVI hold multiple tracks (audio, video).
- Codecs (coder-decoder) compress/decompress individual tracks (e.g., H.264, AAC).
- Industry naming (e.g., MPEG-4 Part 10 for H.264) causes confusion.
- FFmpeg and VLC discard file format extensions (.MP4) and analyze file content.
- This handles cases where file extensions don't match actual format.
- File extension provides a hint, bumping the priority of the corresponding demuxer.
- VLC was designed as a client for streaming solutions (late '90s).
- It's engineered to work with potentially damaged UDP network inputs.
- This 'don't trust your inputs' philosophy makes it robust with broken files, like those from incomplete downloads.
- Video codecs remove spatial and temporal redundancy using mathematical properties.
- Compression is asymmetric: costly in CPU/financial resources, but cheaper to decompress.
- Error resilience and stream joinability are key design goals.
- Backgrounds that remain static across frames are redundant.
- Reusing information from previous frames significantly reduces data size.
- Modern codecs leverage memory and compute power for extensive comparisons.
- Codecs balance encoding complexity against decoding difficulty.
- Some codecs prioritize fast encoding for streaming, others prioritize efficient decoding for playback.
- Modern codecs like AV1 and VVC are collections of tools for different image types.
- FFmpeg provides low-level libraries for codecs, muxers/demuxers, and filters.
- It's used as a library within VLC, Chrome, smart TVs, and most online video platforms.
- Tools like FFmpeg, FFprobe, libavcodec, libavformat, libavfilter are available.
- FFmpeg creates a level playing field for personal and corporate video processing.
- Companies use FFmpeg via long command lines or APIs.
- It enables complex tasks, akin to Adobe After Effects, via command line.
- The core vision of FFmpeg and VLC is to simplify technically complex systems.
- Users interact with simple interfaces (e.g., dropping a file into VLC).
- This democratization enabled the podcast and streaming revolutions.
- FFmpeg, VLC, x264, and VideoLAN are fully open source projects.
- Open source provides the 'recipe' and 'oven' to remake and modify software.
- Software is a long recipe of instructions; computers execute them rapidly.
- Thousands of people have contributed to FFmpeg since its inception.
- Projects like Linux kernel and FFmpeg rely on online collaboration.
- Contributors work for the 'greater good' and benefit of everyone.
- Licenses act as a social contract, governing community interaction and rights.
- They allow for forks and merging back, fostering community evolution (e.g., GCC, WebKit).
- The core problem FFmpeg and VLC address is making multimedia easy for everyone.
- Permissive licenses (MIT, BSD, Apache) have few conditions.
- Copyleft licenses (GPL, AGPL) require derivative works to be shared under similar terms.
- Public domain is not a worldwide legal concept; all licenses use copyright law.
- Permissive licenses (MIT, BSD) allow broad usage, sometimes requiring attribution.
- Copyleft licenses (GPL, AGPL) mandate sharing modifications back to the community.
- LGPL is a 'weaker' copyleft, allowing proprietary use of libraries if modifications are shared.
- libVLC core shifted from GPL to LGPL to enable third-party application integration.
- LGPL allows commercial use without forcing entire applications to be open source.
- This facilitated integration into game engines and other proprietary solutions.
- Changing licenses requires consent from all original contributors.
- Open source projects are 'joint works' where copyright is held by individuals.
- Contacting hundreds of contributors, sometimes tracking them down, is necessary.
- Contributors span all walks of life, including those in challenging circumstances.
- The community is largely introverted, requiring effort to engage.
- Code quality is paramount, regardless of contributor background.
- Linus Torvalds is known for his harsh code reviews, often directed at maintainers.
- His creation of Git is considered more impactful than the Linux kernel itself.
- Linux powers the vast majority of servers and Android devices.
- VLC's core community is ~5 people; FFmpeg's is ~10-15.
- These small teams maintain code from thousands of past contributors.
- Maintainability and excellence are crucial due to limited resources.
- Low-level technical communities develop a distinct subculture and tone.
- Online communication can be misinterpreted due to lack of non-verbal cues.
- Harshness is often directed at results ('crap code'), not personal attacks.
- Jean-Baptiste Kempf repeatedly refused lucrative offers to monetize VLC with ads or spyware.
- The decision stems from a moral commitment to the 'greater good' and ethical money-making.
- VLC's origin story involves a student project at École Centrale Paris managing a campus network.
- In the '80s, the campus deployed a token ring network.
- By the mid-'90s, students needed faster networking for video games and streaming.
- The Network 2000 project hacked together an early video streaming solution using MPEG-2.
- Two students, Christophe Massiot among them, created the VideoLAN project.
- They spent three years convincing the university to open-source the MPEG-2 decoders.
- VideoLAN client became VLC, which Jean-Baptiste Kempf joined in 2003.
- The project nearly died in 2005 with only two active developers.
- Kempf dedicated himself to growing VLC from hundreds of thousands to billions of users.
- Offers involved bundling toolbars, changing search engines, or in-app advertising.
- Kempf believes in winning money ethically, not through sneaky advertising or data theft.
- Shady ad companies were the primary potential partners, not services like Netflix.
- Compromising the software's spirit would betray other contributors and users.
- Google used AI to generate security reports for FFmpeg, a volunteer-driven project.
- Reports were publicized before fixes, and funding was limited.
- The vulnerability was on an obscure 1990s game codec, deemed low-impact.
- Google's viewpoint: contributing by finding vulnerabilities in ubiquitous open source.
- Security community often uses aggressive language ('You will get popped').
- AI-generated reports are verbose, potentially causing a denial-of-service for maintainers.
- Trillion-dollar corporations expect free, urgent support from volunteers.
- Microsoft Teams marked an issue as high priority but offered minimal payment for long-term maintenance.
- This highlights the disconnect between corporate reliance and volunteer contribution.
- The core issue is the imbalance between AI-driven vulnerability discovery and manual patching efforts.
- Google and other large companies use FFmpeg extensively but contribute disproportionately.
- The XZ fiasco and Google's AI reports led to increased donations and awareness.
- Shout-outs to Andreas Rheinhardt and Anton Khirnov for massive refactorings.
- Highlighting young contributors like Daniel Kang (16) and Ruikai Peng (16) who found and fixed issues.
- Emphasizing that FFmpeg's quality is maintained by a small, dedicated core team.
- Love for the subject matter (e.g., watching anime) is a primary driver.
- FFmpeg and VLC offer the best programming education, with rigorous code reviews.
- Contributors stay for the technical excellence and the impact of their work on billions.
- Multimedia programming requires understanding CPU pipelining, SIMD, ALU, and I/O.
- This low-level knowledge is often missing in modern software engineers.
- Debates over assembly instructions impacting performance by mere cycles are critical.
- FFmpeg likely runs on hundreds of millions or billions of CPUs globally.
- Every instruction matters due to the massive scale of operations.
- Optimization is key to extracting maximum power from hardware.
- FFmpeg and VLC coexist and succeed due to mutual reliance, like Android and Linux.
- Many developers are shared across both projects.
- They form a virtuous cycle, feeding off each other's development and reach.
- x264, the H.264 encoder, is a VideoLAN project and a key driver of FFmpeg's popularity.
- VLC uses FFmpeg, gaining reach and exposure to diverse file formats.
- VideoLAN's ecosystem includes libdvdcss, libvlc, libbluray, and the dav1d decoder.
- Fabrice Bellard: Creator of the initial FFmpeg concept.
- Michael Niedermayer (2000s): Expanded DivX, Xvid, and MPEG-4 Part 2 support.
- H.264's maturity (2008 onwards): Ushered in HD video and reverse engineering efforts.
- Kostya Shishkov, a borderline genius, reverse-engineered complex codecs.
- He tackled 20-30 megabyte binary blobs, a month's work per megabyte.
- Reverse-engineered GoToMeeting's proprietary codec in two months for VLC.
- Requires identifying the decompression module and dumping raw YUV data.
- Uses intuition and pattern recognition to find DCT, entropy coding, and prediction logic.
- Debugging involves stepping through millions of instructions in a disassembler, often within a VM.
- Bit exactness means every implementation must produce identical output bits for a given sample.
- This standard, common from the 2000s, wasn't present in early MPEG-2.
- FFmpeg's success is partly due to its ability to achieve bit exactness across many codecs.
- FATE tests FFmpeg across numerous OSs, compilers, and instruction sets (x86, ARM, RISC-V).
- Volunteer-hosted systems run thousands of tests, detecting miscompilations and compiler bugs.
- Ensures reliability and consistency across a vast array of configurations.
- Kieran's company, Open Broadcast Systems, deals with 10-bit video challenges.
- Processing 10-bit data natively on CPU requires 16-bit, wasting 6 bits.
- Handwritten assembly is used for format conversions, supporting multiple CPU generations and OSs.
- VLC runs on Windows XP to Windows 11, macOS 10.7+, iOS 9+, Linux, BSD, Solaris, and even OS/2.
- Supporting older OS versions like iOS 9 requires 'Frankenstein' versions of Xcode.
- This broad support ensures accessibility for users with older hardware.
- Assembly writes code directly using processor instructions.
- SIMD (Single Instruction, Multiple Data) allows operations on vectors of data simultaneously.
- Handwritten SIMD assembly in FFmpeg yields 10x-50x speed improvements over C.
- dav1d is a royalty-free AV1 decoder developed by VideoLAN.
- It features 30,000 lines of C and 240,000 lines of handwritten assembly.
- Achieves 720p decoding on one or two CPU cores, essential as AV1 adoption grows.
- Handwritten assembly in dav1d significantly outperforms compiler-generated code.
- Modern compilers' auto-vectorization is orders of magnitude slower than optimized assembly.
- This optimization is crucial as hardware gains slow and demand for processing power increases.
- FFmpeg and dav1d push hardware limits, using instructions for unintended purposes (e.g., crypto instructions for video).
- dav1d bypasses standard OS calling conventions for speed.
- This requires deep understanding of computer architecture and assembly language.
- asm-lessons teaches assembly focusing on practical problems, not just grammar.
- It emphasizes high school math and C pointers as prerequisites.
- Aims to preserve the 'dying art' of assembly programming, demonstrated by dav1d's success.
- Assembly offers a direct, intimate connection with the processor, like flying a Spitfire.
- It allows pushing hardware beyond intended limits through clever instruction usage.
- This direct control and art form is unique in software development.
- Rust excels at memory safety and ownership, making it ideal for new projects.
- Interoperability with existing C codebases is challenging.
- The 'rewrite everything' mentality in some Rust communities is often counterproductive.
- Reading code is an order of magnitude harder than writing it.
- Understanding legacy code requires grasping undocumented business logic and design decisions.
- Rewriting complex codebases often fails to capture the original wisdom.
- The checkasm project aims to instrument assembly at compile time.
- This prevents assembly code from jumping to arbitrary memory locations, enhancing security.
- Inline assembly in Rust can undermine security if not carefully managed.
- Henrik Gramner (Intel x86) and Martin Storsjö (ARM) are leading assembly experts.
- They possess deep knowledge of CPU architectures and instruction timings.
- Their work optimizes code for diverse hardware, including mobile and specialized processors.
- Forks occur in open source due to disagreements over governance or development.
- GCC and KHTML/WebKit/Blink are examples of successful forks.
- The FFmpeg/Libav split eventually merged back, strengthening FFmpeg.
Summary, takeaways, and chapters were generated by AI from the video's transcript and may contain errors. The video belongs to its creator, Lex Fridman.