use custom LUT

Questions and answers on how to get the most out of FFAStrans
kalamazandy
Posts: 6
Joined: Tue Jun 18, 2024 6:24 pm

use custom LUT

Post by kalamazandy »

I only just started with FFAStrans and I'm trying to search for things the best I can, but I'm failing at trying to add custom LUTs. I have d-log, which doesn't seem to exist.

I thought you could add something like: lut3d='DJI_ZENMUSE_X9_DLog_To_Rec709.cube' to the Custom x264 options. (I put the lut next to both x86 and x64 ffmpeg, just in case) and I tried the full path for where I would actually want it as well.

I'm trying to use a conditional statement, which actually worked, to figure out which camera it is, and apply the correct LUT.
I'm using %s_info_exiftool% is equal to, regex, "DJI RONIN 4D" which is working.

I tested the footage with the color correction using one of the other LUTs that are built in and that worked. I could probably just figure out which one is the closest to the linear transformation I need and no one would notice. We just don't want to show preview files to people in log, and we also want to add a watermark, that looks easy enough, I just haven't done it yet. I should probably do the linear conversion first, then watermark, then push that into the video format. I'm just trying to figure out the part that isn't working for me first.
emcodem
Posts: 1692
Joined: Wed Sep 19, 2018 8:11 am

Re: use custom LUT

Post by emcodem »

Hi Mr. kalamazandy,
welcome to the Forum and thank you for using FFAStrans!
Thats a very good question.


I am not 100% sure if this works but looking at the source code it should work:
1) Create a user_variable and use a populate processor to set this variable to the full path of your lut file.
2) in the encoder processor, choose the same variable in the "Apply LUT" section

This should do it but @FranceBB might be able to confirm. Also i can test it later on, i am interested too.
There seems to be one pitfall tough, it looks like you must make sure that your lut file does NOT have the extension ".cube", any other extension could work tough.

Btw, In custom x264 options only pass options to the x264 encoder, applying a lut is not connected to the encoding in any way, it is filtering.
emcodem, wrapping since 2009 you got the rhyme?
emcodem
Posts: 1692
Joined: Wed Sep 19, 2018 8:11 am

Re: use custom LUT

Post by emcodem »

Just tested the described procedure and it seems to work for me, even when the lut file extension is .cube.
emcodem, wrapping since 2009 you got the rhyme?
kalamazandy
Posts: 6
Joined: Tue Jun 18, 2024 6:24 pm

Re: use custom LUT

Post by kalamazandy »

You know, I should have guessed that when I was looking at user variables because I saw it show up in the Luts list. I was just focused so much on trying to figure out what the syntax would be for the additional ffmpeg code.

Thank you so much for suggesting And testing that out. I will work it out that way. I Really wish Iconik had a way to do this, but they have however they are using ffmpeg really closed off and all they have is a way to change rec2020 to rec709.
emcodem
Posts: 1692
Joined: Wed Sep 19, 2018 8:11 am

Re: use custom LUT

Post by emcodem »

Hehe well since when are "builtin" ways for ingest/transcode flexible?
emcodem, wrapping since 2009 you got the rhyme?
kalamazandy
Posts: 6
Joined: Tue Jun 18, 2024 6:24 pm

Re: use custom LUT

Post by kalamazandy »

A bit frustrating, but I did get it to work eventually. I don't think I know how to specify a directory, and I had to remove the ".cube" text from the file. AND I could only get it to work directly in the H.264 node.
After I connected it there I got an error "C:/FFAStrans/FFAStrans1.4.0.6/processors/avs_plugins/LUTs/%s_camera_lut%.cube: No such file or directory.
I put the LUT there, called it only by name with no path and no .cube and it worked.

I don't think I understand the Conditional statement. I put some files into a watch folder, intentionally putting some that didn't match the camera, and after it looked at the first file it just stopped. I hit reset and then it did all of the files. Is there a way to have it not throw an error on the conditional statement?
I'm hoping to basically do something like If the camera name matches Cam1 then populate variable with Cam1 lut, else if camera name matches Cam2 then populate variable with Cam2 lut, and so on with all of the cameras we might use. Although, I'd like it the workflow to also just use no lut if it doesn't match any of the conditional statements, just so it doesn't error out.
emcodem
Posts: 1692
Joined: Wed Sep 19, 2018 8:11 am

