Output Frame Sync signal via LED or audio out?

Started by bjorneeE, October 21, 2013, 06:12:46 PM

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

bjorneeE

Is it possible to output a frame sync signal when filming, regardless of frame rate, either via LED or audio output?

I was reading yesterday about this open source film scanner
http://www.redsharknews.com/technology/item/946-this-is-what-the-world-really-needs-an-open-source-film-scanner

I have some analogue film that needs unexpensive digitizing, I've tried just filming the sceeen for a start - frames constantly drift in and out of sync. Almost useless.

One way to success would be to sync the projector (or equivalent device) to the camera so that you flash each frame when the sensor is being exposed (slow shutter speed) but then you need a sync signal! Either (preferably) high during the whole exposure, or a strobe.
This would also come in handy if you want so use strobe lighting!

I'vs seen other threads regarding sync
http://www.magiclantern.fm/forum/index.php?topic=1596.0
http://www.magiclantern.fm/forum/index.php?topic=6907.0

Is it at all possible?

Cheers!
BjornEEE

a1ex

With the LED it takes 2-3 lines of code, anyone with minimal C skills can do this. Simply toggle the LED from some vsync hook.

With audio it's a little harder, not sure how big is the lag for audio playback.

bjorneeE

Ok! -Then Sync Output via LED is indeed a feature request!  :)
Living in hope! //BjE

rosteu

Hello!

Since this is my first post I'll start with a Massive Thank You to all the contributors to the ML project!!!

I'm a phd-student and I have been using magic lantern for building a microscope. It's working really well, but to take the project to the next level, I need to time some events to the frame rate and keep in sync for a couple of minutes. Therefore any kind of frame-synced output from the camera during video recording would be extremely useful! I also imagine that any diy-oriented project involving magic lantern would benefit a lot from an output sync.

