Skip to content

Instantly share code, notes, and snippets.

@culurciello
Created October 3, 2014 01:44
Show Gist options
  • Select an option

  • Save culurciello/6000f736e77895eedd1e to your computer and use it in GitHub Desktop.

Select an option

Save culurciello/6000f736e77895eedd1e to your computer and use it in GitHub Desktop.
-- 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
@culurciello
Copy link
Author

use:
video = require("osxvideo"):init{ifile = opt.videoPath,
h = resolutions[opt.camRes].h, w = resolutions[opt.camRes].w}
frame = video:forward()

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment