コード例 #1
0
def main():
    '''
    Overly long main function that does most of the heavy lifting.
    '''
    ififuncs.check_existence(['rawcooked', 'ffmpeg'])
    args = setup()
    run_loop(args)
コード例 #2
0
def main(args_):
    '''
    Launch the various functions that will make a h264/mp4 access copy.
    '''
    ififuncs.check_existence(['ffprobe', 'ffmpeg'])
    args = set_options(args_)
    video_files = get_filenames(args)
    for filename in video_files:
        filter_list = build_filter(args, filename)
        make_h264(filename, args, filter_list)
コード例 #3
0
def main():
    '''
    Simple recursive process that makes framemd5 sidecar reports.
    '''
    ififuncs.check_existence(['ffmpeg'])
    args = parse_args()
    source = args.i
    fmd5 = source + '_source.framemd5'
    if os.path.isfile(source):
        cmd = ['ffmpeg', '-i', source, '-f', 'framemd5', '-an', fmd5]
        subprocess.call(cmd)
    else:
        for root, _, filenames in os.walk(source):
            for filename in filenames:
                if filename.endswith(('.mov', '.mkv', '.dv')):
                    if filename[0] != '.':
                        full_path = os.path.join(root, filename)
                        cmd = [
                            'ffmpeg', '-i', full_path, '-f', 'framemd5', '-an',
                            full_path + '_source.framemd5'
                        ]
                        subprocess.call(cmd)
コード例 #4
0
ファイル: massqc.py プロジェクト: mercuryswitch/IFIscripts
def main():
    '''
    Simple recursive process that makes QCTools sidecar reports.
    '''
    ififuncs.check_existence(['qcli'])
    source = sys.argv[1]
    if os.path.isfile(source):
        cmd = [
            'qcli',
            '-i',
            source]
        subprocess.call(cmd)
    else:
        for root, _, filenames in os.walk(source):
            for filename in filenames:
                if filename.endswith(('.mov', '.mkv','.dv', '.m2t')):
                    if filename[0] != '.':
                        cmd = [
                            'qcli',
                            '-i',
                            os.path.join(root, filename)
                        ]
                        subprocess.call(cmd)
コード例 #5
0
def main():
    '''
    Launches the functions that will validate your FFV1/MKV files.
    '''
    ififuncs.check_existence(['mediaconch'])
    args = parse_args()
    source = args.input
    user = ififuncs.get_user()
    for root, _, filenames in os.walk(source):
        for filename in filenames:
            if filename[0] != '.' and filename.endswith('.mkv'):
                if setup(os.path.join(root, filename), user) == 'skipping':
                    continue
                else:
                    log_name_source, user, mediaconch_xmlfile, manifest, full_path, parent_dir = setup(
                        os.path.join(root, filename), user)
                    launch_mediaconch(
                        log_name_source,
                        user,
                        mediaconch_xmlfile,
                        manifest,
                        full_path,
                    )
                    validation_outcome = parse_mediaconch(mediaconch_xmlfile)
                    print(str(validation_outcome))
                    if int(validation_outcome['fail_count']) > 0:
                        print('Validation failed!')
                        event_outcome = 'fail'
                    elif int(validation_outcome['fail_count']) == 0:
                        print('validation successful')
                        event_outcome = 'pass'
                    ififuncs.generate_log(
                        log_name_source,
                        'EVENT = eventType=validation, eventOutcome=%s, eventDetail=%s'
                        % (event_outcome, str(validation_outcome)))
                    log_results(manifest, log_name_source, parent_dir)
