Skip to content

Instantly share code, notes, and snippets.

@porjo
porjo / pulseaudio_rtp.md
Last active March 28, 2024 21:01
Use Pulseaudio to stream audio file to network via RTP

RTP Server

Setup

pacmd load-module module-null-sink sink_name=rtp format=s16le channels=1 rate=16000
pacmd load-module module-rtp-send source=rtp.monitor

This sets up a multicast socket for RTP streams. When I tested this was 224.0.0.56:46136

@porjo
porjo / dump_route53_records.md
Last active February 15, 2024 14:19
Export route53 records to CSV

Retrieve hosted zones with aws route53 list-hosted-zones then enter the zone Id below:

aws route53 list-resource-record-sets --hosted-zone-id "/hostedzone/xxxxxxxxxxx" | \
   jq -r '.ResourceRecordSets[] | [.Name, .Type, (.ResourceRecords[]? | .Value), .AliasTarget.DNSName?]  | @tsv'
@porjo
porjo / random_ip.go
Created February 11, 2019 00:12
Generate random IPs with Go
package main
import (
"encoding/binary"
"fmt"
"math/rand"
"net"
)
func main() {

My TrueNAS Scale server recently started throwing the following zfs module kernel panic on boot:

PANIC at space_map.c:405:space_map_load_callback()

What follows are the steps I took to retrieve the data from the corrupted zfs pool.

Getting setup

@porjo
porjo / ipset_update.sh
Last active June 8, 2023 12:49
Create Geo fencing country blocks for use by iptables
#!/bin/bash
#
# Update the ipset that iptables references for allowing/blocking based on country.
# Takes 2 parameters: ipset name (no spaces), country name e.g. 'Australia'
#
# iptables should have an existing '--match-set' rule e.g
# $ iptables -I INPUT -p tcp --dport 22 -m set --match-set australia4 src -j ACCEPT
# $ ip6tables -I INPUT -p tcp --dport 22 -m set --match-set australia6 src -j ACCEPT
#
@porjo
porjo / timelapse.md
Last active May 25, 2023 16:14
ffmpeg time-lapse

Convert sequence of JPEG images to MP4 video

Simple glob:

ffmpeg -r 24 -i '*.JPG' -s hd1080 -vcodec libx264 timelapse.mp4

Start from DSC_0079.JPG

ffmpeg -r 24 -f image2 -start_number 79 -i DSC_%04d.JPG -s hd1080 -vcodec libx264 timelapse2.mp4
#!/usr/bin/perl
# Credit to Ryan Barnett at Spiderlabs.com for original idea
#
# Usage: modgrep.pl -a <logfile>
# -s <search keyword> (optional)
#
use strict;
use warnings;
use Getopt::Std;
@porjo
porjo / capture.md
Last active May 3, 2022 22:18
Capture video + audio using EasyCAP USB analog to digital converter
  • Capture audio from device1 (hw:1)
  • Capture video from /dev/video0 as PAL (720x576 50hz)
  • de-interlace (yadif)
  • encode video using 'fast' preset (using slow was getting dropped frames)
  • encode audio as AAC 128kb

software encoding

ffmpeg \
@porjo
porjo / hwaccel.md
Last active July 16, 2020 04:00
Hardware accelerated video encoding with ffmpeg

Using ffmpeg-3.1.6-1.fc25.x86_64 on Fedora 25, available from rpmfusion-free repo. It has been built with va-api support.

The following ffmpeg invocation works for me.

ffmpeg -hwaccel vaapi -hwaccel_output_format vaapi -vaapi_device /dev/dri/renderD128 \
   -i input.mkv -vf 'format=nv12,hwupload' -map 0:0 -map 0:1 -threads 4 \
   -acodec copy -vcodec h264_vaapi -qp:v 23 \
   output.mp4
@porjo
porjo / phpredis_pecl_centos6.md
Last active February 6, 2020 04:33
how to install phpredis on Centos6 using pecl

How to install phpredis extension on Centos6 using pecl:

# Enable EPEL repository
yum install epel-release

# Install Autoconf v2.68
yum install autoconf268

# Install the extension