Ejemplo n.º 1
0
    def test_file_readonly(self):
        test_file = os.path.join(sandbox, "readonly_file.aaf")
        f = aaf.open(test_file, 'w')
        f.save()
        f.close()

        f = aaf.open(test_file, 'r')
        f.save()
Ejemplo n.º 2
0
    def test_file_readonly(self):
        test_file = os.path.join(sandbox,"readonly_file.aaf")
        f = aaf.open(test_file, 'w')
        f.save()
        f.close()

        f = aaf.open(test_file, 'r')
        f.save()
Ejemplo n.º 3
0
    def test_file_modify(self):
        test_file = os.path.join(sandbox, "modify_file.aaf")
        f = aaf.open(test_file, 'w')
        f.save()
        f.close()

        f = aaf.open(test_file, 'rw')

        f.save()
Ejemplo n.º 4
0
    def test_file_modify(self):
        test_file = os.path.join(sandbox,"modify_file.aaf")
        f = aaf.open(test_file, 'w')
        f.save()
        f.close()

        f = aaf.open(test_file, 'rw')

        f.save()
Ejemplo n.º 5
0
    def test_skip(self):
        f = aaf.open(main_test_file)
        iterable = f.storage.mobs()

        assert len(iterable) == 199

        skip_amount = 100
        iterable.skip(skip_amount)

        assert iter_count(iterable) == 199 - skip_amount

        iterable.reset()

        assert len(iterable) == 199

        iterable.skip(skip_amount)

        try:
            iterable.skip(1000)
        except IndexError:
            pass
        else:
            raise

        assert iter_count(iterable) == 199 - skip_amount
Ejemplo n.º 6
0
    def test_file_transient(self):

        output_file =  os.path.join(sandbox,"transient_output.aaf")
        f = aaf.open(None, 't')
        f.save() # Doesn't do anything but should crash
        f.save(output_file)
        f.close()
def read_from_file(filepath, simplify=True):

    f = aaf.open(filepath)

    storage = f.storage

    # Note: We're skipping: f.header
    # Is there something valuable in there?

    __names.clear()
    masterMobs = {}

    result = _transcribe(storage, masterMobs=masterMobs)
    top = storage.toplevel_mobs()
    if top:
        # re-transcribe just the top-level mobs
        # but use all the master mobs we found in the 1st pass
        __names.clear()  # reset the names back to 0
        result = _transcribe(top, masterMobs=masterMobs)

    # AAF is typically more deeply nested than OTIO.
    # Lets try to simplify the structure by collapsing or removing
    # unnecessary stuff.
    if simplify:
        result = _simplify(result)

    # OTIO represents transitions a bit different than AAF, so
    # we need to iterate over them and modify the items on either side.
    # Note that we do this *after* simplifying, since the structure
    # may change during simplification.
    _fix_transitions(result)

    return result
def read_from_file(filepath, simplify=True):

    f = aaf.open(filepath)

    storage = f.storage

    # Note: We're skipping: f.header
    # Is there something valuable in there?

    __names.clear()
    masterMobs = {}

    result = _transcribe(storage, masterMobs=masterMobs)
    top = storage.toplevel_mobs()
    if top:
        # re-transcribe just the top-level mobs
        # but use all the master mobs we found in the 1st pass
        __names.clear()  # reset the names back to 0
        result = _transcribe(top, masterMobs=masterMobs)

    _fix_transitions(result)

    if simplify:
        result = _simplify(result)

    return result
Ejemplo n.º 9
0
 def test_basic(self):
     f = aaf.open(main_test_file, 'w')
     
     try:
         typdef = aaf.define.TypeDefRecord(f, [('some_int')], TypeId_Mixed, 'MixedRecord')
         
     except ValueError:
         pass
         print(traceback.format_exc())
     else:
         raise
     
     auid_typedef = f.dictionary.lookup_typedef("AUID")
     
     record_name_typedef_pairs = [('int64', 'int64'),
                                   ('uint64', 'uint64'), 
                                   ("auid", auid_typedef),
                                   ("UInt8Array8", "UInt8Array8"),
                                   ("FilmType", "FilmType")
                                   
                                   ]
     
     typedef = aaf.define.TypeDefRecord(f, record_name_typedef_pairs, TypeId_Mixed, 'MixedRecord')
     
     print(typedef.keys(), typedef.typedef_dict())
Ejemplo n.º 10
0
    def test_file(self):
        f = aaf.open(main_test_file, "r")
        mob = f.storage.lookup_mob(mob_id)

        for slot in mob.slots():
            for i, p in enumerate(slot.segment.parameter["testParam"].points()):
                assert point_values[i] == float(p.value)
Ejemplo n.º 11
0
    def test_walk_file(self):
        test_file = main_test_file

        f = aaf.open(test_file)

        header = f.header

        def walk_properties(space, iter_item):

            for item in iter_item:
                value = item
                if isinstance(item, aaf.property.PropertyItem):
                    value = item.value
                name = ""
                if hasattr(item, 'name'):
                    name = item.name or ""

                #print space,name, value
                s = space + '   '
                if isinstance(value, aaf.base.AAFObject):
                    #print space, value.class_name
                    walk_properties(s, value.properties())
                if isinstance(value, aaf.iterator.BaseIterator):


                    walk_properties(s, value)
                    #print "iterator!"

        walk_properties("", header.properties())
