FileFlows icon indicating copy to clipboard operation
FileFlows copied to clipboard

Feature: Add support for transcoding to HDR and HDR10+/Dolby Vision

Open GamerBene19 opened this issue 2 years ago • 6 comments

As far as I can tell FileFlows does not currently support having HDR or HDR10+/DV metadata in output. I think support for it could be achieved fairly simply.

Some example steps for HDR, HDR10+ and DV are below. They are taken (and partly adapted/updated) from here and here.

HDR

  1. Extract mastering display metadata from output of ffprobe
  2. Encode Video

HDR10+

  1. Have hdr10plus_tool installed and in PATH
  2. Step 1 of HDR
  3. Extract HDR10+ metadata to JSON:
    ffmpeg -loglevel panic -i <input> -c:v copy -vbsf hevc_mp4toannexb -f hevc - | hdr10plus_tool extract -o metadata.json -
  4. Encode video

    Note: The user has to have a ffmpeg build with support for HDR10+ enabled. It it isn't enabled the output of ffmpeg during encoding will contain the message x265 [warning]: --dhdr10-info disabled. Enable HDR10_PLUS in cmake.

DV

I haven't tested these steps myself (I did test/verify the HDR(10+) steps). I might/will update this section once I have successfully encoded with DV

  1. Have dovi_tool installed and in PATH
  2. Step 1 of HDR
  3. Extract RPU: ffmpeg -i <input> -c:v copy -vbsf hevc_mp4toannexb -f hevc - | dovi_tool extract-rpu - -o RPU.bin
  4. Encode: ffmpeg -i <input> -f yuv4mpegpipe -strict -1 -pix_fmt yuv420p10le - | x265-10b - --input-depth 10 --output-depth 10 --y4m --preset veryfast --crf 22 --master-display "G(8500,39850)B(6550,2300)R(35400,14600)WP(15635,16450)L(40000000,50)" --max-cll "0,0" --colormatrix bt2020nc --colorprim bt2020 --transfer smpte2084 --dolby-vision-rpu glass.rpu --dolby-vision-profile 8.1 --vbv-bufsize 20000 --vbv-maxrate 20000 <output>.hevc
  5. Remux to container (mkv) with -c:v copy (FFmpeg 5.0+ required)

Also see this section in regards to step 3 and 4

GamerBene19 avatar Apr 24 '22 16:04 GamerBene19

These solution are not cross platform, ie they wont run on windows. And what benefit does this achieve creating a new output file? You could just run the executor or function node to execute a process afterwards?

revenz avatar Apr 25 '22 02:04 revenz

These solution are not cross platform

Why wouldn't they? There are binaries available for Windows aswell for both tools and ffprobe is included with fffmpeg.

And what benefit does this achieve creating a new output file?

I don't quite understand what you mean by "creating a new output file" - I think there might be a misunderstanding here.
AFAIK without these options/steps FFmpeg will not write the HDR10+/DV metadata. I thought it would not write HDR metadata aswell, but on Discord you mentioned

... if the soruce is HDR it will remain HDR

so I'm not quite sure on that :thinking:

You could just run the executor or function node to execute a process afterwards?

As I understand it the steps (to extract metadata) have to be run before encoding, so that you can then encode the file with proper HDR(10+)/DV metadata. There won't be any additional files (apart from the temporary metadata-files).

GamerBene19 avatar Apr 25 '22 06:04 GamerBene19

ffmpeg -i -c:v copy -vbsf hevc_mp4toannexb -f hevc - | dovi_tool extract-rpu - -o RPU.bin I thought that command was creating a new file and the other command also was creating a new output file, and that's what you were after.

Yeah, if the file is HDR it remains HDR. I had to add an HDR to SDR node to remove the HDR (my playback devices don't work well with HDR,).

You can still use the function node to execute and create these files, then just pass those into the ffmpeg command to use.

Including this in FF atm has some hurdles

  1. FFMPEG 5. Im using the jellyfin prebuilt in docker which is 4.4
  2. Include these extra utils in the windows installer/docker.

If you are running this outside docker, upgrading to ffmpeg 5 shouldn't be a problem, neither would installing these additional utils, then just use the function node to run them.

If executing from docker, then it makes it more complex since ffmpeg will be reverted/those utils would be gone on upgrade. This could be eased with a external script that reapplied these for you.

So what does this achieve exactly? Ensuring if you transcoding from HDR, HDR10+/Dolby Vision in remains in that? Or does it imitate and convert a non HDR to HDR? I'm guessing the former, but just want to be clear.

I could add nodes that did this in the FFMPEG Builder, that would need tools for these added in the tools page (that's what this page was intended to be used for). Updating the docker with ffmpeg 5 is the primary thing stopping me atm. Getting a ffmpeg built from source with all the hardware encoders/decoders is difficult, and hence why I'm using jellyfins prebuilt.
Windows I could just say, you need to download and install these additional packages.

revenz avatar Apr 25 '22 06:04 revenz

I thought that command was creating a new file and the other command also was creating a new output file, and that's what you were after.

That command does indeed create a new file. But it is a temporary file that is only needed for encoding the video. I don't want/need that file after encoding. Sorry for the misunderstanding

FFMPEG 5. Im using the jellyfin prebuilt in docker which is 4.4

Yes, I (even on Arch) had to download a build from here. I do have FFmpeg 5 installed, but the version I have is not compiled with support for the --dhdr10-info and --dolby-vision-rpu flags for the x265 encoder.

Include these extra utils in the windows installer/docker.

Yes, I also thought about this. It would make windows install/docker more complex.

So what does this achieve exactly? Ensuring if you transcoding from HDR, HDR10+/Dolby Vision in remains in that?

Yes excatly. I basically want to keep HDR(10+)/DV information from the source in my transcoded output.

If you are running this outside docker, upgrading to ffmpeg 5 shouldn't be a problem, neither would installing these additional utils, then just use the function node to run them.

I do have installed via the zip and that's what I've got planned for today.

I could add nodes that did this in the FFMPEG Builder, that would need tools for these added in the tools page (that's what this page was intended to be used for)

That would be awesome, as I would not have to create the commands by hand that way. However I guess you would need more details for creating those nodes? If you are looking for sample files here are the ones I've found these for HDR, HDR10+ and DV.

GamerBene19 avatar Apr 25 '22 07:04 GamerBene19

I could add nodes that did this in the FFMPEG Builder, that would need tools for these added in the tools page (that's what this page was intended to be used for)

Whats the current plan on this? Are you planning to implement it? If not I'd try to find a solution that works with the executor node

GamerBene19 avatar Apr 26 '22 15:04 GamerBene19

its blocked until jellyfin release a ffmpeg 5 version.

revenz avatar Apr 26 '22 21:04 revenz