Skip to content

Instantly share code, notes, and snippets.

Avatar
🐢
on going

yoh yohhoy

🐢
on going
View GitHub Profile
@yohhoy
yohhoy / aac_parser.py
Last active Sep 24, 2020
Parse AAC/ADTS header
View aac_parser.py
#!/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 / cv2ff.cpp
Created Feb 17, 2016
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 / ffmpeg_tb.md
Last active Sep 23, 2020
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 / threads.h
Last active Sep 18, 2020
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 / ff2cv.cpp
Last active Sep 18, 2020
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>
View utf8_util.hpp
bool starts_with_utf8bom(std::string_view s)
{
constexpr char utf8_bom[3] = { 0xEF, 0xBB, 0xBF };
return s.length() >= 3 && std::equal(utf8_bom, utf8_bom + 3, s.begin());
}
std::string& erase_utf8bom(std::string& text)
{
if (starts_with_utf8bom(text)) {
text.erase(0, 3);
@yohhoy
yohhoy / delayqueue.cpp
Last active Aug 24, 2020
C++ delay queue - unbound blocking queue with delay of element deque (like Java's java.util.concurrent.DelayQueue)
View delayqueue.cpp
#include <chrono>
#include <condition_variable>
#include <mutex>
#include <utility>
#include <vector>
struct closed_queue : std::exception {};
template <typename T, typename Clock = std::chrono::system_clock>
@yohhoy
yohhoy / isobmff.md
Last active Aug 20, 2020
ISO Base Media File Format
View isobmff.md

AAC

ISO/IEC 14496-3, 1.6.2.1 AudioSpecificConfig

AudioSpecificConfig() {
	audioObjectType = GetAudioObjectType();
	samplingFrequencyIndex; // 4 bslbf
	if (samplingFrequencyIndex == 0xf) {
		samplingFrequency; // 24 uimsbf
	}
View decltype.cpp
#include <type_traits>
int main() {
int x = 42;
static_assert(std::is_same_v<decltype( x ), int>);
static_assert(std::is_same_v<decltype((x)), int&>);
int (y) = 42; // redundant parentheses
static_assert(std::is_same_v<decltype( y ), int>);
static_assert(std::is_same_v<decltype((y)), int&>);
@yohhoy
yohhoy / yuvrgb.md
Last active Aug 14, 2020
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
You can’t perform that action at this time.