Ejemplo n.º 12
0
 def test_result(self):
     f = aaf.open(main_test_file, 'r')
     
     assert len(f.storage.master_mobs()) == 1
     mob = f.storage.lookup_mob(mob_id)
     assert mob.name == mob_name
     
     for i, slot in enumerate(mob.slots()):
         print(slot.name)
         assert slot.name == slot_names[i]
         
         seg = slot.segment
         print(seg)
         if slot.slotID == NumMobSlots:
             assert isinstance(seg, aaf.component.Sequence)
         else:
             assert isinstance(seg, aaf.component.SourceClip)
             
             src_mob =  seg.resolve_ref()
             for s in src_mob.slots():
                 tape_mob = s.segment.resolve_ref()
                 tape_description = tape_mob.essence_descriptor
                 print(tape_mob)
                 print(tape_description)
                 print("ManufacturerID =", tape_description['ManufacturerID'].value)
                 assert tape_description['ManufacturerID'].value == manufacturer
                 print("Model", tape_description['Model'].value)
                 assert tape_description['Model'].value == model
                 print("FormFactor", tape_description['FormFactor'].value)
Ejemplo n.º 13
0
    def test_basic(self):
        f = aaf.open(main_test_file, 'w')

        try:
            typdef = aaf.define.TypeDefRecord(f, [('some_int')], TypeId_Mixed, 'MixedRecord')

        except ValueError:
            pass
            print(traceback.format_exc())
        else:
            raise

        auid_typedef = f.dictionary.lookup_typedef("AUID")

        record_name_typedef_pairs = [('int64', 'int64'),
                                      ('uint64', 'uint64'),
                                      ("auid", auid_typedef),
                                      ("UInt8Array8", "UInt8Array8"),
                                      ("FilmType", "FilmType")

                                      ]

        typedef = aaf.define.TypeDefRecord(f, record_name_typedef_pairs, TypeId_Mixed, 'MixedRecord')

        print(typedef.keys(), typedef.typedef_dict())
Ejemplo n.º 14
0
    def test_basic(self):

        test_file = os.path.join(sandbox, "test_SourceClip.aaf")

        f = aaf.open(None, 't')

        source_mob = f.create.SourceMob()
        f.storage.add_mob(source_mob)
        slot = source_mob.add_nil_ref(1, 100, "picture", "25/1")

        source_ref = aaf.util.SourceRef()
        source_ref.mob_id = source_mob.mobID
        source_ref.slot_id = slot.slotID
        source_ref.start_time = 10
        #source_ref.

        source_clip = f.create.SourceClip("picture", 10, source_ref)

        assert source_clip.source_ref.mob_id == source_mob.mobID
        print(source_clip.source_ref.slot_id)

        assert source_clip.source_ref.slot_id == slot.slotID

        s = str(source_clip.source_ref)

        #slot = source_clip.resolve_slot()

        assert source_clip.start_time == 10
        source_clip.start_time = 5
        assert source_clip.start_time == 5
Ejemplo n.º 15
0
    def test_file_transient(self):

        output_file = os.path.join(sandbox, "transient_output.aaf")
        f = aaf.open(None, 't')
        f.save()  # Doesn't do anything but should crash
        f.save(output_file)
        f.close()
Ejemplo n.º 16
0
    def test_setting_property(self):
        
        f = aaf.open(main_test_file)
        
        mob = f.storage.composition_mobs()[0]
        
        mob_id = mob['MobID'].value
        
        d = mob_id.to_dict()
        d['instanceLow'] = 10
        d['length'] = 2

        mob['MobID'].value = d
        
        assert mob['MobID'].value != mob_id
        
        mob['MobID'].value = mob_id
        
        assert mob['MobID'].value == mob_id
        
        mob_id2 = aaf.util.MobID.from_dict(d)
        
        assert mob_id2 != mob_id
        
        mob['MobID'].value = str(mob_id2)
        assert mob['MobID'].value == mob_id2 
Ejemplo n.º 17
0
 def test_skip(self):
     f = aaf.open(main_test_file)
     iterable = f.storage.mobs()
     
     assert len(iterable) == 199
     
     
     skip_amount = 100
     iterable.skip(skip_amount)
     
     assert iter_count(iterable) == 199 - skip_amount
     
     iterable.reset()
     
     assert len(iterable) == 199
     
     
     iterable.skip(skip_amount)
     
     try:
         iterable.skip(1000)
     except IndexError:
         pass
     else:
         raise
     
     assert iter_count(iterable) == 199 - skip_amount
Ejemplo n.º 18
0
    def test_result(self):
        f = aaf.open(main_test_file, 'r')

        assert len(f.storage.master_mobs()) == 1
        mob = f.storage.lookup_mob(mob_id)
        assert mob.name == mob_name

        for i, slot in enumerate(mob.slots()):
            print slot.name
            assert slot.name == slot_names[i]

            seg = slot.segment
            #print seg
            if slot.slotID == NumMobSlots:
                assert isinstance(seg, aaf.component.Sequence)
            else:
                assert isinstance(seg, aaf.component.SourceClip)

                src_mob = seg.resolve_ref()
                for s in src_mob.slots():
                    tape_mob = s.segment.resolve_ref()
                    tape_description = tape_mob.essence_descriptor
                    print tape_mob
                    print tape_description
                    print "ManufacturerID =", tape_description[
                        'ManufacturerID'].value
                    assert tape_description[
                        'ManufacturerID'].value == manufacturer
                    print "Model", tape_description['Model'].value
                    assert tape_description['Model'].value == model
                    print "FormFactor", tape_description['FormFactor'].value