コード例 #6
0
ファイル: testfiles.py プロジェクト: muthusalami/IFIscripts-1
def main(args_):
    '''
    Creates three v210/mov tesfiles in a test_files subdirectory
    '''
    ififuncs.check_existence(['ffmpeg'])
    args = parse_args(args_)
    output_dir = os.path.join(os.path.abspath(args.o), 'test_files')
    ten_bit_dpx_dir = os.path.join(output_dir, 'ten_bit_dpx')
    sixteen_bit_dpx_dir = os.path.join(output_dir, 'sixteen_bit_dpx')
    multi_reel_dir = os.path.join(output_dir, 'multi_reel')
    reel1 = os.path.join(multi_reel_dir, 'whatever_reel1')
    reel2 = os.path.join(multi_reel_dir, 'whatever_reel2')
    reel3 = os.path.join(multi_reel_dir, 'whatever_reel3')
    bars_cmd = [
        'ffmpeg', '-f', 'lavfi', '-i', 'testsrc', '-n', '-f', 'lavfi', '-i',
        'sine', '-c:v', 'v210', '-ac', '2', '-c:a', 'pcm_s24le', '-t', '20',
        os.path.join(output_dir, 'bars_v210_pcm24le_stereo_20sec.mov')
    ]
    mandel_cmd = [
        'ffmpeg', '-f', 'lavfi', '-i', 'mandelbrot', '-n', '-c:v', 'v210',
        '-t', '5',
        os.path.join(output_dir, 'mandel_silent.mov')
    ]

    life_cmd = [
        'ffmpeg', '-f', 'lavfi', '-i', 'testsrc', '-pix_fmt', 'gbrp10le', '-t',
        '20',
        os.path.join(ten_bit_dpx_dir, 'ten_bit_%06d.dpx'), '-f', 'lavfi', '-i',
        'sine', '-ac', '2', '-c:a', 'pcm_s24le', '-t', '20',
        os.path.join(ten_bit_dpx_dir, 'ten_bit.wav')
    ]
    reel1_cmd = [
        'ffmpeg', '-f', 'lavfi', '-i', 'testsrc', '-pix_fmt', 'gbrp10le', '-t',
        '20',
        os.path.join(reel1, 'ten_bit_reel1_%06d.dpx'), '-f', 'lavfi', '-i',
        'sine', '-ac', '2', '-c:a', 'pcm_s24le', '-t', '20',
        os.path.join(reel1, 'ten_bit_reel1.wav')
    ]
    reel2_cmd = [
        'ffmpeg', '-f', 'lavfi', '-i', 'testsrc2', '-pix_fmt', 'gbrp10le',
        '-t', '20',
        os.path.join(reel2, 'ten_bit_reel2_%06d.dpx'), '-f', 'lavfi', '-i',
        'sine', '-ac', '2', '-c:a', 'pcm_s24le', '-t', '20',
        os.path.join(reel2, 'ten_bit_reel2.wav')
    ]
    reel3_cmd = [
        'ffmpeg', '-f', 'lavfi', '-i', 'mandelbrot', '-pix_fmt', 'gbrp10le',
        '-t', '20',
        os.path.join(reel3, 'ten_bit_reel3_%06d.dpx'), '-f', 'lavfi', '-i',
        'sine', '-ac', '2', '-c:a', 'pcm_s24le', '-t', '20',
        os.path.join(reel3, 'ten_bit_reel3.wav')
    ]
    dpx16_cmd = [
        'ffmpeg', '-f', 'lavfi', '-i', 'testsrc2', '-pix_fmt', 'rgb48le', '-t',
        '20',
        os.path.join(sixteen_bit_dpx_dir, 'sixteen_bit_%06d.dpx')
    ]
    if not os.path.isdir(output_dir):
        os.makedirs(output_dir)
    subprocess.call(bars_cmd)
    subprocess.call(mandel_cmd)
    if not args.onlyvideo:
        if not os.path.isdir(ten_bit_dpx_dir):
            os.makedirs(ten_bit_dpx_dir)
        if not os.path.isdir(sixteen_bit_dpx_dir):
            os.makedirs(sixteen_bit_dpx_dir)
        if not os.path.isdir(reel1):
            os.makedirs(reel1)
        if not os.path.isdir(reel2):
            os.makedirs(reel2)
        if not os.path.isdir(reel3):
            os.makedirs(reel3)
        subprocess.call(dpx16_cmd)
        subprocess.call(reel1_cmd)
        subprocess.call(reel2_cmd)
        subprocess.call(reel3_cmd)
        subprocess.call(life_cmd)
コード例 #7
0
ファイル: makezip.py プロジェクト: muthusalami/IFIscripts-1
                print('Python has not detected any errors in your zipfile')
            else:
                print('ERROR DETECTED IN %s '% result)
    verify_finish = datetime.datetime.now()
    total_zip = zip_finish - zip_start
    total_verify = verify_finish - verify_start
    print('Zipping duration = %s seconds' % (str(total_zip)))
    print('Verification duration = %s seconds' % (str(total_verify)))
    print('Total duration = %s seconds' % (str(total_zip + total_verify)))
    return result, full_zip

