Example #1
0
def make_csv(csv_filename):
    '''
    Writes a CSV with IFI database headings.
    '''
    ififuncs.create_csv(csv_filename, [
        'Reference Number', 'Donor', 'Edited By', 'Date Created',
        'Date Last Modified', 'Film Or Tape', 'Date Of Donation',
        'Accession Number', 'Habitat', 'backup_habitat', 'TTape Origin',
        'Type Of Deposit', 'Depositor Reference', 'Master Viewing',
        'Language Version', 'Condition Rating', 'Companion Elements',
        'EditedNew', 'FIO', 'CollectionTitle', 'Created By',
        'instantiationIdentif', 'instantDate_other', 'instantDate_type',
        'instantiationDate_mo', 'instantiationStandar', 'instantMediaty',
        'instantFileSize_byte', 'instantFileSize_gigs', 'instantTimeStart',
        'instantDataRate', 'instantTracks', 'instantColors', 'instantLanguage',
        'instantAltMo', 'essenceTrackEncodvid', 'essenceFrameRate',
        'essenceTrackSampling', 'essenceBitDepth_vid', 'essenceFrameSize',
        'essenceAspectRatio', 'essenceTrackEncod_au', 'essenceBitDepth_au',
        'instantiationDuratio', 'instantiationChanCon', 'PixelAspectRatio',
        'FrameCount', 'ColorSpace', 'ChromaSubsampling', 'ScanType',
        'Interlacement', 'Compression_Mode', 'colour_primaries',
        'transfer_characteris', 'matrix_coefficients', 'pix_fmt', 'audio_fmt',
        'audio_codecid', 'video_codecid', 'video_codec_version',
        'video_codec_profile', 'channels', 'colour_range', 'format_version',
        'TimeCode_FirstFrame', 'TimeCode_Source', 'app_company_name',
        'app_name', 'app_version', 'library_name', 'library_version',
        'reproduction_creator', 'reproduction_reason', 'dig_object_descrip'
    ])
Example #2
0
def main():
    '''
    Launches the commands that generate the CSV error report
    '''
    args = parse_args()
    source = args.input
    csv_filename = os.path.join(
        ififuncs.make_desktop_logs_dir(),
        time.strftime("%Y-%m-%dT%H_%M_%S_videoerrors.csv"))
    print('Report stored as %s' % csv_filename)
    if not os.path.isfile(csv_filename):
        ififuncs.create_csv(
            csv_filename,
            ['filename', 'start_time', 'timestamp', 'error', 'notes'])
    for root, _, filenames in os.walk(source):
        for filename in filenames:
            if filename.endswith('.m2t'):
                with open(csv_filename, 'r') as fo:
                    if not filename in fo.read():
                        try:
                            start_time = bitc.getffprobe(
                                'start_time', 'stream=start_time',
                                os.path.join(root, filename)).rsplit()[0]
                            json_output = subprocess.check_output([
                                'ffprobe', '-sexagesimal',
                                os.path.join(root, filename), '-show_error',
                                '-show_log', '16', '-show_frames', '-of',
                                'json'
                            ])
                            errors = False
                            ffprobe_dict = json.loads(json_output)
                            for values in ffprobe_dict:
                                for more in ffprobe_dict[values]:
                                    if 'logs' in more:
                                        errors = True
                                        print(more['pkt_pts_time'],
                                              more['logs'])
                                        ififuncs.append_csv(
                                            csv_filename, [
                                                filename, start_time,
                                                more['pkt_pts_time'],
                                                more['logs'], ''
                                            ])
                            if errors == False:
                                ififuncs.append_csv(csv_filename, [
                                    filename, start_time, 'no errors',
                                    'no errors', ''
                                ])
                        except subprocess.CalledProcessError:
                            ififuncs.append_csv(csv_filename, [
                                filename, start_time,
                                'script error - process file manually', '', ''
                            ])
    print('Report stored as %s' % csv_filename)
Example #3
0
def make_register():
    '''
    This sends a placeholder accessions register to the desktop logs directory.
    This should get rid of some of the more painful, repetitive identifier matching.
    '''
    desktop_logs_dir = ififuncs.make_desktop_logs_dir()
    register = os.path.join(
        desktop_logs_dir, 'register_' + time.strftime("%Y-%m-%dT%H_%M_%S.csv"))
    ififuncs.create_csv(register, (
        'entry number', 'accession number', 'date acquired',
        'date accessioned', 'acquired from', 'acquisition method',
        'simple name; basic description; identification; historical information',
        'notes'))
    return register
