From 99bb0e9db4d8cdbccd73d907d7b485cc0b518322 Mon Sep 17 00:00:00 2001 From: eggy Date: Tue, 29 Nov 2022 14:49:06 -0500 Subject: [PATCH] Add november albatross --- content/blog/2022/av1-foss-video-codec.md | 47 ++++++++ .../rust-changes-how-you-think-and-code.md | 103 ++++++++++++++++++ 2 files changed, 150 insertions(+) create mode 100644 content/blog/2022/av1-foss-video-codec.md create mode 100644 content/blog/2022/rust-changes-how-you-think-and-code.md diff --git a/content/blog/2022/av1-foss-video-codec.md b/content/blog/2022/av1-foss-video-codec.md new file mode 100644 index 0000000..a62a3c3 --- /dev/null +++ b/content/blog/2022/av1-foss-video-codec.md @@ -0,0 +1,47 @@ +--- +title: "AV1 — The FOSS Video Codec" +date: 2022-11-13 +tags: +- tech +- albatross +--- + +This article is [also published in *The FOSS Albatross.*](https://medium.com/the-foss-albatross/av1-the-foss-video-codec-1761ad9b0a4a) + + + +More than 60% of all internet traffic is video — YouTube and Netflix are 20% alone! In fact, during COVID, so many people started to watch so much video that that number climbed up to 25%, even as they reduced the quality and size of the videos they served. + +This much traffic costs lots of money for internet service providers, who carry on this cost to the streaming service. + +And so, media companies, including YouTube and Netflix, have banded together as the Alliance of Open Media (AOM) to develop a video format to reduce the file size of videos: AV1! + + + +## How did they shrink video? + +Digital video today is represented as a collection of many still pictures known as “frames” that are shown to the viewer really quickly to create the *illusion* of motion. + +Each individual frame contains thousands to *millions* of tiny squares called *pixels.* + +However, at a typical 24 to 30 frames per second, you’d have to store more than a *thousand* frames per minute! Uncompressed, a 1080p would need to stream nearly 50 million pixels per second, or 50 MB/s. You might see how this could grow expensive for both the streaming service and the consumer, *fast*. + +So, someone figured out that, hey, we can compress pictures! Why don’t we also compress video, too? + +And that’s exactly what we did — video *codecs* were created to provide a standard format to compress or “encode” video, providing large file size savings at the cost of more resources required to decode them upon playback. + +For example, MPEG-2 in DVDs was able to use only 0.25 MB/s of bandwidth for 1080p video when pushed to its limits, though it was a pixelated, smeary mess. + +## Why not use H.265? + +H.265 is the successor to the ubiquitous H.264 codec that virtually every video player can process. Popularised on many physical media such as Blu-Rays, no browser is currently able to natively play back H.265-encoded content, for one very good reason: MPEG-LA, the organisation that designed it, charges royalties for each of its users. + +Understandably, browsers don’t want to have to pay millions of dollars recurringly just to play video, so it’s been stuck playing local media. + +Why doesn’t H.264 have this problem, you ask? [Cisco generously open sourced](https://en.wikipedia.org/wiki/OpenH264) their implementation of the codec and agreed to pay royalties to MPEG-LA, letting anyone legally use the codec for free. + +## Support AV1! + +In light of these problems, Google led the development of AV1 as a royalty-free, high quality alternative to H.265. All modern browsers today have already implemented AV1 playback, and hardware released within the last two years all support hardware decoding of AV1, meaning that the performance and power cost of supporting the codec has decreased drastically. + +By supporting open standards, you can support a world where outdated royalty models no longer exist, and we can all benefit off of each others’ work. \ No newline at end of file diff --git a/content/blog/2022/rust-changes-how-you-think-and-code.md b/content/blog/2022/rust-changes-how-you-think-and-code.md new file mode 100644 index 0000000..b083168 --- /dev/null +++ b/content/blog/2022/rust-changes-how-you-think-and-code.md @@ -0,0 +1,103 @@ +--- +title: "Rust Changes How You Think And Code" +date: 2022-11-27 +tags: +- tech +- rust +- albatross +--- + +This article is [also published in *The FOSS Albatross.*](https://medium.com/the-foss-albatross/rust-changes-how-you-think-and-code-2b5ee4d8def2) + +--- + +Rust is the hot new language on the block (as new as a language from 2006 can be) that boasts reliability and efficiency. + +How does it do this? Well, Rust has something that no other language does — it guarantees memory and thread safety while maintaining the same high performance of C or C++, all the while having high level features such as pattern matching and functional programming! + +Some languages come close: Go is known for being both fast to run and to write, but its garbage collector and xenophobia toward other languages adds overhead that means that it is not suited for a systems programming language. + + + +In safe Rust, there is *no such thing* as undefined behaviour. Everything your code says it does will happen — segfaults and NullPointerExceptions are impossible. + +For simpler issues, the rustc compiler tells you more or less exactly what went wrong, along with a helpful error code, a link for examples on how to fix the error code, and even a suggestion that applies directly to your current code, which more times than not immediately fixes the issue. + +```rust +error: format argument must be a string literal +--> helloworld.rs:3:14 + | +3 | println!(123); + | ^^^ + | +help: you might be missing a string literal to format with + | +3 | println!("{}", 123); + | +error[E0384]: cannot assign twice to immutable variable `a` + --> helloworld.rs:3:5 + | +2 | let a = 123; + | - + | | + | first assignment to `a` + | help: consider making this binding mutable: `mut a` +3 | a *= 2; + | ^^^^^^ cannot assign twice to immutable variable +``` + +Thanks, rustc! + +In time, you come to stop thinking less about the edges in the language and focus more on implementing what you want to implement. Rust makes it so that you don't have to stop and ask yourself these questions every minute: + +- What if this variable isn't initialised or defined? +- What if this variable is already used? +- What if I'm modifying a variable that isn't supposed to be modified? +- What if another thread changes this data while I'm reading it? +- Did I forget to handle an error? +- Did I forget to check the error? + +So how does it do this? + +## Immutability by default + +There are debates on whether immutable or mutable objects are better. Well, Rust provides both — but you have to *explicitly* tell Rust that you want your variables to be mutable. For example, the second error message in this article shows that you need the `mut` keyword to let the compiler let you change variable values. + +```rust +let mut a = 1; +``` + +This applies to everything: from references to function arguments. If a variable isn't passed as `mut`, it's not mutable, and there is nothing else you can do to get around that. This isn't like JavaScript's `const`, either — the internal variables of a struct also have to be declared mutable in order to overwrite them. + +This added friction to mutability means that developers tend to prefer immutable objects when possible, so it's very clear when a variable can change! + +## The borrow checker + +Perhaps Rust's flagship feature, this is how Rust manages memory without the complexity of manual memory management or the overhead of a garbage collector. In a nutshell, each variable is given an owner, and they may only have one owner. + +You can "borrow" the value if you want to do something with it but give it back to use later, but the typical pitfalls of pointers don't exist in Rust because *there are no pointers in Rust!* (At least, not safe Rust.) + +Here's an example of what Rust prevents — if you operated on vector B, it would change C, so Rust's safety guarantees would not hold. That's why the compiler doesn't let you run this in the first place. + +```rust +let a = vec![1, 2, 3]; +let b = a; +let c = a; + +2 | let a = vec![1, 2, 3]; + | - move occurs because `a` has type `Vec`, which does not implement the `Copy` trait +3 | let b = a; + | - value moved here +4 | let c = a; + | ^ value used here after move +``` + +And it's here that you really have to appreciate how much information the compiler gives you. It: + +- tells you where the value originated from +- tells you where the value was used +- and tells you where the value was used *again*, which is not allowed + +## Conclusion + +Though there is a rather steep learning curve from just *how much* there is to unlearn about the finnicky things you can do in more traditional languages, Rust is a language that lets the computer calculate if your program is correct, letting you think purely on how to solve your problems. \ No newline at end of file