Skip to content

Instantly share code, notes, and snippets.

internal static class Extensions
{
static unsafe string av_strerror(int error)
{
var bufferSize = 1024;
var buffer = stackalloc byte[bufferSize];
ffmpeg.av_strerror(error, buffer, (ulong)bufferSize);
var message = Marshal.PtrToStringAnsi((IntPtr)buffer);
return message;
}
@tqk2811
tqk2811 / DeepCopyExtension.cs
Last active April 5, 2024 15:53
DeepCopy and keep your pointer of class not change. Note: for IEnumerable<T> only support Array, IList, IDictionary and can't keep pointer of items.
public static class DeepCopyExtension
{
public static T CloneByJson<T>(this T obj, JsonSerializerSettings? jsonSerializerSettings = null)
{
return JsonConvert.DeserializeObject<T>(JsonConvert.SerializeObject(obj, jsonSerializerSettings), jsonSerializerSettings)!;
}
public static object? CloneByJson(this object obj, Type type, JsonSerializerSettings? jsonSerializerSettings = null)
{
return JsonConvert.DeserializeObject(JsonConvert.SerializeObject(obj, jsonSerializerSettings), type, jsonSerializerSettings)!;
@tqk2811
tqk2811 / YuvColorSpaceWindow.xaml
Last active March 13, 2024 03:22
wpf Yuv Color Space
<Window x:Class="Yuv.YuvColorSpaceWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
mc:Ignorable="d"
Title="YuvColorSpace" Height="470" Width="450">
<Grid>
<Rectangle >
<Rectangle.Fill>
@tqk2811
tqk2811 / background.js
Last active June 15, 2023 09:12
AutoLoginGoogleExt
chrome.runtime.onMessage.addListener(function (message, sender, callback) {
if (message && message == "close_tab_call") {
chrome.tabs.remove(sender.tab.id, function () {});
}
});
@tqk2811
tqk2811 / background.js
Created April 12, 2021 18:28
ProxyExt
var config = {
mode: "fixed_servers",
rules: {
singleProxy: {
scheme: "http",
host: "{host}",
port: "{port}"
},
bypassList: ["localhost"]
}
@tqk2811
tqk2811 / Extensions.cs
Last active April 26, 2023 13:15
LiveStream loop video
using System;
using System.Runtime.InteropServices;
using FFmpeg.AutoGen;
namespace StreamVideo.Ffmpeg
{
internal static class Extensions
{
static unsafe string av_strerror(int error)
{
CancellationTokenSource source = null;
void Run()
{
if(source?.IsCancellationRequested != false)//true hoặc source null
{
source?.Dispose();
source = new CancellationTokenSource();
}
Task.Run(() =>
//https://github.com/tqk2811/FFmpegArgs
FFmpegArg ffmpegArg = new FFmpegArg();
var colorInput = new FilterGraphInput();
colorInput.FilterGraph.ColorFilter().Size(new Size(width,height)).Color(Color.Transparent);
var colorVideo = ffmpegArg.AddVideoInput(colorInput,1,0);
var colorMap = colorVideo.ImageMaps.First();
List<ImageMap> maps = new List<ImageMap>();
@tqk2811
tqk2811 / 0_using.cpp
Last active April 26, 2023 13:13
NV12ToRgbShader
NV12ToRgbShader* shader = new NV12ToRgbShader();
if(shader->Init())
{
AVFrame* src = ...;
AVFrame* dst = ...;
if(shader->Convert(src,dst))
{
}
}
public static class AdbHelper
{
public static string AdbPath = "adb.exe";
public static MemoryStream ExecuteCommandBuffer(string command)
{
using(Process process = new Process())
{
process.StartInfo.FileName = AdbPath;
process.StartInfo.WorkingDirectory = Directory.GetCurrentDirectory();