SlideShare a Scribd company logo
I Wrote an FFV1 Decoder in Go for Fun:
What I Learned Going from Spec to Implementation
derek@videolan.org
@daemon404
Derek Buitenhuis
5 December 2019
Budapest, Hungary
NTTW4
But… why?
15 December 2019
• Because why not?
• It seemed fun.
• I wanted to see how hard it was to write something while trying not to use anything but a spec.
• Why? How do you spend your weekends? This is normal.
• But mostly: To make the spec better and aid in adoption of free and open codecs and standards.
• More implementations means a better spec.
• Doing it while trying not to reference anything else would expose anything missing or confusing.
NTTW4
You’ll end up reading sections out-of-order
and multiple times
25 December 2019 NTTW4
• Specs are not written in the order you actually have to perform
the steps in, or the order you’ll write them in.
• A second monitor really helps with all the back-and-forth
referencing between your code and the spec.
• Pseudo-code in one section will use variables defined in
other sections / scopes.
Third party implementation is important!
35 December 2019 NTTW4
• There can be many things missing or unclear in a spec until at least one non-author implements it.
• Things that may be obvious or clear to the author
may not be to everyone else.
• The end result is a much more robust, tested spec.
Having background and context in the spec
is extremely useful.
45 December 2019 NTTW4
• Not many ‘professional’ specs have context or background in them, so why something is the
way it is, or important implementation consequences may not be obvious.
• The FFV1 spec has lots of background, and it came in very useful.
Having contact with the spec author(s) is
extremely useful.
55 December 2019 NTTW4
• It’s good to confirm you’re not going crazy trying to figure
something out.
• Lean on the knowledge of those who came before you.
Writing a spec based on an existing
codebase makes for “interesting” specs
65 December 2019 NTTW4
• Lots of the spec bugs I found were assumptions based on FFmpeg’s encoder or
decoder behavior.
• Annoying implications like requiring 17-bit buffers for predicting 16-bit RGB, which are
not spelled out in the spec at all. I hit this right as I finished up.
• On the flip side, the spec also had advice for how to multithread based off of the slice
footers, and other real-world tips.
A bunch of LaTeX math and a paper reference
alone aren’t as good as pseudocode
75 December 2019 NTTW4
• Looking at you range coder.
• Paper was OK, but implementation details were annoying.
• Not gonna lie, I based my implementation off of Wikipedia + FFV1 spec constants.
Some Quick Notes on the Code
85 December 2019 NTTW4
• Not exactly idiomatic Go, in order to remain as close as possible to the spec.
• Goal is be a good reference.
• Everything is annotated with references to
spec sections.
• I used a bit of Perl for code generation…
Links
95 December 2019 NTTW4
• FFV1 Go Implementation: https://github.com/dwbuiten/go-ffv1
• godoc: https://godoc.org/github.com/dwbuiten/go-ffv1/ffv1
• Simple Matroska Go Package: https://github.com/dwbuiten/matroska
• godoc: https://godoc.org/github.com/dwbuiten/matroska
• FFV1 Spec: https://tools.ietf.org/id/draft-ietf-cellar-ffv1-10.html
• FFV1 Repo: https://github.com/FFmpeg/FFV1/
105 December 2019 NTTW4
Questions?

More Related Content

PDF
Opening up Open Source
PDF
Multimedia Buzzword Bingo: Translating to English
PDF
Search-Driven Programming
PPTX
Effective Code Review (Or How To Alienate Your Coworkers)
PDF
Porque Odeio Branches
PPTX
Trunk Based Development in the Enterprise - Its Relevance and Economics
PPTX
How to Work Efficiently in a Hybrid Git-Perforce Environment
PPTX
Is Trunk-based Development Easy in Game Development?
Opening up Open Source
Multimedia Buzzword Bingo: Translating to English
Search-Driven Programming
Effective Code Review (Or How To Alienate Your Coworkers)
Porque Odeio Branches
Trunk Based Development in the Enterprise - Its Relevance and Economics
How to Work Efficiently in a Hybrid Git-Perforce Environment
Is Trunk-based Development Easy in Game Development?

What's hot (16)

PPTX
Build software like a bag of marbles, not a castle of LEGO®
PPTX
Long Life Software
PDF
mnNOG 3: IP technology adoption in Mongolia
PPTX
Cleaning Code - Tools and Techniques for Large Legacy Projects
PDF
C++ for Marine Streamer Positioning and Navigation - ACCU 2011
PPTX
AgileLINC Continous Slides by Daniel Harp
PDF
Debugging distributed systems
PPTX
Life in Apache Software Foundation
ODP
Levelling up in open source
PDF
How to write maintainable code - Peter Hilton - Codemotion Amsterdam 2017
PDF
Debugging distributed systems
PDF
Skills Matter DevSecOps eXchange Forum 2022 - Software architecture in a DevO...
PPT
Bridging the Gap - Laracon 2013
PDF
Software architecture in a DevOps world
PDF
JavaLand 2022 - Debugging distributed systems
PDF
Writing clean and maintainable code
Build software like a bag of marbles, not a castle of LEGO®
Long Life Software
mnNOG 3: IP technology adoption in Mongolia
Cleaning Code - Tools and Techniques for Large Legacy Projects
C++ for Marine Streamer Positioning and Navigation - ACCU 2011
AgileLINC Continous Slides by Daniel Harp
Debugging distributed systems
Life in Apache Software Foundation
Levelling up in open source
How to write maintainable code - Peter Hilton - Codemotion Amsterdam 2017
Debugging distributed systems
Skills Matter DevSecOps eXchange Forum 2022 - Software architecture in a DevO...
Bridging the Gap - Laracon 2013
Software architecture in a DevOps world
JavaLand 2022 - Debugging distributed systems
Writing clean and maintainable code
Ad