Ejemplo n.º 19
0
def create_aaf(path, media_streams, mobname):

    f = aaf.open(path, 'w')

    mastermob = f.create.MasterMob(mobname)
    f.storage.add_mob(mastermob)

    edit_rate = None
    for stream in media_streams:
        if stream['type'] == 'video':
            edit_rate = stream['frame_rate']
            break

    for stream in media_streams:
        if stream['type'] == 'video':
            print "importing video..."
            start = time.time()
            if stream['profile'].startswith("dnxhr"):
                import_dnxhr_video_essence(f, mastermob, stream)
            else:
                import_dnxhd_video_essence(f, mastermob, stream)

            print "imported video in %f secs" % (time.time()- start)
        if stream['type'] == 'audio':
            print "importing audio..."
            start = time.time()
            sample_rate = stream['sample_rate']
            mastermob.import_audio_essence(stream['path'], stream['channels'], sample_rate, sample_rate)

            print "imported audio in %f secs" % (time.time()- start)

    f.save()
    f.close()
Ejemplo n.º 20
0
    def test_basic(self):

        test_file = os.path.join(sandbox, "test_SourceClip.aaf")

        f = aaf.open(None, 't')

        source_mob = f.create.SourceMob()
        f.storage.add_mob(source_mob)
        slot = source_mob.add_nil_ref(1, 100, "picture", "25/1")

        source_ref = aaf.util.SourceRef()
        source_ref.mob_id = source_mob.mobID
        source_ref.slot_id = slot.slotID
        source_ref.start_time = 10
        #source_ref.

        source_clip = f.create.SourceClip("picture", 10, source_ref)

        assert source_clip.source_ref.mob_id == source_mob.mobID
        print(source_clip.source_ref.slot_id)

        assert source_clip.source_ref.slot_id == slot.slotID

        s = str(source_clip.source_ref)

        #slot = source_clip.resolve_slot()

        assert source_clip.start_time == 10
        source_clip.start_time = 5
        assert source_clip.start_time == 5
Ejemplo n.º 21
0
    def test_walk_file(self):
        test_file = main_test_file

        f = aaf.open(test_file)

        header = f.header

        def walk_properties(space, iter_item):

            for item in iter_item:
                value = item
                if isinstance(item, aaf.property.PropertyItem):
                    value = item.value
                name = ""
                if hasattr(item, 'name'):
                    name = item.name or ""

                #print space,name, value
                s = space + '   '
                if isinstance(value, aaf.base.AAFObject):
                    #print space, value.class_name
                    walk_properties(s, value.properties())
                if isinstance(value, aaf.iterator.BaseIterator):

                    walk_properties(s, value)
                    #print "iterator!"

        walk_properties("", header.properties())
Ejemplo n.º 22
0
    def test_create_comments(self):
        test_file = os.path.join(sandbox, 'comments_create.aaf')
        f = aaf.open(test_file, 'w')

        header = f.header
        d = f.dictionary

        mob = d.create.MasterMob("bob")
        f.storage.add_mob(mob)

        d = {'comment1': 'value1', 'comment2': "value2", 'comment3': "value3"}
        for key, value in d.items():
            mob.append_comment(key, value)

        for item in mob.comments():
            print '**', item.name, item.value
            assert d[item.name] == item.value.value

        mob.remove_comment_by_name('comment3')

        for item in mob.comments():
            assert item.name != 'comment3'

        f.save()
        f.close()
Ejemplo n.º 23
0
    def test_create_comments(self):
        test_file = os.path.join(sandbox, 'comments_create.aaf')
        f = aaf.open(test_file, 'w')

        header = f.header
        d = f.dictionary

        mob = d.create.MasterMob("bob")
        f.storage.add_mob(mob)

        d = {'comment1':'value1', 'comment2': "value2", 'comment3':"value3"}
        for key, value in d.items():
            mob.append_comment(key,value)

        for item in mob.comments():
            print('**', item.name, item.value)
            assert d[item.name] == item.value

        mob.remove_comment_by_name('comment3')

        for item in mob.comments():
            assert item.name != 'comment3'

        f.save()
        f.close()
Ejemplo n.º 24
0
    def test_setting_property(self):

        f = aaf.open(main_test_file)

        mob = f.storage.composition_mobs()[0]

        mob_id = mob['MobID'].value

        d = mob_id.to_dict()
        d['instanceLow'] = 10
        d['length'] = 2

        mob['MobID'].value = d

        assert mob['MobID'].value != mob_id

        mob['MobID'].value = mob_id

        assert mob['MobID'].value == mob_id

        mob_id2 = aaf.util.MobID.from_dict(d)

        assert mob_id2 != mob_id

        mob['MobID'].value = str(mob_id2)
        assert mob['MobID'].value == mob_id2
Ejemplo n.º 25
0
 def test_typedef_set(self):
     f = aaf.open()
     marker = f.create.DescriptiveMarker()
     elements = [1,2,3]
     marker.set_described_slot_ids([1,2,3])
     self.assertTrue(elements == list(marker['DescribedSlots'].value))
     self.assertTrue(marker['DescribedSlots'].typedef.size(
                 marker['DescribedSlots'].property_value()) == len(elements))
