Esempio n. 1
0
    def test_dnxhd(self):
        frames = 3
        for profile_name in [
                'dnx_1080p_36_23.97', 'dnx_720p_90x_25', 'dnx_1080i_120_25',
                'dnx_1080p_175x_23.97'
        ]:
            new_file = os.path.join(common.sandbox(),
                                    '%s_import_essence.aaf' % profile_name)
            sample = common.generate_dnxhd(profile_name,
                                           '%s-import.dnxhd' % profile_name,
                                           frames=frames)

            with aaf2.open(new_file, 'w') as f:
                profile = video.dnx_profiles.get(profile_name)

                mob = f.create.MasterMob(profile_name)
                f.content.mobs.append(mob)
                mob.import_dnxhd_essence(sample, profile['frame_rate'])

            with aaf2.open(new_file, 'r') as f:
                mob = next(f.content.sourcemobs())
                stream = mob.essence.open('r')
                dump_path = os.path.join(common.sample_dir(),
                                         '%s-import-dump.dnxhd' % profile_name)
                with io.open(dump_path, 'wb') as out:
                    out.write(stream.read())

                assert common.compare_files(dump_path, sample)
                assert mob.slots[0].segment.length == frames
                assert mob.descriptor.length == frames
Esempio n. 2
0
    def test_basic_video_link(self):
        profile_name = 'dnx_1080p_36_23.97'
        video_sample = common.generate_dnxhd(profile_name,
                                             "mxf_link_video.mxf",
                                             10,
                                             fmt='mxf_opatom')

        meta = common.probe(video_sample)
        video_mob_id = mobid.MobID(
            meta['format']['tags']['material_package_umid'])
        video_source_mob_id = mobid.MobID(
            meta['streams'][0]['tags']['file_package_umid'])

        new_file = os.path.join(common.sandbox(), 'mxf_link_video.aaf')

        with aaf2.open(new_file, 'w') as f:
            f.content.link_external_mxf(video_sample)

        with aaf2.open(new_file, 'r') as f:
            assert len(f.content.mobs) == 2
            for mob in f.content.mobs:
                if isinstance(mob, mobs.MasterMob):
                    assert mob.mob_id == video_mob_id
                elif isinstance(mob, mobs.SourceMob):
                    if isinstance(mob.descriptor, essence.CDCIDescriptor):
                        assert mob.mob_id == video_source_mob_id
Esempio n. 3
0
    def test_dnx_iter(self):
        profile_name = 'dnx_1080p_36_23.97'
        sample = common.generate_dnxhd(profile_name, "dnx_iter01.dnxhd", 10)
        with io.open(sample, 'rb') as f:
            for i, packet in enumerate(video.iter_dnx_stream(f)):
                cid, width, height, bitdepth, interlaced = video.read_dnx_frame_header(
                    packet)
                assert not interlaced
                assert bitdepth == 8

                assert (width, height) == (1920, 1080)

            assert i + 1 == 10

        profile_name = 'dnx_1080i_120_25'
        sample = common.generate_dnxhd(profile_name, "dnx_iter02.dnxhd", 10)
        with io.open(sample, 'rb') as f:
            for i, packet in enumerate(video.iter_dnx_stream(f)):
                cid, width, height, bitdepth, interlaced = video.read_dnx_frame_header(
                    packet)
                assert interlaced
                assert bitdepth == 8
                assert (width, height) == (1920, 540)

            assert i + 1 == 10

        frame_rate = '23.97'
        profile_name = 'dnxhr_lb'
        uhd2160 = (3840, 2160)
        sample = common.generate_dnxhd(profile_name,
                                       "dnx_iter03.dnxhd",
                                       10,
                                       size=uhd2160,
                                       frame_rate=frame_rate)
        with io.open(sample, 'rb') as f:
            for i, packet in enumerate(video.iter_dnx_stream(f)):
                cid, width, height, bitdepth, interlaced = video.read_dnx_frame_header(
                    packet)
                assert not interlaced
                assert (width, height) == uhd2160
                assert bitdepth == 8

            assert i + 1 == 10
Esempio n. 4
0
    def test_dnxhr(self):

        frame_rate = '23.97'
        uhd2160 = (960, 540)

        frames = 3

        timecode_fps = 30
        start_time = int(timecode_fps * 60 * 60)  # 1 hour

        for profile_name in ['dnxhr_lb', 'dnxhr_sq', 'dnxhr_hq']:
            new_file = os.path.join(common.sandbox(),
                                    '%s_import_essence.aaf' % profile_name)
            with aaf2.open(new_file, 'w') as f:

                profile = video.dnx_profiles.get(profile_name)
                sample = common.generate_dnxhd(profile_name,
                                               "%s-import.dnxhd" %
                                               profile_name,
                                               frames=frames,
                                               size=uhd2160,
                                               frame_rate=frame_rate)

                # create a tape
                tape_mob = f.create.SourceMob()
                tape_mob.create_tape_slots(profile_name, frame_rate,
                                           timecode_fps)
                f.content.mobs.append(tape_mob)
                tape = tape_mob.create_source_clip(1, start=start_time)

                mob = f.create.MasterMob(profile_name)
                f.content.mobs.append(mob)
                timecode = f.create.Timecode(timecode_fps)
                mob.import_dnxhd_essence(sample, frame_rate, tape=tape)

            with aaf2.open(new_file, 'r') as f:
                source_mobs = []
                tape_mobs = []
                for mob in f.content.sourcemobs():
                    if isinstance(mob.descriptor, aaf2.essence.TapeDescriptor):
                        tape_mobs.append(mob)
                    else:
                        source_mobs.append(mob)

                mob = source_mobs[0]
                stream = mob.essence.open('r')
                dump_path = os.path.join(common.sample_dir(),
                                         '%s-import-dump.dnxhd' % profile_name)
                with io.open(dump_path, 'wb') as out:
                    out.write(stream.read())

                assert common.compare_files(dump_path, sample)
                assert mob.slots[0].segment.length == frames
                assert mob.slots[0].segment.start == start_time
                assert mob.descriptor.length == frames
