motioncam icon indicating copy to clipboard operation
motioncam copied to clipboard

Is it possible to use Motion Cam for RAW video?

Open tomurtogu opened this issue 3 years ago • 110 comments

Hello, Thank you for the project.

I was developing a similar app for personal use. What I want to do is recording a 10-15 second DNG sequence in RAW10 format at 24FPS with 1/48 shutter speed. For this, I wanted to create a buffer and empty a certain part of it during shooting and reuse it. But I couldn't do it because it was too complicated for me. Looks like you've already done the important part. Do you have any plans to develop your app so that it can be used for video as I mentioned?

tomurtogu avatar Aug 22 '21 13:08 tomurtogu

What would you want to do with the 10-15 seconds of RAW10 data? Keep in mind on a 12 MP sensor 15 seconds worth of RAW10 data is over 5GB.

mirsadm avatar Aug 23 '21 10:08 mirsadm

Hi, thank you for the response.

A movie usually consists of combination of 10-15 seconds of parts. I want to make a short film and this duration is enough for me. RAW10 data takes up a lot of space, but believe me, 5GB size is nothing for cinema and video production (I am recording about 80-90GB data for a daily videologs). With RAW video recording, mobile phones can turn into a great cinema camera with other practical features (portability, integrated battery, light weight, high-resolution touch screen, etc.).

Raw video is "Holy Bowl" of the cinema production. You can check these links: https://www.raspberrypi.org/forums/viewtopic.php?t=296776 https://magiclantern.fm/

tomurtogu avatar Aug 26 '21 12:08 tomurtogu

Smartphones and raw video! A revolutionary and long-awaited feature. Hopefully soon an app will make this possible.

Mrdoumhann avatar Aug 30 '21 13:08 Mrdoumhann

SAF storage access framework could be used to set the save path to an SDcard or even USB storage. Open Camera has this as an option but defaults to saving under DCIM for simplicity. Assuming the storage device is fast enough to not choke this could improve the usefulness of taking even short clips since one might take a few of them at a go and rapidly fill internal storage.

locuturus avatar Oct 10 '21 20:10 locuturus

I think the storage + amount of RAM on most modern devices is actually enough to be able to write RAW video. I've been thinking about this recently and it would be possible but would require a lot of RAM and a reasonably recent flagship device. It is something I'd like to explore. I don't know much about RAW video though, what file format is commonly used?

mirsadm avatar Oct 16 '21 10:10 mirsadm

I think there is no dominantly used format. I read through this stackexchange thread and I see that for the most part people start with the format provided by their camera OEM.

But there are some open standards:

  • Cineform is open source, compressed raw. GoPro uses it, seems to compare well to Apple Prores in a quick Google search
  • CinemaDNG is an open standard by Adobe, each frame is a DNG image
  • FFV1 is open source, lossless compressed codec built by ffmpeg

I think the above are all called intermediate codecs. Someone would start with the proprietary OEM raw video, but optionally they might convert to one of the many intermediate codecs to do their processing before then exporting to a lossy delivery codec.

locuturus avatar Oct 16 '21 17:10 locuturus

One possibility, which would be the easiest for me to implement, would be to create a ZIP of all the frames as DNG files. Would that be useful? I can see through a quick Google search that certain apps (Resolve) seem to be able to import them.

mirsadm avatar Oct 18 '21 11:10 mirsadm

Hello, correct frame rate and shutter speed combination is the most important part of cinematic video ( 24fps - 1/48 shutter speed or 25fps - 1/50 shutter speed) If this part is okay than there is no problem with dng files. Almost all editing softwares supports importing dng files as a dng sequences. Also I think there is no reason to zip dng files at all. Just store all files related to shot in their own folder for practical usage.

Mrdoumhann avatar Oct 18 '21 13:10 Mrdoumhann

I've managed to get it to work. On my device (OnePlus7 Pro) I can record about 30 seconds before running out of memory. The storage is not quite fast enough to be able to keep up in real time. Still 30 seconds of footage is over 10 GB. I need to write a small tool to convert the output into DNG then I'll upload a test version.

mirsadm avatar Oct 19 '21 20:10 mirsadm

Wow! 30 seconds recording time is really impressive for raw video. I can't wait to try it!! I do not know it is possible but if you able to crop raw sensor data to another aspect ratio (16:9-3840x2160 or 2.35:1-3384x1440) before convert to dng format there is a big potential for get small video sizes.

Mrdoumhann avatar Oct 20 '21 03:10 Mrdoumhann

I've put up a test build here: https://github.com/mirsadm/motioncam/releases

