Created
January 11, 2020 22:37
-
-
Save vshmoylov/12b400e684123baa827fc830cfda10b2 to your computer and use it in GitHub Desktop.
Simple MJPEG timelapse lua script for Canon cameras runnung Magic Lantern firmware
This file contains 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
-- timelapse script for Magic Lantern firmware | |
require('dryos') | |
require('io') | |
function image_path(number, extenstion) | |
return dryos.dcim_dir.path .. dryos.prefix .. (number+dryos.shooting_card.file_number) .. extenstion | |
end | |
function main() | |
local frames_amount = 60 | |
local timelapse_interval = 1*1000 | |
menu.close() | |
console.show() | |
local initial_file_num = dryos.shooting_card.file_number | |
console.write("File num: " ) | |
console.write(initial_file_num) | |
console.write("\n") | |
local new_timelapse_file = image_path(1, ".MJP") | |
console.write("file: " .. new_timelapse_file .. "\n") | |
local videofile, err = io.open(new_timelapse_file, "wb") | |
console.write(videofile) | |
console.write("\n") | |
if err then console.write("error opening file: " .. err .. "\n") end | |
videofile:setvbuf("no") | |
for i = 1, frames_amount do | |
camera.shoot() | |
beep() -- keeps you awake :D | |
msleep(500) -- wait until frame is written to card, camera.wait() was unavailable in my env | |
-- below part is pretty slow, takes several seconds to complete | |
local current_file = image_path(0, ".JPG") | |
local latest_jpeg, err2 = io.open(current_file, "rb") | |
if (err2) then console.write("error jpeg file: " .. err2 .. "\n") end | |
local jpeg_data = latest_jpeg:read("*all") -- read all jpeg | |
videofile:write(jpeg_data) -- write current frame | |
jpeg_data = "" -- dereference jpeg data so gc can collect | |
latest_jpeg:close() | |
beep(2) | |
msleep(timelapse_interval-500) -- wait until next frame time comes | |
end | |
videofile:close() | |
console.show() | |
print "Timelapse done" | |
key.wait() | |
console.hide() | |
end | |
keymenu = menu.new | |
{ | |
name = "RAW MJPEG timelapse", | |
help = "WOW! Even good old 550D can do this!", | |
select = function(this) task.create(main) end, | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Hi, I am using your script in a 550D, but after finishing the timelapse, when try to open the MPJ video... I can´t open it. I have just achived once, with a nice video, but I have failed in the other cases. I am missing any configuration required? and do you think is possible to create another video format?
Nice script, thanks