Author Topic: Small python script parsing MLV metadata  (Read 865 times)

byte_order

  • New to the forum
  • *
  • Posts: 1
Small python script parsing MLV metadata
« on: March 01, 2018, 06:29:22 PM »
Hi all,

To quickly extract MLV file duration (and some others) information from a command line interface, I wrote a small python script parsing most MLV metadata.
I dunno if it's useless for anybody but me, but if someone have some CLI-based MLV  workflow and mayb be interested, here the script:

https://gist.github.com/anonymous/e23af5a078f2d34f97fca5094b0691a9

It's for python 2.7. Should be easy to fix for python3, though.

a1ex

  • Administrator
  • Hero Member
  • *****
  • Posts: 12223
  • Maintenance mode
Re: Small python script parsing MLV metadata
« Reply #1 on: March 02, 2018, 05:01:56 PM »
Very useful - even as documentation.

Minor patch to show pixel binning info:
Code: [Select]
--- mlv_info.py
+++ mlv_info.py
@@ -1,4 +1,4 @@
-#!/usr/bin/evn python
+#!/usr/bin/env python
 # -*- coding: utf-8 -*-
 
 import struct
@@ -15,7 +15,7 @@
 mlv_lens_hdr = struct.Struct(block_hdr_fmt + 'H H H ? ? I I 32s 32s')
 mlv_expo_hdr = struct.Struct(block_hdr_fmt + 'I I I I Q')
 mlv_diso_hdr = struct.Struct(block_hdr_fmt + 'I I')
-mlv_rawc_hdr = struct.Struct(block_hdr_fmt + 'H H H')
+mlv_rawc_hdr = struct.Struct(block_hdr_fmt + 'H H H H B B B B h h')
 
 
 raw_info_struct = struct.Struct('< I I i i i i i') #  i i i i i i i i i i 2i i i 18i i')
@@ -81,8 +81,16 @@
 
 
 def parse_rawc_block(block):
-    _, _, _, sensor_xres, sensor_yres, sensor_crop_factor = mlv_rawc_hdr.unpack_from(block)
-    print "  sensor:  %d x %d (crop factor: %.2f)" % (sensor_xres, sensor_yres, sensor_crop_factor/100.0)
+    _, _, _, sensor_xres, sensor_yres, sensor_crop_factor, _, \
+        binning_x, skipping_x, binning_y, skipping_y, _, _ = mlv_rawc_hdr.unpack_from(block)
+    print "  sensor:  %d x %d" % (sensor_xres, sensor_yres)
+    print "  crop factor: %.2f" % (sensor_crop_factor/100.0)
+    print "  pixel binning:  %d x %d %s" % (binning_x + skipping_x, binning_y + skipping_y, "(with line skipping)" if skipping_y else "")
+    assert skipping_x == 0
+    assert binning_x == 1 or binning_x == 3
+    assert binning_y > 0
+    if binning_y > 1:
+        assert skipping_y == 0
 
 def parse_info_block(block):
     _, blocksize, _ = mlv_block_hdr.unpack_from(block)