ilia3101 / LibMLV

MLV Reading/Writing library
5 stars 1 forks source link

Adding new matrices #5

Open 2blackbar opened 2 years ago

2blackbar commented 2 years ago

I wanted to add new matrice "MotionCam", { 0.0127, 0.0727, 0.5789, -0.2806, 1.0683, 0.2451, 1.2341, -0.6660, 0.0994 }, { -0.0558, 0.1620, 0.5206, -0.3982, 1.2675, 0.1412, 1.0612, -0.4169, -0.1001 } }, {

But structure of raw2mlv changed so much im unable to compile windows exe, can someone help with that ? I wanted to add this new matrice , its for enabling motioncam dng files to be read by mlvapp after conversion, it records 4k dng video on a phone so i really want to get it working nicely .Also im not sure if it doesnt have r/g/b channels swapped so... i was able to pinpoint that out , anyway here is dng file : https://drive.google.com/file/d/1PTRT0ZH15ylJwobYu6MwhLsE6kjJ_9U6/view?usp=sharing

Can someone help me to get it working nicely in mlvapp, i mean the colour matrix, its currently swapped so the one i posted might be better. If not then this is original one from exiftool , and maybe swapping these will help cause they have swapped channels as is but the one i posted on top should work i believe: Color Matrix 1 : 0.8321 -0.1664 -0.1268 -0.6419 1.5928 0.0317 - 0.1743 0.3566 0.4755 Color Matrix 2 : 1.5469 -0.7578 -0.1953 -0.7109 1.8672 -0.2266 -0.0859 0.2422 0.5547

Its very weird, i tried to edit values in exiftool, they are changed, identical to pixel2 matrice file, but after raw2mlv its still rgb swapped in mlvapp, i dont get it , what do i need to change with exiftool.

masc4ii commented 2 years ago

I think this is no issue in LibMLV. MLVApp holds the camera matrices in dependency to the "camera_id". The motioncam has the invalid "camera_id = 0". This way it will be hard to decide what matrix to load. MLVApp also is currently made for RGGB sensors only. All debayer algorithms have to be pushed for other bayer formats. For easy testing go into those algorithms and change function "FC" - then you get the correct channels (for DNGs of this bayer type only).

Bildschirmfoto 2021-12-15 um 10 07 56

2blackbar commented 2 years ago

Wow You got it right, i spent entire night on this changing every valye by exif tool without luck. What do you mean by going into algorithms and changing function "FC" ? Is it debayering algo? i dont have it in mlvapp 13. Or its a thing i have to edit in mlvapp source ? cameraid is not available in exiftool for this dng OK i edited FC in amaze_demosaic, can i somehow clone it so its visible in mlvapp as amaze_flipped along with untouched amaze or something ? Cause now i compiled separate version of mlvapp just for this situation.

OK its not totally right, blue is oversaturated in shadows , i have it like this :
static inline int FC(int row, int col) { register int row2 = row%2; register int col2 = col%2; if (row2 == 0 && col2 == 0) return 2; / red / else if (row2 == 1 && col2 == 1) return 0; / blue / else return 1; / green / } image

masc4ii commented 2 years ago

Your function is correct now. Next you need to adjust black level in app gui. Blue is extremely off, so here you additionally have to use e.g. the curve tool. But also here, shadows are bluish... DR of blue is way smaller as for green and red. Maybe this would be better with camera matrix - if there would be a way to integrate... Yes, it would be possible, but that's not good programming style. It would be better e.g. to read meta data and set the debayer automatically. But I don't know if MLV header includes this metadata - for Canon it is not needed.

2blackbar commented 2 years ago

Theres huge spike on blue channel, something is off elsewhere imo, max and min for this channel maybe, cause when i tinker with rgb swapping, i can get the spike on green as well, so there must be something else i can do to push that spike down and widen the channel. Fixing by hand by rgb curves is almost impossible.It kinda looks like blue channel has linear curve ? on waveform it looks like this :
image image

It looks like you did not had that issue at all, your rgb parade looks fine ?

masc4ii commented 2 years ago

As I wrote - same here. But I used the gradation curve tool and pulled the blue channel down. This still doesn't look nice for my taste. All 3 channels are linear in the RAW file. And the profile converts it to whatever you setup. But the blue channel has very little DR compared to red and green.

2blackbar commented 2 years ago

Ok so camera_id is empty ? Should it say pixel2 or something? heres is front cam, can you tell me whats its camera id ? how do i check this on my own ? Maybe if this could be changed, ill get it working, its front/selfie camera from same phone, but it has proper rgb. https://drive.google.com/file/d/1AT3x3nBNDobJY_I2Lq5g7QSTvhaMzPky/view?usp=sharing Do You have any ideas how to use exif tool to fix this ? I definitely wont be able to fix that by rgb curves

OR, where i can find camera id functions in mlvapp? i want to force it to 1 or something else, just to see what will hapen

masc4ii commented 2 years ago

CameraIDs are numbers: 0x80000218 = 5D2 0x80000250 = 7D ... No idea how non-Canon cams could look like here.

Find all this information in camera_id.c in MLVApp.

2blackbar commented 2 years ago

so editing this should get me better result ?

    0x00000000,
    { "Unknown Camera", "Using 5D3", "Matrixes & Focal Info" },
    { 7234, 10000, -1413, 10000, -600, 10000, -3631, 10000, 11150, 10000, 2850, 10000, -382, 10000, 1335, 10000, 6437, 10000 },
    { 6722, 10000, -635, 10000, -963, 10000, -4287, 10000, 12460, 10000, 2028, 10000, -908, 10000, 2162, 10000, 5668, 10000 },
    { 7868, 10000, 92, 10000, 1683, 10000, 2291, 10000, 8615, 10000, -906, 10000, 27, 10000, -4752, 10000, 12976, 10000 },
    { 7637, 10000, 805, 10000, 1201, 10000, 2649, 10000, 9179, 10000, -1828, 10000, 137, 10000, -2456, 10000, 10570, 10000 },
    { 5760000, 1461 },
    { 3840000, 972 },
    2
}
masc4ii commented 2 years ago

