Created
October 3, 2014 01:44
-
-
Save culurciello/6000f736e77895eedd1e to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| -- E. Culurciello Oct 2014 | |
| -- video file loading in macos | |
| -- a cheap ffmpeg hack / alternative: | |
| require("image") | |
| local lfs = require "lfs" | |
| video = {} | |
| function video:init(args) | |
| self.ifile = args.ifile or assert(false) | |
| self.h = args.h or 640 | |
| self.w = args.w or 360 | |
| -- use ffmpeg to create a dir of images from a video file: | |
| -- ffmpeg -i video.mp4 -vf scale=640:360 -f image2 scratch/image-%3d.jpeg | |
| os.execute('mkdir scratch') | |
| print('ffmpeg -i "'..self.ifile..'" -vf scale='..self.w..':'..self.h..' -f image2 scratch/image-%3d.jpeg') | |
| os.execute('ffmpeg -i '..self.ifile..' -vf scale='..self.w..':'..self.h..' -f image2 scratch/image-%3d.jpeg') | |
| -- a table of filenames | |
| self.frames = {} | |
| self.idx = 3 -- to skip . and .. files in dir! | |
| -- load images from the list of files | |
| for file in lfs.dir('scratch') do | |
| -- file is the current file or directory name | |
| table.insert(video.frames,file) | |
| end | |
| return self | |
| end | |
| function video:forward() | |
| local frame = image.load('scratch/'..video.frames[video.idx]) | |
| video.idx=video.idx+1 | |
| return frame | |
| end | |
| return video |
Author
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
use:
video = require("osxvideo"):init{ifile = opt.videoPath,
h = resolutions[opt.camRes].h, w = resolutions[opt.camRes].w}
frame = video:forward()