#!/usr/bin/env pf # Using an external movie player (ffmpeg/mencoder) for input. # This script illustrates the use of open-program, which enables pf to connect # to the standard input/output of any unix program. Here ffmpeg (or mencoder) is # used to decode a movie file, and transfer the output to pf. load-image load-blit variable stream # the stream object variable movie # movie file name variable movtype # type description for raw stream # see wrapper scripts in libpf/bin # these dump raw video to stdout "pf-rawvideo.ffmpeg" # preferred # "pf-rawvideo.mencoder" # if your codec is not supported by ffmpeg variable! pf-rawvideo : dims 2 list (bitmap i420) swoncat movtype ! ; "( w h -- )\tInterpret raw stream from pipe using these dimensions." doc # assume this is standard 320 240 dims : open-movie pf-rawvideo @ movie @ 2 list movtype @ ' >string map list:+ # build command line "r" open-program stream ! ; # open stream : open movie ! # save movie filename open-movie ; "( name -- )\tOpen movie file." doc : grab movtype @ stream @ read-raw-packet # grab raw bitmap from stream >image ; # convert to image "( -- image )\tGrab next frame." doc : re-grab try grab recover drop open-movie grab endtry ; : tv open-movie { re-grab blit } is tick ; "( -- )\tPlay movie. Restart ffmpeg/mencoder after movie is done." doc cr "Raw video input demo" . cr cr "dims\t" . help dims "open\t" . help open "grab\t" . help grab "tv\t" . help tv cr interactive