Ejemplo n.º 26
0
    def test_basic(self):
        f = aaf.open(main_test_file, 'w')

        mob = f.create.CompositionMob()
        mob.usage_code = 'Usage_TopLevel'

        self.assertEqual(mob['UsageCode'].value, 'Usage_TopLevel')
        mob['UsageCode'].value = 'Usage_SubClip'

        f.storage.add_mob(mob)
        f.save()
        f.close()

        f = aaf.open(main_test_file, 'r')
        mob = f.storage.mobs()[0]

        self.assertEqual(mob['UsageCode'].value, 'Usage_SubClip')
Ejemplo n.º 27
0
 def test_typedef_set(self):
     f = aaf.open()
     marker = f.create.DescriptiveMarker()
     elements = [1, 2, 3]
     marker.set_described_slot_ids([1, 2, 3])
     self.assertTrue(elements == list(marker['DescribedSlots'].value))
     self.assertTrue(marker['DescribedSlots'].typedef.size(
         marker['DescribedSlots'].property_value()) == len(elements))
Ejemplo n.º 28
0
    def test_file(self):
        f = aaf.open(main_test_file, 'r')
        mob = f.storage.lookup_mob(mob_id)

        for slot in mob.slots():
            for i, p in enumerate(
                    slot.segment.parameter['testParam'].points()):
                assert point_values[i] == float(p.value)
Ejemplo n.º 29
0
 def test_lookup(self):
     test_mobID = "urn:smpte:umid:060a2b34.01010101.01010f00.13000000.060e2b34.7f7f2a80.48c9f1f4.2abb0184"
     
     f = aaf.open(main_test_file)
     
     mob = f.storage.lookup_mob(test_mobID)
     
     assert mob.mobID == test_mobID
Ejemplo n.º 30
0
    def test_lookup(self):
        test_mobID = "urn:smpte:umid:060a2b34.01010101.01010f00.13000000.060e2b34.7f7f2a80.48c9f1f4.2abb0184"

        f = aaf.open(main_test_file)

        mob = f.storage.lookup_mob(test_mobID)

        assert mob.mobID == test_mobID
Ejemplo n.º 31
0
    def test_external_mob(self):
        output_aaf = os.path.join(sandbox, 'external_essence_create.aaf')
        output_xml = os.path.join(sandbox, 'external_essence_create.xml')
        if os.path.exists(output_aaf):
            os.remove(output_aaf)
        f = aaf.open(output_aaf, 'rw')
        
        header = f.header
        d = f.dictionary
        
        master_mob = d.create.MasterMob("external_mob")
        f.storage.add_mob(master_mob)
        
        media_kind = "picture"
        
        phys_source_mob = d.create.SourceMob()
        phys_source_mob.name = "IMG.PHYS"
        desc = d.create.CDCIDescriptor()
        
        for item in desc.classdef().propertydefs():
            print '  ', item.name, item.optional
        
        loc = d.create.NetworkLocator()
        loc.path = "file:///Giraffe/Avid%20MediaFiles/MXF/1/IMG_4943.JPG1378511522A699C.mxf"
        
        desc.append_locator(loc)
        desc.sample_rate = "23976/1000"
        desc.container_format = "AAFKLV"
        print desc.container_format
        desc.compression = "Avid_DNxHD_Legacy"
        print desc.compression
        width,height = 1280, 720
        
        desc.stored_view = (width, height)
        desc.sampled_view = (width, height, 0, 0)
        desc.display_view = (width, height, 0, 0)
        desc.aspect_ratio = "16/9"
        
        desc.line_map = (26,0)
        desc.color_range = 255
        desc.horizontal_subsampling = 2
        desc.vertical_subsampling = 1
        desc.component_width = 8
        
        desc.image_alignment = 8192
        
        
        phys_source_mob.essence_descriptor = desc
        f.storage.add_mob(phys_source_mob)
        
        phys_source_mob.add_nil_ref(1, 39, 'picture',"23976/1000" )
        
        master_mob.add_master_slot(media_kind, 1, phys_source_mob, 1)

        
        f.save()
        f.save(output_xml)
        f.close()
Ejemplo n.º 32
0
    def test_header(self):
        test_file = main_test_file

        f = aaf.open(test_file)

        header = f.header

        for p in header.properties():
            pass
Ejemplo n.º 33
0
    def test_header(self):
        test_file = main_test_file

        f = aaf.open(test_file)

        header = f.header

        for p in header.properties():
            pass
Ejemplo n.º 34
0
    def test_basic(self):
        test_file = os.path.join(sandbox, "test_EdgeCode.aaf")
        f = aaf.open(test_file, 'w')

        mob = f.create.CompositionMob()

        f.storage.add_mob(mob)

        edge_code_header = 'BOB'

        # manually initialize
        edgecode =  aaf.component.EdgeCode(f, header=edge_code_header)

        edgecode['Length'].value = 10

        mob.append_new_timeline_slot("0/1", edgecode, 0, "edgecode", 0)

        #print(edgecode.header)
        assert edgecode.header == edge_code_header


        # test create interface
        edgecode2 = f.create.EdgeCode(100, header=edge_code_header)

        assert edgecode2.header == edge_code_header
        assert edgecode2['Length'].value == 100


        edgecode.header = u"BOB2"

        assert edgecode.header == "BOB2"


        f.save()
        f.close()


        f = aaf.open(test_file, 'r')

        mob = f.storage.composition_mobs()[0]

        edgecode =  mob.slots()[0].segment

        assert edgecode.header == "BOB2"
