1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
|
#!/usr/bin/python
import sys
import os
import ntpath
import tempfile
import shutil
import xml.etree.ElementTree as ET
if len(sys.argv) < 2:
print 'Syntax: %s <film>' % sys.argv[1]
sys.exit(1)
tree = ET.parse(os.path.join(sys.argv[1], 'metadata.xml'))
try:
os.makedirs(os.path.join(sys.argv[1], 'dummy'))
except:
pass
for c in tree.getroot().find('Playlist').findall('Content'):
type = c.find('Type').text
if type == 'DCP':
# Find the ASSETMAP
assetmap_file = None
for p in c.findall('Path'):
if os.path.basename(p.text) == 'ASSETMAP':
assetmap_file = p.text
assert(assetmap_file is not None)
dir = os.path.dirname(assetmap_file)
assets = {}
assetmap = ET.parse(assetmap_file)
ns = {'am': 'http://www.digicine.com/PROTO-ASDCP-AM-20040311#'}
for a in assetmap.getroot().find('am:AssetList', ns).findall('am:Asset', ns):
assets[a.find('am:Id', ns).text[9:]] = a.find('am:ChunkList', ns).find('am:Chunk', ns).find('am:Path', ns).text
cpl_id = None
for k, v in assets.iteritems():
try:
e = ET.parse(os.path.join(dir, v))
if e.getroot().tag == '{http://www.digicine.com/PROTO-ASDCP-CPL-20040511#}CompositionPlaylist':
cpl_id = k
except:
pass
assert(cpl_id is not None)
cpl = ET.parse(os.path.join(dir, assets[cpl_id]))
ns = {'cpl': 'http://www.digicine.com/PROTO-ASDCP-CPL-20040511#'}
for r in cpl.find('cpl:ReelList', ns).findall('cpl:Reel', ns):
for a in r.find('cpl:AssetList', ns).iter():
if a.tag == '{%s}MainPicture' % ns['cpl']:
id = a.find('cpl:Id', ns).text[9:]
duration = int(a.find('cpl:IntrinsicDuration', ns).text)
black_png = tempfile.NamedTemporaryFile('wb', suffix='.png')
black_j2c = tempfile.NamedTemporaryFile('wb', suffix='.j2c')
os.system('convert -size 1998x1080 xc:black %s' % black_png.name)
os.system('image_to_j2k -i %s -o %s' % (black_png.name, black_j2c.name))
j2c_dir = tempfile.mkdtemp()
print j2c_dir
for i in range(0, duration):
shutil.copyfile(black_j2c.name, os.path.join(j2c_dir, '%06d.j2c' % i))
os.system('asdcp-wrap -a %s %s %s' % (id, j2c_dir, os.path.join(sys.argv[1], 'dummy', assets[id])))
elif a.tag == '{%s}MainSound' % ns['cpl']:
wav = tempfile.NamedTemporaryFile('wb', suffix='.wav')
id = a.find('cpl:Id', ns).text[9:]
duration = int(a.find('cpl:IntrinsicDuration', ns).text)
edit_rate = int(a.find('cpl:EditRate', ns).text.split()[0])
os.system('sox -n -r 48000 -c 6 %s trim 0.0 %f' % (wav.name, float(duration) / edit_rate))
os.system('asdcp-wrap -a %s %s %s' % (id, wav.name, os.path.join(sys.argv[1], 'dummy', assets[id])))
elif type == 'Sndfile':
audio_frame_rate = int(c.find('AudioFrameRate').text)
channels = int(c.find('AudioMapping').find('InputChannels').text)
path = os.path.join(sys.argv[1], 'dummy', ntpath.basename(c.find('Path').text))
audio_length = int(c.find('AudioLength').text)
os.system('sox -n -r %d -c %d %s trim 0.0 %f' % (audio_frame_rate, channels, path, float(audio_length) / audio_frame_rate))
elif type == 'FFmpeg':
if c.find('VideoFrameRate') is not None:
video_frame_rate = int(c.find('VideoFrameRate').text)
video_length = int(c.find('VideoLength').text)
path = os.path.join(sys.argv[1], 'dummy', ntpath.basename(c.find('Path').text))
os.system('ffmpeg -t %d -s qcif -f rawvideo -pix_fmt rgb24 -r %d -i /dev/zero -f lavfi -i anullsrc=channel_layout=stereo:sample_rate=48000 -shortest "%s"' % (float(video_length) / video_frame_rate, video_frame_rate, path))
elif type == 'Image':
width = int(c.find('VideoWidth').text)
height = int(c.find('VideoHeight').text)
path = os.path.join(sys.argv[1], 'dummy', ntpath.basename(c.find('Path').text))
os.system('convert -size %dx%d xc:black "%s"' % (width, height, path))
else:
print 'Skipped %s' % type
|