Opened 8 years ago

Last modified 4 months ago

#4364 open enhancement

Support for DNG (RAW)

Reported by: Clément Bœsch Owned by:
Priority: wish Component: avcodec
Version: git-master Keywords: tif
Cc: Blocked By:
Blocking: Reproduced by developer: no
Analyzed by developer: no

Description

Currently only detects the preview:

☭ ./ffprobe /tmp/L1004220.DNG
ffprobe version N-70643-gb7cb8b3 Copyright (c) 2007-2015 the FFmpeg developers
  built with gcc 4.9.2 (GCC) 20150304 (prerelease)
  configuration: --prefix=/home/ux/local --enable-gpl --enable-nonfree --enable-libx264 --enable-libfaac --enable-libvorbis --enable-libfontconfig --enable-libfreetype --enable-libass --enable-libmp3lame --samples=/home/ux/fate-samples --assert-level=2
  libavutil      54. 20.100 / 54. 20.100
  libavcodec     56. 26.100 / 56. 26.100
  libavformat    56. 25.101 / 56. 25.101
  libavdevice    56.  4.100 / 56.  4.100
  libavfilter     5. 12.100 /  5. 12.100
  libswscale      3.  1.101 /  3.  1.101
  libswresample   1.  1.100 /  1.  1.100
  libpostproc    53.  3.100 / 53.  3.100
[tiff_pipe @ 0x2c39c60] Stream #0: not enough frames to estimate rate; consider increasing probesize
Input #0, tiff_pipe, from '/tmp/L1004220.DNG':
  Duration: N/A, bitrate: N/A
    Stream #0:0: Video: tiff, rgb24, 320x216 [SAR 1:1 DAR 40:27], 25 tbr, 25 tbn, 25 tbc

Overview: https://en.wikipedia.org/wiki/Digital_Negative
Sample: http://kenrockwell.com/leica/m9/sample-photos-3.htm

Change History (21)

comment:1 by Clément Bœsch, 8 years ago

Summary: Support for DMG (RAW)Support for DNG (RAW)

comment:2 by Michael Niedermayer, 8 years ago

Keywords: tif added; tiff removed

consistent keyword with other tiff tickets

comment:3 by compn, 7 years ago

Is there a dng spec somewhere?

comment:4 by Reto Kromer, 7 years ago

Last edited 7 years ago by Reto Kromer (previous) (diff)

comment:6 by Carl Eugen Hoyos, 7 years ago

Keywords: dmg raw removed
Status: newopen

comment:7 by Balling, 13 months ago

It now says

[tiff @ 0000018cc81ba000] non increasing IFD offset is not implemented. Update your FFmpeg version to the newest one from Git. If the problem still occurs, it means that your file has a feature which has not been implemented.

in reply to:  7 comment:8 by Michael Niedermayer, 7 months ago

Replying to Balling:

It now says

[tiff @ 0000018cc81ba000] non increasing IFD offset is not implemented. Update your FFmpeg version to the newest one from Git. If the problem still occurs, it means that your file has a feature which has not been implemented.

patch which fixes this regression is on the ML "[PATCH] avcodec/tiff: Fix loop detection"

comment:9 by Michael Koch, 7 months ago

Here are a few DNG images for testing:

This image was taken with a Canon 6D camera (in CR2 format) and converted to DNG by Adobe DNG converter V12.4:
http://www.astro-electronic.de/IMG_3459.dng

This image was taken with a Canon 5D-MK4 camera (in CR2 format) and converted to DNG by Adobe DNG converter V12.4:
http://www.astro-electronic.de/Canon_5D.dng

This image was directly generated by a Pentax K5 camera:
http://www.astro-electronic.de/Pentax_K5.DNG

Some other DNG images are linked in this thread:
http://ffmpeg.org/pipermail/ffmpeg-user/2020-August/049681.html

comment:10 by Balling, 6 months ago

So to support RAW like GRBG or more common RGGB you just need to support mosaicing from raw planes and then some demosaicing alogorithm, AMaZE, LMMSE, RCD, etc. See Rawtherapee code. You should also support quite complex color managment both before and after.

comment:11 by Michael Koch, 6 months ago

I don't understand why this must be invented again. The work is already done in Libraw. DNG and many other RAW formats. People want to import RAW images from their digital cameras for making timelapse videos. If RAW images can be imported directly, then DNG is an unnecessary intermediate step. https://www.libraw.org/