Ejemplo n.º 35
0
    def test_basic(self):
        
        test_file = os.path.join(sandbox, "test_TimelineMobSlot.aaf")
        
        f = aaf.open(test_file, 'w')
        
        timeline = f.create.TimelineMobSlot()
        
        timeline.mark_in = 1
        assert timeline.mark_in == 1
        timeline.mark_in = 2
        assert timeline.mark_in == 2
        
        timeline.mark_out = 100
        assert timeline.mark_out == 100
        timeline.mark_out = 10
        assert timeline.mark_out == 10

        # File won't save unless MobSlot has a segment
        seq = f.create.Sequence("picture")
        timeline.segment = seq
        
        mob = f.create.MasterMob()
        
        mob.append_slot(timeline)
        
        f.storage.add_mob(mob)
        
        
        f.save()
        f.close()
        
        f = aaf.open(test_file, 'r')
        
        mob = f.storage.master_mobs()[0]
        
        timeline = mob.slots()[0]
        
        print(timeline)
        
        assert timeline.mark_in == 2
        assert timeline.mark_out == 10
        
        f.close()
Ejemplo n.º 36
0
    def test_basic(self):

        test_file = os.path.join(sandbox, "test_TimelineMobSlot.aaf")

        f = aaf.open(test_file, 'w')

        timeline = f.create.TimelineMobSlot()

        timeline.mark_in = 1
        assert timeline.mark_in == 1
        timeline.mark_in = 2
        assert timeline.mark_in == 2

        timeline.mark_out = 100
        assert timeline.mark_out == 100
        timeline.mark_out = 10
        assert timeline.mark_out == 10

        # File won't save unless MobSlot has a segment
        seq = f.create.Sequence("picture")
        timeline.segment = seq

        mob = f.create.MasterMob()

        mob.append_slot(timeline)

        f.storage.add_mob(mob)

        f.save()
        f.close()

        f = aaf.open(test_file, 'r')

        mob = f.storage.master_mobs()[0]

        timeline = mob.slots()[0]

        print(timeline)

        assert timeline.mark_in == 2
        assert timeline.mark_out == 10

        f.close()
Ejemplo n.º 37
0
    def test_audio_mono(self):
        output_aaf = os.path.join(sandbox, "mono_audio_export.aaf")
        output_xml = os.path.join(sandbox, "mono_audio_export.xml")

        f = aaf.open(output_aaf, "w")

        header = f.header
        d = f.dictionary

        count = 0

        name = "mono_audio_export"

        mastermob = d.create.MasterMob(name)
        f.storage.add_mob(mastermob)

        rate = 48000

        sampe_rate = "%d/1" % rate

        essence = mastermob.create_essence(
            1,
            "sound",
            "PCM",
            sampe_rate,
            sampe_rate,
            compress=False,
            # fileformat = 'RIFFWAVE'
        )
        essence.codec_flavour = "Flavour_None"
        format = essence.get_emptyfileformat()

        format["AudioSampleBits"] = 16
        format["NumChannels"] = 1

        essence.set_fileformat(format)

        del format

        pcm_file = generate_pcm_audio_mono(name, rate, 2)
        pcm = open(pcm_file, "rb")

        readsize = essence.max_sample_size

        while True:
            chunk = pcm.read(readsize)
            if not chunk:
                break
            if len(chunk) != readsize:
                break
            essence.write(chunk)

        essence.complete_write()
        f.save()
        f.save(output_xml)
Ejemplo n.º 38
0
    def test_audio_mono(self):
        output_aaf = os.path.join(sandbox, 'mono_audio_export.aaf')
        output_xml = os.path.join(sandbox, 'mono_audio_export.xml')

        f = aaf.open(output_aaf, 'w')

        header = f.header
        d = f.dictionary

        count = 0

        name = "mono_audio_export"

        mastermob = d.create.MasterMob(name)
        f.storage.add_mob(mastermob)

        rate = 48000

        sampe_rate = "%d/1" % rate

        essence = mastermob.create_essence(
            1,
            "sound",
            "PCM",
            sampe_rate,
            sampe_rate,
            compress=False,
            #fileformat = 'RIFFWAVE'
        )
        essence.codec_flavour = "Flavour_None"
        format = essence.get_emptyfileformat()

        format['AudioSampleBits'] = 16
        format['NumChannels'] = 1

        essence.set_fileformat(format)

        del format

        pcm_file = generate_pcm_audio_mono(name, rate, 2)
        pcm = open(pcm_file, 'rb')

        readsize = essence.max_sample_size

        while True:
            chunk = pcm.read(readsize)
            if not chunk:
                break
            if len(chunk) != readsize:
                break
            essence.write(chunk)

        essence.complete_write()
        f.save()
        f.save(output_xml)
