Skip to content

Instantly share code, notes, and snippets.

ffmpeg -y -i $input_file$ -pass 1 -passlogfile $private_tmp_path$/$record_id$_2pass -s $width$x$height$ -vcodec libx264 -b 192k -bt 192k -flags +loop -cmp +chroma -partitions 0 -me_method epzs -subq 1 -trellis 0 -refs 1 -coder 0 -me_range 16 -g 300 -keyint_min 30 -sc_threshold 40 -i_qfactor 0.71 -maxrate 10M -bufsize 10M -rc_eq 'blurCplx^(1-qComp)' -qcomp 0.6 -qmin 10 -qmax 51 -qdiff 4 -level 30 -aspect 4:3 -acodec libfaac -ar 22050 -an $private_tmp_path$/$record_id$_pass1.mp4
ffmpeg -y -i $input_file$ -pass 2 -passlogfile $private_tmp_path$/$record_id$_2pass -s $width$x$height$ -vcodec libx264 -b 192k -bt 192k -flags +loop -cmp +chroma -partitions +parti4x4+partp4x4+partp8x8+partb8x8 -me_method umh -subq 7 -trellis 2 -refs 1 -coder 0 -me_range 16 -g 300 -keyint_min 30 -sc_threshold 40 -i_qfactor 0.71 -maxrate 10M -bufsize 10M -rc_eq 'blurCplx^(1-qComp)' -qcomp 0.6 -qmin 10 -qmax 51 -qdiff 4 -level 30 -aspect 4:3 -acodec libfaac -ar 22050 -an $private_tmp_path$/$record_id$_noqt.mp4
qt-faststart $private_tmp_p
def nearly_eq(value,target_value,off_by):
"""
an equality function with a margin for error (off_by)
"""
return target_value-off_by < value < target_value+off_by
def make_transparent(blob, threshold=210, tolerance=30):
r = png.Reader(bytes=blob)
(width,height,pixels,meta) = r.asRGBA8()
w = png.Writer(
@chrisfarms
chrisfarms / xmpplogging.py
Created March 12, 2011 23:35
Python logging handler to send error logs via XMPP/Jabber
from google.appengine.api import xmpp
import logging
import logging.handlers
import os
DEFAULT_FROM_JID = 'logs@%s.appspotchat.com' % os.environ['APPLICATION_ID']
class XmppLogHandler(logging.Handler):
def __init__(self, jid, from_jid):
def main():
from lib.xmpplogging import XmppLogHandler
XmppLogHandler.add('your@jabber.id')
run_wsgi_app(application)
@chrisfarms
chrisfarms / each.py
Created March 22, 2011 15:54
Function to map over all entities in a GAE query
from google.appengine.ext import db
def each(query, batch_size=100):
"""yields each entity in the query over the whole dataset in batches"""
entities = query.fetch(batch_size)
while entities:
for entity in entities:
yield entity
# if the query was keys only then the entity IS a key
if hasattr(entities[-1],"key"):
@chrisfarms
chrisfarms / basemodel.py
Created March 22, 2011 19:50
GAE base model class with to_json serialisation
SIMPLE_TYPES = (int, long, float, bool, dict, basestring, list)
class BaseModel(db.Model):
def to_json_friendly_value(self, v):
if v is None or isinstance(v, SIMPLE_TYPES):
value = v
elif isinstance(v, datetime.date):
# Convert date/datetime to ms-since-epoch ("new Date()").
ms = time.mktime(v.utctimetuple()) * 1000
@chrisfarms
chrisfarms / sencha-multiple-dv.js
Created May 3, 2011 11:14
Issue with multiple DataViews with one store
// Create a model (with any proxy)
Ext.regModel('Car', {
fields: ['id', 'name', 'sports'],
proxy: {
type: 'localstorage',
id : 'cars'
}
});
// Create a store to access the records
@chrisfarms
chrisfarms / HookedModel.py
Created May 22, 2011 21:33
async safe before and after save hooks for AppEngine db.Model
class HookedModel(db.Model):
def before_put(self):
logging.error("before put")
def after_put(self):
logging.error("after put")
def before_delete(self):
@chrisfarms
chrisfarms / ae.py
Created August 10, 2011 14:37
An google-appengine loading module to aid writing scripts for GAE
######################################################
# allow scripts to use appengine apis
#
# assumes you store your data in a "data" directory
# in your app directory. See connect_local_datastore()
# and assumes that you have a HRD app id with "~"
######################################################
#
# locate app-engine SDK:
AE_PATH = "/your/path/to/sdk/google_appengine/"
@chrisfarms
chrisfarms / console.py
Created August 10, 2011 14:41
An appengine python console
#!/usr/bin/env python
import getopt
import os
import ae
import sys
import code
def usage():
print """