# of reference frames in various video codecs

AVC

https://www.ibc.org/download?ac=14095

AVC allows up to 16 reference frames to be used, but in practice, it
is rare to use more than 5.

HEVC

From x265 manual https://x265.readthedocs.io/en/2.5/cli.html#cmdoption-ref

— ref <1..16>
Max number of L0 references to be allowed. This number has a linear multiplier effect on the amount of work performed in motion search, but will generally have a beneficial affect on compression and distortion.

Note that x265 allows up to 16 L0 references but the HEVC specification only allows a maximum of 8 total reference frames.
- if you have B frames…


medium

Example 1:

Input: s = "babad"
Output: "bab"
Note: "aba" is also a valid answer.

Example 2:

Input: s = "cbbd"
Output: "bb"

Example 3:

Input: s = "a"
Output…

medium

C++ stl container is very convenient for this problem

Design a time-based key-value data structure that can store multiple values for the same key at different time stamps and retrieve the key’s value at a certain timestamp.

Implement the TimeMap class:

  • TimeMap() Initializes the object of the data structure.
  • void set(String key, String value, int timestamp) Stores the key key with the value value at the given time timestamp.
  • String get(String key, int timestamp) Returns a value such that set was called previously, with timestamp_prev <= timestamp. If there are multiple such values, it returns the value associated with…

linux signal hander

#include <signal.h>
#include <unistd.h> // for STDOUT_FILENO
#include <stdio.h>
void handler(int num) {
write(STDOUT_FILENO, "refuse to die\n", 13);
}
int main() {
// with…

binutils

strings executablereadelf -symbols executableobjdump -t executable // symbol tableobjdump -s executable // different sectionsobjdump -d executable // disassemblereadelf --segments ./test.elfsegments: segment of memory
sections…

shim layer for library

Simple replacement layer that replace gnu library

Application

// test.cpp
#include <stdio.h>
#include <stdlib.h>
int main(int argc, char** argv) {
for (int i=0; i<5; i++) {
printf("%d: %d\n", i, rand());
}
return 0;
}

Shim layer for rand()

// shim.cpp
extern "C" {
int rand();
}
int rand() {
return 888;
}

Makefile

CC=g++
CFLAGS=-Wall -g
BINS=test.elf shim.so
all: $(BINS)%.so: %.cpp
$(CC) $(CFLAGS) -fPIC -shared -o $@ $^
%.elf: %.cpp
$(CC) $(CFLAGS) -o $@ $^
clean:
rm $(BINS)
rm -r *.so

Run

$ make
g++ -Wall -g -o test.elf test.cpp
g++ -Wall -g -fPIC -shared -o shim.so shim.cpp
$ LD_PRELOAD=./shim.so ./test.elf
0: 888
1…

C++ linux

Application

#include <stdio.h>
#include <stdlib.h>
#include <dlfcn.h> // for dlopen, dlsym, dlclose
int main(int argc, char** argv) {
if (argc < 3) {
printf("usage: %s <library> <number>\n", argv[0]);
exit(1);
}
char* libPath = argv[1];
int number = atoi(argv[2]);
void* libHandle = dlopen(libPath, RTLD_LAZY);
if (libHandle == nullptr) {
perror("dlopen failed");
exit(1);
}
typedef int (*func)(int);
func f;
f = (func)dlsym(libHandle, "perform");
if (f == nullptr) {
perror("dlsym failed");
exit(1);
}
printf("%d --> %d\n", number, f(number));
dlclose(libHandle);
return 0;
}

Library

extern "C" {
// C++ mangles function name. …

medium

Given a rows x cols screen and a sentence represented as a list of strings, return the number of times the given sentence can be fitted on the screen.

The order of words in the sentence must remain unchanged, and a word cannot be split into two lines. A single space must separate two consecutive words in a line.

Example 1:

Input: sentence = ["hello","world"], rows = 2, cols = 8
Output: 1
Explanation:
hello---
world---
The character '-' signifies an empty space on the screen.

Example 2:

Input: sentence = ["a", "bcd", "e"], rows = 3, cols =…

Poby’s Home

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store