Ejemplo n.º 39
0
    def test_read_curve(self):
        f = aaf.open(main_test_file, 'r')

        print "iter"
        for i, item in enumerate(f.storage.toplevel_mobs()):
            print i, item

        comp = f.storage.toplevel_mobs()[0]

        print comp

        seqs = [item.segment for item in comp.slots()]
        print seqs

        op_group = seqs[1].components()[0]
        print op_group

        speed_map = None
        offset_map = None

        speed_map = op_group.parameter['PARAM_SPEED_MAP_U']
        offset_map = op_group.parameter['PARAM_SPEED_OFFSET_MAP_U']

        print speed_map['PointList'].value

        print speed_map.count()

        print speed_map.interpolation_def().name

        for p in speed_map.points():
            print "  ", float(p.time), float(p.value), p.edit_hint
            for prop in p.point_properties():
                print "    ", prop.name, prop.value, float(prop.value)

        print offset_map.interpolation_def().name
        for p in offset_map.points():
            edit_hint = p.edit_hint
            time = p.time
            value = p.value

            pass
            #print "  ", float(p.time), float(p.value)

        for i in xrange(100):
            float(offset_map.value_at("%i/100" % i))

        # Test file PARAM_SPEED_MAP_U is AvidBezierInterpolator
        # currently no implement for value_at
        try:
            speed_map.value_at(.25)
        except NotImplementedError:
            pass
        else:
            raise
Ejemplo n.º 40
0
    def test_tape(self):
        output_aaf = os.path.join(sandbox, 'tape_essence_create.aaf')
        output_xml = os.path.join(sandbox, 'tape_essence_create.xml')

        if os.path.exists(output_aaf):
            os.remove(output_aaf)
        f = aaf.open(output_aaf, 'rw')

        header = f.header
        d = f.dictionary

        tape_name = "tape_01"

        master_mob = d.create.MasterMob("clip1")
        f.storage.add_mob(master_mob)

        source_mob = d.create.SourceMob()
        source_mob.name = tape_name
        tape_desc = d.create.TapeDescriptor()
        source_mob.essence_descriptor = tape_desc
        f.storage.add_mob(source_mob)

        # Now add Video and Audio Tracks
        for track in range(3):

            # Create A New Slot
            timeline = d.create.TimelineMobSlot()
            timeline.editrate = "23976/1000"
            timeline.origin = 0
            timeline.slotID = track + 1

            # set the audio channel, zero if video
            timeline.physical_num = track

            media_kind = "sound"
            if track == 0:
                media_kind = 'picture'

            # Create a clip NULL clip
            clip = d.create.SourceClip(length= 100, media_kind=media_kind)

            # Set the Segemnt to the clip
            timeline.segment = clip

            # Add the timeline to the Source Mob
            source_mob.insert_slot(track, timeline)

            # Add the SourceMob slot to the Master Mob Slot
            master_mob.add_master_slot(media_kind, track+1, source_mob, track+1)

        f.save()
        f.save(output_xml)
        f.close()
Ejemplo n.º 41
0
    def test_tape(self):
        output_aaf = os.path.join(sandbox, 'tape_essence_create.aaf')
        output_xml = os.path.join(sandbox, 'tape_essence_create.xml')
        
        if os.path.exists(output_aaf):
            os.remove(output_aaf)
        f = aaf.open(output_aaf, 'rw')
        
        header = f.header
        d = f.dictionary
        
        tape_name = "tape_01"

        master_mob = d.create.MasterMob("clip1")
        f.storage.add_mob(master_mob)
        
        source_mob = d.create.SourceMob()
        source_mob.name = tape_name
        tape_desc = d.create.TapeDescriptor()
        source_mob.essence_descriptor = tape_desc
        f.storage.add_mob(source_mob)
        
        # Now add Video and Audio Tracks
        for track in xrange(3):
            
            # Create A New Slot
            timeline = d.create.TimelineMobSlot()
            timeline.editrate = "23976/1000"
            timeline.origin = 0
            timeline.slotID = track + 1
            
            # set the audio channel, zero if video
            timeline.physical_num = track
            
            media_kind = "sound"
            if track == 0:
                media_kind = 'picture'
            
            # Create a clip NULL clip
            clip = d.create.SourceClip(length= 100, media_kind=media_kind)
            
            # Set the Segemnt to the clip
            timeline.segment = clip
            
            # Add the timeline to the Source Mob
            source_mob.insert_slot(track, timeline)
            
            # Add the SourceMob slot to the Master Mob Slot
            master_mob.add_master_slot(media_kind, track+1, source_mob, track+1)
        
        f.save()
        f.save(output_xml)
        f.close()
Ejemplo n.º 42
0
    def test_basic(self):
        test_file = os.path.join(sandbox, "test_EdgeCode.aaf")
        f = aaf.open(test_file, 'w')

        mob = f.create.CompositionMob()

        f.storage.add_mob(mob)

        edge_code_header = 'BOB'

        # manually initialize
        edgecode = aaf.component.EdgeCode(f, header=edge_code_header)

        edgecode['Length'].value = 10

        mob.append_new_timeline_slot("0/1", edgecode, 0, "edgecode", 0)

        #print(edgecode.header)
        assert edgecode.header == edge_code_header

        # test create interface
        edgecode2 = f.create.EdgeCode(100, header=edge_code_header)

        assert edgecode2.header == edge_code_header
        assert edgecode2['Length'].value == 100

        edgecode.header = u"BOB2"

        assert edgecode.header == "BOB2"

        f.save()
        f.close()

        f = aaf.open(test_file, 'r')

        mob = f.storage.composition_mobs()[0]

        edgecode = mob.slots()[0].segment

        assert edgecode.header == "BOB2"
Ejemplo n.º 43
0
    def test_comments(self):
        test_file = main_test_file
        f = aaf.open(test_file)
        header = f.header
        storage = f.storage

        for mob in storage.mobs():

            comments = list(mob.comments())
            if comments:
                print(mob.name)
                for c in comments:
                    print('  ', c.name, c.value)