"Should" is the right word for it. I tried adapting the first two rows to the values you wrote above - but no difference so far. But the forward matrices are missing (line 3 and 4 of this number package), as will as the values for the last two lines.

2blackbar commented 2 years ago

forward matrice from exif look like this, im trying to edit and swap first 3 and last 3

ExifTool Version Number : 12.37 File Name : 0pixel.dng Directory : D:/RAW/VIDEO_20211214_231248 File Size : 23 MiB File Modification Date/Time : 2021:11:16 16:09:51+01:00 File Access Date/Time : 2021:12:15 05:18:01+01:00 File Creation Date/Time : 2021:12:15 05:18:01+01:00 File Permissions : -rw-rw-rw- File Type : DNG File Type Extension : dng MIME Type : image/x-adobe-dng Exif Byte Order : Little-endian (Intel, II) Subfile Type : Full-resolution image Image Width : 4032 Image Height : 3032 Bits Per Sample : 16 Compression : Uncompressed Photometric Interpretation : Color Filter Array Image Description : Make : Google Camera Model Name : Pixel 2 XL Strip Offsets : (Binary data 25920 bytes, use -b option to ext ract) Orientation : Horizontal (normal) Samples Per Pixel : 1 Rows Per Strip : 1 Strip Byte Counts : (Binary data 15159 bytes, use -b option to ext ract) X Resolution : 72 Y Resolution : 72 Planar Configuration : Chunky Resolution Unit : inches Software : google/taimen/taimen:8.1.0/OPM1.171019.011/444 8085:user/release-keys Modify Date : 2021:11:16 16:09:51 CFA Repeat Pattern Dim : 2 2 CFA Pattern 2 : 2 1 1 0 Copyright : Exposure Time : 1/50 F Number : 1.8 ISO : 337 Date/Time Original : 2021:11:16 16:09:51 Focal Length : 4.5 mm TIFF-EP Standard ID : 1 0 0 0 DNG Version : 1.4.0.0 DNG Backward Version : 1.1.0.0 Unique Camera Model : Pixel 2 XL-Google-google CFA Plane Color : Red,Green,Blue CFA Layout : Rectangular Black Level Repeat Dim : 2 2 Black Level : 63.78 63.42 63.2 63.74 White Level : 1023 Default Scale : 1 1 Default Crop Origin : 8 8 Default Crop Size : 4016 3008 Color Matrix 1 : 0.8203125 -0.1640625 -0.125 -0.6328125 1.57031 25 0.03125 -0.171875 0.3515625 0.46875 Color Matrix 2 : 1.546875 -0.7578125 -0.1953125 -0.7109375 1.86 71875 -0.2265625 -0.0859375 0.2421875 0.5546875 Camera Calibration 1 : 1 0 0 0 1 0 0 0 1 Camera Calibration 2 : 1.0078125 0 0 0 1 0 0 0 1 As Shot Neutral : 0.4765625 1 0.6796875 Baseline Exposure : 0.01 Calibration Illuminant 1 : D65 Calibration Illuminant 2 : Standard Light A Active Area : 8 0 3032 4032 Forward Matrix 1 : 0.671875 0.1015625 0.1875 0.2734375 0.6796875 0.046875 0.03125 -0.3515625 1.1484375 Forward Matrix 2 : 0.5859375 0.125 0.2578125 0.2109375 0.6171875 0.171875 -0.0078125 -0.5859375 1.421875 Opcode List 2 : GainMap, GainMap, GainMap, GainMap Opcode List 3 : Noise Profile : 0.001194916047 7.67411666168e-006 0.0011949160 47 7.67411666168e-006 0.001194916047 7.67411666168e-006 Aperture : 1.8 CFA Pattern : [Blue,Green][Green,Red] Image Size : 4032x3032 Megapixels : 12.2 Shutter Speed : 1/50 Focal Length : 4.5 mm Light Value : 5.6 -- press ENTER --

masc4ii commented 2 years ago

Hmmm...

{ 8321, 10000, -1664, 10000, -1268, 10000, -6419, 10000, 15928, 10000, 317, 10000, 1743, 10000, 3566, 10000, 4755, 10000 }, { 15469, 10000, -7578, 10000, -1953, 10000, -7109, 10000, 18672, 10000, -2266, 10000, -859, 10000, 2422, 10000, 5547, 10000 }, { 6718, 10000, 1015, 10000, 1875, 10000, 2734, 10000, 6796, 10000, 468, 10000, 312, 10000, -3515, 10000, 11484, 10000 }, { 5859, 10000, 1250, 10000, 2578, 10000, 2109, 10000, 6171, 10000, 1718, 10000, -78, 10000, -5859, 10000, 14218, 10000 },

