Skip to content

Instantly share code, notes, and snippets.

Avatar
🐢
on going

yoh yohhoy

🐢
on going
View GitHub Profile
@yohhoy
yohhoy / cv2ff.cpp
Created February 17, 2016 15:41
Convert from OpenCV image and write movie with FFmpeg
View cv2ff.cpp
/*
* Convert from OpenCV image and write movie with FFmpeg
*
* Copyright (c) 2016 yohhoy
*/
#include <iostream>
#include <vector>
// FFmpeg
extern "C" {
#include <libavformat/avformat.h>
@yohhoy
yohhoy / mdspan_hilbert.cpp
Last active March 15, 2023 00:55
Hilbert curve layout for std::mdspan
View mdspan_hilbert.cpp
#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 / mdspan-test.cpp
Created March 4, 2023 14:38
mdspan constructors & deduction guides
View mdspan-test.cpp
#include <cassert>
#include <array>
#include <span>
#if 1
#include <https://raw.githubusercontent.com/kokkos/mdspan/single-header/mdspan.hpp>
using namespace std::experimental;
#else
#include <mdspan>
using namespace std;
#endif
@yohhoy
yohhoy / threads.h
Last active February 24, 2023 09:56
C11 <threads.h> emulation library
View threads.h
/*
* 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 / yuvrgb.md
Last active February 23, 2023 18:02
RGB <=> YCbCr(YPbPr) color space conversion
View yuvrgb.md
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 / ff2cv.cpp
Last active February 20, 2023 13:38
Read video frame with FFmpeg and convert to OpenCV image
View ff2cv.cpp
/*
* 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 / cv2ff.cpp
Created August 4, 2021 16:27
Convert from OpenCV image and write movie with FFmpeg (OpenCV 4.5, FFmpeg 4.4)
View cv2ff.cpp
/*
* 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 / ffmpeg_tb.md
Last active November 15, 2022 08:32
time-base in FFmpeg
View ffmpeg_tb.md

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 / mm.c
Last active September 22, 2022 04:44
View mm.c
// https://groups.google.com/g/golang-nuts/c/Gze1TRtdLdc/m/RoD2AxssDgAJ
// http://svr-pes20-cppmem.cl.cam.ac.uk/cppmem/
int main() {
int x = 0;
atomic_int int y = 0;
{{{ { x = 1;
y.store(1);
x = 1;
y.store(1); }
||| { y.load().readsvalue(0);
View barrier.md

Full barrier

P: =p0=\ /----\ /=p1=\ /----\ /=
        *      *      *      *
C: ----/ \=c0=/ \----/ \=c1=/ \-

Half barrier

P: p0=\--------/=p1=\--------/=