Example #4
0
def get_input():
    if len(sys.argv) < 2:
        print 'IFI FFV1.MKV SCRIPT'
        print 'USAGE: PYTHON makeffv1.py FILENAME'
        print 'OR'
        print 'USAGE: PYTHON makeffv1.py DirectoryNAME'
        print 'If input is a directory, all files will be processed'
        print 'If input is a file, only that file will be processed'
        sys.exit()
    else:
        # Input, either file or firectory, that we want to process.
        input = sys.argv[1]
        # Store the directory containing the input file/directory.
        wd = os.path.dirname(input)
        # Change current working directory to the value stored as "wd"
        os.chdir(os.path.abspath(wd))
        # Store the actual file/directory name without the full path.
        file_without_path = os.path.basename(input)
        csv_report_filename = (os.path.basename(input) + 'makeffv1_results' +
                               time.strftime("_%Y_%m_%dT%H_%M_%S") + '.csv')
        # Check if input is a file.
        # AFAIK, os.path.isfile only works if full path isn't present.
        if os.path.isfile(file_without_path):
            print "single file found"
            video_files = []  # Create empty list
            video_files.append(file_without_path)  # Add filename to list
        # Check if input is a directory.
        elif os.path.isdir(file_without_path):
            os.chdir(file_without_path)
            video_files = (glob('*.mov') + glob('*.mp4') + glob('*.mxf') +
                           glob('*.mkv') + glob('*.avi') + glob('*.y4m'))
        else:
            print "Your input isn't a file or a directory."
            print "What was it? I'm curious."
        # temporary hack to stop makeffv1 from processing DV
        dv_test = []
        for test_files in video_files:
            codec = get_mediainfo('codec', '--inform=Video;%Codec%',
                                  test_files).rstrip()
            if codec == 'DV':
                dv_test.append(test_files)
                print 'DV file found, skipping'
        for i in dv_test:
            if i in video_files:
                video_files.remove(i)
        create_csv(csv_report_filename,
                   ('FILENAME', 'Lossless?', 'Source size in bits',
                    'FFV1 size in bits', ' Compression ratio'))
        return video_files, csv_report_filename
Example #5
0
def make_oe_register():
    '''
    This sends a placeholder oe register to the desktop logs directory.
    This should get rid of some of the more painful, repetitive identifier matching.
    '''
    desktop_logs_dir = ififuncs.make_desktop_logs_dir()
    oe_register = os.path.join(
        desktop_logs_dir,
        'oe_helper_register_' + time.strftime("%Y-%m-%dT%H_%M_%S.csv"))
    ififuncs.create_csv(
        oe_register,
        ('OE No.', 'Date Received', 'Quantity', 'Format', 'Description',
         'Contact Name', 'Type of Acquisition', 'Accession No.',
         'Additional Information', 'Habitat', 'Vinegar No'))
    return oe_register
Example #6
0
def make_register():
    '''
    A placeholder function until we figure out where to put this.
    As too much is unknown, this should really just log which OE numbers map
    to which accession numbers. everything else can be manually filled
    in a spreadsheet editor.
    '''
    ififuncs.create_csv('register.csv', (
        'entry number',
        'accession number',
        'date acquired',
        'acquired from',
        'acquisition method',
        'simple name; basic description; identification; historical information',
        'notes'
    ))
    return 'register.csv'
Example #7
0
def setup():
    '''
    Sets up a lot of the variables and filepaths.
    '''
    csv_report_filename = os.path.join(
        os.path.expanduser("~/Desktop/"),
        'dpx_transcode_report' + time.strftime("_%Y_%m_%dT%H_%M_%S") + '.csv')
    parser = argparse.ArgumentParser(
        description='Transcode all DPX or TIFF'
        ' image sequence in the subfolders of your'
        ' source directory to FFV1 Version 3'
        ' in a Matroska Container.'
        'CSV report is generated on your desktop.'
        ' Written by Kieran O\'Leary.')
    parser.add_argument('source_directory', help='Input directory')
    parser.add_argument('destination', help='Destination directory')
    args = parser.parse_args()
    create_csv(csv_report_filename,
               ('Sequence Name', 'Lossless?', 'Start time', 'Finish Time',
                'Transcode Start Time', 'Transcode Finish Time',
                'Transcode Time', 'Frame Count', 'Encode FPS', 'Sequence Size',
                'FFV1 Size', 'Pixel Format', 'Sequence Type', 'Width',
                'Height', 'Compression Ratio'))
    return args, csv_report_filename
Example #8
0
                    print '***********************' + 'removing: ' + path
                    os.remove(path)


csv_report_filename = os.path.expanduser(
    "~/Desktop/") + 'dpx_transcode_report' + time.strftime(
        "_%Y_%m_%dT%H_%M_%S") + '.csv'
dpxconfig = os.path.expanduser("~/Desktop/") + 'make_dpx_config.txt'
with open(dpxconfig, 'r') as fo:
    config = fo.readlines()
emails = config[0].split(',')

source_directory = sys.argv[1]

create_csv(csv_report_filename,
           ('Sequence Name', 'Lossless?', 'Start time', 'Finish Time',
            'Sequence Size', 'FFV1 Size', 'Compression Ratio'))
for root, dirnames, filenames in os.walk(source_directory):
    #if "tiff_scans"  in dirnames:
    source_directory = root  # + '/tiff_scans'
    total_size = 0

    remove_bad_files(source_directory)
    source_parent_dir = os.path.dirname(source_directory)
    normpath = os.path.normpath(source_directory)
    relative_path = normpath.split(os.sep)[-1]
    split_path = os.path.split(os.path.basename(source_directory))[1]
    start = datetime.datetime.now()
    source_manifest = source_parent_dir + '/%s_manifest.md5' % relative_path
    #make_manifest(os.path.dirname(source_directory), os.path.basename(source_directory), source_manifest)
    info = make_framemd5(source_directory, 'dpx_framemd5')