But something else must be wrong... still all white.

2blackbar commented 2 years ago

I even remoevd unknown cam, from cameraid c file and it still loads, so what camera id its using for it if unknown cam is not in the code ? I want to remove all camera ids and leave just one, then try to adapt matrices from dng exif info

masc4ii commented 2 years ago

See the code... sry... I did not play much with all this since it exists... Somewhere this matrices are loaded. You need to find the place.

2blackbar commented 2 years ago

ok i left just that, removed all cam ids, and it still loads with swapped rgb? :

static camera_id_t camera_id[] = { { 0x00000000, { "Unknown Camera", "Using 5D3", "Matrixes & Focal Info" }, 2 } };

I think something else takes care of it.

masc4ii commented 2 years ago

Be careful... what you do will lead to bad memory access... pointers lead into nothing with that code...

2blackbar commented 2 years ago

I know, once i get the rgb swap, ill bring that back, why it works if i removed all cam ids, and what file takes care of assigning the id ?

2blackbar commented 2 years ago

YEah when rgb are imported and are swapped then red channel is spiking image But when i swap the R and B channels in FC then now blue channel is spiking, how to solve this ? Im sure theres one more place to find to get this right. image

ilia3101 commented 2 years ago

@masc4ii

I think this is no issue in LibMLV. MLVApp holds the camera matrices in dependency to the "camera_id". The motioncam has the invalid "camera_id = 0". This way it will be hard to decide what matrix to load.

I actually changed this a while ago, MLV App should load the matrix from the MLV file if it's not a recognised camera. If my memory serves me correctly!

I hope I'm not making that up.

I believe I did it around the same time I made raw2mlv.

masc4ii commented 2 years ago

@ilia3101 This would explain, why we can change the 0x0000000 matrix in MLVApp and the result doesn't change at all. Does LibMLV transport the DNG matrix into the MLV structure?

ilia3101 commented 2 years ago

Does LibMLV transport the DNG matrix into the MLV structure?

Yes raw2mlv does that. It does all it can to write the correct matrix to the MLV.

One thing I didn't add to raw2mlv was bayer pattern awarness, so some raw files start with blue pixel instead of red and therefore blue/red get swapped.

masc4ii commented 2 years ago

Can you tell me, in which variable inside mlv.h I can find this? Debugger is running and I would like to see those variables from above. With the swap: we just have to tell this to the debayer and it will work. But also here I need the metadata for creating the switch. If I get this information, the correction is easy. Also here: is there a variable in mlv structure for this?

masc4ii commented 2 years ago

Okay... found it. It is in: RAWI.raw_info.color_matrix1 But all odd values are 0, all even values are 10000.

And at the similar place I've found the bayer info: RAWI.raw_info.cfa_pattern = 0x02010100 for this file.

I'll see if I can push that info into the debayer algorithms...

2blackbar commented 2 years ago

Great ! I think that would solve all the rgb swapping issues Would it be able to use camera matrix? I had to use exif to change :
exif -uniqueCameraModel="Pixel 2 XL-Google-google" -ext dng .

So it would use/force pixel 2 xl camera matrix, also these files from motioncam dont retain original phone model , they use motioncam as camera model...

2blackbar commented 2 years ago

HEres another file from other phone in motioncam it has swapped rgb as well: https://drive.google.com/file/d/1YLVE9koF9KysULetgboTeSQLy8yWkzfv/view?usp=sharing

2blackbar commented 2 years ago

Hey , motioncam can record full res 4.5k maybe even more with ssd drive over usb ! Is no lag and no dropped frames, how can i get pixel footage working in mlvapp ? Where i have to look for? Also app has sound recording now ! But i couldnt get wav file to be included in mlv file when i had it in folder with dngs , how can i do this ? This is HUGE, anyone knows fullframe android camera ? From now on, all android cameras have raw dng recording over usb 3, id say its a revolution once again.

masc4ii commented 2 years ago

At the moment you can't get DNG sequences with sound into MLVApp. There is no such feature existing. And no... it doesn't work for all android cameras. E.g. all my android devices are not supported. ;)

2blackbar commented 2 years ago

It works on all phones with cameraapi2, that is available since about lollipop (2014) and most cameras after that have it. Yeah some companies do block it but it is intentional, my 2 phones have it, but 2 of them have RGGB and BGGR on front/back cams so its a thing id like to fix somehow, I tried every exif property, but something like " CFA Pattern [Blue,Green][Green,Red] " is not editable . I dont think theres a lot of people editing phone dngs on mlvapp but i like tonemaping in it. There is something in that DNG from motioncam that wont let raw2mlv converter to use its own matrix, i succesfully swapped R and B year ago in back camera of pixel2 and it works fine in mlvapp(no swapped colours)it isincluded in raw2mlv but now after motioncam saves dngs then colours are back to wrong ones again and i cant compile raw2mlv , i dont even know if that would sove it cause in exif matrix is good in dng from motioncam.

masc4ii commented 2 years ago

Nope... my devices have camera api 2 support, but motioncam doesn't work at all. Even installing is impossible. Device is 2017 and supports "RAW" photos out of the box. Those photos have extreme chroma blur, so "RAW" is relative... ;) Why should one edit the CFA pattern? If you edit it, you'll have to cut frist row and column.

Btw: MLVApp extension for CFA is harder than expected... I had to revert all changes because app completely stopped working... will see when I have time for another 2nd try.