comment:12 by Balling, 5 months ago

Thanks to bf64a75c5ae58ed575303f70b2ab9b2208ded339 there are no longer any crazy problems when you convert to png or jpeg xl. Tnanks.

comment:13 by Michael Koch, 5 months ago

There is still the problem that the PNG or JXL output images have the wrong size. In the first three cases there are black or noisy borders visible, and in the 4th case the image size is doubled:

http://www.astro-electronic.de/IMG_3459.dng
Should be 5472x3648, but is 5568x3708

http://www.astro-electronic.de/Canon_5D.dng
Should be 6720x4480, but is 6880x4544

http://www.astro-electronic.de/Pentax_K5.DNG
Should be 4928x3264, but is 4992x3284

http://ffmpeg.org/pipermail/ffmpeg-user/2020-August/049681.html
Should be 3008x1600, but is 6016x3200

P.S. Colors seem to be better in JXL than in PNG. But maybe I'm doing something wrong. I'd like to see an example for conversion to PNG.

P.P.S. In case of the 4th image, I'm not sure what's the correct size.
IrfanView: 3008x1600
FastStone Image Viewer: 3008x1600
ExifTool: 6016x3200
FFprobe: 6016x3200
RawTherapee: reports 6008x3192, but shows only a black image
Fitswork: 6016x3200

Last edited 5 months ago by Michael Koch (previous) (diff)

comment:14 by Balling, 5 months ago

P.S. Colors seem to be better in JXL than in PNG. But maybe I'm doing something wrong. I'd like to see an example for conversion to PNG

That is because jpeg xl supports tagging as linear transfer, ffplay does not support linear transfer, use mpv. It is still not perfect, blue is desaturated.

Last edited 5 months ago by Balling (previous) (diff)

comment:15 by Michael Koch, 5 months ago

FFmpeg fails to import a DNG image which was taken by a Panasonic GH5S camera (in RW2 format) and converted to DNG by Adobe DNG Converter 12.4.0.555.
Here is a sample:
http://www.astro-electronic.de/GH5S.dng

comment:16 by Michael Koch, 5 months ago

A possible algorithm for cropping could work as follows.

The following tags from the DNG files are required:
"Default Crop Size", "Default Crop Origin" and "Active Area"

The cropping size is "Default Crop Size", or if this tag isn't set, then no cropping is required.
The cropping origin is the sum of "Default Crop Origin" and "Active Area", but please note that in "Active Area" the order is y before x.
If "Active Area" isn't set, then use only "Default Crop Origin".
If "Default Crop Origin" is also unset, then use 0,0 as cropping origin.

This algorithm should work at least for images from Canon 6D, Canon 5D-MK4, Pentax K1, Pentax K5 and DJI Zemuse X7.

comment:17 by Carl Eugen Hoyos, 5 months ago

I have implemented this and will send a patch.

comment:18 by Michael Koch, 5 months ago

If anybody has DNG images from other cameras which weren't yet mentioned here, please post a link to sample files.

P.S. Does anybody have a DNG test image with known colors?

Last edited 5 months ago by Michael Koch (previous) (diff)

comment:19 by Balling, 5 months ago

P.S. Does anybody have a DNG test image with known colors?

RAW cannot be shown on SDR display. See new Photosop 2023 and Camera Raw 15 feature. https://www.youtube.com/watch?v=FW7hee5j49w (Use HDR display.)

We know how color managment works in DNG.

Last edited 5 months ago by Balling (previous) (diff)

in reply to:  19 comment:20 by Michael Koch, 5 months ago

Replying to Balling:

P.S. Does anybody have a DNG test image with known colors?

RAW cannot be shown on SDR display. See new Photosop 2023 and Camera Raw 15 feature. https://www.youtube.com/watch?v=FW7hee5j49w (Use HDR display.)

We know how color managment works in DNG.

What can be done to import DNG images with the correct colors?
Are there any workarounds?

comment:21 by Adrian, 4 months ago

Here's a sample dng file which crashes ffmpeg, but works in other players (eg. Resolve, and Windows can show thumbnail)

https://eddy.cx/files/B001_029_20221207_000001.DNG

This file was compressed by SlimRaw, and the original file was working correctly in ffmpeg

Note: See TracTickets for help on using tickets.