Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 13 additions & 16 deletions python_raw2dng/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,9 @@ This will, however, automatically make a directory where it will put the output
Requirements
------------

Python 2.7
Python 3

This might work in Python 3 as well, but it has not been tested.

Windows users will need Python 2.7, available here: https://www.python.org/downloads/release/python-278/
Windows users will need Python, [available here](https://www.python.org/downloads/windows/)

Instructions
------------
Expand All @@ -26,21 +24,20 @@ Copy the script file, pyraw2dng.py and the raw 16 bit format video into the same

Open a terminal in that directory and use a command similar to the following, but replacing (width) and (length) with the horizontal and vertical resolutions of the video, and (filename.raw) with the name of the raw video file.

For Windows:
python pyraw2dng.py -w (width) -l (length) (filename.raw)
Note: Under default install (without python in PATH), the first term "python" has to be replaced with "c:\Python27\python.exe"
### For Windows

python pyraw2dng.py -w (width) -l (length) (filename.raw)

Under default install (without python in PATH), the first term "python" has to be replaced with "c:\Python37\python.exe"

For Linux:
./pyraw2dng.py -w (width) -l (length) (filename.raw)
### For Linux:

./pyraw2dng.py -w (width) -l (length) (filename.raw)

Optional arguments to add to decode 12-bit videos:
The --packed option will decode the raw file as a 12-bit packed format
generated from cameras with a software version v0.3.1 and newer.
The --oldpack option will attempt to decode the raw file as a 12-bit
packed format generated from software versions v0.3.0 and older. However
due bugs in this encoding format, there may be off-by-one pixel errors
in the encoded files. This is most noticeable as colour corruption
after demosiac.

* --packed option will decode the raw file as a 12-bit packed format generated from cameras with a software version v0.3.1 and newer.
* --oldpack option will attempt to decode the raw file as a 12-bit packed format generated from software versions v0.3.0 and older. However due bugs in this encoding format, there may be off-by-one pixel errors in the encoded files. This is most noticeable as colour corruption after demosiac.

If the script runs successfully, there will be a folder with the same name as your file containing the .dng images and the text "(filename).raw" will appear in the terminal.

Expand Down
34 changes: 17 additions & 17 deletions python_raw2dng/pyraw2dng.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#!/usr/bin/python2.7
#!/usr/bin/python

# standard python imports
import sys
Expand Down Expand Up @@ -28,7 +28,7 @@ class Type:
IFD = (13,4) # IFD (Same as Long)

Types = [(getattr(Type,n),n) for n in dir(Type) if n!="__doc__" and n!="__module__"]
Types.sort()


class Tag:
Invalid = (0,Type.Invalid)
Expand Down Expand Up @@ -144,11 +144,11 @@ class Tag:
BaselineExposureOffset = (51109,Type.Srational) # 1.4 Spec says rational but mentions negative values?
NewRawImageDigest = (51111,Type.Byte)

IfdNames = [n for n in dir(Tag) if n!="__doc__" and n!="__module__"]
IfdValues = [getattr(Tag,n) for n in IfdNames]
IfdIdentifiers = [getattr(Tag,n)[0] for n in IfdNames]
IfdTypes = [getattr(Tag,n)[1][0] for n in IfdNames]
IfdLookup = dict(zip(IfdIdentifiers,IfdNames))
# IfdNames = [n for n in dir(Tag) if n!="__doc__" and n!="__module__"]
# IfdValues = [getattr(Tag,n) for n in IfdNames]
# IfdIdentifiers = [getattr(Tag,n) for n in IfdNames]
# IfdTypes = [getattr(Tag,n) for n in IfdNames]
# IfdLookup = dict(list(zip(IfdIdentifiers,IfdNames)))

class dngHeader(object):
def __init__(self):
Expand Down Expand Up @@ -188,12 +188,12 @@ def setValue(self, value):
elif self.DataType == Type.Rational: self.Value = struct.pack('<%sL' % (len(value)*2), *[item for sublist in value for item in sublist]) # ... This... uhm... flattens the list of two value pairs
elif self.DataType == Type.Srational: self.Value = struct.pack('<%sl' % (len(value)*2), *[item for sublist in value for item in sublist])
elif self.DataType == Type.Ascii:
self.Value = struct.pack('<%scx0L' % len(value), *value)
self.Value = struct.pack('<%scx0L' % len(value), *[bytes(x, 'utf-8') for x in value])
self.DataCount += 1
elif self.DataType == Type.IFD:
self.Value = "\x00\x00\x00\x00"
self.Value = b'\x00\x00\x00\x00'
self.subIFD = value[0]
self.Value += '\x00'*(((len(self.Value)+3) & 0xFFFFFFFC) - len(self.Value))
self.Value += b'\x00'*(((len(self.Value)+3) & 0xFFFFFFFC) - len(self.Value))


def setBuffer(self, buf, tagOffset, dataOffset):
Expand Down Expand Up @@ -298,7 +298,7 @@ def dataLen(self):
return (totalLength + 3) & 0xFFFFFFFC

def write(self):
struct.pack_into("<ccbbI", self.buf, 0, 'I', 'I', 0x2A, 0x00, 8) # assume the first IFD happens immediately after header
struct.pack_into("<ccbbI", self.buf, 0, b'I', b'I', 0x2A, 0x00, 8) # assume the first IFD happens immediately after header

for ifd in self.IFDs:
ifd.write()
Expand Down Expand Up @@ -480,17 +480,17 @@ def main():
options, args = getopt.getopt(sys.argv[1:], 'CMpw:l:h:',
['help', 'color', 'packed', 'mono', 'width', 'length', 'height', 'oldpack'])
except getopt.error:
print 'Error: You tried to use an unknown option.\n\n'
print helptext
print('Error: You tried to use an unknown option.\n\n')
print(helptext)
sys.exit(0)

if len(sys.argv[1:]) == 0:
print helptext
print(helptext)
sys.exit(0)

for o, a in options:
if o in ('--help'):
print helptext
print(helptext)
sys.exit(0)

elif o in ('-C', '--color'):
Expand All @@ -512,14 +512,14 @@ def main():
width = int(a)

if len(args) < 1:
print helptext
print(helptext)
sys.exit(0)

elif len(args) == 1:
inputFilename = args[0]
dirname = os.path.splitext(inputFilename)[0]
basename = os.path.basename(inputFilename)
print basename
print(basename)
outputFilenameFormat = dirname + '/frame_%06d.DNG'
else:
inputFilename = args[0]
Expand Down