2blackbar commented 2 years ago

I believe it can be fixed on raw2mlv side cause i had this issue before, i swapped camera matrix in matrices file from raw2mlv , it fixed it, but i cant do it again, source changed too much to compile on windows.changing matrice in exif wont solve it cause its already good.Its matrices file in raw2mlv that needs change. I also see there is a limit of how many dngs can be in a folder, it wont work with over 800 dngs.MLV wont be created and shows up error that it cant open mlv, when i remove files so thers like 600 dngs, it works. So i think its raw2mlv that isnt ready for converting so many dngs to mlv. Yes i did try to compile old raw2mlv build but mingw changed packages and theres just no way with my skills, crucial dlls are missing like libraw r 19.dll, it wont even download older dlls and they dont exist sepqrately on web

2blackbar commented 2 years ago

Allright after over 5 hour long battle, i won and compiled raw2mlv older version on windows... so, where i can find that 600-700 dng limit and lift it ?


Matrice issue solved, added matrice to the source, it was the old one, i just cloned repo from 2019 december 16 , right before major changes.Cause this one worked, and it works again, oh man , i spent like over 10 hours solving it ! But its satisfying, i almost gave up many times and restarted many times.I can find my peace now. image image

"MotionCam", { 0.0127, 0.0727, 0.5789, -0.2806, 1.0683, 0.2451, 1.2341, -0.6660, 0.0994 }, { -0.0558, 0.1620, 0.5206, -0.3982, 1.2675, 0.1412, 1.0612, -0.4169, -0.1001 } raw2mlv.zip

As for the different color channels R/B with back and front cameras, i created extra "motioncams" matrix , its for swapped, i use exif to change all swapped dngs matrix to it. Masc isnt it easier if we could pick different color matrices ourselves in mlvapp ? or import it maybe as txt or something so mlvapp would force it.

masc4ii commented 2 years ago

Nice work! Do all motioncam android devices have this matrix? Or does this just work for your device? If it is possible to convert the matrix into the right place from DNG to MLV, I think this would be the best solution - we can't do anything wrong with that.

2blackbar commented 2 years ago

Yes, it works with 3 phones i tried for main cam, unless selfie cam or other secondary cam is not working cause R and B are flipped ( thats how 3 of my phones work, front and back cams have r/b reversed relative to each other).In that case, i use exiftool to change uniquename to "MotionCams", and it works. There is a place that lets us read the channel order its - CFA Pattern : [Red,Green][Green,Blue] - or - CFA Pattern : [Blue,Green][Green,Red] - So yeah, its not ultimately a real solution, i think it would need one more point of detection , just for R and B channels to determine which ones are first, and adjust matrix on the fly accordingly when importing.

masc4ii commented 2 years ago

The CFA pattern was already included in your DNGs. I can read it also from the MLV files. I just have big problems in getting this info through all functions into the different debayer algorithms in MLVApp... and some of these algorithms aren't made for something else than RGGB...

2blackbar commented 2 years ago

I see.. yeah frankensteining code just to get this working would take a lot of time, thats why i wanted to just edit raw2mlv , i think for me new motioncam matrix is enough for what i wanted, i can also compile alternative raw2mlv with reversed rgb for motion cam nad just swap exe files if i shoot on front or back cameras. I really recommend trying out motioncam on a phone that works, footage has very nice dynamic range on low isos ( on pixel up to 400 is ok) It kinda looks like 16mm film when rendered in mlvapp , and its 4.6k. Depending on whats your dng frame size. Ill try to obtain some phones with 8000x6000 res dngs.

Heres tutorial for me if i start wtih fresh OS or anyone who wants to compile raw2mlv for windows, all folders are ready, you just have to download mingw stuff , read "steps"txt" :

Raw2MLVwinexe.zip

Now... im getting "filename extension is too long" when i want to throw in 800 dngs into raw2mlv, how to lift that limit ? Maybe its this ? https://docs.microsoft.com/en-us/troubleshoot/windows-client/shell-experience/command-line-string-limitation

masc4ii commented 2 years ago

Seems I was misinterpreting CFA variable: it is always 33620224=0x02010100 0x(blue)(green)(green)(red) - for both, the converted phone MLV (from DNG by raw2mlv) and also for Canon MLVs. One of the two must be 0x00010102 ... I would now thing the phone MLV. Is this variable really converted from DNG to MLV? Or is 0x02010100 kind of default?

Edit: määäh

/* Set default bayer pattern */ Writer->RAWI.block.raw_info.cfa_pattern = 0x02010100;

Seems we need a function reading CFA from DNG and setting to MLV. In MLVApp I now changed many many functions for other CFA. For AHD and Bilinear it won't work, because it is RGGB only. For "Simple" I tried to adapt. Now I need a MLV with correct CFA from the phone for testing...

2blackbar commented 2 years ago

I can send you phone dngs , this one is tricky image

Heres dngs , theyre from 3 phones, so there are various orders of rgb, you can look cfa in exif, theyre different on all 3, i only changed cameramodel by exif but all of them should be motioncam. dng1.zip dng2.zip When motioncam converts raw to dng, it replaces phone id with motioncam but, heres dng from pixel that was swapped in mlvapp before i edited matrice year ago, it preserves phone model in exif: 0pixel.zip

Youre on mac and cant use my custom raw2mlv so, heres mlvs with motioncam matrix :

mlv1.zip mlv2.zip mlv3.zip

