Skip to content

Instantly share code, notes, and snippets.

@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 / cancellable-sender.cpp
Last active June 24, 2025 16:52
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;
}
@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 / yuvrgb.md
Last active May 30, 2025 23:21
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 / 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().
@yohhoy
yohhoy / mdspan-test.cpp
Last active May 2, 2024 07:22
mdspan constructors & deduction guides
#include <cassert>
#include <array>
#include <span>
#include <type_traits>
#if 0
#include <mdspan>
#else
#include <https://raw.githubusercontent.com/kokkos/mdspan/single-header/mdspan.hpp>
#endif
using namespace std;