Skip to content

Instantly share code, notes, and snippets.

@yohhoy
yohhoy / av1-codec.md
Last active August 14, 2019 09:50
AV1 video codec memorandum

AV1 coding scheme

  • Arithmetic coding
    • multi-symbols (up to 16 values)
    • Coefficients coding: lv_map
    • CDF: Cumulative distribution function
      • CDF update (at the end of frame)
      • CDF update (adaptive per symbol)
  • Image blocking
@yohhoy
yohhoy / premium_fri.cpp
Last active April 14, 2018 12:03
listing next "Premium Friday" (last friday in month) with C++20 Standard Library.
#include <chrono>
#include <iostream>
using namespace std::chrono;
year_month_day premium_friday(year y, month m)
{
return sys_days{y/m/Friday[last]};
}
@yohhoy
yohhoy / output.s
Created November 15, 2017 13:01
std::string_view constructor and UDL (g++7.1 -std=c++1z -O1)
.LC0:
.string "ABCDEFGHIJKLMNOP"
main:
subq $8, %rsp
movl $16, %edi
movl $.LC0, %esi
call sink(std::basic_string_view<char, std::char_traits<char> >)
movl $16, %edi
movl $.LC0, %esi
call sink(std::basic_string_view<char, std::char_traits<char> >)
*********** NAL UNIT (VPS) ***********
0 forbidden_zero_bit u(1) : 0
1 nal_unit_type u(6) : 32
2 nuh_layer_id u(6) : 0
3 nuh_temporal_id_plus1 u(3) : 1
=========== Video Parameter Set ===========
4 vps_video_parameter_set_id u(4) : 0
5 vps_base_layer_internal_flag u(1) : 1
6 vps_base_layer_available_flag u(1) : 1
7 vps_max_layers_minus1 u(6) : 0
@yohhoy
yohhoy / heic2hevc.cpp
Created August 12, 2017 07:16
convert HEIC file to H.265 bitstream(Annex.B)
/*
* heic2hevc.cpp -- convert HEIC file to H.265 bitstream(Annex.B)
* Copyright(c) 2017 yohhoy
*
* depends https://github.com/nokiatech/heif
*/
#include <iostream>
#include "hevcimagefilereader.hpp"
int extract(const char* srcfile, const char* dstfile)
@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 / huffman1.py
Last active April 17, 2017 16:06
Huffman encode PGM image
#!/usr/bin/env python3
import math
import sys
from operator import itemgetter
pgmfile = sys.argv[1]
with open(pgmfile, 'rb') as f:
# parse PGM header
f.readline()
const char *n2b(unsigned n, int l) {
static char buf[32+1];
for (int i = 0; i < l; i++) {
buf[l - i - 1] = (n & 1) ? '1': '0';
n >>= 1;
}
buf[l] = '\0';
return buf;
}
@yohhoy
yohhoy / jpegeval.sh
Last active March 25, 2017 15:16
RD-curve evaluation of libjpeg/mozjpeg encoder
#!/bin/bash
LIBJPEG=/usr/local/opt/jpeg/bin/cjpeg
MOZJPEG=/usr/local/opt/mozjpeg/bin/cjpeg
LIBJEPG_OPTS=""
MOZJPEG_OPTS=""
QRANGE=`seq 80 100`
# ImageMagick
IDENTIFY=/usr/local/opt/imagemagick/bin/identify
@yohhoy
yohhoy / httpsv.py
Created February 9, 2017 09:11
http server with header dump
#!/usr/bin/env python3
from http import server
server_address = ('localhost', 8080)
class Handler(server.SimpleHTTPRequestHandler):
def do_GET(self):
print('-' * 79)
super(Handler, self).do_GET()
print(self.headers)