Re: use custom LUT

Post by emcodem »

kalamazandy wrote: Wed Jun 19, 2024 1:23 pm AND I could only get it to work directly in the H.264 node.
It should work in all "encoding" nodes. Where else would you have expected it to "work"?
kalamazandy wrote: Wed Jun 19, 2024 1:23 pm After I connected it there I got an error "C:/FFAStrans/FFAStrans1.4.0.6/processors/avs_plugins/LUTs/%s_camera_lut%.cube: No such file or directory.
In this case, you did not set a value to s_camera_lut before the encoding node. You can do this by inserting a populate vars processor before the encoding and set
s_camera_lut = ...full path to cube file...
kalamazandy wrote: Wed Jun 19, 2024 1:23 pm I don't think I understand the Conditional statement. I put some files into a watch folder, intentionally putting some that didn't match the camera, and after it looked at the first file it just stopped. I hit reset and then it did all of the files. Is there a way to have it not throw an error on the conditional statement?
I'm hoping to basically do something like If the camera name matches Cam1 then populate variable with Cam1 lut, else if camera name matches Cam2 then populate variable with Cam2 lut, and so on with all of the cameras we might use. Although, I'd like it the workflow to also just use no lut if it doesn't match any of the conditional statements, just so it doesn't error out.
The conditional is like if/else statement but the else causes the workflow to go the error path. All you need to do is to "catch" the error after the conditional processor by hitting the input pin of the next processor and set it to execute "on error"
See "error handling" here: https://ffastrans.com/wiki/doku.php?id= ... w_building
There is one other thing you can do with conditional: ignore the error completely and force the job to delete itself from history. You do this by hitting "dispel" checkbox.

try this example workflow, it will apply c:\temp\1.cube if the submitted filename contains 1 and otherwise it will apply c:\temp\2.cube:
emcodem_custom_lut_decision.json
(5.79 KiB) Downloaded 199 times
emcodem, wrapping since 2009 you got the rhyme?
User avatar
FranceBB
Posts: 250
Joined: Sat Jun 25, 2016 3:43 pm
Contact:

Re: use custom LUT

Post by FranceBB »

Well, the only reason why a D-Log LUT doesn't exist is that when I created it a very long time ago (around 2019) I only had samples from one camera (a drone) on one shooting (they went out to shoot a new car they had to promote) and no documentation, so I wasn't really confident enough to put it anywhere. I noticed that you mentioned applying a watermark, in which case you really can't use the LUT function in the encoder, unless your watermark is also in D-Log, of course. :P

The best thing to do this is using Avisynth and luckily you can automate the whole thing in FFAStrans (that's the "AS" in the name). :)

The first thing you need to do is add the A/V Decoder and make sure it's set to "Same as Source" everywhere and that the "Force 8bit" is unticked.
Then, go to http://avisynth.nl/index.php/Avsresize and download "avsresize" (right hand side).
Put the 64bit dll wherever you want (but I suggest in the FFAStrans, processors, avs_plugins folder as all the examples will use that folder).
Put your LUT in the LUTs folder, namely in the FFAStrans installation folder, processors, avs_plugins, LUTs.

In your workflow, add a Custom AVS Script and inside it you can write:

Code: Select all

LoadPlugin("%s_ffastrans_dir%\Processors\avs_plugins\AVSCube\x64\vscube.dll")
LoadPlugin("%s_ffastrans_dir%\Processors\avs_plugins\avsresize.dll")

#Screw frame properties
propclearall(m_clip)
AssumeFrameBased()

#Bring everything to RGB Full Range 16bit
z_ConvertFormat(pixel_type="RGBP16", colorspace_op="709:709:709:limited=>rgb:709:709:full", resample_filter_uv="Spline64", dither_type="error_diffusion", use_props=0)

#Apply the LUT to go to BT709 with 16bit precision and tetrahedral interpolation
Cube("%s_ffastrans_dir%\Processors\avs_plugins\LUTs\DJI_ZENMUSE_X9_DLog_To_Rec709.cube", fullrange=1, interp=1)

#Go back to YUV Limited TV range 8bit with dithering
z_ConvertFormat(pixel_type="YUV420P8", colorspace_op="rgb:709:709:full=>709:709:709:limited", resample_filter_uv="Spline64", dither_type="error_diffusion", use_props=0)

#Clipping
Limiter(min_luma=16, max_luma=235, min_chroma=16, max_chroma=240)

#Workaround for the filter builder
AssumeFieldBased() #workaround for filter builder since 1.3.1
propSet("_FieldBased", 0) #progressive
propSet("_ColorRange", 1) #Limited TV Range
propSet("_Matrix", 1) #BT709
propSet("_Transfer", 1) #BT709
propSet("_Primaries", 1) #BT709

m_clip=last

Return m_clip
Then, after this, you can connect the watermark node and after that the encoding node to get your desired output ;)