def main(args_):
    '''
    Zips and verifies all files and folders within your input directory.
    '''
    args = parse_args(args_)
    print(args)
    print('makezip.py started')
    source = args.i
    destination = args.o
    if args.basename:
        name = args.basename
    else:
        name = os.path.basename(source) + '.zip'
    result, full_zip = create_zip(source, destination, name)
    return result, full_zip

if __name__ == '__main__':
    ififuncs.check_existence(['7za'])
    main(sys.argv[1:])
コード例 #8
0
def main(args_):
    '''
    Launch all the functions for creating an IFI SIP.
    '''
    args = parse_args(args_)
    start = datetime.datetime.now()
    inputs = args.i
    for input in inputs:
        if ififuncs.check_av_or_doc(input) == 'av':
            ififuncs.check_existence(['mediainfo'])
        elif ififuncs.check_av_or_doc(input) == 'doc':
            ififuncs.check_existence(['sf', 'exiftool'])
    if args.d:
        try:
            import clairmeta
            clairmeta_version = clairmeta.__version__
        except ImportError:
            print(
                'Exiting as Clairmeta is not installed. If there is a case for not using clairmeta, please let me know and i can make a workaround'
            )
            sys.exit()
    if args.zip:
        ififuncs.check_existence(['7za'])
    print(args)
    user = ififuncs.determine_user(args)
    object_entry = get_object_entry(args)
    sip_path = make_folder_path(os.path.join(args.o), args, object_entry)
    uuid, uuid_event = determine_uuid(args, sip_path)
    new_log_textfile = os.path.join(sip_path,
                                    'logs' + '/' + uuid + '_sip_log.log')
    if args.d:
        content_title = create_content_title_text(sip_path, args)
    ififuncs.generate_log(new_log_textfile, 'EVENT = sipcreator.py started')
    ififuncs.generate_log(
        new_log_textfile, 'eventDetail=sipcreator.py %s' %
        ififuncs.get_script_version('sipcreator.py'))
    ififuncs.generate_log(new_log_textfile,
                          'Command line arguments: %s' % args)
    ififuncs.generate_log(new_log_textfile, 'EVENT = agentName=%s' % user)
    ififuncs.generate_log(new_log_textfile, uuid_event)
    if not args.sc:
        ififuncs.generate_log(
            new_log_textfile, 'EVENT = eventType=Identifier assignement,'
            ' eventIdentifierType=object entry, value=%s' % object_entry)
    metadata_dir = os.path.join(sip_path, 'metadata')
    supplemental_dir = os.path.join(metadata_dir, 'supplemental')
    logs_dir = os.path.join(sip_path, 'logs')
    if args.accession:
        accession_number = ififuncs.get_accession_number()
        reference_number = ififuncs.get_reference_number()
        parent = ififuncs.ask_question(
            'What is the parent record? eg MV 1234. Enter n/a if this is a born digital acquisition with no parent.'
        )
        donor = ififuncs.ask_question(
            'Who is the source of acquisition, as appears on the donor agreement? This will not affect Reproductions.'
        )
        reproduction_creator = ififuncs.ask_question(
            'Who is the reproduction creator? This will not affect acquisitions. Enter n/a if not applicable'
        )
        depositor_reference = ififuncs.ask_question(
            'What is the donor/depositor number? This will not affect Reproductions.'
        )
        acquisition_type = ififuncs.get_acquisition_type('')
        donation_date = ififuncs.ask_question(
            'When was the donation date in DD/MM/YYYY format? Eg. 31/12/1999 - Unfortunately this is NOT using ISO 8601.'
        )
    if args.zip:
        inputxml, inputtracexml, dfxml = ififuncs.generate_mediainfo_xmls(
            inputs[0], args.o, uuid, new_log_textfile)
        if args.manifest:
            shutil.copy(
                args.manifest,
                args.manifest.replace('_manifest.md5', '_manifest-md5.txt'))
            source_manifest = args.manifest.replace('_manifest.md5',
                                                    '_manifest-md5.txt')
        else:
            source_manifest = os.path.join(
                args.o,
                os.path.basename(args.i[0]) + '_manifest-md5.txt')
            ififuncs.generate_log(
                new_log_textfile,
                'EVENT = message digest calculation, status=started, eventType=messageDigestCalculation, agentName=hashlib, eventDetail=MD5 checksum of source files within ZIP'
            )
            ififuncs.hashlib_manifest(args.i[0], source_manifest,
                                      os.path.dirname(args.i[0]))
            ififuncs.generate_log(
                new_log_textfile,
                'EVENT = message digest calculation, status=finished, eventType=messageDigestCalculation, agentName=hashlib, eventDetail=MD5 checksum of source files within ZIP'
            )
        ififuncs.generate_log(
            new_log_textfile,
            'EVENT = packing, status=started, eventType=packing, agentName=makezip.py, eventDetail=Source object to be packed=%s'
            % inputs[0])
        makezip_judgement, zip_file = makezip.main([
            '-i', inputs[0], '-o',
            os.path.join(sip_path, 'objects'), '-basename', uuid + '.zip'
        ])
        ififuncs.generate_log(
            new_log_textfile,
            'EVENT = packing, status=finished, eventType=packing, agentName=makezip.py, eventDetail=Source object packed into=%s'
            % zip_file)
        if makezip_judgement is None:
            judgement = 'lossless'
        else:
            judgement = makezip_judgement
        ififuncs.generate_log(
            new_log_textfile,
            'EVENT = losslessness verification, status=finished, eventType=messageDigestCalculation, agentName=makezip.py, eventDetail=embedded crc32 checksum validation, eventOutcome=%s'
            % judgement)
        ififuncs.generate_log(
            new_log_textfile,
            'EVENT = losslessness verification, status=finished, eventType=messageDigestCalculation, agentName=makezip.py, eventDetail=embedded crc32 checksum validation, eventOutcome=%s'
            % judgement)
    else:
        log_names = move_files(inputs, sip_path, args, user)
    ififuncs.get_technical_metadata(sip_path, new_log_textfile)
    ififuncs.hashlib_manifest(metadata_dir,
                              metadata_dir + '/metadata_manifest.md5',
                              metadata_dir)
    if args.sc:
        normalise_objects_manifest(sip_path)
    new_manifest_textfile = consolidate_manifests(sip_path, 'objects',
                                                  new_log_textfile)
    if args.zip:
        if zip_file.endswith('.001'):
            for split_archive in os.listdir(os.path.dirname(zip_file)):
                ififuncs.generate_log(
                    new_log_textfile,
                    'EVENT = Message Digest Calculation, status=started, eventType=message digest calculation, eventDetail=%s module=hashlib'
                    % split_archive)
                ififuncs.manifest_update(
                    new_manifest_textfile,
                    os.path.join(os.path.dirname(zip_file), split_archive))
                ififuncs.generate_log(
                    new_log_textfile,
                    'EVENT = Message Digest Calculation, status=finished, eventType=message digest calculation, eventDetail=%s module=hashlib'
                    % split_archive)
        else:
            ififuncs.generate_log(
                new_log_textfile,
                'EVENT = Message Digest Calculation, status=started, eventType=message digest calculation, eventDetail=%s module=hashlib'
                % zip_file)
            ififuncs.manifest_update(new_manifest_textfile, zip_file)
            ififuncs.generate_log(
                new_log_textfile,
                'EVENT = Message Digest Calculation, status=finished, eventType=message digest calculation, eventDetail=%s module=hashlib'
                % zip_file)
    consolidate_manifests(sip_path, 'metadata', new_log_textfile)
    ififuncs.hashlib_append(logs_dir, new_manifest_textfile,
                            os.path.dirname(os.path.dirname(logs_dir)))
    if args.supplement:
        os.makedirs(supplemental_dir)
        supplement_cmd = [
            '-i', args.supplement, '-user', user, '-new_folder',
            supplemental_dir,
            os.path.dirname(sip_path), '-copy'
        ]
        package_update.main(supplement_cmd)
    if args.zip:
        os.makedirs(supplemental_dir)
        supplement_cmd = [
            '-i', [inputxml, inputtracexml, dfxml, source_manifest], '-user',
            user, '-new_folder', supplemental_dir,
            os.path.dirname(sip_path), '-copy'
        ]
        package_update.main(supplement_cmd)
    if args.sc:
        print('Generating Digital Forensics XML')
        dfxml = accession.make_dfxml(args, sip_path, uuid)
        ififuncs.generate_log(
            new_log_textfile,
            'EVENT = Metadata extraction - eventDetail=File system metadata extraction using Digital Forensics XML, eventOutcome=%s, agentName=makedfxml'
            % (dfxml))
        ififuncs.manifest_update(new_manifest_textfile, dfxml)
        sha512_log = manifest.main([sip_path, '-sha512', '-s'])
        sha512_manifest = os.path.join(os.path.dirname(sip_path),
                                       uuid + '_manifest-sha512.txt')
        ififuncs.merge_logs_append(sha512_log, new_log_textfile,
                                   new_manifest_textfile)
        ififuncs.checksum_replace(sha512_manifest, new_log_textfile, 'sha512')
        os.remove(sha512_log)
    ififuncs.sort_manifest(new_manifest_textfile)
    if not args.quiet:
        if 'log_names' in locals():
            log_report(log_names)
    finish = datetime.datetime.now()
    print('\n- %s ran this script at %s and it finished at %s' %
          (user, start, finish))
    if args.d:
        process_dcp(sip_path, content_title, args, new_manifest_textfile,
                    new_log_textfile, metadata_dir, clairmeta_version)
    if args.accession:
        register = accession.make_register()
        filmographic_dict = ififuncs.extract_metadata(args.filmo_csv)[0]
        for filmographic_record in filmographic_dict:
            if filmographic_record['Reference Number'].lower(
            ) == reference_number.lower():
                if filmographic_record['Title'] == '':
                    title = filmographic_record[
                        'TitleSeries'] + '; ' + filmographic_record['EpisodeNo']
                else:
                    title = filmographic_record['Title']
        oe_register = make_oe_register()
        ififuncs.append_csv(
            oe_register,
            (object_entry.upper()[:2] + '-' + object_entry[2:], donation_date,
             '1', '', title, donor, acquisition_type[1], accession_number,
             'Representation of %s|Reproduction of %s' %
             (reference_number, parent), ''))
        accession_cmd = [
            os.path.dirname(sip_path), '-user', user, '-force', '-number',
            accession_number, '-reference', reference_number, '-register',
            register, '-filmo_csv', args.filmo_csv, '-pbcore'
        ]
        if not parent.lower() == 'n/a':
            accession_cmd.extend(['-parent', parent])
        accession_cmd.extend(['-donor', donor])
        accession_cmd.extend(['-depositor_reference', depositor_reference])
        accession_cmd.extend(['-acquisition_type', acquisition_type[2]])
        accession_cmd.extend(['-donation_date', donation_date])
        accession_cmd.extend(['-reproduction_creator', reproduction_creator])
        print(accession_cmd)
        accession.main(accession_cmd)
    return new_log_textfile, new_manifest_textfile
