Package Parser¶
Package Parser is a Python library to probe and analyze audiovisual packages :
- DCP : Digital Cinema Package
- IMP : Interoperable Master Package
It uses a third party library not provided in this package to parse MXF Cinecert asdcplib
Find a ready for use Docker container and Package parser CLI.
Installation¶
pip install packageparser
Usage¶
from packageparser import DcpAnalyzor, DcpProbe,dcp_match_vf_ov
from packageparser import ImpAnalyzor, ImpProbe
da = DcpAnalyzor(dcp_path, skip_hash, skip_ff, skip_mxf_analyze)
da.analyze()
dp = DcpProbe(dcp_path, skip_mxf_analyze)
dp.probe()
dcp_match_vf_ov(vf_dcp_path, ov_dcp_path)
ia = ImpAnalyzor(imp_path, skip_hash, skip_ff, skip_mxf_analyze)
ia.analyze()
ip = ImpProbe(imp_path, skip_mxf_analyze)
ip.probe()
DCP Analyzor¶
-
class
packageparser.dcpanalyzor.DcpAnalyzor(dcp_path, skip_hash=False, skip_ff=False, skip_mxf_analyze=False)¶ Bases:
packageparser.dcpprobe.DcpProbeDigital Cinema Package Analyzor
Parameters: - dcp_path (string) – absolute path to the DCP
- skip_hash (boolean) – skip SHA-1 hash files
- skip_ff (boolean) – set foreing file detection as error(True) or warring(False)
- skip_mxf_analyze (boolean) – skip asdcp MXF analyze
-
analyze()¶ - Steps :
- ASSETMAP : check extension
- ASSETMAP : check schema
- ASSETMAP : check smpte packinglist
- ASSETMAP : check volindex
- ASSETMAP : check file
- ASSETMAP : check foreing file
- ASSETMAP : check file path
- ASSETMAP : check uuid
- PKL : check header
- PKL : check asset size
- PKL : check asset hash
- PKL : check signature
- CPL : check header
- CPL : check signature
- CPL : check reels
- set check status
- returns (dictionnary):
- info (list)
- warning (list)
- error (list)
- foreing_file (list)
- asset_from_ov (list)
- version ‘OV(Original Version) / VF(Version File)’
- status ‘FAILED / SUCCEEDED’
-
assetmap_check_extension()¶ Check ASSETMAP file extension
-
assetmap_check_file()¶ Check missing files from ASSETMAP and link uuid to file
-
assetmap_check_file_path()¶ Check if files path contains space
-
assetmap_check_foreing_file()¶ Check foreing files from ASSETMAP
-
assetmap_check_schema()¶ Compare PKL, CPL and assets schema with ASSETMAP schema
-
assetmap_check_smpte_packinglist()¶ Check SMPTE PackingList block
-
assetmap_check_uuid()¶ Check PKL, CPL and assets UUID
-
assetmap_check_volindex()¶ Check VOLINDEX extension and VolumeIndex value
-
check_signature(xml_id, kind, signature, anchor, xmlsn)¶ Commun to PKL and CPL signature
Parameters: - xml_id (string) – uuid of the checked item
- kind (string) – ‘CPL / PKL’
- signature (dict) –
- anchor (string) –
- xmlsn (string) –
-
check_uuid(tested_uuid)¶ Check uuid regexp and if it is refered to the ASSETMAP
-
cpl_check_header()¶ - CPL main information checks:
- content title text
- issue date
- subtitle language
- creator
- issuer
- content kind
- CPL tests : IDCF, CST and EDCF
-
cpl_check_reel()¶ CPL’s structure and MXF assets against CPL reel information checks
- CPL structure checks :
- reel count
- reel duration
- global editrate
- global framerate
- global high framerate
- global encryption
- global aspect ratio
- global picture format
- global stereoscopy
- Reel by reel asset checks:
- editrate
- samplerate
- label
- aspect ratio
- resolution
- framerate
- high framerate
- encryption
- max bitrate
- average bitrate
- intrinsic duration
- container duration
- audio quantization
-
cpl_check_signature()¶ Find CPL signature blocks
-
pkl_check_asset_hash()¶ Check assets hash based on the PKL
-
pkl_check_asset_size()¶ Check assets size based on the PKL
-
pkl_check_header()¶ Check issue date, issuer and creator in the PKL
-
pkl_check_signature()¶ Find PKL signature blocks
-
set_status()¶ Set the global status based on error count
DCP Probe¶
-
class
packageparser.dcpprobe.DcpProbe(dcp_path, skip_mxf_analyze=False)¶ Bases:
objectDigital Cinema Package Probe
Parameters: - dcp_path (string) – absolute path to the DCP
- skip_mxf_analyze (boolean) – skip asdcp MXF analyze
Raises: ValueError– ASSETMAP not foundValueError– PKL not foundValueError– CPL not found
Returns: dictionnary
-
asset_probe()¶ Probe picture, sound, subtitle and atmos MXF
-
get_assetlist()¶ Extract asset path and uuid from ASSETMAP
-
get_reel_list()¶ Extract reel list from CPL and links asset to asset uuid
-
probe()¶ Extract information from DCP’s XML and MXF
- Probe steps :
- ASSETMAP
- PKL
- CPL
- MXF
- returns (dictionnary):
- assetmap_list (list)
- assetmap (dict)
- asset_uuid (dict)
- count_file (list)
- cpl_list (list)
- dcp_path (string)
- package_type ‘OV(Original Version) / VF(Version File)’
- pkl_list (list)
- reel_list (list)
- size (string)
- volindex (dict)
- schema ‘InterOP / SMPTE’
- type ‘DCP’
-
xml_in_assetmap()¶ Remove foreign CPL or PKL not refered in the ASSETMAP
DCP XML¶
-
packageparser.dcpxml.assetmap_parse(xml_path)¶ Test if the ASSETMAP xml meets the xmlns requirements and parse it
Parameters: xml_path (string) – path to the xml file
Raises: ValueError– ASSETMAP is not a fileValueError– ASSETMAP is not a xmlValueError– ASSETMAP key not foundValueError– ASSETMAP xmlns unknown
Returns: dictionnary
-
packageparser.dcpxml.cpl_parse(xml_path)¶ Test if the CPL xml meets the xmlns requirements and parse it
Parameters: xml_path (string) – path to the xml file
Raises: ValueError– CPL is not a fileValueError– CPL is not a xmlValueError– CPL xmlns unknown
Returns: dictionnary
-
packageparser.dcpxml.find_assetmap(dcp_path, files_path_list)¶ Find the ASSETMAP in the DCP
-
packageparser.dcpxml.find_cpl(xml_list)¶ Find CPLs in the DCP
-
packageparser.dcpxml.find_pkl(xml_list)¶ Find PKLs in the DCP
-
packageparser.dcpxml.find_volindex(dcp_path, files_path_list)¶ Find the VOLINDEX in the DCP
-
packageparser.dcpxml.font_test(font_path)¶ Test if the file is a font
Parameters: font_path (string) – path to the font file Raises: ValueError– CPL is not a file- Returns
- True or False
-
packageparser.dcpxml.kdm_parse(xml_path)¶ Test if the KDM xml meets the xmlns requirements and parse it
Parameters: xml_path (string) – full path to a xml file
Raises: ValueError– KDM is not a fileValueError– KDM is not a xmlValueError– DCinemaSecurityMessage key not found
Returns: dictionnary
-
packageparser.dcpxml.pkl_parse(xml_path)¶ Test if the PKL xml meets the xmlns requirements and parse it
Parameters: xml_path (string) – path to the xml file
Raises: ValueError– PKL is not a fileValueError– PKL is not a xmlValueError– PKL xmlns unknown
Returns: dictionnary
-
packageparser.dcpxml.reel_list_parse(cpl_reel)¶ Parameters: cpl_reel (list / dict) – list of reels in the CPL
Raises: ValueError– MainPicture or MainStereoscopicPicture not found in CPL reelValueError– MainSound not found in CPL reelValueError– AssetList not found in the CPL reel
- Items probed:
- CPL id
- auxdata
- picture
- sound
- subtitle
- encryption
- position in the CPL
- CPL frame duration
- CPL time code duration
Returns: dictionnary
DCP match vf ov¶
-
packageparser.dcp_match_vf_ov.dcp_match_vf_ov(vf_dcp_path, ov_dcp_path)¶ Launch DcpAnalyzor for a Version File(VF) and an Original Version(OV) DCP. Check if VF DCP needed assets are in OV DCP.
Parameters: - vf_dcp_path (string) – absolute path to a VF DCP
- ov_dcp_path (string) – absolute path to an OV DCP
Raises: ValueError– first DCP path must be a Version FileValueError– second DCP path must be an Original Version
Returns: List of result asset by asset
Return type: stdtout (list)
IMP Analyzor¶
-
class
packageparser.impanalyzor.ImpAnalyzor(imp_path, skip_hash=False, skip_ff=False, skip_mxf_analyze=False)¶ Bases:
packageparser.impprobe.ImpProbeInteroperable Master Package Analyzor
Parameters: - imp_path (string) – absolute path to the IMP
- skip_hash (boolean) – skip SHA-1 hash files
- skip_ff (boolean) – set foreing file detection as error(True) or warring(False)
- skip_mxf_analyze (boolean) – skip asdcp MXF analyze
-
analyze()¶ - Steps :
- ASSETMAP : check extension
- ASSETMAP : check schema
- ASSETMAP : check smpte packinglist
- ASSETMAP : check volindex
- ASSETMAP : check file
- ASSETMAP : check foreing file
- ASSETMAP : check file path
- ASSETMAP : check uuid
- PKL : check header
- PKL : check asset size
- PKL : check asset hash
- PKL : check signature
- CPL : check header
- CPL : check signature
- CPL : check segment
- set check status
- returns (dictionnary):
- info (list)
- warning (list)
- error (list)
- foreing_file (list)
- asset_from_ov (list)
- version ‘OV(Original Version) / VF(Version File)’
- status ‘FAILED / SUCCEEDED’
-
assetmap_check_extension()¶ Check ASSETMAP file extension
-
assetmap_check_file()¶ Check missing files from ASSETMAP and link uuid to file
-
assetmap_check_file_path()¶ Check if files path contains space
-
assetmap_check_foreing_file()¶ Check foreing files from ASSETMAP
-
assetmap_check_schema()¶ Compare PKL, CPL and assets schema with ASSETMAP schema
-
assetmap_check_smpte_packinglist()¶ Check SMPTE PackingList block
-
assetmap_check_uuid()¶ Check PKL, CPL and assets UUID
-
assetmap_check_volindex()¶ Check VOLINDEX extension and VolumeIndex value
-
check_signature(xml_id, kind, signature, anchor, xmlsn)¶ Commun to PKL and CPL signature
Parameters: - xml_id (string) – uuid of the checked item
- kind (string) – ‘CPL / PKL’
- signature (dict) –
- anchor (string) –
- xmlsn (string) –
-
check_uuid(tested_uuid)¶ Check uuid regexp and if it is refered to the ASSETMAP
-
cpl_check_header()¶ - CPL Main information checks:
- content title
- issue date
- subtitle language
- creator
- issuer
- content kind
- edit rate
- content version
- composition timecode
- locale list
-
cpl_check_segment()¶ CPL’s structure and MXF assets against CPL segment information checks
- CPL structure checks :
- segment count
- global audio editrate
- global picture editrate
- global encryption
- Sequence by sequence asset checks:
- editrate
- samplerate
- label
- aspect ratio
- resolution
- framerate
- high framerate
- encryption
- max bitrate
- average bitrate
- intrinsic duration
- container duration
- audio quantization
-
cpl_check_signature()¶ Find CPL signature blocks
-
pkl_check_asset_hash()¶ Check assets hash based on the PKL
-
pkl_check_asset_size()¶ Check assets size based on the PKL
-
pkl_check_header()¶ Check issue date, issuer and creator in the PKL
-
pkl_check_signature()¶ Find PKL signature blocks
-
set_status()¶ Set the global status based on error count
IMP Probe¶
-
class
packageparser.impprobe.ImpProbe(imp_path, skip_mxf_analyze=False)¶ Bases:
objectInteroperable Master Package Probe
Parameters: - imp_path (string) – absolute path to the IMP
- skip_mxf_analyze (boolean) – skip asdcp MXF analyze
Raises: ValueError– ASSETMAP not foundValueError– PKL not foundValueError– CPL not foundValueError– MainImageSequence not found in segment listValueError– MainAudioSequence not found in segment list
Returns: dictionnary
-
asset_probe(segement)¶ Probe picture, sound and subtitle MXF
-
get_assetlist()¶ Extract asset path and uuid from ASSETMAP
-
get_segment_list()¶ Extract segment list from CPL and links assets to asset uuid
-
probe()¶ Extract information from IMP’s XML and MXF
- Probe steps :
- ASSETMAP
- PKL
- CPL
- MXF
- returns (dictionnary):
- assetmap_list (list)
- assetmap (dict)
- asset_uuid (dict)
- count_file (list)
- cpl_list (list)
- opl_list (list)
- imp_path (string)
- pkl_list (list)
- segment_list (list)
- package_type ‘OV(Original Version) / VF(Version File)’
- size (string)
- volindex (dict)
- schema ‘SMPTE’
- type ‘IMP’
-
xml_in_assetmap()¶ Remove foreign CPL or PKL not refered in the ASSETMAP
IMP XML¶
-
packageparser.impxml.assetmap_parse(xml_path)¶ Test if the ASSETMAP xml meets the xmlns requirements and returns metadata as a dictionary
Parameters: xml_path (string) – path to the xml file
Raises: ValueError– ASSETMAP is not a fileValueError– ASSETMAP is not a xmlValueError– ASSETMAP key not foundValueError– ASSETMAP xmlns unknown
Returns: dictionnary
-
packageparser.impxml.cpl_parse(xml_path)¶ Test if the xml meets the CPL xmlns requirements and returns the metadata dictionary
Parameters: xml_path (string) – path to the xml file
Raises: ValueError– CPL is not a fileValueError– CPL is not a xmlValueError– CPL xmlns unknown
Returns: dictionnary
-
packageparser.impxml.find_assetmap(imp_path, files_path_list)¶ Find the ASSETMAP in the IMP
-
packageparser.impxml.find_cpl(xml_list)¶ Find CPLs in the IMP
-
packageparser.impxml.find_opl(xml_list)¶ Find OPL in the IMP
-
packageparser.impxml.find_pkl(xml_list)¶ Find PKLs in the IMP
-
packageparser.impxml.find_volindex(imp_path, files_path_list)¶ Find the VOLINDEX in the IMP
-
packageparser.impxml.opl_parse(xml_path)¶ Test if the xml meets the OPL xmlns requirements and returns the metadata dictionary
Parameters: xml_path (string) – path to the xml file
Raises: ValueError– OPL is not a fileValueError– OPL is not a xmlValueError– OPL xmlns unknown
Returns: dictionnary
-
packageparser.impxml.pkl_parse(xml_path)¶ Test if the PKL xml meets the xmlns requirements and returns metadata as a dictionary
Parameters: xml_path (string) – path to the xml file
Raises: ValueError– PKL is not a fileValueError– PKL is not a xmlValueError– PKL xmlns unknown
Returns: dictionnary
MXF Process¶
-
packageparser.mxfprocess.cmd_exists(cmd)¶
-
packageparser.mxfprocess.dcp_mxf_info(asset_dict)¶ Uses asdcp-info subprocess to get and parse DCP MXF metadata
Parameters: asset_dict (dictionnary) – asset metadata from CPL
Raises: ValueError– asdcp-info :: subprocess failed and returns 1ValueError– asdcp-info :: subprocess failed error
Returns: asset_dict (dictionnary)
-
packageparser.mxfprocess.imp_mxf_info(asset_dict)¶ Uses as-02-info subprocess to get and parse IMP MXF metadata
Parameters: asset_dict (dictionnary) – asset metadata from CPL
Raises: ValueError– as-02-info :: subprocess failed and returns 1ValueError– as-02-info :: subprocess failed error
Returns: asset_dict (dictionnary)
Utils¶
-
packageparser.utils.format_duration(edit_rate, picture_duration)¶ Format picture duration into Time Code hour:min:sec:frame based on edit rate
Parameters: - edit_rate (int) – video edit_rate
- picture_duration (int) – reel duration in frame
Returns: hour:min:sec:frame
Return type: time_conde (string)
-
packageparser.utils.format_framerate(framerate)¶ Format ‘X Y’ framerate into int or float
Parameters: framerate (string) – X Y Returns: Return type: framerate(int or float)
-
packageparser.utils.format_time(duration_sec)¶ Format second duration into hour:min:sec
Parameters: duration (int) – time elpased in seconde Returns: hh:mm:ss Return type: time(string)
-
packageparser.utils.get_folder_size(folder, human=True)¶ Calculate folder’s size
Parameters: folder (string) – folder absolute path Returns: Return type: folder_size (string)
-
packageparser.utils.humansize(nbytes, power_of_1024=0)¶ Format bytes int into human readable string 1024 > 1kB
Parameters: - nbytes (int) –
- power (int) –
Returns: Return type: size (string)
-
packageparser.utils.list_package_files(folder_path)¶ List files in a package folder
Parameters: folder_path (string) – Returns: full paths of xml files files_path_list(list): full paths files file_list(list): relative paths to the current folder path Return type: xml_list(list) Raises: ValueError– folder_path is not a folder
-
packageparser.utils.sha_base64(file_path, buff=None)¶ Compute the file sha1 base64
Parameters: - file_path (string) –
- buff (int) – file buffer
Returns: base64 encoded result
Return type: hash_base_64(string)
Raises: ValueError– file not found
-
packageparser.utils.xml_dict(xml_path)¶ Open xml file and return dict