Skip to content

Instantly share code, notes, and snippets.

View crearo's full-sized avatar
🥨

Rish Bhardwaj crearo

🥨
View GitHub Profile
@crearo
crearo / fragment_shader_NV12_to_RGB.frag
Last active December 5, 2025 13:35
A fragment shader to convert NV12 to RGB.
/** A fragment shader to convert NV12 to RGB.
* Input textures Y - is a block of size w*h.
* texture UV is of size w*h/2.
* Remember, both U and V are individually of size w/2*h/2, but they are interleaved.
* The layout looks like this :
* ----------
* | |
* | Y | size = w*h
* | |
* |________|
@crearo
crearo / fragment_shader_YUV420P_to_RGB.frag
Last active August 12, 2025 14:57
A fragment shader to convert YUV420P to RGB.
/** A fragment shader to convert YUV420P to RGB.
* Input textures Y - is a block of size w*h.
* texture U is of size w/2*h/2.
* texture V is of size w/2*h/2.
* In this case, the layout looks like the following :
* __________
* | |
* | Y | size = w*h
* | |
* |________|
@crearo
crearo / foreignKeyFlaskAlchemy.py
Last active May 8, 2024 23:12
A flask sqlalchemy database with foreign key references and integrity constraints
from flask import Flask, jsonify, request, make_response
from flask.ext.httpauth import HTTPBasicAuth
from flask_sqlalchemy import SQLAlchemy
from flask import render_template, redirect, url_for
from sqlalchemy import UniqueConstraint, exc
app = Flask(__name__)
app.config['SQLALCHEMY_DATABASE_URI'] = 'sqlite:///memes.db'
app.config['SECRET_KEY'] = 'HALO'
@crearo
crearo / ColorConversions.java
Last active February 4, 2024 17:06
YUV420P to RGBA8888 color conversion - with explanation as to why you may fail trying this in java
/**
* It took me a whole 6 hours to finally get the color conversion right.
* I have a fairly good understanding of the various color formats (YUV420P, SP, 422, etc etc),
* and how to access individual Y, U, and V components.
* I however struggled because of a very simple yet hair-pulling gotcha.
* All primitives in Java are signed! If you come from a Python-like world where 0xFF prints 255,
* you see yourself struggle just the same. I am however embarrassed at spending 6 hours on this.
*
* @author rish
*/
@crearo
crearo / gstreamer-recording-dynamic.c
Last active January 17, 2024 18:26
Example of dynamic pipeline in Gstreamer (recording + display). Stop recording at will by hitting ctrl+c.
#include <string.h>
#include <gst/gst.h>
#include <signal.h>
#include <unistd.h>
#include <stdlib.h>
#include <stdio.h>
// v4l2src ! tee name=t t. ! x264enc ! mp4mux ! filesink location=/home/rish/Desktop/okay.264 t. ! videoconvert ! autovideosink
static GMainLoop *loop;
@crearo
crearo / gstreamer-recording-dynamic-from-stream.c
Last active December 14, 2023 22:03
Example of dynamic recording of a stream received from udpsrc.
#include <string.h>
#include <gst/gst.h>
#include <signal.h>
#include <unistd.h>
#include <stdlib.h>
#include <stdio.h>
// udpsrc port=8554 caps="application/x-rtp, media=(string)video, clock-rate=(int)90000, width=(int)720, height=(int)480, encoding-name=(string)H264, payload=(int)96" !
// rtpjitterbuffer name=rtpjitbuff ! rtph264depay !
// tee name=t t. ! avdec_h264 ! appsink name=sink sync=false
@crearo
crearo / gstreamer-tee-recording-and-display.c
Created March 20, 2017 11:47
Example of tee in gstreamer. recording + display.
#include <string.h>
#include <gst/gst.h>
#include <signal.h>
#include <unistd.h>
#include <stdlib.h>
// v4l2src ! tee name=t t. ! x264enc ! mp4mux ! filesink location=/home/rish/Desktop/okay.264 t. ! videoconvert ! autovideosink
static GMainLoop *loop;
static GstElement *pipeline, *src, *tee, *encoder, *muxer, *filesink, *videoconvert, *videosink, *queue_record, *queue_display;
@crearo
crearo / gstreamer-recording.c
Created March 20, 2017 09:45
A Gstreamer example using GstElements to record a v4l2src stream.
#include <string.h>
#include <gst/gst.h>
#include <signal.h>
#include <unistd.h>
#include <stdlib.h>
// gst-launch-1.0 v4l2src ! x264enc ! mp4mux ! filesink location=/home/rish/Desktop/okay.264 -e
static GMainLoop *loop;
static GstElement *pipeline, *src, *encoder, *muxer, *sink;
static GstBus *bus;
@crearo
crearo / nosql-optimize-reads
Last active May 28, 2023 07:29
Big no to NoSQL: This showcases how it optimizes either reads or writes. You can't do both.
{
"users": [
{
"_id": "user1",
"email": "user1@example.com",
"name": "User One",
"gender": "male",
"friends": [
{
"_id": "user2",
@crearo
crearo / whatsapp-automater.py
Created June 3, 2018 13:14
Sends messages and calls a friend in a continuous loop to annoy them
#! /usr/bin/env python
'''
Created on June 3, 2018
@author: rish
This snippet sends messages or video calls a friend on Whatsapp.
This requires you to keep the Whatsapp chat page open for this to work.
'''