Ejemplo n.º 44
0
    def test_file_modify_identification(self):
        test_file = os.path.join(sandbox,"identification_modify_file.aaf")
        ident = {'product_id': AUID('12345678-1234-1234-1234-123456789901'),
                 "company_name": "Some Company",
                 "product_name": "Product",
                 'product_version_string': "12345"
                 }

        f = aaf.open(test_file, 'w', ident)
        f.save()
        f.close()

        f = aaf.open(test_file, 'rw', ident)

        f.save()

        self.assertTrue(len(f.header['IdentificationList'].value) == 2)
        for i in f.header['IdentificationList'].value:
            self.assertTrue(i['CompanyName'].value == ident['company_name'])
            self.assertTrue(i['ProductName'].value == ident['product_name'])
            self.assertTrue(i['ProductVersionString'].value == ident['product_version_string'])
            self.assertTrue(i['ProductID'].value == ident['product_id'])
Ejemplo n.º 45
0
    def test_comments(self):
        test_file = main_test_file
        f = aaf.open(test_file)
        header = f.header
        storage = f.storage

        for mob in storage.mobs():

            comments = list(mob.comments())
            if comments:
                print mob.name
                for c in comments:
                    print '  ', c.name, c.value
Ejemplo n.º 46
0
    def test_dictionary(self):
        test_file = main_test_file

        f = aaf.open(test_file)

        header = f.header

        dictionary = f.dictionary
        storage = f.storage

        for p in dictionary.properties():
            pass
            #print p.name, p.value_typedef(),p.property_def(), p.value
        print(dictionary.classdef().parent().name)
Ejemplo n.º 47
0
    def test_dictionary(self):
        test_file = main_test_file

        f = aaf.open(test_file)

        header = f.header

        dictionary = f.dictionary
        storage = f.storage

        for p in dictionary.properties():
            pass
            #print p.name, p.value_typedef(),p.property_def(), p.value
        print dictionary.classdef().parent().name
Ejemplo n.º 48
0
    def test_compare(self):
        f = aaf.open(main_test_file)
        comp_mob1 = f.storage.toplevel_mobs()[0]
        comp_mob2 = f.storage.toplevel_mobs()[0]

        for slot_a, slot_b in zip(comp_mob1.slots(), comp_mob2.slots()):
            self.assertEqual(slot_a, slot_b)

        self.assertNotEqual(comp_mob1.slots()[0], comp_mob1.slots()[1])
        self.assertNotEqual(comp_mob1.slots()[0], comp_mob2.slots()[1])

        self.assertNotEqual(comp_mob1.slots()[0], f.storage)

        self.assertNotEqual(comp_mob1.slots()[0], None)
Ejemplo n.º 49
0
    def test_len(self):
        f = aaf.open(main_test_file)
        iterable = f.storage.mobs()

        assert len(iterable) == 199

        count = 0
        for i, item in enumerate(iterable):
            #print item
            assert len(iterable) == 199
            count += 1

        assert count == len(iterable)
        assert len(iterable) == 199
Ejemplo n.º 50
0
 def test_len(self):
     f = aaf.open(main_test_file)
     iterable = f.storage.mobs()
     
     assert len(iterable) == 199
 
     count = 0 
     for i, item in enumerate(iterable):
         #print item
         assert len(iterable) == 199
         count += 1
         
     assert count == len(iterable)
     assert len(iterable) == 199
Ejemplo n.º 51
0
    def test_create_sound_essence(self):
        output_aaf = os.path.join(sandbox, 'sound_essence_create.aaf')
        output_xml = os.path.join(sandbox, 'sound_essence_create.xml')
        if os.path.exists(output_aaf):
            os.remove(output_aaf)
        f = aaf.open(output_aaf, 'rw')


        header = f.header
        storage = f.storage
        d = f.dictionary

        sound_mastermob = d.create.MasterMob("sound Mob 1")

        storage.add_mob(sound_mastermob)


        rateHz = 44100
        rate = "%d/1" % rateHz

        sound_essence = sound_mastermob.create_essence(1,
                                                     media_kind= "sound",
                                                     codec_name="WAVE",
                                                     edit_rate = rate,
                                                     sample_rate = rate,
                                                     compress=False)


        slot = list(sound_mastermob.slots())[0]
        clip = slot.segment
        source_mob = clip.resolve_ref()
        WAVEDesc = source_mob.essence_descriptor

        format = sound_essence.get_emptyfileformat()
        format['AudioSampleBits'] =  16
        sound_essence.set_fileformat(format)

        numSamples = int(20 * rateHz / 25) # 2 pal frames in duration.
        samplesToWrite = 10

        for c in chunks([1 for i in range(numSamples)], samplesToWrite):
            ret = sound_essence.write(c, len(c), 'UInt16')
            #print "wrote", ret

        sound_essence.complete_write()

        f.save()
        f.save(output_xml)
        f.close()