Example #9
0
def main():
    desktop_logdir = os.path.expanduser("~/Desktop/") + 'seq_csv_reports'
    if not os.path.isdir(desktop_logdir):
        os.makedirs(desktop_logdir)
    all_files = sys.argv[1:]
    permission = ''
    if not permission == 'y' or permission == 'Y':
        print '\n\n**** All image sequences within these directories will be converted the input for this script.\n'
        for i in all_files:
            print i
        permission = raw_input(
            '\n**** All image sequences within these directories will be converted the input for this script \n**** If this looks ok, please press Y, otherwise, type N\n'
        )
        while permission not in ('Y', 'y', 'N', 'n'):
            permission = raw_input(
                '\n**** All image sequences within these directories will be converted the input for this script \n**** If this looks ok, please press Y, otherwise, type N\n'
            )
        if permission == 'n' or permission == 'N':
            print 'Exiting at your command- Cheerio for now'
            sys.exit()
        elif permission == 'y' or permission == 'Y':
            print 'Ok so!'
    csv_report_filename = desktop_logdir + '/seq2prores_report' + time.strftime(
        "_%Y_%m_%dT%H_%M_%S") + '.csv'
    user = get_user()
    create_csv(csv_report_filename,
               ('Sequence Name', 'Start time', 'Finish Time'))
    for source_directory in all_files:
        for root, dirnames, filenames in os.walk(source_directory):
            #if "tiff_scans"  in dirnames:
            source_directory = root  # + '/tiff_scans'
            total_size = 0
            remove_bad_files(source_directory)
            source_parent_dir = os.path.dirname(source_directory)
            normpath = os.path.normpath(source_directory)
            relative_path = normpath.split(os.sep)[-1]
            split_path = os.path.split(os.path.basename(source_directory))[1]
            start = datetime.datetime.now()

            info = get_filenames(source_directory, 'dpx_framemd5')
            if info == 'none':
                continue
            for files in filenames:
                total_size += os.path.getsize(os.path.join(root, files))
            master_parent_dir = os.path.dirname(source_parent_dir)
            master_object_dir = master_parent_dir + '/objects/image'
            master_metadata_dir = master_parent_dir + '/' + 'metadata'
            middle = os.listdir(
                os.path.dirname(os.path.dirname(master_parent_dir)) +
                '/mezzanine')[0]
            mezzanine_object_dir = os.path.dirname(
                os.path.dirname(
                    master_parent_dir)) + '/mezzanine/%s/objects' % middle
            mezzanine_parent_dir = os.path.dirname(
                os.path.dirname(master_parent_dir)) + '/mezzanine/%s' % middle
            mezzanine_metadata_dir = mezzanine_parent_dir + '/metadata'
            source_manifest = master_parent_dir + '/' + os.path.basename(
                master_parent_dir) + '_manifest.md5'
            mezzanine_manifest = mezzanine_parent_dir + '/' + os.path.basename(
                mezzanine_parent_dir) + '_manifest.md5'
            audio_dir_list = os.listdir(master_parent_dir + '/objects/audio')
            for audio_files in audio_dir_list:
                if not audio_files[0] == '.':
                    if audio_files.endswith('.wav'):
                        master_audio = master_parent_dir + '/objects/audio/' + audio_files
                        audio_date_modified = get_date_modified(master_audio)
            mezzanine_file = mezzanine_object_dir + '/' + os.path.basename(
                mezzanine_parent_dir) + '_mezzanine.mov'
            if os.path.isfile(mezzanine_file):
                print 'Mezzanine file already exists so this script has most likely already been run.. skipping.'
                continue
            image_seq_without_container = info[0]
            start_number = info[1]
            container = info[2]
            image_date_modified = info[3]
            start_number_length = len(start_number)
            number_regex = "%0" + str(start_number_length) + 'd.'
            audio_dir = source_parent_dir + '/audio'
            logs_dir = mezzanine_parent_dir + '/logs'
            intellectual_entity_uuid = str(uuid.uuid4())
            source_representation_uuid = premis_description(
                master_object_dir, master_parent_dir + '/objects/audio', user,
                image_date_modified, audio_date_modified,
                intellectual_entity_uuid)

            os.chdir(audio_dir)
            audio_file_list = glob('*.wav')
            audio_file = os.path.join(audio_dir, audio_file_list[0])
            dpx_filename = image_seq_without_container + number_regex + container
            logfile = logs_dir + '/%s_prores.log' % os.path.basename(
                mezzanine_parent_dir)
            env_dict = os.environ.copy()
            # https://github.com/imdn/scripts/blob/0dd89a002d38d1ff6c938d6f70764e6dd8815fdd/ffmpy.py#L272
            logfile = "\'" + logfile + "\'"
            env_dict['FFREPORT'] = 'file={}:level=48'.format(logfile)
            seq2prores = [
                'ffmpeg', '-y', '-f', 'image2', '-framerate', '24',
                '-start_number', start_number, '-i', root + '/' + dpx_filename,
                '-i', audio_file, '-c:v', 'prores', '-profile:v', '3', '-c:a',
                'pcm_s24le', '-ar', '48000', mezzanine_object_dir + '/' +
                os.path.basename(mezzanine_parent_dir) + '_mezzanine.mov',
                '-f', 'framemd5', '-an', master_metadata_dir + '/image/' +
                os.path.basename(master_parent_dir) + '.framemd5', '-c:a',
                'pcm_s24le', '-f', 'framemd5', '-vn', master_metadata_dir +
                '/audio/' + os.path.basename(master_parent_dir) + '.framemd5'
            ]
            print seq2prores
            subprocess.call(seq2prores, env=env_dict)
            representation_uuid = str(uuid.uuid4())
            split_list = os.path.basename(mezzanine_parent_dir).split('_')
            premisxml, premis_namespace, doc, premis = setup_xml(
                mezzanine_file)
            items = {
                "workflow": "seq2prores",
                "oe": 'n/a',
                "filmographic": split_list[0],
                "sourceAccession": split_list[1],
                "interventions": ['placeholder'],
                "prepList": ['placeholder'],
                "user": user
            }
            premis = doc.getroot()
            xml_info = make_premis(mezzanine_file, items, premis,
                                   premis_namespace, premisxml,
                                   representation_uuid, '????')
            sequence = xml_info[3]

            linking_representation_uuids = []
            linking_representation_uuids.append(xml_info[2])
            linking_representation_uuids.append(
                xml_info[2]
            )  # the duplicate does nothing btw, they are a placeholder from a hardcoded function
            linking_representation_uuids.append(source_representation_uuid)
            create_intellectual_entity(premisxml, premis_namespace, doc,
                                       premis, items, intellectual_entity_uuid)
            create_representation(premisxml, premis_namespace, doc, premis,
                                  items, linking_representation_uuids,
                                  representation_uuid, sequence,
                                  intellectual_entity_uuid)
            doc = xml_info[0]
            premisxml = xml_info[1]
            final_sip_manifest_uuid = str(uuid.uuid4())
            prores_event_uuid = str(uuid.uuid4())

            macMiniTelecineMachineAgent_events = [
                prores_event_uuid, final_sip_manifest_uuid
            ]
            macMiniTelecineMachineAgent = make_agent(
                premis, macMiniTelecineMachineAgent_events,
                '230d72da-07e7-4a79-96ca-998b9f7a3e41')
            macMiniTelecineMachineOSAgent_events = [
                prores_event_uuid, final_sip_manifest_uuid
            ]
            macMiniTelecineOSAgent = make_agent(
                premis, macMiniTelecineMachineOSAgent_events,
                '9486b779-907c-4cc4-802c-22e07dc1242f')

            hashlib_events = [final_sip_manifest_uuid]
            hashlibAgent = make_agent(premis, hashlib_events,
                                      '9430725d-7523-4071-9063-e8a6ac4f84c4')
            ffmpegAgent_events = [prores_event_uuid]
            ffmpegAgent = make_agent(premis, ffmpegAgent_events,
                                     'ee83e19e-cdb1-4d83-91fb-7faf7eff738e')
            operatorEvents = [final_sip_manifest_uuid, prores_event_uuid]
            operatorAgent = make_agent(premis, operatorEvents, user)
            #ffmpegAgent                                 = make_agent(premis,[framemd5_uuid ], 'ee83e19e-cdb1-4d83-91fb-7faf7eff738e')
            make_event(
                premis, 'creation',
                'Image Sequence and WAV re-encoded to Apple Pro Res 422 HQ with 48khz 24-bit PCM audio',
                [
                    macMiniTelecineMachineAgent, macMiniTelecineOSAgent,
                    ffmpegAgent, operatorAgent
                ], prores_event_uuid, [representation_uuid], 'outcome', 'now')

            print premisxml
            mezzanine_mediainfoxml = "%s/%s_mediainfo.xml" % (
                mezzanine_metadata_dir, os.path.basename(mezzanine_parent_dir))
            tracexml = "%s/%s_mediatrace.xml" % (
                mezzanine_metadata_dir, os.path.basename(mezzanine_parent_dir))
            audio_mediainfoxml = "%s/%s_mediainfo.xml" % (
                master_metadata_dir + '/audio', os.path.basename(master_audio))
            audio_mediatracexml = "%s/%s_mediatrace.xml" % (
                master_metadata_dir + '/audio', os.path.basename(master_audio))
            if not os.path.isfile(audio_mediainfoxml):
                make_mediainfo(audio_mediainfoxml, 'audiomediaxmlinput',
                               master_audio)
            if not os.path.isfile(audio_mediatracexml):
                make_mediainfo(audio_mediatracexml, 'audiomediatraceinput',
                               master_audio)
            if not os.path.isfile(mezzanine_mediainfoxml):
                make_mediainfo(
                    mezzanine_mediainfoxml, 'mediaxmlinput',
                    mezzanine_object_dir + '/' +
                    os.path.basename(mezzanine_parent_dir) + '_mezzanine.mov')
            if not os.path.isfile(tracexml):
                make_mediatrace(
                    tracexml, 'mediatracexmlinput',
                    mezzanine_object_dir + '/' +
                    os.path.basename(mezzanine_parent_dir) + '_mezzanine.mov')
            hashlib_manifest(master_parent_dir, source_manifest,
                             master_parent_dir)
            hashlib_manifest(mezzanine_parent_dir, mezzanine_manifest,
                             mezzanine_parent_dir)
            make_event(premis, 'message digest calculation',
                       'Checksum manifest for whole package created', [
                           macMiniTelecineMachineAgent, macMiniTelecineOSAgent,
                           operatorAgent
                       ], final_sip_manifest_uuid, [representation_uuid],
                       'source', 'now')
            write_premis(doc, premisxml)
            finish = datetime.datetime.now()
            append_csv(csv_report_filename,
                       (os.path.basename(master_parent_dir), start, finish))
            '''
Example #10
0
def representation_uuid_csv(filmographic, source_accession, uuid):
    uuid_csv = os.path.expanduser('~/Desktop/uuid.csv')
    print os.path.abspath(uuid_csv)
    if not os.path.isfile(uuid_csv):
        create_csv(uuid_csv, ('reference number','source accession number' 'uuid'))
    append_csv(uuid_csv, (filmographic, source_accession, uuid) )
Example #11
0
if not user == '1' or user == '2':
    user =  raw_input('\n\n**** Who are you?\nPress 1 or 2 or 3\n\n1. Brian Cash\n2. Gavin Martin\n3. Raelene Casey\n' )
    while user not in ('1','2', '3'):
        user =  raw_input('\n\n**** Who are you?\nPress 1 or 2 or 3\n\n1. Brian Cash\n2. Gavin Martin\n3. Raelne Casey\n')
if user == '1':
    user = '******'
    print 'Hi Brian, Congratulations on becoming a father!!!'
elif user == '2':
    user = '******'
    print 'Hi Gavin, Have you renewed your subscription to American Cinematographer?'
elif user == '3':
    user = '******'
    print 'Hi Raelene, Brian Cash must be on paternity leave'
    time.sleep(1)

create_csv(csv_report_filename, ('Sequence Name', 'Lossless?', 'Start time', 'Finish Time'))
for source_directory in all_files:
    for root,dirnames,filenames in os.walk(source_directory):
            source_directory = root
            if not file_check(source_directory) == 'TIFF':
                append_csv(csv_report_filename, (source_directory,'EMPTY DIRECTORY - SKIPPED', 'n/a', 'n/a'))
                continue

            root_dir = os.path.dirname(os.path.dirname(root))
            general_log = root_dir + '/logs/image/%s_image_log.log' % os.path.basename(root_dir)
            generate_log(general_log, 'Input = %s' % root)
            remove_bad_files(source_directory)
            source_parent_dir           = os.path.dirname(source_directory)
            normpath                    = os.path.normpath(source_directory)
            relative_path               = normpath.split(os.sep)[-1]
            split_path                  = os.path.split(os.path.basename(source_directory))[1]
Example #12
0
if not user == '1' or user == '2'or user == '3':
    user =  raw_input('\n\n**** Who are you?\nPress 1 or 2 or 3\n\n1. Brian Cash\n2. Gavin Martin\n3. Raelene Casey\n' )
    while user not in ('1','2','3'):
        user =  raw_input('\n\n**** Who are you?\nPress 1 or 2 or 3\n\n1. Brian Cash\n2. Gavin Martin\n3. Raelene Casey\n')
if user == '1':
    user = '******'
    print 'Hi Brian, Congratulations on becoming a father!!!'
elif user == '2':
    user = '******'
    print 'Hi Gavin, Have you renewed your subscription to American Cinematographer?'
elif user == '3':
    user = '******'
    print 'Hi Raelene, Brian must be out of the office'
    time.sleep(1)

create_csv(csv_report_filename, ('Sequence Name', 'Lossless?', 'Start time', 'Finish Time'))
for source_directory in all_files:
    for root,dirnames,filenames in os.walk(source_directory):
            source_directory = root
            if not file_check(source_directory) == 'TIFF':
                append_csv(csv_report_filename, (source_directory,'EMPTY DIRECTORY - SKIPPED', 'n/a', 'n/a'))
                continue

            root_dir = os.path.dirname(os.path.dirname(root))
            general_log = root_dir + '/logs/image/%s_image_log.log' % os.path.basename(root_dir)
            generate_log(general_log, 'Input = %s' % root)
            remove_bad_files(source_directory)
            source_parent_dir           = os.path.dirname(source_directory)
            normpath                    = os.path.normpath(source_directory)
            relative_path               = normpath.split(os.sep)[-1]
            split_path                  = os.path.split(os.path.basename(source_directory))[1]
Example #13
0
def get_input():
    if len(sys.argv) < 2:
        print 'IFI FFV1.MKV SCRIPT'
        print 'USAGE: PYTHON makeffv1.py FILENAME'
        print 'OR'
        print 'USAGE: PYTHON makeffv1.py DirectoryNAME'
        print 'If input is a directory, all files will be processed'
        print 'If input is a file, only that file will be processed'
        sys.exit()
    else:
        # Input, either file or firectory, that we want to process.
        input = sys.argv[1]
        # Store the directory containing the input file/directory.
        wd = os.path.dirname(input)
        # Change current working directory to the value stored as "wd"
        os.chdir(os.path.abspath(wd))
        # Store the actual file/directory name without the full path.
        file_without_path = os.path.basename(input)
        csv_report_filename = (
            os.path.basename(input)
            + 'makeffv1_results'
            + time.strftime("_%Y_%m_%dT%H_%M_%S") + '.csv'
            )
        # Check if input is a file.
        # AFAIK, os.path.isfile only works if full path isn't present.
        if os.path.isfile(file_without_path):
            print "single file found"
            video_files = []                       # Create empty list
            video_files.append(file_without_path)  # Add filename to list
        # Check if input is a directory.
        elif os.path.isdir(file_without_path):
            os.chdir(file_without_path)
            video_files = (
                glob('*.mov')
                + glob('*.mp4')
                + glob('*.mxf')
                + glob('*.mkv')
                + glob('*.avi')
                + glob('*.y4m')
                )
        else:
            print "Your input isn't a file or a directory."
            print "What was it? I'm curious."
        # temporary hack to stop makeffv1 from processing DV
        dv_test = []
        for test_files in video_files:
            codec =  get_mediainfo(
                'codec', '--inform=Video;%Codec%',
                 test_files
                 ).rstrip()
            if codec == 'DV':
                dv_test.append(test_files)
                print 'DV file found, skipping'
        for i in dv_test:
            if i in video_files:
                video_files.remove(i)
        create_csv(
            csv_report_filename,
            (
                'FILENAME', 'Lossless?',
                'Source size in bits', 'FFV1 size in bits',
                ' Compression ratio'
                )
            )
        return video_files, csv_report_filename
Example #14
0
        for name in files:
            path = os.path.join(root, name)
            for i in rm_these:
                if name == i:
                    print '***********************' + 'removing: ' + path
                    os.remove(path)
csv_report_filename = os.path.expanduser("~/Desktop/") + 'dpx_transcode_report' + time.strftime("_%Y_%m_%dT%H_%M_%S") + '.csv'
parser = argparse.ArgumentParser(description='Transcode all DPX or TIFF image sequence in the subfolders of your source directory to FFV1 Version 3 in a Matroska Container. A CSV report is generated on your desktop.'
                                 ' Written by Kieran O\'Leary.')
parser.add_argument('source_directory', help='Input directory')
parser.add_argument('destination', help='Destination directory')

args                 = parser.parse_args()
source_directory     = args.source_directory
destination          = args.destination # or hardcode
create_csv(csv_report_filename, ('Sequence Name', 'Lossless?', 'Start time', 'Finish Time', 'Transcode Start Time', 'Transcode Finish Time','Transcode Time', 'Frame Count', 'Encode FPS','Sequence Size', 'FFV1 Size','Pixel Format', 'Sequence Type','Width','Height','Compression Ratio'))
for root,dirnames,filenames in os.walk(source_directory):
        source_directory = root # + '/tiff_scans'
        total_size = 0
        #remove_bad_files(source_directory)
        source_parent_dir       = os.path.dirname(source_directory)
        normpath                = os.path.normpath(source_directory)
        relative_path           = normpath.split(os.sep)[-1]
        split_path              = os.path.split(os.path.basename(source_directory))[1]
        start                   = datetime.datetime.now()
        source_manifest         = source_parent_dir + '/%s_manifest.md5' % relative_path
        #make_manifest(os.path.dirname(source_directory), os.path.basename(source_directory), source_manifest)
        info                    = make_framemd5(source_directory, 'dpx_framemd5')
        if info == 'none':
            continue
        for files in filenames:
Example #15
0
csv_report_filename = os.path.expanduser(
    "~/Desktop/") + 'dpx_transcode_report' + time.strftime(
        "_%Y_%m_%dT%H_%M_%S") + '.csv'
parser = argparse.ArgumentParser(
    description=
    'Transcode all DPX or TIFF image sequence in the subfolders of your source directory to FFV1 Version 3 in a Matroska Container. A CSV report is generated on your desktop.'
    ' Written by Kieran O\'Leary.')
parser.add_argument('source_directory', help='Input directory')
parser.add_argument('destination', help='Destination directory')

args = parser.parse_args()
source_directory = args.source_directory
destination = args.destination  # or hardcode
create_csv(
    csv_report_filename,
    ('Sequence Name', 'Lossless?', 'Start time', 'Finish Time',
     'Transcode Start Time', 'Transcode Finish Time', 'Transcode Time',
     'Frame Count', 'Encode FPS', 'Sequence Size', 'FFV1 Size', 'Pixel Format',
     'Sequence Type', 'Width', 'Height', 'Compression Ratio'))
for root, dirnames, filenames in os.walk(source_directory):
    source_directory = root  # + '/tiff_scans'
    total_size = 0
    #remove_bad_files(source_directory)
    source_parent_dir = os.path.dirname(source_directory)
    normpath = os.path.normpath(source_directory)
    relative_path = normpath.split(os.sep)[-1]
    split_path = os.path.split(os.path.basename(source_directory))[1]
    start = datetime.datetime.now()
    source_manifest = source_parent_dir + '/%s_manifest.md5' % relative_path
    #make_manifest(os.path.dirname(source_directory), os.path.basename(source_directory), source_manifest)
    info = make_framemd5(source_directory, 'dpx_framemd5')
    if info == 'none':
Example #16
0
def main():
    desktop_logdir = os.path.expanduser("~/Desktop/") + 'seq_csv_reports'
    if not os.path.isdir(desktop_logdir):
        os.makedirs(desktop_logdir)
    all_files = sys.argv[1:]
    permission = ''
    if not permission == 'y' or permission == 'Y':
        print '\n\n**** All image sequences within these directories will be converted the input for this script.\n'
        for i in all_files:
            print i
        permission =  raw_input('\n**** All image sequences within these directories will be converted the input for this script \n**** If this looks ok, please press Y, otherwise, type N\n' )
        while permission not in ('Y','y','N','n'):
            permission =  raw_input('\n**** All image sequences within these directories will be converted the input for this script \n**** If this looks ok, please press Y, otherwise, type N\n')
        if permission == 'n' or permission == 'N':
            print 'Exiting at your command- Cheerio for now'
            sys.exit()
        elif permission =='y' or permission == 'Y':
            print 'Ok so!'
    csv_report_filename = desktop_logdir + '/seq2prores_report' + time.strftime("_%Y_%m_%dT%H_%M_%S") + '.csv'
    user = get_user()
    create_csv(csv_report_filename, ('Sequence Name', 'Start time', 'Finish Time'))
    for source_directory in all_files:
        for root,dirnames,filenames in os.walk(source_directory):
                #if "tiff_scans"  in dirnames:
                source_directory = root# + '/tiff_scans'
                total_size = 0
                remove_bad_files(source_directory)
                source_parent_dir    = os.path.dirname(source_directory)
                normpath             = os.path.normpath(source_directory)
                relative_path        = normpath.split(os.sep)[-1]
                split_path           = os.path.split(os.path.basename(source_directory))[1]
                start = datetime.datetime.now()

                info = get_filenames(source_directory, 'dpx_framemd5')
                if info == 'none':
                    continue
                for files in filenames:
                    total_size += os.path.getsize(os.path.join(root,files))
                master_parent_dir     = os.path.dirname(source_parent_dir)
                master_object_dir     = master_parent_dir + '/objects/image'
                master_metadata_dir = master_parent_dir + '/' + 'metadata'
                middle =  os.listdir(os.path.dirname(os.path.dirname(master_parent_dir)) + '/mezzanine')[0]
                mezzanine_object_dir            =  os.path.dirname(os.path.dirname(master_parent_dir)) + '/mezzanine/%s/objects' % middle
                mezzanine_parent_dir   = os.path.dirname(os.path.dirname(master_parent_dir)) + '/mezzanine/%s' % middle
                mezzanine_metadata_dir = mezzanine_parent_dir + '/metadata'
                source_manifest =  master_parent_dir + '/' + os.path.basename( master_parent_dir) +  '_manifest.md5'
                mezzanine_manifest =   mezzanine_parent_dir + '/' + os.path.basename( mezzanine_parent_dir) +  '_manifest.md5'
                master_audio =  master_parent_dir + '/objects/audio/' + os.listdir(master_parent_dir + '/objects/audio')[0]
                mezzanine_file =  mezzanine_object_dir + '/' + os.path.basename(mezzanine_parent_dir) + '_mezzanine.mov'
                if os.path.isfile(mezzanine_file):
                    print 'Mezzanine file already exists so this script has most likely already been run.. skipping.'
                    continue
                image_seq_without_container = info[0]
                start_number                = info[1]
                container                   = info[2]
                start_number_length = len(start_number)
                number_regex = "%0" + str(start_number_length) + 'd.'
                audio_dir            = source_parent_dir + '/audio'
                logs_dir            =  mezzanine_parent_dir + '/logs'

                source_representation_uuid = premis_description(master_object_dir, master_parent_dir + '/objects/audio', user)

                os.chdir(audio_dir)
                audio_file_list = glob('*.wav')
                audio_file = os.path.join(audio_dir,audio_file_list[0])
                dpx_filename                = image_seq_without_container + number_regex + container
                logfile = logs_dir + '/%s_prores.log' % os.path.basename(mezzanine_parent_dir)
                env_dict = os.environ.copy()
                # https://github.com/imdn/scripts/blob/0dd89a002d38d1ff6c938d6f70764e6dd8815fdd/ffmpy.py#L272
                logfile = "\'" + logfile + "\'"
                env_dict['FFREPORT'] = 'file={}:level=48'.format(logfile)
                seq2prores= ['ffmpeg','-y','-f','image2','-framerate','24', '-start_number', start_number, '-i', root + '/' + dpx_filename ,'-i', audio_file,'-c:v','prores','-profile:v', '3','-c:a','pcm_s24le', '-ar', '48000', mezzanine_object_dir + '/' + os.path.basename(mezzanine_parent_dir) + '_mezzanine.mov','-f', 'framemd5', '-an', master_metadata_dir + '/image/' + os.path.basename(master_parent_dir) + '.framemd5', '-c:a', 'pcm_s24le', '-f', 'framemd5', '-vn', master_metadata_dir + '/audio/' + os.path.basename(master_parent_dir) + '.framemd5']
                print seq2prores
                subprocess.call(seq2prores,env=env_dict)
                representation_uuid = str(uuid.uuid4())
                split_list = os.path.basename(mezzanine_parent_dir).split('_')
                premisxml, premis_namespace, doc, premis = setup_xml(mezzanine_file)
                items = {"workflow":"seq2prores","oe":'n/a', "filmographic":split_list[0], "sourceAccession":split_list[1], "interventions":['placeholder'], "prepList":['placeholder'], "user":user}
                premis = doc.getroot()
                xml_info    = make_premis(mezzanine_file, items, premis, premis_namespace,premisxml, representation_uuid, '????')
                sequence = xml_info[3]

                linking_representation_uuids = []
                linking_representation_uuids.append(xml_info[2])
                linking_representation_uuids.append(xml_info[2]) # the duplicate does nothing btw, they are a placeholder from a hardcoded function
                linking_representation_uuids.append(source_representation_uuid)
                create_representation(premisxml, premis_namespace, doc, premis, items,linking_representation_uuids, representation_uuid,sequence )
                doc         = xml_info[0]
                premisxml   = xml_info[1]
                final_sip_manifest_uuid                     = str(uuid.uuid4())
                prores_event_uuid                           = str(uuid.uuid4())

                macMiniTelecineMachineAgent_events          = [prores_event_uuid,final_sip_manifest_uuid  ]
                macMiniTelecineMachineAgent                 = make_agent(premis,macMiniTelecineMachineAgent_events, '230d72da-07e7-4a79-96ca-998b9f7a3e41')
                macMiniTelecineMachineOSAgent_events        = [prores_event_uuid,final_sip_manifest_uuid ]
                macMiniTelecineOSAgent                      = make_agent(premis,macMiniTelecineMachineOSAgent_events, '9486b779-907c-4cc4-802c-22e07dc1242f')

                hashlib_events                              = [final_sip_manifest_uuid ]
                hashlibAgent                                = make_agent(premis,hashlib_events, '9430725d-7523-4071-9063-e8a6ac4f84c4')
                ffmpegAgent_events                          = [prores_event_uuid ]
                ffmpegAgent                                 = make_agent(premis,ffmpegAgent_events , 'ee83e19e-cdb1-4d83-91fb-7faf7eff738e')
                operatorEvents                              = [final_sip_manifest_uuid,prores_event_uuid]
                operatorAgent                               = make_agent(premis,operatorEvents ,user)
                #ffmpegAgent                                 = make_agent(premis,[framemd5_uuid ], 'ee83e19e-cdb1-4d83-91fb-7faf7eff738e')
                make_event(premis, 'creation', 'Image Sequence and WAV re-encoded to Apple Pro Res 422 HQ with 48khz 24-bit PCM audio', [macMiniTelecineMachineAgent ,macMiniTelecineOSAgent, ffmpegAgent, operatorAgent ],prores_event_uuid,[representation_uuid], 'outcome')

                print premisxml
                mezzanine_mediainfoxml =  "%s/%s_mediainfo.xml" % (mezzanine_metadata_dir,os.path.basename(mezzanine_parent_dir) )
                tracexml =  "%s/%s_mediatrace.xml" % (mezzanine_metadata_dir,os.path.basename(mezzanine_parent_dir) )
                audio_mediainfoxml = "%s/%s_mediainfo.xml" % (master_metadata_dir + '/audio',os.path.basename(master_audio) )
                audio_mediatracexml = "%s/%s_mediatrace.xml" % (master_metadata_dir + '/audio',os.path.basename(master_audio) )
                if not os.path.isfile(audio_mediainfoxml):
                    make_mediainfo(audio_mediainfoxml,'audiomediaxmlinput',master_audio)
                if not os.path.isfile(audio_mediatracexml):
                    make_mediainfo(audio_mediatracexml,'audiomediatraceinput',master_audio)
                if not os.path.isfile(mezzanine_mediainfoxml):
                    make_mediainfo(mezzanine_mediainfoxml,'mediaxmlinput',mezzanine_object_dir + '/' + os.path.basename(mezzanine_parent_dir) + '_mezzanine.mov')
                if not os.path.isfile(tracexml):
                    make_mediatrace(tracexml,'mediatracexmlinput',mezzanine_object_dir + '/' + os.path.basename(mezzanine_parent_dir) + '_mezzanine.mov')
                hashlib_manifest(master_parent_dir, source_manifest, master_parent_dir)
                hashlib_manifest(mezzanine_parent_dir, mezzanine_manifest, mezzanine_parent_dir)
                make_event(premis, 'message digest calculation', 'Checksum manifest for whole package created', [macMiniTelecineMachineAgent ,macMiniTelecineOSAgent, operatorAgent],final_sip_manifest_uuid,[representation_uuid], 'source')
                write_premis(doc, premisxml)
                finish = datetime.datetime.now()
                append_csv(csv_report_filename, (os.path.basename( master_parent_dir), start, finish))
                '''
