Skip to content

Instantly share code, notes, and snippets.

View cynthia2006's full-sized avatar

Cynthia cynthia2006

  • India
View GitHub Profile

Rust is centred around its grandiose claims of safety, always boasting its guarantees of fearless concurrency, memory safety, zero-cost abstractions and other mumbo-jumbo.

First of all, there's nothing such as zero-cost abstractions. Any abstraction, no matter how close to what its meant to abstract, brings a performance penalty; it applies not only to Rust, but also to its rival languages like C++.

Secondly, concurrency is never a child's play. It maybe easy to spawn a couple of threads to do a task, but it also has to be considered whether that's actually beneficial or even detrimental to performance. The topic of concurrency is complex and hard to get right, and it demands hypothesis, experiments and observations. The algorithm that is designed to do the task in a non-concurrent scenario, may often be suboptimal in a concurrent scenario, and must be modified accordingly, given that it's even possible.

And, I've seen many—if not all—Rust users act with hostility towards unsafe code.

AV1 (AOMedia Video 1) is a next-generation video codec to facilitate VOD (video on demand), storage and live-streaming, as you might already know. It is usually stored in the WebM container, accompanied by Opus as the audio codec. Both are royalty-free codecs; i.e. you need not pay to use them unlike H.264 or H.265; latter of which was the reason AV1 was made, for it was encumbered in a complex web of patents. There are several AV1 encoders to choose from, such as—aomenc, rav1e, SVT-AV1. Although all provide a more-or-less same level of functionality, SVT-AV1 is notable for its speed and scalability.

This is largely a primer meant to familiarise you with some rudimentary aspects of AV1 encoding, which avoids some of the more advanced topics such as—film grain synthesis, variance boost, hierarchical levels, temporal filtering, etc. There's a dedicated community around the codec that document best practises for high-quality encodes.

Presets

Presets are a set of preconfigured encoder options deciding

@cynthia2006
cynthia2006 / xl-convert.rs
Created June 24, 2025 04:13
Fast conversion of pictures into JXL
use std::{
collections::VecDeque,
error::Error,
fs::File,
path::PathBuf,
sync::{
atomic::{AtomicBool, Ordering},
Arc, Mutex,
},
};
@cynthia2006
cynthia2006 / AV1Encoding.md
Last active October 6, 2025 11:59
Tenets of AV1 Encoding using SVT-AV1

Warning

What has been written here earlier maybe somewhat misleading, and it is encouraged to read this primer instead.

Tenets of AV1 Encoding

AV1 is a next-generation video codec developed by Alliance of Open Media to facilitate VOD, storage and live-streaming. Usually paired with the Opus audio codec and stored in WebM or Matroska container, or even MP4 (ISOBMFF) (and streamed using HLS). As of now, besides libaom and rav1e, SVT-AV1 is currently the best production quality encoder available (the matter of discusssion here). This introductory guide is based on the SVT-AV1 documentation.

Presets

Presets (can be selected with --preset option) are a collection of predefined options that influence the speed vs. qualit

Notes on Meson

Meson is primarily a C/C++ build-system, arguably better than CMake or GNU Autotools in terms of UX.

Preliminary Points

These points are essential to both the programmer and the end user who builds the project.

  • A file meson.build must exist at the top-level directory of the project.

  • Meson doesn't allow “in-source builds”, meaning it requires a separate build directory. As customary, separate directories are to made for separate configurations—debug or release.

@cynthia2006
cynthia2006 / parse-args.c
Last active October 15, 2024 10:15
Simple argument parser - a cheap GNU argparse clone
#include <stdio.h>
#include <stdlib.h>
#include <stddef.h>
#include <stdbool.h>
#include <string.h>
typedef int(*arg_type)(void*, int, const char*);
#define arg_type_flag NULL
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
// Chained hashmap.
//
// TODO Keep load-factor constant
// TODO Use union instead of void*
struct my_hash_node
{
function setEqual(a, b) {
for (var i = 0; i < a.length; ++i)
if (b.indexOf(a[i]) === -1)
return false;
for (var i = 0; i < b.length; ++i)
if (a.indexOf(b[i]) === -1)
return false;
return true;
@cynthia2006
cynthia2006 / enum-libavdevice.c
Created April 12, 2024 14:20
Enumerate input/output devices discoverable though libavdevice
#include <stdio.h>
#include <libavformat/avformat.h>
#include <libavdevice/avdevice.h>
#include <libavutil/avutil.h>
static char errbuf[AV_ERROR_MAX_STRING_SIZE];
static void print_streams (int i, int ddev, AVDeviceInfo *d)
{
#include <array>
#include <vector>
/* This idea was inspired by how std::tuple<...> is implemented, that is, using std::pair<K, V>
* as linked-lists. The same idea here is applied in a different fashion to create multidimensional
* std::array<T, N> of homogenous types. A std::vector<T> variant is also made.
*/
template<typename T, int N, int ...dims>
class ndarray {