provide raw-player # this should be a central place for all video file related, except # for quicktime, which uses an in-core plugin. the interface is # roughly the same though. the interface revolves around a 'player' # and a 'recorder' set of words. # RAW VIDEO INPUT # use mencoder/ffmpeg as video input. this way, PF sets the image type # and dimensions, and the underlying encoder app will provide a # conforming raw video stream. : raw-player ( ` pf-rawvideo link-constant # player we're using ` encoding link-constant # bitmap encoding ` height link-constant # image hight & width ` width link-constant undef ` stream link-variable! # pipe to mencoder undef ` file link-variable! # filename : movtype ` bitmap encoding width height ; : rewind pf-rawvideo file @ movtype 6 list "r" open-program stream ! ; : open file ! rewind ; : readargs movtype 4 list stream @ ; : read readargs read-raw-packet ; ) create-binder ; : mp-player "pf-play.mencoder" raw-player ; : ff-player "pf-play.ffmpeg" raw-player ; # the most convenient way to interface is using the yuv4mpeg format # for the mjpegtools suite, which is a sort of de-facto standard for # simple raw video pipes. # RAW VIDEO OUTPUT # here i'm using ffmpeg to encode a raw video output. default is i420 # yuv, the rest will be set from the bitmap type. an ffmpeg invokation # taking raw video looks like: # ffmpeg -r 25 -s 320x240 -f rawvideo -vcodec mpeg4 -i pipe:.yuv : try-rmfile try rmfile recover 2drop endtry ; : raw-ffmpeg-recorder # ( file codec -- ) ( ` codec link-constant variable stream variable file variable commandline : . commandline queue ; : .. ' . for-each ; : build-commandline # ( width height -- ) () commandline ! (pf-ffmpeg -r 25 -s) .. swap >string "x" concat swap >string concat . (-f rawvideo -vcodec) .. codec . (-i pipe:.yuv) .. file @ . ; : openstream # ( width height -- ) build-commandline commandline @> "w" open-program stream ! ; : open file ! ; : create dup try-rmfile open ; : checkstream # ( packet -- packet ) stream @ undef = if typelist unpack 2drop swap openstream then ; : write checkstream stream @ write-raw-packet-buffered ; : close undef stream ! ; ) create-binder ; : mpeg4-recorder ` mpeg4 raw-ffmpeg-recorder ; # FIXME: buffered output # FIXME: yuv4mpeg