Example #17
0
def representation_uuid_csv(filmographic, source_accession, uuid):
    uuid_csv = os.path.expanduser('~/Desktop/uuid.csv')
    if not os.path.isfile(uuid_csv):
        create_csv(uuid_csv, ('reference number', 'source accession number'
                              'uuid'))
    append_csv(uuid_csv, (filmographic, source_accession, uuid))
Example #18
0
    for root, dirs, files in os.walk(root_dir):
        for name in files:
            path = os.path.join(root, name)
            for i in rm_these:
                if name == i:
                    print '***********************' + 'removing: ' + path   
                    os.remove(path)
                    
                    
csv_report_filename = os.path.expanduser("~/Desktop/") + 'dpx_transcode_report' + time.strftime("_%Y_%m_%dT%H_%M_%S") + '.csv'
dpxconfig = os.path.expanduser("~/Desktop/") + 'make_dpx_config.txt'
with open(dpxconfig, 'r') as fo:
    config = fo.readlines()
emails = config[0].split(',')
source_directory = sys.argv[1]
create_csv(csv_report_filename, ('Sequence Name', 'Lossless?', 'Start time', 'Finish Time', 'Sequence Size', 'FFV1 Size', 'Compression Ratio'))
for root,dirnames,filenames in os.walk(source_directory):
        #if "tiff_scans"  in dirnames:
        source_directory = root# + '/tiff_scans'
        total_size = 0
        remove_bad_files(source_directory)
        source_parent_dir    = os.path.dirname(source_directory)
        normpath             = os.path.normpath(source_directory) 
        relative_path        = normpath.split(os.sep)[-1]
        split_path           = os.path.split(os.path.basename(source_directory))[1]
        start = datetime.datetime.now()
        source_manifest = source_parent_dir + '/' + os.path.basename(os.path.dirname(root)) + time.strftime("%Y%m%dT%H_%M_%S") +  '_manifest.md5'
        info = get_filenames(source_directory, 'dpx_framemd5')
        if info == 'none':
            continue
        for files in filenames: