Skip to content

Instantly share code, notes, and snippets.

@yohhoy
yohhoy / ff2cv.cpp
Last active April 12, 2024 06:49
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 / yuvrgb.md
Last active March 29, 2024 00:19
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 / binsem.cpp
Last active February 23, 2024 12:48
binary semaphore for C++11
#include <mutex>
#include <condition_variable>
// binary semaphore
class binsem {
public:
explicit binsem(int init_count = count_max)
: count_(init_count) {}
// P-operation / acquire
@yohhoy
yohhoy / hevcdec.java
Created August 5, 2017 17:24
render "single I-frame HEVC bitstream" with MediaCodec decoder
package jp.yohhoy.hevcdec;
import android.app.Activity;
import android.content.Context;
import android.media.MediaCodec;
import android.media.MediaFormat;
import android.os.Bundle;
import android.util.Log;
import android.util.Size;
import android.view.Surface;
@yohhoy
yohhoy / submdspan-test.cpp
Created January 31, 2024 14:19
submdspan
#include <cassert>
#include <concepts>
#include <span>
#include <tuple>
#include <utility>
#include <ranges>
#if 1
#include <https://raw.githubusercontent.com/kokkos/mdspan/single-header/mdspan.hpp>
#else
#include <mdspan>
@yohhoy
yohhoy / cv2ff.cpp
Created August 4, 2021 16:27
Convert from OpenCV image and write movie with FFmpeg (OpenCV 4.5, FFmpeg 4.4)
/*
* Convert from OpenCV image and write movie with FFmpeg
*
* Copyright (c) 2021 yohhoy
*/
#include <iostream>
#include <vector>
// FFmpeg
extern "C" {
#include <libavformat/avformat.h>
@yohhoy
yohhoy / isobmff.md
Last active December 12, 2023 14:27
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 / threads.h
Last active December 6, 2023 00:35
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 / mdspan_hilbert.cpp
Last active November 25, 2023 17:07
Hilbert curve layout for std::mdspan
#include <cassert>
#include <bit>
#include <iostream>
#include <utility>
#if 1
#include <https://raw.githubusercontent.com/kokkos/mdspan/single-header/mdspan.hpp>
using std::experimental::mdspan;
using std::experimental::dextents;
#else
#include <mdspan>
@yohhoy
yohhoy / cv2ff.cpp
Created February 17, 2016 15:41
Convert from OpenCV image and write movie with FFmpeg
/*
* Convert from OpenCV image and write movie with FFmpeg
*
* Copyright (c) 2016 yohhoy
*/
#include <iostream>
#include <vector>
// FFmpeg
extern "C" {
#include <libavformat/avformat.h>