#!/bin/sh## Usage:## jpg2h264 photos/foo/ bar# produces bar.mp4 from the directory photos/foo## prep the rotation of the images with this:# renrot --extension JPG --no-rename *# or perhaps with:# jhead -autorot## The aspect ratio is still foo, need to run convert or something#DIR=$1OUT=$2.mp4IMGEXT=JPGFPS=.8OUTFPS=25VFOPTS="scale=640:480"X264ENCOPTS="qp=20:threads=auto:subq=4:bframes=3:b_pyramid:weight_b:trellis=2:mixed_refs:frameref=5:8x8dct:me=umh:b_pyramid:subq=6:partitions=all:weight_b"LAVFOPTS="format=mp4"LAVCOPTS="vcodec=libx264"cd $DIRrm -f divx2pass.log# -lavfopts i_certify_that_my_video_stream_does_not_use_b_frames \# -vf $VFOPTS \mencoder \ "mf://*.$IMGEXT" \ -mf fps=$FPS \ -of lavf \ -lavfopts $LAVFOPTS \ -ovc x264 \ -x264encopts $X264ENCOPTS:pass=1 \ -of lavf \ -lavcopts $LAVCOPTS \ -ofps $OUTFPS \ -quiet \ -vf $VFOPTS \ -o "$OUT"exitmencoder \ "mf://*.$IMGEXT" \ -mf fps=$FPS \ -of lavf \ -lavfopts $LAVFOPTS \ -ovc x264 \ -x264encopts $X264ENCOPTS:pass=2 \ -lavcopts $LAVCOPTS \ -ofps $OUTFPS \ -quiet \ -vf $VFOPTS \ -o "$OUT"# mencoder muxing is apparently buggy. h264 supposedly can't do AVI and mplayer warns when this is used. This is default if nothing is specified but works fine with mplayer. Using the lines below you get a MOV but chatter says mencoder's MOVs aren't very compatible. And not using b_frames probably sucks. Garr.# -of lavf \# -lavfopts i_certify_that_my_video_stream_does_not_use_b_frames \# Macroblocks: QuickTime 7 does not support 8x8 DCT macroblocks. This option (8x8dct) is off by default, so just be sure not to explicitly enable it.# vdpart is listed in the man page, but complains: "Option x264encopts: Unknown suboption vdpart"# fast_pskip Performs early skip detection in P-frames (default: enabled). This usually improves speed at no cost, but it can sometimes produce artifacts in areas with no details, like sky.# nr=<0-100000> Noise reduction, 0 means disabled. 100-1000 is a useful range for typical content, but you may want to turn it up a bit more for very noisy content (default: 0). Given its small impact on speed, you might want to prefer to use this over filtering noise away with video filters like denoise3d or hqdn3d.#--subme 6, --partitions all, --trellis 1, --8x8dct, --ref 3, --mixed-refs# subq=6:partitions=all:8x8dct:me=umh:frameref=5:bframes=3:b_pyramid:weight_b# or to build with mplayer & `x264`#mkfifo "$2.y4m" #mplayer \# "mf://*.$IMGEXT" \# -mf fps=$FPS \# -noframedrop \# -vf $VFOPTS \# -vo yuv4mpeg:file="$2.y4m" \# -quiet # on another terminal run:# x264 foo.y4m -o foo.mkv