コード例 #9
0
ファイル: normalise.py プロジェクト: muthusalami/IFIscripts-1
def main(args_):
    ififuncs.check_existence(['ffmpeg', 'mediainfo'])
    print('\n - Normalise.py started')
    args = parse_args(args_)
    print(args)
    source = args.i
    output_folder = args.o
    file_list = sorted(ififuncs.get_video_files(source))
    if args.sip:
        if args.user:
            user = args.user
        else:
            user = ififuncs.get_user()
        if args.oe:
            if args.oe[:2] != 'oe':
                print(
                    'First two characters must be \'oe\' and last four characters must be four digits'
                )
                object_entry = ififuncs.get_object_entry()
            elif len(args.oe[2:]) not in range(4, 6):
                print(
                    'First two characters must be \'oe\' and last four characters must be four digits'
                )
                object_entry = ififuncs.get_object_entry()
            elif not args.oe[2:].isdigit():
                object_entry = ififuncs.get_object_entry()
                print(
                    'First two characters must be \'oe\' and last four characters must be four digits'
                )
            else:
                object_entry = args.oe
        else:
            object_entry = ififuncs.get_object_entry()
    if args.sip:
        oe_digits = int(object_entry.replace('oe', ''))
    for filename in file_list:
        log_name_source = os.path.join(
            args.o,
            '%s_normalise_log.log' % time.strftime("_%Y_%m_%dT%H_%M_%S"))
        ififuncs.generate_log(log_name_source, 'normalise.py started.')
        ififuncs.generate_log(log_name_source,
                              'Command line arguments: %s' % args)
        if args.sip:
            ififuncs.generate_log(log_name_source,
                                  'EVENT = agentName=%s' % user)
        print('\n - Processing: %s' % filename)
        ififuncs.generate_log(
            log_name_source,
            'EVENT = Normalization, status=started, eventType=Normalization, agentName=ffmpeg, eventDetail=Source object to be normalised=%s'
            % filename)
        output, output_uuid, fmd5, ffv1_logfile = normalise_process(
            filename, output_folder)
        ififuncs.generate_log(
            log_name_source,
            'EVENT = Normalization, status=finished, eventType=Normalization, agentName=ffmpeg, eventDetail=Source object normalised into=%s'
            % output)
        inputxml, inputtracexml, dfxml = ififuncs.generate_mediainfo_xmls(
            filename, output_folder, output_uuid, log_name_source)
        fmd5_logfile, fmd5ffv1, verdict = verify_losslessness(
            output_folder, output, output_uuid, fmd5)
        ififuncs.generate_log(
            log_name_source,
            'EVENT = losslessness verification, status=finished, eventType=messageDigestCalculation, agentName=ffmpeg, eventDetail=MD5s of AV streams of output file generated for validation, eventOutcome=%s'
            % verdict)
        if args.sip:
            object_entry_complete = 'oe' + str(oe_digits)
            supplement_cmd = ['-supplement', inputxml, inputtracexml, dfxml]
            sipcreator_cmd = [
                '-i', output, '-move', '-u', output_uuid, '-user', user, '-oe',
                object_entry_complete, '-o', args.o
            ]
            if args.supplement:
                supplement_cmd.extend(args.supplement)
            sipcreator_cmd.extend(supplement_cmd)
            sipcreator_log, sipcreator_manifest = sipcreator.main(
                sipcreator_cmd)
            metadata_dir = os.path.join(
                os.path.dirname(os.path.dirname(sipcreator_log)), 'metadata')
            shutil.move(fmd5, metadata_dir)
            shutil.move(fmd5_logfile, os.path.dirname(sipcreator_log))
            shutil.move(fmd5ffv1, metadata_dir)
            shutil.move(
                ffv1_logfile.replace('\\\\', '\\').replace('\:', ':'),
                os.path.dirname(sipcreator_log))
            logs_dir = os.path.dirname(sipcreator_log)
            ififuncs.manifest_update(
                sipcreator_manifest,
                os.path.join(metadata_dir, os.path.basename(fmd5)))
            ififuncs.manifest_update(
                sipcreator_manifest,
                os.path.join(metadata_dir, os.path.basename(fmd5ffv1)))
            ififuncs.manifest_update(
                sipcreator_manifest,
                os.path.join(
                    logs_dir,
                    os.path.basename(
                        ffv1_logfile.replace('\\\\', '\\').replace('\:',
                                                                   ':'))))
            ififuncs.manifest_update(
                sipcreator_manifest,
                os.path.join(
                    logs_dir,
                    os.path.basename(
                        fmd5_logfile.replace('\\\\', '\\').replace('\:',
                                                                   ':'))))
            ififuncs.merge_logs(log_name_source, sipcreator_log,
                                sipcreator_manifest)
            os.remove(dfxml)
            os.remove(inputxml)
            os.remove(inputtracexml)
            print(
                'The judgement above only refers to the copyit job, the losslessness judgement is: %s'
                % verdict)
            oe_digits += 1