Couple of things to note:

  1. The app records a ZIP file to the internal storage Documents folder.
  2. The ZIP file needs to be converted to a set of DNG files. I've written a tool that will do that which is here: https://github.com/mirsadm/motioncam/tree/main/bin/mac

I've only compiled it for an x86 Mac for now. I'll look into creating a Linux binary as well. Otherwise the source code for it is here: https://github.com/mirsadm/motioncam/tree/main/raw2dng

mirsadm avatar Oct 21 '21 13:10 mirsadm

Hello I tried the application but did not get a successful record. The application crashes after pressing stop button so I cannot obtain any zip file.

I tried some of shots with increasing/decreasing amount of memory but the result did not change.

My phone is Redmi Note 7 4GB

Also, there is no place where we can set the frame rate yet. What is the default frame rate which the application records?

Mrdoumhann avatar Oct 21 '21 15:10 Mrdoumhann

The frame rate is currently fixed at 30 FPS. I forgot to mention that you should disable dual exposure controls. Does it crash if you start and stop in one second? Are you able to provide adb logs?

mirsadm avatar Oct 21 '21 16:10 mirsadm

Pixel 4a on Android 12. Turned off dual exposure, recorded ~9 sec (very laggy preview but no crash) and I see a zip with 177 frames inside. So far so good! No idea yet how it looks I'll have to get that all converted first.

locuturus avatar Oct 21 '21 17:10 locuturus

@locuturus I'm guessing it did drop some frames. It is a bit too aggressive in trying to compress the frames before writing to disk. It might be too much for that particular SOC.

Next I will look to add the ability to crop the frame, even 16:9 would be a significant saving in IO bandwidth. Also adding the ability to control the frame rate. 24 fps would also make a big difference.

mirsadm avatar Oct 21 '21 19:10 mirsadm

I got the raw2dng utility to build and run on Arch Linux using this CMakeLists.txt file. The file goes in motioncam/raw2dng. I don't really know much about build systems and got this working by trial and error, so I'm sure there are lots of things done incorrectly.

./setupenv.sh must have been run successfully, and OpenCV must be installed, before building this.

On this line in CameraProfile.h I had to replace __unused with __attribute__((__unused__)) to get it to compile - apparently it's defined in a OSX header but not on Linux.

I am also testing with a Pixel 4a (not the newer 5G version). Only recorded a couple seconds to try it so far.

paolodepetrillo avatar Oct 22 '21 01:10 paolodepetrillo

Ah great. Thanks for that. I'll set up CMake with that as a reference when I get a chance. FYI I changed the location of some of the code so it'll break your CMakeLists.txt in case you pull the latest code.

@locuturus @Mrdoumhann There's a new release out at https://github.com/mirsadm/motioncam/releases I added the option to toggle the frame rate and crop the sensor output vertically. On my device I can record a longish video at 30% crop at 24 FPS. That's cropping from 4000x3000 (12MP) to 4000x2100 (8.4MP).

mirsadm avatar Oct 22 '21 11:10 mirsadm

Hello, I tried the new version but sadly crashed again. It seems that there is an issue on writing to documents folder which did not exist as default. I created it manually. Here is the error log:


Build fingerprint: 'xiaomi/lavender/lavender:10/QKQ1.190910.002/V12.0.1.0.QFGCNXM:user/release-keys' Revision: '0' ABI: 'arm64' Timestamp: 2021-10-22 21:13:51+0300 pid: 12148, tid: 12262, name: com.motioncam >>> com.motioncam <<< uid: 10397 signal 6 (SIGABRT), code -1 (SI_QUEUE), fault addr -------- Abort message: 'terminating with uncaught exception of type motioncam::IOException: Can't create /storage/emulated/0/Documents/VIDEO_20211022_211351_0.zip' x0 0000000000000000 x1 0000000000002fe6 x2 0000000000000006 x3 0000007f14f5a9f0 x4 fefeff7ea3756c3f x5 fefeff7ea3756c3f x6 fefeff7ea3756c3f x7 7f7f7f7fff7f7f7f x8 00000000000000f0 x9 d178c6176b07c4ba x10 0000000000000001 x11 0000000000000000 x12 fffffff0fffffbdf x13 000000006172ff5f x14 0014a36116d1d611 x15 00007076487f47be x16 0000007fa47988c0 x17 0000007fa4774900 x18 0000007ecaa84000 x19 0000000000002f74 x20 0000000000002fe6 x21 00000000ffffffff x22 ffffff80ffffffc8 x23 0000007f14f5ac40 x24 0000007f14f5ab20 x25 0000007f14f5ab60 x26 0000007f14f5c020 x27 0000007f14f5b5f8 x28 0000000000000002 x29 0000007f14f5aa90 sp 0000007f14f5a9d0 lr 0000007fa47260c4 pc 0000007fa47260f0