Esempio n. 5
0
def create_video_clip_import(f):
    frame_rate = 25
    profile_name = 'dnx_1080p_36_25'
    sample = common.generate_dnxhd(profile_name, "transition.dnxhd", 200)

    tape = None
    master_mob = f.create.MasterMob("MasterMob")
    f.content.mobs.append(master_mob)
    slot = master_mob.import_dnxhd_essence(sample, frame_rate, tape=tape)

    return master_mob.create_source_clip(slot.slot_id, start=50)
Esempio n. 6
0
    def test_range_lock(self):

        frame_rate = '23.97'
        size = (960, 540)
        profile_name = 'dnxhr_lb'
        frames = 1600
        overwrite = True
        sample = common.generate_dnxhd(profile_name,
                                       "%s-import.dnxhd" % profile_name,
                                       frames=frames,
                                       size=size,
                                       frame_rate=frame_rate,
                                       overwrite=overwrite)

        test_file = common.get_test_file("test-rangelock.aaf")
        with aaf2.open(test_file, 'wb+') as f:
            pass
        mobids = []
        s = time.time()

        # generate a aaf file thats larger then 2gb
        with aaf2.open(test_file, 'rb+') as f:
            for v in range(30):
                start = time.time()
                mob = f.create.MasterMob("item-%d" % v)
                f.content.mobs.append(mob)
                mob.import_dnxhd_essence(sample, frame_rate)

                # print(v, time.time() - start)

        print('%d secs' % (time.time() - s))
        with aaf2.open(test_file, 'r') as f:
            # print(RANGELOCKSECT)
            # print(len(f.cfb.fat))
            # print(f.cfb.fat[RANGELOCKSECT])
            assert f.cfb.fat[RANGELOCKSECT] == ENDOFCHAIN
Esempio n. 7
0
    def test_multi(self):
        frame_rate = 30.0
        frames = 4
        audio_duration = frames / frame_rate
        uhd2160 = (960, 540)
        new_file = os.path.join(common.sandbox(), 'multi_import_essence.aaf')
        audio_profile_name = 'pcm_48000_s24le'

        sample_format = audio.pcm_profiles[audio_profile_name]['sample_format']
        sample_rate = audio.pcm_profiles[audio_profile_name]['sample_rate']
        audio_sample = common.generate_pcm_audio_mono(
            audio_profile_name,
            sample_format=sample_format,
            sample_rate=sample_rate,
            duration=audio_duration)
        samples = {}
        mastermobs = {}

        timecode_fps = 30
        start_time = int(timecode_fps * 60 * 60)
        tape_id = None
        with aaf2.open(new_file, 'w') as f:
            # create a tape
            tape_mob = f.create.SourceMob()
            tape_mob.create_tape_slots("mulit-import", frame_rate,
                                       timecode_fps)
            tape_id = tape_mob.mob_id
            f.content.mobs.append(tape_mob)

            for i, profile_name in enumerate(
                ['dnxhr_lb', 'dnxhr_sq', 'dnxhr_hq'], 1):
                profile = video.dnx_profiles.get(profile_name)
                sample = common.generate_dnxhd(profile_name,
                                               "%s-mulit-import.dnxhd" %
                                               profile_name,
                                               frames=frames,
                                               size=uhd2160,
                                               frame_rate=frame_rate)

                mob = f.create.MasterMob(profile_name)
                f.content.mobs.append(mob)

                tape = tape_mob.create_source_clip(1, start=start_time)

                vs_slot = mob.import_dnxhd_essence(sample,
                                                   frame_rate,
                                                   tape=tape)
                as_slot = mob.import_audio_essence(audio_sample, frame_rate)

                vs_mob = vs_slot.segment.mob
                as_mob = as_slot.segment.mob

                mob.comments['profile'] = profile_name
                mob.comments['integer'] = 100
                mob.comments['integer'] = i
                mastermobs[mob.mob_id] = (profile_name, i)

                v_dump_path = os.path.join(
                    common.sample_dir(),
                    '%s-multi-import-dump.wav' % profile_name)
                a_dump_path = os.path.join(
                    common.sample_dir(),
                    '%s-multi-import-dump.dnxhd' % profile_name)

                samples[vs_mob.mob_id] = (sample, v_dump_path, start_time)
                samples[as_mob.mob_id] = (audio_sample, a_dump_path,
                                          start_time)

                start_time += 100

        with aaf2.open(new_file, 'r') as f:
            tape_mob = f.content.mobs.get(tape_id)
            for mob_id, (profile_name, v) in mastermobs.items():
                mob = f.content.mobs.get(mob_id)
                assert mob.comments['profile'] == profile_name
                assert mob.comments['integer'] == v

            for mob_id, (original_path, dump_path,
                         start_time) in samples.items():
                mob = f.content.mobs.get(mob_id)

                if isinstance(mob.descriptor, aaf2.essence.PCMDescriptor):
                    mob.export_audio(dump_path)
                    assert common.compare_files(dump_path, original_path)
                    assert mob.slots[0].segment.length == frames

                if isinstance(mob.descriptor, aaf2.essence.CDCIDescriptor):
                    stream = mob.essence.open('r')
                    with io.open(dump_path, 'wb') as out:
                        out.write(stream.read())
                    assert common.compare_files(dump_path, original_path)
                    assert mob.slots[0].segment.length == frames
                    assert mob.slots[0].segment.start == start_time
                    assert mob.slots[0].segment.mob_id == tape_id