コード例 #10
0
ファイル: prores.py プロジェクト: muthusalami/IFIscripts-1
def main(args_):
    '''
    Launch the various functions that will make a h264/mp4 access copy.
    '''
    ififuncs.check_existence(['ffmpeg'])
    args = set_options(args_)
    prores_options = []

    if args.yadif:
        prores_options.append('-yadif')

    if args.scale:
        prores_options.append('-scale')
        width_height = args.scale

    number_of_effects = len(prores_options)

    # Input, either file or firectory, that we want to process.
    input = args.input

    # 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(wd)

    # Store the actual file/directory name without the full path.
    file_without_path = os.path.basename(input)

    # 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):
        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'))

    # Prints some stuff if input isn't a file or directory.
    else:
        print("Your input isn't a file or a directory.")

    for filename in video_files:
        #pdb.set_trace()

        if args.o:
            output = args.o + '/' + os.path.basename(filename) + "_prores.mov"
        else:
            output = filename + "_prores.mov"
        ffmpeg_args = [
            'ffmpeg',
            '-i',
            filename,
        ]
        pix_fmt = ififuncs.get_ffmpeg_fmt(filename, 'video')
        ffmpeg_args = [
            'ffmpeg',
            '-i',
            filename,
            '-c:a',
            'copy',
        ]
        if ('rgb' in pix_fmt) or ('gbr' in pix_fmt):
            ffmpeg_args.extend(['-c:v', 'prores_ks'])
        else:
            ffmpeg_args.extend(['-c:v', 'prores'])
        if not args.map:
            ffmpeg_args.append('-map')
            ffmpeg_args.append('0:a?')
            ffmpeg_args.append('-map')
            ffmpeg_args.append('0:v')

        if args.hq:
            ffmpeg_args.append('-profile:v')
            ffmpeg_args.append('3')
        if args.wide:
            ffmpeg_args.append('-aspect')
            ffmpeg_args.append('16:9')
        if args.yadif or args.scale:

            filter_options = '-vf'

            if args.yadif:
                filter_options += ' yadif'

            if args.scale:
                if number_of_effects > 1:
                    filter_options += (',scale=%s' % width_height)
                else:
                    filter_options += (' scale=%s' % width_height)

            filter_options = filter_options.split()
            for item in filter_options:
                ffmpeg_args.append(item)
        ffmpeg_args.append(output)
        print(ffmpeg_args)
        subprocess.call(ffmpeg_args)
