Skip to content

Instantly share code, notes, and snippets.

@pabloko
pabloko / 0000-ffmpeg 4.4 with NDI support (updated SDK, fixed timestamps errors).md
Last active February 2, 2024 18:11
ffmpeg 4.4 with NDI support (updated SDK, fixed timestamps errors)

update: https://framagit.org/tytan652/ffmpeg-ndi-patch use this patch. this gist is outdated

ffmpeg 4.4 with NDI

This patch adds libndi_newtek to last ffmpeg version, and fix timecode related issues that produces wrong PTS/DTS timestamps that seems to happen with newer NDI SDKs.

changes

  • Updated libndi methods by newer versions (v2/v3)
@pabloko
pabloko / serial.cpp
Created April 27, 2021 19:09
Lua 5.1 / luajit - Serial port library (rs232) [win/mac/linux]
//Using rs232 library: https://github.com/mrh1997/rs232/ by Frédéric Meslin, Florent Touchard
#include <Windows.h>
#pragma comment(lib, "kernel32")
#pragma comment(lib, "lua5.1.lib")
#include <lua.hpp>
#include "rs232.h"
char buffer[0xFFF] = { 0 };
BOOL luaopen_serial (lua_State* L)
{
@pabloko
pabloko / wicimagedecoder.hpp
Created February 22, 2022 08:39
Image Decoder based on WIC
/*
* Image decoder based on WIC
* ------------------------------------------------
* Provides synchronous loading of images and copy
* frames in ARGB format.
*
* Example of loading images:
* ImageDecoder::Init();
* ImageDecoder* img = ImageDecoder::FromFile("C:\\path\\to\\image.png");
* ImageDecoder* img = ImageDecoder::FromURL("http://example.com/img.jpg");
@pabloko
pabloko / 1.Query information from NT Handles of shared D3D11 Textures.md
Last active May 11, 2023 11:28
Query information from NT Handles of shared D3D11 Textures

Query information from NT Handles of shared D3D11 Textures

tl;dr: you can't. Only D3D12 and Vulkan resources expose API to query it's physical size

Looking into using the gl extension EXT_external_objects_win32 stumbled upon this <size> parameter in glImportMemoryWin32HandleEXT when using a D3D11 resources

tl;dr: Use 0 as size when using HANDLE_TYPE_D3D11_IMAGE_EXT / HANDLE_TYPE_D3D11_IMAGE_KMT_EXT

the driver implmentation will figure out the internal size of the resource. This size would be alignedWidth * alignedHeight * Bpp where alignment varies depending of the graphics card vendor, model and driver version.

To give some context, here are some values from my NV card with updated drivers

@pabloko
pabloko / AndroidJSInterfaceComplexTypes.java
Created December 8, 2018 13:20
Lets have any JSON serializable type and methods to callback on Android WebView's JSInterface
//How it works: all the script relies on a tiny javascript stub injected to webView's document that uses Proxy api and json serialicing stuff. Calls to our internal objects are proxified to a single method "__mm_handle_method", that using reflection find the target method and populate arguments exchanged in json, plus a custom interface for methods passed as argument.
package es.pabloko.webviewbridge;
import android.app.Activity;
import android.content.Context;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.util.Log;
import android.webkit.JavascriptInterface;
@pabloko
pabloko / 1-D3D9IEOverlay.md
Last active September 29, 2022 16:34
D3D9 Overlay with IE and alpha

D3D9 Overlay with IE and alpha

Many times working with Direct3D9, you want to build a simple GUI to overlay over your graphics, many libraries does this in some way but at some point you may want to use a web browser and options are much more limited. CEF is great, but heavy and IPC can be a real pain to handle, ultralight stopped supporting x86 arch... few other webui libs out there, they all have its pros and cons but we lost the sense of simplicity we wanted on first hand.

Then theres MSHTML (Internet Explorer) that is shipped on every windows os, enough versatile and fast to be used as overlay. Shamefully for Microsoft, this control never supported transparent background, even on .net webforms/WPF webbrowser depends from MSHTML and always cast a background.

This demo explores two ways to overcome this long standing issue and get 1bit alpha or 255bit alpha by color difference interpolation.

  • 1bit alpha: Uses green rgb(0,255,0) background that is simply keyed, can be used on boxed UI with less re
@pabloko
pabloko / ArtNet.cs
Last active September 1, 2021 01:15
[C#] Very simple Art-Net DMX sender-only class
using System;
using System.Net;
using System.Net.Sockets;
using System.Text;
namespace ArtNetDmx
{
class ArtNet
{
//Udp socket object to make requests
@pabloko
pabloko / usbhid.cpp
Created April 28, 2021 16:22
Lua 5.1 / luajit - Usb HID library (hidapi) [win/mac/linux]
//using hidapi library: https://github.com/signal11/hidapi/ by Alan Ott
#include <stdio.h>
#include <malloc.h>
#include "hidapi.h"
#pragma comment(lib, "setupapi.lib")
#pragma comment(lib, "hidapi.lib")
#include <Windows.h>
#include <lua.hpp>
#pragma comment(lib, "lua5.1.lib")
unsigned char buffer[0xFFF] = { 0 };
@pabloko
pabloko / readme.md
Created March 18, 2020 18:49
(C/C++) Embed file assets into binaries automaticly with VisualStudio build tasks

(C/C++) Embed file assets into binaries automaticly with VisualStudio build tasks

Sometimes developing apps, we need to reduce the build to a single exe containing handful of asset files, in this scenario, you can use the great library PhysFS that will let you zip everithing and load those files on runtime. We can further automatize this process by adding a VisualStudio Pre-build event that zips a custom folder, but also packs it on the final executable.

To start, locate your project folder and add a www asset directory and vendor directory, where we will put neccessary files 7z.exe, 7z.dll, objcopy.exe, www.bat 7zip will pack the files on a generated "resources.zip" this can be edited or even removed, it may even include the usage of zip password as PhysFS supports it. Objcopy, its part of some VS distributions and generated a .lib static library with the asset, exporting its start and end address.

Pre-build event: call "$(MSBuildProjectDirectory)\vendor\www.bat"

/vendor/www.bat (notice you w

Fast short previews from videos

Hi! as I needed to create bulk previews of long videos, like short cuts merged on one scaled video. As i searched for some examples to do this using ffmpeg, stumbled upon a common problem on every snippet there and here... long story short: seeking will make you waste a lot of time unless you seek cleverly.

This script will do the only fast seeking method seeming to work, -ss from input, pipe a chunk and exit that process. Several chunks are piped the encoder process that writes final file. Theres no temporary files, and if your source is h264, also no transcoding on input reading.