Skip to content

Instantly share code, notes, and snippets.

@lambdan
lambdan / extract_highlights.py
Created December 29, 2020 17:03
extract highlights from video using list of timestamps
import os, subprocess, sys
# usage: extract_highlights.py <path-to-video> <path-to-timestamps>
# timestamps file format:
# hh:mm:ss bla bla bla
before_secs = 5 # secs to include before clip timestamp
after_secs = 25 # -"- after -" ... 5+25 = 30 sec clip
safe_chars = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ -0123456789."
@lambdan
lambdan / .zshrc
Last active November 29, 2020 22:36
zsh function to get absolute path to any file/folder using python3
# add this to to your .zshrc, then you can do `path file` to get the full path to that file, requires python
path() { python -c "import os;print(os.path.realpath(\""$1\""))" }
@lambdan
lambdan / extract_remove_cc.py
Created September 13, 2020 13:08
Extract EIA-608 CC embedded in video stream to SRT and remove from original file
# Requires ffmpeg and ffprobe
# Thanks to ffmpeg command from https://stackoverflow.com/a/51439554
delete_original = True # delete the original file?
sub_lang = ".eng"
import os, subprocess, sys, shutil
file = os.path.abspath(sys.argv[1]) # input file
@lambdan
lambdan / remove_cc.py
Last active August 29, 2020 21:09
Remove closed captions from h264 videos without quality loss using ffmpeg and ffprobe
# Requires ffmpeg and ffprobe
# Thanks to ffmpeg command from https://stackoverflow.com/a/51439554
delete_original = True # delete the original file?
import os, subprocess, sys, shutil
file = os.path.abspath(sys.argv[1]) # input file
if not os.path.isfile(file):
@lambdan
lambdan / suffix_video_info.py
Created July 12, 2020 19:05
Suffix video codec, resolution and bitrate to end of video filename
# Requires ffprobe and other-transcode (https://github.com/donmelton/other_video_transcoding) available in path
# Suffixes video info eg: video.mp4 ---> video (h264 720p 3000kbps).mp4
import sys, os, shutil, re
import subprocess
import json
import datetime
from subprocess import DEVNULL
# settings !
@lambdan
lambdan / irssi twitch.txt
Last active March 17, 2025 03:33
Twitch chat with irssi - October 2023
Tested working 15 Jun 2020, irssi version 1.2.2
(Update: still works October 2023!)
This is a TLDR version of https://blog.crunchprank.net/connecting-to-twitch-chat-via-irssi/
Get your OAuth token (password) here: https://twitchapps.com/tmi/
# Network setup:
/network add -nick YOUR_TWITCH_USERNAME Twitch
@lambdan
lambdan / Toggle macOS Screenshot Shadows.sh
Created June 6, 2020 17:25
Toggle macOS Screenshot Shadows
#!/bin/bash
# If you never disabled shadows before there will be an error on your
# first run because the disable-shadow key does not exist yet
current=$(defaults read com.apple.screencapture disable-shadow)
if [ "$current" -eq "1" ]
then
echo "Shadows are disabled, Enabling them..."
@lambdan
lambdan / timer_srt.py
Created May 9, 2020 16:41
Create SRT with timecodes to overlay speedrun for timing
from datetime import datetime
import os
# input your times
# HH:MM:SS.FFF
video_length = "00:06:42.984"
start_time = "00:00:20.649"
end_time = "00:06:05.899"
fps = 60
outfile = 'time.srt'
@lambdan
lambdan / UploadImage.py
Last active April 29, 2020 19:22
Upload image/screenshot to your web server with SCP and get resulting URL (Python 3)
import os
import subprocess
import sys
import hashlib
import webbrowser
from PIL import Image
import tempfile
def md5string(string): # https://stackoverflow.com/a/5297483
return str((hashlib.md5(string.encode('utf-8')).hexdigest()))
@lambdan
lambdan / gifit.bat
Created April 12, 2020 17:08
BAT file to create GIF using FFMPEG
@echo off
REM just do: gifit.bat video.mp4
REM and go on with your life
REM needs ffmpeg
ffmpeg -i "%1" -filter_complex "[0:v]scale=480:-1:lanczos,split [a][b];[a] palettegen [p];[b][p] paletteuse" "%~n1.gif"