コード例 #11
0
ファイル: concat.py プロジェクト: muthusalami/IFIscripts-1
def main(args_):
    '''
    Launches the functions that prepare and execute the concatenation.
    '''
    ififuncs.check_existence(['ffmpeg', 'mkvpropedit', 'mediainfo'])
    uuid = ififuncs.create_uuid()
    args = parse_args(args_)
    print(args)
    log_name_source = os.path.join(
        args.o, '%s_concat_log.log' % time.strftime("_%Y_%m_%dT%H_%M_%S"))
    ififuncs.generate_log(log_name_source, 'concat.py started.')
    if args.mov:
        container = 'mov'
    else:
        container = 'mkv'
    ififuncs.generate_log(
        log_name_source,
        'eventDetail=concat.py %s' % ififuncs.get_script_version('concat.py'))
    ififuncs.generate_log(log_name_source, 'Command line arguments: %s' % args)
    if args.user:
        user = args.user
    else:
        user = ififuncs.get_user()
    if args.oe:
        if args.oe[:2] != 'oe':
            print(
                'First two characters must be \'oe\' and last four characters must be four digits'
            )
            object_entry = ififuncs.get_object_entry()
        elif len(args.oe[2:]) not in range(4, 6):
            print(
                'First two characters must be \'oe\' and last four characters must be four digits'
            )
            object_entry = ififuncs.get_object_entry()
        elif not args.oe[2:].isdigit():
            object_entry = ififuncs.get_object_entry()
            print(
                'First two characters must be \'oe\' and last four characters must be four digits'
            )
        else:
            object_entry = args.oe
    else:
        object_entry = ififuncs.get_object_entry()
    ififuncs.generate_log(log_name_source, 'EVENT = agentName=%s' % user)
    source_uuid_check = ''
    if os.path.isfile(args.i[0]):
        source_uuid = ififuncs.get_source_uuid()
    elif os.path.isdir(args.i[0]):
        source_uuid_check = ififuncs.check_for_uuid(args)
    if source_uuid_check == False:
        source_uuid = ififuncs.get_source_uuid()
    else:
        source_uuid = source_uuid_check
    ififuncs.generate_log(
        log_name_source,
        'Relationship, derivation, has source=%s' % source_uuid)
    video_files = args.i
    concat_file = ififuncs.get_temp_concat('concat_stuff')
    ififuncs.generate_log(log_name_source,
                          'concatenation file=%s' % concat_file)
    if args.r:
        video_files = recursive_file_list(video_files)
    video_files = ififuncs.sanitise_filenames(video_files)
    for source_files in video_files:
        ififuncs.generate_log(log_name_source,
                              'source_files = %s' % source_files)
    make_chapters(video_files)
    ififuncs.concat_textfile(video_files, concat_file)
    ififuncs.generate_log(
        log_name_source,
        'EVENT = Concatenation, status=started, eventType=Creation, agentName=ffmpeg, eventDetail=Source media concatenated into a single file output=%s'
        % os.path.join(args.o, '%s.%s' % (uuid, container)))
    source_bitstream_md5, fmd5_logfile = ffmpeg_concat(concat_file, args, uuid,
                                                       container)
    output_file = os.path.join(args.o, '%s.%s' % (uuid, container))
    ififuncs.generate_log(
        log_name_source,
        'EVENT = Concatenation, status=finished, eventType=Creation, agentName=ffmpeg, eventDetail=Source media concatenated into a single file output=%s'
        % os.path.join(args.o, '%s.%s' % (uuid, container)))
    ififuncs.generate_log(
        log_name_source,
        'EVENT = losslessness verification, status=started, eventType=messageDigestCalculation, agentName=ffmpeg, eventDetail=MD5s of AV streams of output file generated for validation'
    )
    validation_logfile = os.path.join(args.o,
                                      '%s_validation.log' % uuid).replace(
                                          '\\', '\\\\').replace(':', '\:')
    validation_env_dict = ififuncs.set_environment(validation_logfile)
    output_bitstream_md5 = subprocess.check_output(
        [
            'ffmpeg', '-report', '-i', output_file, '-f', 'md5', '-map', '0:v',
            '-map', '0:a?', '-c', 'copy', '-'
        ],
        env=validation_env_dict).rstrip()
    ififuncs.generate_log(
        log_name_source,
        'EVENT = losslessness verification, status=finished, eventType=messageDigestCalculation, agentName=ffmpeg, eventDetail=MD5s of AV streams of output file generated for validation'
    )
    if source_bitstream_md5 == output_bitstream_md5:
        print('process appears to be lossless')
        print(source_bitstream_md5, output_bitstream_md5)
        ififuncs.generate_log(
            log_name_source,
            'EVENT = losslessness verification, eventOutcome=pass')
    else:
        print('something went wrong - not lossless!')
        print(source_bitstream_md5, output_bitstream_md5)
        ififuncs.generate_log(
            log_name_source,
            'EVENT = losslessness verification, eventOutcome=fail')
    if args.nochapters != True:
        subprocess.call(['mkvpropedit', output_file, '-c', 'chapters.txt'])
        ififuncs.generate_log(
            log_name_source,
            'EVENT = eventType=modification, agentName=mkvpropedit, eventDetail=Chapters added to file detailing start point of source clips.'
        )
        ififuncs.concat_textfile(video_files, concat_file)
        with open(log_name_source, 'r') as concat_log:
            concat_lines = concat_log.readlines()
    if not args.no_sip:
        sipcreator_log, sipcreator_manifest = sipcreator.main([
            '-i', output_file, '-u', uuid, '-oe', object_entry, '-user', user,
            '-o', args.o
        ])
        shutil.move(fmd5_logfile, os.path.dirname(sipcreator_log))
        shutil.move(
            validation_logfile.replace('\\\\', '\\').replace('\:', ':'),
            os.path.dirname(sipcreator_log))
        logs_dir = os.path.dirname(sipcreator_log)
        ififuncs.manifest_update(
            sipcreator_manifest,
            os.path.join(logs_dir, os.path.basename(fmd5_logfile)))
        ififuncs.manifest_update(
            sipcreator_manifest,
            os.path.join(logs_dir, (os.path.basename(
                validation_logfile.replace('\\\\', '\\').replace('\:', ':')))))
        ififuncs.merge_logs(log_name_source, sipcreator_log,
                            sipcreator_manifest)