So all these have the same id "motioncam" but they have different color matrix in exif also cfa is different between them as each phone and sensor has its own order.

masc4ii commented 2 years ago

Thank you very much. I will have a look later on the files. Right... I don't get raw2mlv compiled at the moment, because libRaw is "Intel-Only" and I don't have a cross-compiler atm. RGGB and BGGR should work in the future... but GBRG is really bad - no idea what to do here. Not sure if any of our debayers are build for something like that. I just could imagine cropping the image until we again get RGGB...

2blackbar commented 2 years ago

5d2 has grbg or gbrg , and it works, you can lookup in exif but i tried to change camera name from motioncam to Canon EOS 5D Mark II and its not working despite CFA being the same

edit, heres 5D2 exif: F Number : 0 Exposure Program : Manual ISO : 640 Exif Version : 0221 Date/Time Original : 2021:12:20 12:29:46 Create Date : 2021:12:20 12:29:46 Components Configuration : Y, Cb, Cr, - Shutter Speed Value : 1/49 Aperture Value : Inf Flash : Off, Did not fire Focal Length : 50.0 mm Macro Mode : Normal Self Timer : Off Quality : RAW Canon Flash Mode : Off Continuous Drive : Continuous Focus Mode : Manual Focus (3) Record Mode : CR2 Canon Image Size : n/a Easy Mode : Movie Snap Digital Zoom : None Contrast : +4 Saturation : Normal Metering Mode : Center-weighted average Focus Range : Not Known Canon Exposure Mode : Easy Max Focal Length : 0 mm Min Focal Length : 0 mm Focal Units : 1/mm Flash Activity : 0 Flash Bits : (none) Zoom Source Width : 0 Zoom Target Width : 0 Manual Flash Output : n/a Color Tone : Normal SRAW Quality : n/a Auto ISO : 100 Base ISO : 617 Measured EV : 4.50 Target Exposure Time : 1/51 Exposure Compensation : 0 White Balance : Manual Temperature (Kelvin) Slow Shutter : None Shot Number In Continuous Burst : 0 Optical Zoom Code : n/a Camera Temperature : 21 C Flash Guide Number : 0 Flash Exposure Compensation : 0 Auto Exposure Bracketing : Off AEB Bracket Value : 0 Control Mode : Camera Local Control Measured EV 2 : 4.625 Bulb Duration : 0 Camera Type : EOS High-end ND Filter : n/a Canon Image Type : Canon EOS 5D Mark II Canon Firmware Version : Firmware Version 2.1.2 Owner Name : Serial Number : 0530306836 Flash Metering Mode : Off Camera Orientation : Horizontal (normal) Focus Distance Upper : 0 m Focus Distance Lower : 0 m Lens Type : Unknown (0) Firmware Version : 2.1.2 File Index : 2121 Directory Index : 100 Contrast Standard : -1 Sharpness Standard : 7 Saturation Standard : 0 Color Tone Standard : 0 Contrast Portrait : 0 Sharpness Portrait : 2 Saturation Portrait : 0 Color Tone Portrait : 0 Contrast Landscape : 0 Sharpness Landscape : 4 Saturation Landscape : 0 Color Tone Landscape : 0 Contrast Neutral : 4 Sharpness Neutral : 7 Saturation Neutral : 0 Color Tone Neutral : 0 Contrast Faithful : 0 Sharpness Faithful : 0 Saturation Faithful : 0 Color Tone Faithful : 0 Contrast Monochrome : 0 Sharpness Monochrome : 3 Filter Effect Monochrome : None Toning Effect Monochrome : None Contrast User Def 1 : -1 Sharpness User Def 1 : 3 Saturation User Def 1 : -2 Color Tone User Def 1 : 0 Filter Effect User Def 1 : None Toning Effect User Def 1 : None Contrast User Def 2 : 0 Sharpness User Def 2 : 3 Saturation User Def 2 : 0 Color Tone User Def 2 : 1 Filter Effect User Def 2 : None Toning Effect User Def 2 : None Contrast User Def 3 : -4 Sharpness User Def 3 : 0 Saturation User Def 3 : 0 Color Tone User Def 3 : 0 Filter Effect User Def 3 : None Toning Effect User Def 3 : None User Def 1 Picture Style : PC 1 User Def 2 Picture Style : PC 2 User Def 3 Picture Style : PC 3 Canon Model ID : EOS 5D Mark II Thumbnail Image Valid Area : 0 159 7 112 Serial Number Format : Format 2 AF Area Mode : Single-point AF Num AF Points : 9 Valid AF Points : 1 Canon Image Width : 5616 Canon Image Height : 3744 AF Image Width : 5616 AF Image Height : 3744 AF Area Widths : 1122 0 0 0 0 0 0 0 0 AF Area Heights : 744 0 0 0 0 0 0 0 0 AF Area X Positions : 80 0 0 0 0 0 0 0 0 AF Area Y Positions : 0 0 0 0 0 0 0 0 0 AF Points In Focus : (none) AF Points Selected : 0 Original Decision Data Offset : 0 Bracket Mode : Off Bracket Value : 0 Bracket Shot Number : 0 Raw Jpg Size : Large Long Exposure Noise Reduction 2 : Off WB Bracket Mode : Off WB Bracket Value AB : 0 WB Bracket Value GM : 0 Live View Shooting : On Shutter Mode : Mechanical Flash Exposure Lock : Off Lens Model : Internal Serial Number : Dust Removal Data : (Binary data 1024 bytes, use -b option to extr act) Crop Left Margin : 0 Crop Right Margin : 0 Crop Top Margin : 0 Crop Bottom Margin : 0 Exposure Level Increments : 1/3 Stop ISO Speed Increments : 1/3 Stop ISO Expansion : On AEB Auto Cancel : On AEB Sequence : 0,-,+ Safety Shift : Disable Flash Sync Speed Av : Auto Long Exposure Noise Reduction : Off High ISO Noise Reduction : Off Highlight Tone Priority : Disable Auto Lighting Optimizer : Disable Lens Drive No AF : Focus search off Lens AF Stop Button : AF start AF Point Selection Method : Normal Superimposed Display : Off AF Assist Beam : Does not emit Mirror Lockup : Disable AF Point Area Expansion : Disable AF Microadjustment : Disable; 255; 0; 255; 0 Shutter Button AF On Button : Metering + AF start AF On AE Lock Button Switch : Disable Set Button When Shooting : Normal (disabled) Dial Direction Tv Av : Normal Focusing Screen : Eg-A Add Original Decision Data : Off Assign Func Button : LCD brightness Aspect Ratio : 3:2 Cropped Image Width : 5616 Cropped Image Height : 3744 Cropped Image Left : 0 Cropped Image Top : 0 Tone Curve : Standard Sharpness : 7 Sharpness Frequency : n/a Sensor Red Level : 0 Sensor Blue Level : 0 White Balance Red : 0 White Balance Blue : 0 Color Temperature : 4800 Picture Style : Neutral Digital Gain : 0 WB Shift AB : 0 WB Shift GM : 0 Measured RGGB : 424 1024 1024 425 VRD Offset : 0 Sensor Width : 5792 Sensor Height : 3804 Sensor Left Border : 168 Sensor Top Border : 56 Sensor Right Border : 5783 Sensor Bottom Border : 3799 Black Mask Left Border : 0 Black Mask Top Border : 0 Black Mask Right Border : 0 Black Mask Bottom Border : 0 Color Data Version : 6 (50D/5DmkII) WB RGGB Levels As Shot : 2203 1024 1024 1869 Color Temp As Shot : 4797 WB RGGB Levels Auto : 2198 1024 1024 1768 Color Temp Auto : 5015 WB RGGB Levels Measured : 2196 1023 1024 1767 Color Temp Measured : 5015 WB RGGB Levels Daylight : 2305 1024 1024 1759 Color Temp Daylight : 5200 WB RGGB Levels Shade : 2655 1024 1024 1452 Color Temp Shade : 7000 WB RGGB Levels Cloudy : 2485 1024 1024 1584 Color Temp Cloudy : 6000 WB RGGB Levels Tungsten : 1745 1086 1086 2948 Color Temp Tungsten : 3200 WB RGGB Levels Fluorescent : 2011 1044 1044 2626 Color Temp Fluorescent : 3674 WB RGGB Levels Kelvin : 2203 1024 1024 1869 Color Temp Kelvin : 4797 WB RGGB Levels Flash : 2503 1024 1024 1567 Color Temp Flash : 6108 Average Black Level : 1024 1024 1024 1024 Raw Measured RGGB : 39149 96080 95432 39933 Per Channel Black Level : 1024 1024 1023 1023 Normal White Level : 14800 Specular White Level : 15312 Linearity Upper Margin : 10000 Picture Style User Def : PC 1; PC 2; PC 3 Picture Style PC : Neutral; Faithful; Neutral Custom Picture Style File Name : AF Micro Adj Mode : Disable AF Micro Adj Value : 0 Vignetting Corr Version : 0 Peripheral Lighting : Off Distortion Correction : Off Chromatic Aberration Corr : Off Peripheral Lighting Value : 0 Distortion Correction Value : 0 Original Image Width : 5616 Original Image Height : 3744 Peripheral Lighting Setting : Off User Comment : Sub Sec Time : 82 Sub Sec Time Original : 82 Sub Sec Time Digitized : 82 Flashpix Version : 0100 Color Space : Uncalibrated Exif Image Width : 5616 Exif Image Height : 3744 Interoperability Index : R98 - DCF basic file (sRGB) Interoperability Version : 0100 Focal Plane X Resolution : 3849.211789 Focal Plane Y Resolution : 3908.141962 Focal Plane Resolution Unit : inches Custom Rendered : Normal Exposure Mode : Manual Scene Capture Type : Standard GPS Version ID : 2.2.0.0 Thumbnail Offset : 44460 Thumbnail Length : 10188 Photometric Interpretation : RGB Samples Per Pixel : 3 Rows Per Strip : 234 Planar Configuration : Chunky Strip Offsets : 2913840 Strip Byte Counts : 21764270 CR2 CFA Pattern : [Green,Blue][Red,Green] Raw Image Segmentation : 2 1936 1920 SRaw Type : 1 Drive Mode : Continuous Shooting File Number : 100-2121 Lens : 0.0 mm Shooting Mode : Movie Snap WB RGGB Levels : 2203 1024 1024 1869 Aperture : Inf Blue Balance : 1.825195 Image Size : 5616x3744 Lens ID : Unknown (0) Megapixels : 21.0 Preview Image : (Binary data 1982646 bytes, use -b option to e xtract) Red Balance : 2.151367 Scale Factor To 35 mm Equivalent: 1.0 Shutter Speed : 1/50 Create Date : 2021:12:20 12:29:46.82 Date/Time Original : 2021:12:20 12:29:46.82 Modify Date : 2021:12:20 12:29:46.82 Thumbnail Image : (Binary data 10188 bytes, use -b option to ext ract) Lens : 0.0 mm (35 mm equivalent: 0.0 mm) Circle Of Confusion : 0.031 mm Depth Of Field : inf (0.00 m - inf) Field Of View : 40.5 deg Focal Length : 50.0 mm (35 mm equivalent: 48.8 mm) Hyperfocal Distance : Inf m -- press ENTER --

