Skip to content

Instantly share code, notes, and snippets.

@aferriss
aferriss / xmlProcess.py
Last active March 7, 2016 23:34
Formatting bad processing docs.
import sys
import re
from BeautifulSoup import BeautifulSoup
def processFile(filename):
print "reading and writing from: " + str(filename)
file = open(filename, "r+")
#lines = file.readlines()
@aferriss
aferriss / readFile.py
Created December 8, 2015 03:44
read a big file in python
with open("myFile.txt") as f:
for line in f:
print line
@aferriss
aferriss / svhn.py
Created December 9, 2015 00:33
Small script for extracting images out of the svhn dataset
import scipy.io
import numpy as np
from PIL import Image
np.set_printoptions(threshold=np.nan)
mat = scipy.io.loadmat('train_32x32.mat')
arr = np.array(mat["X"])
for i in range(5000):
@aferriss
aferriss / ffmpegImageSeqToMp4
Last active March 7, 2016 23:26
ffmpeg command for creating video from image sequence
ffmpeg -f image2 -framerate 15 -i %05d.jpg -c:v libx264 -pix_fmt yuv420p -r 15 128Mov2.mp4
# -r forces framerate
# -f image2 tells ffmpeg its an image sequence
@aferriss
aferriss / ffmpeg loop video
Last active July 3, 2020 23:55
ffmpeg loop video
for i in {1..60}; do printf "file '%s'\n" 128Mov2.mp4 >>list.txt; done
ffmpeg -f concat -i list.txt -c copy output.mp4
@aferriss
aferriss / ffmpegTitleBars
Last active March 7, 2016 23:24
ffmpeg add black bars
ffmpeg -i 128Mov2Cat.mp4 -vf pad=1280:800:576:336 128Mov2CatBars.mp4
#default pad is black
#pad=width:height:x:y
@aferriss
aferriss / ffmpegLZW
Created March 7, 2016 22:36
ffmpeg lzw compression - from Jennifer Steinkamp
ffmpeg -i in.%%04d.tif -compression_algo lzw out.%%04d.tif
@aferriss
aferriss / mogrifyLZW
Created March 7, 2016 22:38
imageMagick LZW
mogrify -path outFolder -depth 16 -endian msb -compress lzw rawImages/*.tif
#outFolder is a newFolder where images will be saved
#rawImages is a folder where the images to be compressed are stored.
@aferriss
aferriss / ffmpegPipeIO
Last active March 7, 2016 23:18
ffmpeg pipes for render without saving
#I think it might be possible to do this all in a single shell by using single ampersand (&) at end of each command
#make two pipes
mkfifo /tmp/pipe1 /tmp/pipe2
#send input1 to pipe1
ffmpeg -y -i input1.mp4 -c copy -f nut /tmp/pipe1
#open a new shell window/tab
#send input2 to pipe2
@aferriss
aferriss / ffmpegVideoCompress
Last active March 7, 2016 23:38
ffmpeg compress video to MP4
ffmpeg -i input.mov -c:v libx264 -maxrate 20000k -bufsize 3000k -pix_fmt yuv420p -crf 24 out.mp4
# see here https://trac.ffmpeg.org/wiki/Encode/H.264
# -pix_fmt may not be necessary but I use it sometimes for backwards compatibility.
# -bufsize tells ffmpeg how often to check that bitrate is at the requested rate
# -crf is not necessary but can get videos really small if set >30 (at the expense of quality)