backtrace: #00 pc 00000000000830f0 /apex/com.android.runtime/lib64/bionic/libc.so (abort+160) (BuildId: 328a3518945f3e056fc055f1eea1cc35) #01 pc 00000000000cec88 /data/app/com.motioncam-c97Es_1oEa5VKQSPdDHtRQ==/base.apk!libc++_shared.so (offset 0xa63000) (BuildId: 6e8a2cc265a0f94db25dde860981c546dca61a70)

Mrdoumhann avatar Oct 22 '21 18:10 Mrdoumhann

@paolodepetrillo I've pushed the CMake files. If you run ./setupenv.sh it'll build the tool to convert the ZIP -> DNG files automatically (stored in ./tools/bin/convert).

@Mrdoumhann Ah! Yeah at least that's a simple one to fix. Did it start recording once you created the Documents folder? It might be an issue with newer versions of Android not allowing apps to write there anymore. I need to look into that.

mirsadm avatar Oct 22 '21 20:10 mirsadm

Hello, no it did not started to record, crashed again. Maybe you must record into DCIM folder which other camera apps uses without problem.

Mrdoumhann avatar Oct 22 '21 21:10 Mrdoumhann

For what it's worth my Pixel 4a records just fine into the Documents folder on Android 12.

locuturus avatar Oct 22 '21 22:10 locuturus

The application you have published on Play Store runs without any problems, but this one crashes because Documents folder is not available by default on some Android devices like Xiaomi Redmi Note. If the user creates the directory manually, "IOException" will thrown due to your application does not have permission to write to this directory. So I recommend using the DCIM folder reserved for media.

tomurtogu avatar Nov 02 '21 11:11 tomurtogu

Yep, writing to the Document folder was always a hack just to test this feature. What I intend on doing is to save to the apps private storage area first then save the DNGs out to the DCIM folder afterwards.

mirsadm avatar Nov 03 '21 11:11 mirsadm

hi, i also tried, i think is crushing because lack of permissions maybe?>

xtrul avatar Nov 13 '21 21:11 xtrul

I've put up a test build here: https://github.com/mirsadm/motioncam/releases

Couple of things to note:

  1. The app records a ZIP file to the internal storage Documents folder.
  2. The ZIP file needs to be converted to a set of DNG files. I've written a tool that will do that which is here: https://github.com/mirsadm/motioncam/tree/main/bin/mac

I've only compiled it for an x86 Mac for now. I'll look into creating a Linux binary as well. Otherwise the source code for it is here: https://github.com/mirsadm/motioncam/tree/main/raw2dng

Can you please repost the zip to dng conversion tool? I'm getting a 404. Thank you and keep up the great work!

owlgreens avatar Nov 16 '21 21:11 owlgreens

I'm almost done with an update that will convert the files to DNG on the device itself after they are captured. The utility needs to be compiled at the moment. I will let you guys know when it's done.

mirsadm avatar Nov 17 '21 10:11 mirsadm

@owlgreens I've uploaded a new release here https://github.com/mirsadm/motioncam/releases/download/6.0.3-alpha0/MotionCam.6.0.3-alpha0.apk

It will convert the video to DNG on the device after capture

@akirayui I'm hoping this will also fix your problem with the Documents folder

mirsadm avatar Nov 21 '21 21:11 mirsadm

Wow is working!

Is it possible to capture ALL the frames into folder instead of zips? also is possible to convert outside of the phone? because it takes a lot of time to convert even on a fast soc...

Can you please add focus lock, manual focus, 1fps mode(for timelapses), a way how to convert outside the app, better capture structure

example: for 25second of recording, are created 6 folders, and each folder has 4 zips(and each folder start from frame0), is there a chance to make it more linear?

For some reason on other phones is not working, but some crazy falks got pretty crazy about this app on telegram https://t.me/AMVR_en

Congrats i am still shocked... wow and again wow

xtrul avatar Nov 21 '21 22:11 xtrul

That's cropping from 4000x3000 (12MP) to 4000x2100 (8.4MP).

Add scaling also, to get 3840x2160 or something close And software binning options for 2000x1050 as example 2021-05-22 12_07_04-IMX378_Software_Reference_Manual_0 0 1 寄存 (3) pdf - Adobe Acrobat Pro image

eszdman avatar Nov 22 '21 11:11 eszdman

The app doesn't crash anymore but I couldn't find where the video was saved.

tomurtogu avatar Nov 22 '21 15:11 tomurtogu