masc4ii commented 2 years ago

Hm... All MLVs and CR2s from my 5D2 were working fine with our old RGGB-only debayer algorithms in MLVApp... But maybe the usable area is cropped.

2blackbar commented 2 years ago

Heres some more with GBRG from lg v30, bought it cause of log video which in reality was crap but it handles motioncam nicely, can get about 15 seconds of 4k raw in cinemascope, so if 5D2 had the same CFA as these, why it isnt working ? I tried to copy 5d2 matrices in raw2mlv to motioncam in camera ids and convert, to force it it didnt solved anything. These are shot with firstlight, so it preserved phone id as lg v30 lg v30 selfie.zip lg v30 back wide.zip

Maybe theres something else , not CFA that handles this? If i only could copy entire exif data from 5d2 to these dngs from phones, maybe that would change something.5d2 has a lot of extra properties in exif.

What this tells me is that red channel is cloned into blue one so theres magenta on histogram thats identical cause B/R look identical, and theres green flipped , maybe blue channel is lost during conversion.I might be wrong tho. image

Getting closer, i got rid of magenta, image

heres the matrix for that for myself in case i messup "MotionCam", { -0.2806, 1.0683, 0.2451, 0.0127, 0.0727, 0.5789, 1.2341, -0.6660, 0.0994 }, { -0.0558, 0.1620, 0.5206, 1.0612, -0.4169, -0.1001, -0.3982, 1.2675, 0.1412 }