Ejemplo n.º 52
0
    def test_create_sound_essence(self):
        output_aaf = os.path.join(sandbox, 'sound_essence_create.aaf')
        output_xml = os.path.join(sandbox, 'sound_essence_create.xml')
        if os.path.exists(output_aaf):
            os.remove(output_aaf)
        f = aaf.open(output_aaf, 'rw')
        
        
        header = f.header
        storage = f.storage
        d = f.dictionary
        
        sound_mastermob = d.create.MasterMob("sound Mob 1")

        storage.add_mob(sound_mastermob)
        
        
        rateHz = 44100
        rate = "%d/1" % rateHz
         
        sound_essence = sound_mastermob.create_essence(1,
                                                     media_kind= "sound",
                                                     codec_name="WAVE",
                                                     edit_rate = rate,
                                                     sample_rate = rate, 
                                                     compress=False)
         
        
        slot = list(sound_mastermob.slots())[0]
        clip = slot.segment
        source_mob = clip.resolve_ref()
        WAVEDesc = source_mob.essence_descriptor
        
        format = sound_essence.get_emptyfileformat()
        format['AudioSampleBits'] =  16
        sound_essence.set_fileformat(format)
        
        numSamples = 20 * rateHz / 25 # 2 pal frames in duration.
        samplesToWrite = 10
        
        for c in chunks([1 for i in xrange(numSamples)], samplesToWrite):
            ret = sound_essence.write(c, len(c), 'UInt16')
            #print "wrote", ret
        
        sound_essence.complete_write()

        f.save()
        f.save(output_xml)
        f.close()
Ejemplo n.º 53
0
    def test_pulldown(self):
        output_aaf = os.path.join(sandbox, 'pulldown_create.aaf')
        output_xml = os.path.join(sandbox, 'pulldown_create.xml')
        if os.path.exists(output_aaf):
            os.remove(output_aaf)
        f = aaf.open(output_aaf, 'rw')

        header = f.header
        d = f.dictionary


        source_mob = d.create.SourceMob()
        source_mob.name = "IMG"

        source_mob.add_nil_ref(1, 39, 'picture',"23976/1000" )
        f.storage.add_mob(source_mob)

        desc = d.create.ImportDescriptor()
        source_mob.essence_descriptor = desc

        timeline = d.create.TimelineMobSlot()
        timeline.editrate = "23976/1000"
        timeline.origin = 0
        timeline.slotID = 2
        timeline.physical_num = 1

        pulldown = d.create.Pulldown("Picture")

        timecode = d.create.Timecode(98, 216000, 60)
        timecode.media_kind = "Timecode"

        pulldown.segment = timecode
        pulldown.length = 39

        pulldown.kind = "TwentyFourToSixtyPD"
        pulldown.direction = "TapeToFilmSpeed"
        pulldown.phase = 0

        print(pulldown.kind)
        print(pulldown.direction)
        print(pulldown.phase)

        timeline.segment = pulldown

        source_mob.insert_slot(1, timeline)

        f.save()
        f.save(output_xml)
        f.close()
Ejemplo n.º 54
0
    def test_pulldown(self):
        output_aaf = os.path.join(sandbox, 'pulldown_create.aaf')
        output_xml = os.path.join(sandbox, 'pulldown_create.xml')
        if os.path.exists(output_aaf):
            os.remove(output_aaf)
        f = aaf.open(output_aaf, 'rw')
        
        header = f.header
        d = f.dictionary
        

        source_mob = d.create.SourceMob()
        source_mob.name = "IMG"
        
        source_mob.add_nil_ref(1, 39, 'picture',"23976/1000" )
        f.storage.add_mob(source_mob)
        
        desc = d.create.ImportDescriptor()
        source_mob.essence_descriptor = desc
        
        timeline = d.create.TimelineMobSlot()
        timeline.editrate = "23976/1000"
        timeline.origin = 0
        timeline.slotID = 2
        timeline.physical_num = 1
        
        pulldown = d.create.Pulldown("Picture")
        
        timecode = d.create.Timecode(98, 216000, 60)
        timecode.media_kind = "Timecode"
        
        pulldown.segment = timecode
        pulldown.length = 39
        
        pulldown.kind = "TwentyFourToSixtyPD"
        pulldown.direction = "TapeToFilmSpeed"
        pulldown.phase = 0
        
        print pulldown.kind
        print pulldown.direction
        print pulldown.phase
        
        timeline.segment = pulldown

        source_mob.insert_slot(1, timeline)
        
        f.save()
        f.save(output_xml)
        f.close()
Ejemplo n.º 55
0
    def test_comp_mobs(self):

        test_file = main_test_file

        f = aaf.open(test_file)

        header = f.header

        dictionary = f.dictionary
        storage = f.storage

        #print storage.count_mobs()

        for mob in storage.composition_mobs():
            print mob
Ejemplo n.º 56
0
    def test_comp_mobs(self):

        test_file = main_test_file

        f = aaf.open(test_file)

        header = f.header

        dictionary = f.dictionary
        storage = f.storage

        #print storage.count_mobs()

        for mob in storage.composition_mobs():
            print(mob)
Ejemplo n.º 57
0
    def test_umid(self):
        umid = u"0x060A2B340101010101010F001300000051D2066BDCF6003E060E2B347F7F2A80"

        mob_id = aaf.util.MobID()

        mob_id.umid = umid
        assert mob_id.umid == umid
        assert mob_id == umid

        f = aaf.open()
        mob = f.create.MasterMob()
        mob.umid = umid
        print(umid)
        print(mob.mobID)
        print(aaf.util.MobID(umid))
        assert mob.umid == umid
Ejemplo n.º 58
0
    def test_toplevel_mobs(self):

        test_file = main_test_file

        f = aaf.open(test_file)

        header = f.header

        dictionary = f.dictionary
        storage = f.storage

        print(storage.count_mobs())

        for mob in storage.toplevel_mobs():
            compMob = mob
            definition = compMob.classdef()