Similar to I Wrote an FFV1 Decoder in Go for Fun: What I Learned Going from Spec to Implementation (20)

PPTX
Developers Best Practices
PPTX
Code smells and Other Malodorous Software Odors
PDF
Engage 2020: Hello are you listening, There is stream for everything
PDF
How to write maintainable code
PPTX
Your Journey to the Uknown: A tale of how I debunk new codebases.
PDF
AAU UX club presentation - April 23, 2015
KEY
Driving application development through behavior driven development
PDF
Querix 4 gl app analyzer 2016 journey to the center of your 4gl application
PPTX
Untangling - fall2017 - week 7
PPTX
14 Habits of Great SQL Developers
PDF
Designing self-service support content – SD Expo Europe 2019
PDF
Python debuggers slides
PPTX
Internet of Things, TYBSC IT, Semester 5, Unit II
PDF
NLJUG Speaker academy 2025 - first session
PDF
Traits of a Good Engineer
PDF
Handsome UI KIts
PDF
Technical Debt - The Code Monster in the Closet
PDF
WordCamp US: Clean Code
PDF
Are Video Codecs... Done?
PDF
NLJUG speaker academy 2024 - session 1, June 2024
Developers Best Practices
Code smells and Other Malodorous Software Odors
Engage 2020: Hello are you listening, There is stream for everything
How to write maintainable code
Your Journey to the Uknown: A tale of how I debunk new codebases.
AAU UX club presentation - April 23, 2015
Driving application development through behavior driven development
Querix 4 gl app analyzer 2016 journey to the center of your 4gl application
Untangling - fall2017 - week 7
14 Habits of Great SQL Developers
Designing self-service support content – SD Expo Europe 2019
Python debuggers slides
Internet of Things, TYBSC IT, Semester 5, Unit II
NLJUG Speaker academy 2025 - first session
Traits of a Good Engineer
Handsome UI KIts
Technical Debt - The Code Monster in the Closet
WordCamp US: Clean Code
Are Video Codecs... Done?
NLJUG speaker academy 2024 - session 1, June 2024
Ad

More from Derek Buitenhuis (8)

PDF
Colorspace: Useful For More Than Just Color? - SF Video Tech Meetup - 27 May ...
PDF
A Progressive Approach to the Past: Ensuring Backwards Compatability Through ...
PDF
Let's Be HAV1ng You - London Video Tech October 2019
PDF
Vimeo and Open Source (SMPTE Forum 2015)
PPTX
Let's Write a JPEG Decoder (Vimeo Lunch Talks)
PPTX
FFMS2: Indexing, Edge Cases, and Insanity
PDF
Every Solution is Wrong: Normalizing Ambiguous, Broken, and Pants-on-Head Cra...
PPTX
Things Developers Believe About Video Files (Proven Wrong by User Uploads)
Colorspace: Useful For More Than Just Color? - SF Video Tech Meetup - 27 May ...
A Progressive Approach to the Past: Ensuring Backwards Compatability Through ...
Let's Be HAV1ng You - London Video Tech October 2019
Vimeo and Open Source (SMPTE Forum 2015)
Let's Write a JPEG Decoder (Vimeo Lunch Talks)
FFMS2: Indexing, Edge Cases, and Insanity
Every Solution is Wrong: Normalizing Ambiguous, Broken, and Pants-on-Head Cra...
Things Developers Believe About Video Files (Proven Wrong by User Uploads)

Recently uploaded (20)

