#!/bin/sh
#
# Simple script to take a group of single frame images in PNM format and
# convert them into one large file called "raw_frames" in YUV format.
# This is then suitable for the "theora_encode" program to convert to output.ogg
# NOTE: the -V option on theora_encode controls the compression and also output
# quality, so the raw_frames file is not deleted because probably you want to 
# tinker with different encoding rates.
#
# Not all linux distributions actually install the "theora_encode" program with
# their theora package, so you may need to compile it yourself from the theora
# source -- it is listed as the example encoder.
#
# TODO: at some future stage, probably the pnm_YUV4MPEG2 program should be
# combined with parts of the theora_encode program and just access the theora
# library directly. This would avoid the intermediate frames file, and probably
# be a more useful program.
#


(
	# Magic header
	echo "YUV4MPEG2 W640 H480 F20:1 Ip A1:1 C420jpeg"

	for i in $(ls done_*.ppm | sort )
	do
		cat $i | ./pnm_YUV4MPEG2
	done

) > raw_frames

theora_encode -V 300 --soft-target --two-pass -o output.ogg --speed=0 raw_frames

# /bin/rm raw_frames