I moved middle row from first set (cause its green) and moevd it to top of first set so its G as first , then i moved middle row from second set to bottom of second set so its ends on G It would help if i would know what actually these arrays for matrices represent https://www.adobe.com/content/dam/acom/en/products/photoshop/pdfs/dng_spec_1.4.0.0.pdf

Weird, if i change first set to 1's it doesnt affect image at all, only second set affects it

` "MotionCam", { 1, 1, 1, 1, 1, 1, 1, 1, 1

    },
    {
        -0.0558,  0.1620,  0.5206,
        1.0612, -0.4169, -0.1001,
       -0.3982,  1.2675,  0.1412
    }
},
{`

OK tested with other cams, it looks like changing second set of matrices changes the channels, that is color matrix 2 i think.Maybe thats why i had no luick with exiftool.

OK gave up for now, it just looks like it skips blue channel, i have 3 paints Red green and blyue, and i can get red and green but blue paint is all black. i think its lost during convetion to mlv.

masc4ii commented 2 years ago

I am now watching into your MLV files. 7 and 8 looks very nice. All the others have wrong channels. But I remember clip 8 with wrong channels - did you change something? All 6 clips tell me CFA=0x02010100 -> RGGB. So my new debayer switch is still idle... but 2 clips are correct now which I remember wrong before.

Edit: I see... the channel correction is done by the matrix. Without matrix, 7 and 8 are wrong, with matrix their are correct. Cool. And for 4 and 6 it is the opposite - not so cool. :-D

2blackbar commented 2 years ago

Yeah its all the GBRG that are pita despite 5D2 having the sa CFA. cause greens are first and last, you cant just swap them so easily or i cant find a way to do it. I cant even get blue channel to showup in mlvapp no matter what i do with matrix. I can only get fake blue by swapping red. Its like if blue channel was rejected on import to mlvapp or conversion to mlv in raw2mlv.

masc4ii commented 2 years ago

No matter what bayer it really is - the MLV tells RGGB. So the debayer algorithms will do it this way. If we now have GRBG or GBRG, red or blue or both could be demage - in dependency how the algorithm works. Maybe it becomes better, if the correct CFA is saved in the MLV. I am at a point where I could test if my switch works. But for this, I need the correct CFA info inside a MLV. You can adjust this hardcoded in MLVWriter init function. (for now)

2blackbar commented 2 years ago

