Skip to content

Instantly share code, notes, and snippets.

@porjo
porjo / retext.css
Last active August 13, 2018 03:54 — forked from elclanrs/retext.css
Markdown theme for ReText
body {
color: #333;
font-family: Arial, sans-serif;
max-width: 7.5in;
margin: 0 auto;
}
a:link, a:visited {
color: #1B70D1;
text-decoration: none;
@porjo
porjo / ffmpeg_recipies.md
Last active August 15, 2018 08:35
ffmpeg recipes

Mux mp4 + subtitles into an MKV

ffmpeg -fflags +genpts -i infile.mp4 -f srt -i subtitles.srt \
-map 0:0 -map 0:1 -map 1:0 -c:v copy -c:a copy -c:s srt outfile.mkv

-fflags +genpts necessary if you get Can't write packet with unknown timestamp errors.

Extract part of video using start + end times

@porjo
porjo / jq_cheatsheet.md
Last active November 16, 2017 04:09
jq JSON utility - cheatsheet

Apache Logs

Output entries between 2 times, showing IP and query

$ cat access_log.json | \
  jq -r 'select (.time > "2017-10-21T02:00:00.000Z" and .time < "2017-10-22T02:00:00.000Z") | [.remote_addr,.query] | @csv'

Output entries where client IP matches prefix

$ cat access_log.json | \
@porjo
porjo / busy-page.php
Last active December 14, 2017 02:32
Generate a simple HTML page showing which Asterisk extensions are idle or busy
#!/bin/php
<?php
#
# Generate a HTML page showing which extensions are idle and which are busy, together with number dialled
# Run this from crontab and redirect stdout to a file in /var/www/html
#
$Outfile = "/var/www/html/busy.html";
error_reporting(E_ALL & ~E_NOTICE);
@porjo
porjo / usage.sh
Last active July 3, 2017 02:46
Simple interface byte counter script for Linux
#!/bin/ash
#
# Track bytes in/out on selected interface
#
# Run this script once a month/week/day to calculate how much data usage occuring
# on given interface
#
STOR="bwmon.store"
STAT_DIR="/sys/class/net/$1/statistics/"
@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 / 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 / js_bracket_fix.md
Last active March 28, 2017 05:52
Fix open braces in Javascript file
sed ':a $!N;s/\n\s*{/ {/;ta P;D' <inputfile>
function()
{
@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 / 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 \