It has been discussed earlier, and mentioned as a matter of  "...2-3 lines of code..." (http://www.magiclantern.fm/forum/index.php?topic=8912.0). I have some basic coding experience but none in the ML-environment, therefore I'm starting out by reiterating that old feature request :)

/arvid

vonj

TL/DR:  I need some kind of frame sync output, LED would be nicest.

I am building a film scanner, for 35mm (and maybe later 16mm) film.

The idea is to take a picture across the width of the film, through a thin slit.

Then advance the film a tiny increment with a stepper motor, repeat.

Each captured image would represent only one line of the scanned film. For a "2K" width scan, you'd want maybe 3000 lines per (still image) or 1500 lines for a 2 perf cine image.

Just to be clear, each taken image would in my post processing throw away almost all of the image data. For instance a 1920x1080 picture would be converted to a "1920x1" image and then 3000 of those would be assembled into one "1920x3000".

I could do this with still images but it would take a million years and 3000 still images.

Something MUCH nicer would be to use video, but then the question comes about syncing camera frames with advancement of film. (With the stepper motor.)

The nicest, cleanest way would be if the camera outputs a pulse on the LED each video frame it captures. Then I can strobe a lightsource behind the film each time.

There are other ways to try to compensate in post, for instance by advancing the film more slowly and oversample (or something), but it would be slowing down an already slow process and add a lot of complexity.


I can program in C, I have done embedded programming etc, but it feels very daunting to cold start where to find my way in the codebase - help deeply appreciated.

I also think this feature would be very welcome for other purposes, like trick filming and motion control rigs.


a1ex

Start here:

https://www.magiclantern.fm/forum/index.php?topic=991
https://www.magiclantern.fm/forum/index.php?topic=19232

Then, look for CBR_VSYNC in other modules. That's a function called once for each LiveView frame (right after the image readout). Toggle the LED state from there.

You could also program a small LED pulse for each LiveView frame, but you need to be careful - the CBR routine must return very quickly; you cannot use a sequence like led_on(); delay(10ms); led_off(), as it will be too slow and will interfere with LiveView timings. You can, however, use SetHPTimerAfterNow() to schedule a led_off() later, e.g. after 5 ms; that would happen from an interrupt (i.e. outside regular DryOS tasks).

If you need this to work while recording, you'll have to block the regular LED activity. That's doable, but requires hooking in Canon's file I/O routines (where they turn on the LED).

Next, find a good name for this module (to fit in 8 characters), find a good place for it in the menu, and publish it.

Side note: there is some highly experimental support for the VSync event in Lua, but it's disabled by default. Reason: this code needs to be very fast, as it runs in sync with Canon's LiveView.

vonj

Thank you so much for giving me pointers. This looks possible to do for me. Though, I think I do need to blink some LED while recording, how else can I dump my data to a file? Could I get a couple of lines in LiveView and save it out as JPEG? Even low or medium quality JPEG is probably fine, since I need only a line?

The reason I was thinking about video recording, is that you easily get 24-30 fps and the camera already provably can save video to the SD card fast enough. So I assumed I have to use video recording.

But are you implying I could just let the camera linger in LiveView and I could save image data myself instead?

Quote from: a1ex on May 18, 2019, 08:31:26 AM

If you need this to work while recording, you'll have to block the regular LED activity. That's doable, but requires hooking in Canon's file I/O routines (where they turn on the LED).

a1ex

Right - for your use case, you only need a slit-scan image. The silent picture module implements one, and only saves the final image at the end, so... you can just add the LED blink in the vsync routine from there.

Caveat: the silent picture implementation is limited to LiveView resolution (i.e. it's not going to save a very tall picture, if you need that). Can be done by tweaking the memory allocation calls.

vonj

Quote from: a1ex on May 18, 2019, 11:42:21 PM
Right - for your use case, you only need a slit-scan image. The silent picture module implements one, and only saves the final image at the end, so... you can just add the LED blink in the vsync routine from there.

Caveat: the silent picture implementation is limited to LiveView resolution (i.e. it's not going to save a very tall picture, if you need that). Can be done by tweaking the memory allocation calls.

I need as wide a picture as possible, tall is irrelevant. 1 line high would suffice, but makes it harder to calibrate the camera to hit the slit. 100 pixels tall or something would probably be perfect.

Do you think silent picture can take pictures at say, 25 or 30 fps? (Or, even higher?! The higher the better, really.)

Another thought I had - could the yellow front LED be blinked instead of the red SD card LED?

(Or some other output altogether, like audio out? But I read somewhere that there could be timing problems with audio out.)


Ignoring my usecase and thinking about motion control rigs in general, video recording is best, of course.


a1ex

Yellow front LED - I only know how to control it on the EOS M2 (where it's red). It's not under direct control of the main CPU. What camera are you using, btw?

Audio out could work. Timing issues were just something to watch for; I don't think anybody actually tested this method. At the hardware level, this is done with DMA transfers; if the sound pulse is computed in advance, it may actually work just fine. Caveat: some camera models are not able to play beeps from ML yet; it needs further reverse engineering.

Wide picture at high frame rate: this is already available on 5D3, with regular crop_rec_4k builds: 5796x400 @ 48 fps. I plan to implement this on all camera models, just not sure how much each camera is going accept (i.e. height vs frame rate).

I was also thinking about triggering image acquisition from half-shutter signals (i.e. some sort of genlock). These signals are forwarded by the MPU to the main CPU, so there will be a delay - need to measure it somehow (or at least the jitter). Or from mic input, but we'd have to monitor that signal with polling, i.e. not "too often", to avoid interference with DryOS task scheduling. Or there might be some useful signals on the USB/AV jack (unexplored territory).

vonj

Quote from: a1ex on May 19, 2019, 08:25:20 AM
Yellow front LED - I only know how to control it on the EOS M2 (where it's red). It's not under direct control of the main CPU. What camera are you using, btw?

Audio out could work. Timing issues were just something to watch for; I don't think anybody actually tested this method. At the hardware level, this is done with DMA transfers; if the sound pulse is computed in advance, it may actually work just fine. Caveat: some camera models are not able to play beeps from ML yet; it needs further reverse engineering.

Wide picture at high frame rate: this is already available on 5D3, with regular crop_rec_4k builds: 5796x400 @ 48 fps. I plan to implement this on all camera models, just not sure how much each camera is going accept (i.e. height vs frame rate).

I was also thinking about triggering image acquisition from half-shutter signals (i.e. some sort of genlock). These signals are forwarded by the MPU to the main CPU, so there will be a delay - need to measure it somehow (or at least the jitter). Or from mic input, but we'd have to monitor that signal with polling, i.e. not "too often", to avoid interference with DryOS task scheduling. Or there might be some useful signals on the USB/AV jack (unexplored territory).


I'm using a Canon 100D.

If I find a solution which fits my camera, it would be nice and I'll take it. Would be even cooler if people could build a cheap film scanning device all over the world with any ML capable camera.

With high horizontal resolution, I mean about 2k and up.

In raw video mode, I notice that my 100D goes to max 1728 resolution. Is that also the max resolution I can expect in full resolution silent pictures?
(1728 is OK for motion picture scanning but a bit low for stills pictures.)

I am still leaning towards that recording regular video (not raw) with some kind of sync output is best. But is it possible to hook into frame sync for regular video recordning, or only for MLV recording?

Danne

Quote from: vonj on May 19, 2019, 12:05:10 AM
I need as wide a picture as possible, tall is irrelevant. 1 line high would suffice, but makes it harder to calibrate the camera to hit the slit. 100 pixels tall or something would probably be perfect.

Do you think silent picture can take pictures at say, 25 or 30 fps? (Or, even higher?! The higher the better, really.)
Not at all familiar with thsi concept but you could check this build for 100D:
https://www.magiclantern.fm/forum/index.php?topic=16040.msg208816#msg208816

The 4k setting could probably be modified to 24 fps and even broaden. That is height could be sacrificed. So could you be more specific maybe about width/height/fps and maybe I can test to build it.

vonj

Quote from: Danne on May 19, 2019, 02:18:38 PM
Not at all familiar with thsi concept but you could check this build for 100D:
https://www.magiclantern.fm/forum/index.php?topic=16040.msg208816#msg208816

The 4k setting could probably be modified to 24 fps and even broaden. That is height could be sacrificed. So could you be more specific maybe about width/height/fps and maybe I can test to build it.

I need as high fps as possible and as high width as possible. Height is completely irrelevant, 1 pixel high would be OK. I guess it needs to be 16 pixels high or something? The lower height the better, because I will throw away almost all rows of pixels anyway when scanning.