This automatically assumes that your LUT is made to work in full pc range (normal RGB), however this might not be the case.
If this isn't the case (i.e if your LUT is made to work in limited tv range, what people call Studio RGB) then you need to change the "full" to "limited" in both z_ConvertFormat() calls.
One very important note is that the LUT function in the encoder isn't using Avisynth but rather FFMpeg and - as things stand - does NOT support Studio RGB / Narrow Range / Limited TV Range (different people call it different names), so in case you have such a LUT your only choice is Avisynth, regardless on whether you need to add a watermark node or not.

By the way... is DJI_ZENMUSE_X9_DLog_To_Rec709.cube something you made or something the camera/drone producer made?
In either case, would you mind sharing it so that we can take a look at it?
I'd like to make it go through LUT Calc. :)
emcodem
Posts: 1692
Joined: Wed Sep 19, 2018 8:11 am

Re: use custom LUT

Post by emcodem »

Ah sorey i have overseen that you want to do first color conversion then watermark. In this case you can use avisynth as frank describes or a custom ffmpeg commandline but this would be very limited in regards to input source formats.
emcodem, wrapping since 2009 you got the rhyme?
kalamazandy
Posts: 6
Joined: Tue Jun 18, 2024 6:24 pm

Re: use custom LUT

Post by kalamazandy »

Thank you both for helping. I am sure I will look back at this later, when I inevitably change things up a bit.
I ended up just color correcting the watermark. It's only black and white and isn't all that important. It's only for internal use to discourage people from using the preview and doesn't block all that much of the video. I put it in the top right corner to try and keep it out of the way.

As much as possible, I get the camera to rec.709 from the manufacturer. I had to install Resolve to get Blackmagic's luts, but I am having to use Adobe Media Encoder to convert the braw files first, then use FFAStrans to pick up those files, apply the watermark, resize, and output the file with the lut. Support for braw would be awesome, even if it's just something like, install resolve and just using their converter to handle some things. ffprobe reads it ok, but to decode it you'd need to use something like this: https://github.com/AkBKukU/braw-decode
On quick look, it maybe only works on linux? I don't know anything about compiling things on windows, and I can only follow directions on linux. lol

edit: I forgot to share the luts, so added those. I created the "dummy" lut so that I could have files in the same workflow that get no change. Since I'm applying the lut with a custom variable I still had to apply A lut, so just made one that doesn't change anything.
The black magic and RED camera luts in there are getting encoded with AME first, but I figured I'd share those as well. I got the black magic ones from Resolve, but they add a flag that doesn't work in adobe so I commented that out. They actually have a Ton of luts from their standard free install, so if you're looking for good luts, that's probably a great place. Resolve is kind of the go-to for colorists as far as I know. We just use AfterEffects so much, and hard drive space is always an issue, so more direct link workflows help.
Attachments
LUTs.zip
(1.73 MiB) Downloaded 188 times
Last edited by kalamazandy on Wed Jun 26, 2024 12:17 pm, edited 1 time in total.
Post Reply