PPTX
Digital-Transformation-Roadmap-for-Companies.pptx
PDF
Review of recent advances in non-invasive hemoglobin estimation
PDF
KodekX | Application Modernization Development
PDF
How UI/UX Design Impacts User Retention in Mobile Apps.pdf
PDF
Profit Center Accounting in SAP S/4HANA, S4F28 Col11
PPT
“AI and Expert System Decision Support & Business Intelligence Systems”
PDF
Unlocking AI with Model Context Protocol (MCP)
PDF
Mobile App Security Testing_ A Comprehensive Guide.pdf
PDF
Encapsulation_ Review paper, used for researhc scholars
PDF
Dropbox Q2 2025 Financial Results & Investor Presentation
PPTX
Understanding_Digital_Forensics_Presentation.pptx
PPTX
Cloud computing and distributed systems.
PDF
TokAI - TikTok AI Agent : The First AI Application That Analyzes 10,000+ Vira...
PPTX
KOM of Painting work and Equipment Insulation REV00 update 25-dec.pptx
PDF
Build a system with the filesystem maintained by OSTree @ COSCUP 2025
PDF
Electronic commerce courselecture one. Pdf
PDF
Blue Purple Modern Animated Computer Science Presentation.pdf.pdf
PPTX
MYSQL Presentation for SQL database connectivity
PDF
Architecting across the Boundaries of two Complex Domains - Healthcare & Tech...
PPTX
20250228 LYD VKU AI Blended-Learning.pptx
Digital-Transformation-Roadmap-for-Companies.pptx
Review of recent advances in non-invasive hemoglobin estimation
KodekX | Application Modernization Development
How UI/UX Design Impacts User Retention in Mobile Apps.pdf
Profit Center Accounting in SAP S/4HANA, S4F28 Col11
“AI and Expert System Decision Support & Business Intelligence Systems”
Unlocking AI with Model Context Protocol (MCP)
Mobile App Security Testing_ A Comprehensive Guide.pdf
Encapsulation_ Review paper, used for researhc scholars
Dropbox Q2 2025 Financial Results & Investor Presentation
Understanding_Digital_Forensics_Presentation.pptx
Cloud computing and distributed systems.
TokAI - TikTok AI Agent : The First AI Application That Analyzes 10,000+ Vira...
KOM of Painting work and Equipment Insulation REV00 update 25-dec.pptx
Build a system with the filesystem maintained by OSTree @ COSCUP 2025
Electronic commerce courselecture one. Pdf
Blue Purple Modern Animated Computer Science Presentation.pdf.pdf
MYSQL Presentation for SQL database connectivity
Architecting across the Boundaries of two Complex Domains - Healthcare & Tech...
20250228 LYD VKU AI Blended-Learning.pptx

I Wrote an FFV1 Decoder in Go for Fun: What I Learned Going from Spec to Implementation

  • 1. I Wrote an FFV1 Decoder in Go for Fun: What I Learned Going from Spec to Implementation derek@videolan.org @daemon404 Derek Buitenhuis 5 December 2019 Budapest, Hungary NTTW4
  • 2. But… why? 15 December 2019 • Because why not? • It seemed fun. • I wanted to see how hard it was to write something while trying not to use anything but a spec. • Why? How do you spend your weekends? This is normal. • But mostly: To make the spec better and aid in adoption of free and open codecs and standards. • More implementations means a better spec. • Doing it while trying not to reference anything else would expose anything missing or confusing. NTTW4
  • 3. You’ll end up reading sections out-of-order and multiple times 25 December 2019 NTTW4 • Specs are not written in the order you actually have to perform the steps in, or the order you’ll write them in. • A second monitor really helps with all the back-and-forth referencing between your code and the spec. • Pseudo-code in one section will use variables defined in other sections / scopes.
  • 4. Third party implementation is important! 35 December 2019 NTTW4 • There can be many things missing or unclear in a spec until at least one non-author implements it. • Things that may be obvious or clear to the author may not be to everyone else. • The end result is a much more robust, tested spec.
  • 5. Having background and context in the spec is extremely useful. 45 December 2019 NTTW4 • Not many ‘professional’ specs have context or background in them, so why something is the way it is, or important implementation consequences may not be obvious. • The FFV1 spec has lots of background, and it came in very useful.
  • 6. Having contact with the spec author(s) is extremely useful. 55 December 2019 NTTW4 • It’s good to confirm you’re not going crazy trying to figure something out. • Lean on the knowledge of those who came before you.
  • 7. Writing a spec based on an existing codebase makes for “interesting” specs 65 December 2019 NTTW4 • Lots of the spec bugs I found were assumptions based on FFmpeg’s encoder or decoder behavior. • Annoying implications like requiring 17-bit buffers for predicting 16-bit RGB, which are not spelled out in the spec at all. I hit this right as I finished up. • On the flip side, the spec also had advice for how to multithread based off of the slice footers, and other real-world tips.
  • 8. A bunch of LaTeX math and a paper reference alone aren’t as good as pseudocode 75 December 2019 NTTW4 • Looking at you range coder. • Paper was OK, but implementation details were annoying. • Not gonna lie, I based my implementation off of Wikipedia + FFV1 spec constants.
  • 9. Some Quick Notes on the Code 85 December 2019 NTTW4 • Not exactly idiomatic Go, in order to remain as close as possible to the spec. • Goal is be a good reference. • Everything is annotated with references to spec sections. • I used a bit of Perl for code generation…
  • 10. Links 95 December 2019 NTTW4 • FFV1 Go Implementation: https://github.com/dwbuiten/go-ffv1 • godoc: https://godoc.org/github.com/dwbuiten/go-ffv1/ffv1 • Simple Matroska Go Package: https://github.com/dwbuiten/matroska • godoc: https://godoc.org/github.com/dwbuiten/matroska • FFV1 Spec: https://tools.ietf.org/id/draft-ietf-cellar-ffv1-10.html • FFV1 Repo: https://github.com/FFmpeg/FFV1/
  • 11. 105 December 2019 NTTW4 Questions?