Skip to content

Instantly share code, notes, and snippets.

@yohhoy
yohhoy / yuvrgb.md
Last active March 20, 2026 17:15
RGB <=> YCbCr(YPbPr) color space conversion
Y  = a * R + b * G + c * B
Cb = (B - Y) / d
Cr = (R - Y) / e
BT.601 BT.709 BT.2020
a 0.299 0.2126 0.2627
b 0.587 0.7152 0.6780
@yohhoy
yohhoy / cancellable-sender.cpp
Last active September 24, 2025 07:59
Cancellable sender in C++26 S/R library
#include <cassert>
#include <stop_token>
#include <utility>
#include <print>
// https://github.com/NVIDIA/stdexec/
#include <stdexec/execution.hpp>
namespace exec = stdexec;
namespace std {
using exec::get_stop_token, exec::sync_wait;
using exec::inplace_stop_source, exec::stoppable_token;
@yohhoy
yohhoy / p2300-words.md
Last active September 24, 2025 01:05
C++26 std::execution paper size
Paper Title Words
P2300R10 std::execution 47495
P3325R5 A Utility for Creating Execution Environments 2168
P3396R1 std::execution wording fixes 3061
P2079R10 Parallel scheduler 9383
P3149R11 async_scope - Creating scopes for non-sequential concurrency 16255
P3284R4 write_env and unstoppable Sender Adaptors 1346
P3433R1 Allocator Support for Operation States 827
@yohhoy
yohhoy / isobmff.md
Last active June 25, 2025 09:34
ISO Base Media File Format

AAC

ISO/IEC 14496-3, 1.6.2.1 AudioSpecificConfig

AudioSpecificConfig() {
	audioObjectType = GetAudioObjectType();
	samplingFrequencyIndex; // 4 bslbf
	if (samplingFrequencyIndex == 0xf) {
		samplingFrequency; // 24 uimsbf
	}
@yohhoy
yohhoy / awaitable-coroutine.cpp
Last active June 13, 2025 09:02
C++26 Sender/Receiver and awaitable Coroutine
#include <coroutine>
#include <print>
// https://github.com/NVIDIA/stdexec/
#include <stdexec/execution.hpp>
namespace ex = stdexec;
template<typename T>
class Lazy {
public:
@yohhoy
yohhoy / ticket_fair_mutex.cpp
Last active April 15, 2025 23:31
ticket-based fair mutex implementation
#include <condition_variable>
#include <mutex>
#include <thread>
class fair_mutex {
std::mutex mtx_;
std::condition_variable cv_;
unsigned int next_, curr_;
public:
@yohhoy
yohhoy / aac_parser.py
Last active March 19, 2025 19:19
Parse AAC/ADTS header
#!/usr/bin/env python3
import sys
import struct
if len(sys.argv) < 2:
print("Usage: aac_parer.py <target.aac>")
exit()
aacfile = open(sys.argv[1], 'rb')
frame_no = 1
@yohhoy
yohhoy / threads.h
Last active February 15, 2025 21:51
C11 <threads.h> emulation library
/*
* C11 <threads.h> emulation library
*
* (C) Copyright yohhoy 2012.
* Distributed under the Boost Software License, Version 1.0.
* (See copy at http://www.boost.org/LICENSE_1_0.txt)
*/
#ifndef EMULATED_THREADS_H_INCLUDED_
#define EMULATED_THREADS_H_INCLUDED_
@yohhoy
yohhoy / ff2cv.cpp
Last active December 14, 2024 12:44
Read video frame with FFmpeg and convert to OpenCV image
/*
* Read video frame with FFmpeg and convert to OpenCV image
*
* Copyright (c) 2016 yohhoy
*/
#include <iostream>
#include <vector>
// FFmpeg
extern "C" {
#include <libavformat/avformat.h>
@yohhoy
yohhoy / ffmpeg_tb.md
Last active November 19, 2024 04:43
time-base in FFmpeg

https://www.ffmpeg.org/doxygen/trunk/dump_8c_source.html#l00454

  • fps = st->avg_frame_rate
  • tbr = st->r_frame_rate
  • tbn = st->time_base
  • tbc = st->codec->time_base

AVStream::avg_frame_rate

Average framerate.

  • demuxing: May be set by libavformat when creating the stream or in avformat_find_stream_info().
  • muxing: May be set by the caller before avformat_write_header().