So what should i have in there to pass cfa from dng to mlv ? ` /** MLV creation **/

/* Allocate memory for the mlv writer object */
MLVWriter_t * writer = malloc(sizeof_MLVWriter());

/* Open file and create pointer for packed frame data */
FILE * mlv_file = fopen(output_name, "wb");
uint8_t * packed_frame_data = NULL;

/* Write each frame */
for (int f = 0; f < num_input_files; ++f)
{
    /* Open raw file with RawReader (wrapper for LibRaw) */
    RawReader_t raw[1];
    if (init_RawReader(raw, input_files[f]) != 0)
        printf("Can't read file %s\n", input_files[f]);

    /* Initialise MLV writer and write MLV headers when it's first frame */
    if (f == 0)
    {
        /* Round bitdepth up to a multiple of 2 */
        source_bitdepth = (int)ceil(log2(RawGetWhiteLevel(raw))/2) * 2;
        shift_bits = source_bitdepth - output_bits;
        if (shift_bits < 0) shift_bits = -shift_bits;
        float lscale = pow(2.0, output_bits - source_bitdepth);

        printf("Detected source bitdepth: %i\n", source_bitdepth);

        /*************************** Set values ***************************/

        width = RawGetWidth(raw);
        height = RawGetHeight(raw);

        packed_frame_data = malloc((width * height * output_bits) / 8);

        /********************* Initialise MLV writer **********************/

        /* Set basic image parameters */
        init_MLVWriter( writer,
                        width, /* Width */
                        height, /* Height */
                        output_bits, /* Bitdepth */
                        output_compression, /* Compressed LJ92? */
                        RawGetBlackLevel(raw)*lscale, /* Black level */
                        RawGetWhiteLevel(raw)*lscale, /* White level */
                        output_fps_top, /* FPS fraction */
                        output_fps_bottom );

        /*********************** Set camera info... ***********************/

        /* Try to look up adobe matrix */
        CameraMatrixInfo_t * mat = FindCameraMatrixInfo(RawGetCamName(raw));
        double * camera_matrix = NULL;

        /* If no matrix found from adobe, use libraw one (most likely the same) */
        if (mat != NULL)
            camera_matrix = mat->ColorMatrix2;
        else
            camera_matrix = RawGetMatrix(raw);

        MLVWriterSetCameraInfo( writer,
                                RawGetCamName(raw), /* Camera name string */
                                0, /* Model ID, only useful for ML cams */
                                camera_matrix /* Daylight camera matrix */);

        /************** Leave blank space in file for headers *************/

        fseek(mlv_file, MLVWriterGetHeaderSize(writer), SEEK_SET);
    }
    else
    {
        /* Make sure everything is right */
        if ( RawGetWidth(raw) != width
         || RawGetHeight(raw) != height)
        {
            printf("File %s has different resolution!\n", input_files[f]);
        }
    }

    /* Calculate frame size, TODO: compressed frames will be different */
    size_t frame_size = (width * height * output_bits) / 8;

    /*************************** Write the frame **************************/

    /* Get frame header size, telling MLVWriter how big the frame is */
    size_t frame_header_size = MLVWriterGetFrameHeaderSize(writer);

    /* Create memory for frame header */
    void * frame_header_data = malloc(frame_header_size);

    /* Get frame header */
    MLVWriterGetFrameHeaderData(writer,f,frame_size,frame_header_data);

    /* Write it */
    fwrite(frame_header_data, frame_header_size, 1, mlv_file);

    free(frame_header_data);

    /* Now write actual frame data */
    uint16_t * bayerimage = RawGetImageData(raw);

    if (output_bits < source_bitdepth)
        for (int i = 0; i < width*height; ++i) bayerimage[i] >>= shift_bits;
    else
        for (int i = 0; i < width*height; ++i) bayerimage[i] <<= shift_bits;

    if (output_bits == 16)
        packed_frame_data = (void *)bayerimage;
    else if (output_bits == 14)
        MLVPackFrame14(bayerimage, width*height, packed_frame_data);
    else if (output_bits == 12)
        MLVPackFrame12(bayerimage, width*height, packed_frame_data);
    else if (output_bits == 10)
        MLVPackFrame10(bayerimage, width*height, packed_frame_data);

    fwrite(packed_frame_data, frame_size, 1, mlv_file);

    written_frames++;

    uninit_RawReader(raw);
}

/***************************** Write headers ******************************/

/* Now go back to the start of the file */
fseek(mlv_file, 0, SEEK_SET);

/* Allocate array for header data */
size_t header_size = MLVWriterGetHeaderSize(writer);
void * header_data = malloc(header_size);

/* Get header data */
MLVWriterGetHeaderData(writer, header_data, written_frames);

/* Write header data to the file */
fwrite(header_data, header_size, 1, mlv_file);

free(header_data);

/********************************** DONE **********************************/

if (packed_frame_data != NULL) free(packed_frame_data);
fclose(mlv_file);
uninit_MLVWriter(writer);
free(writer);
free(input_files);

return 0;

} `

masc4ii commented 2 years ago

There is no function yet to manipulate CFA. Go into LibMLV/old/src/MLVWriter.c , line 127. 0x02010100 = RGGB (R=0, G=1, B=2). If you change this line, it should change the resulting MLV. Better way is to build a function and call it with the DNG information.

2blackbar commented 2 years ago

i found this maybe could work #define cam_CFAPattern 0x01000201 // Green Blue Red Green https://chdk.setepontos.com/index.php?topic=5720.610

// #define cam_CFAPattern 0x01000201 // Green Blue Red Green

define cam_CFAPattern 0x02010100 // Red Green Green Blue

So far it doesnt help much, i have it like this :+1:

/* Set default bayer pattern */
Writer->RAWI.block.raw_info.cfa_pattern = 0x01000201;

-- Yup makes no difference at all to mlvapp, it imports all dngs vonverted this way as normal

masc4ii commented 2 years ago

Compile and please upload the new "correct" MLV. Then I could test if my new switch works... (not commited yet, because highly experimental). You won't see any difference so far.

2blackbar commented 2 years ago

paints.zip HEres mlv with paints,. I think it just rejects blue channel no matter what i do.

masc4ii commented 2 years ago

Hm. That did not work. CFA in MLV is still 0x02010100=33620224.

2blackbar commented 2 years ago

wait, im a dubmass, i did not copied libmlv.dll