Simplify the following script:
import os
import shutil
import time
from datetime import timedelta
import zlib

binary_directory = r"D:\Moka\official_test_place\temp\svt-av1-psy\Bin"  # Directory to search for binaries
benchmark_file_path = r"C:\Users\rurikarakusa\Videos\2023-12-03 20-57-02-00.00.00.000-00.00.29.167.mkv"
scene_file_path = r"C:\Users\rurikarakusa\Videos\2023-12-03 20-57-02-00.00.00.000-00.00.29.167-scn.json"
encoder_flags = "--keyint -1 --tune 3 --enable-tf 0 --crf 40 --preset 4 --color-primaries 1 --transfer-characteristics 1 --matrix-coefficients 1 --lp 2"

f = open("log.txt", "w")

def seconds_to_str(s):
    if s == 0:
        return "00:00"
    return str(timedelta(seconds=s)) 

def create_dir(dirname):
    if not os.path.exists(dirname):
        printf(f"Creating directory: {dirname}")
        os.mkdir(dirname)

def remove_dir(name):
    if os.path.isdir(name):
        printf(f"Removing directory: {name}")
        shutil.rmtree(name)
    else:
        printf(f"Directory {name} does not exist.")

def remove_file(name):
    if os.path.exists(name):
        printf(f"Removing file: {name}")
        os.remove(name)
    else:
        printf(f"File {name} does not exist.")

def printf(txt):
    print(txt)
    f.write(f"{txt}\n")

def crc32(fname):
    with open(fname, "rb") as file:
        file_data = file.read()
        crc = zlib.crc32(file_data) & 0xFFFFFFFF
        printf(f"Calculated CRC32 for {fname}: {hex(crc)}")
        return crc

def get_change(cur: float, prev: float):
    change = abs(((cur - prev) / prev) * 100)
    printf(f"Change calculation: current={cur}, previous={prev}, change={change:.2f}%")
    return change

def benchmark_encoder(binary_path, name, num_runs=3):
    printf(f"Starting Benchmark for {name}")
    total_time = 0
    individual_times = [0] * num_runs
    checksums = [0] * num_runs
    
    create_dir("temp")
    for i in range(num_runs):
        printf(f"Starting run {i + 1} of {num_runs}...")

        # Skip sleep for the first run
        if i > 0:
            time.sleep(20)  # Give some time to cool down the CPU
        
        start_time = time.time()
        os.system(f"av1an -i \"{benchmark_file_path}\" -o \"temp/{i}.mkv\" -s \"{scene_file_path}\" -w 6 -c mkvmerge -e svt-av1 -v \"{encoder_flags}\"")
        end_time = time.time()
        run_time = end_time - start_time
        total_time += run_time
        individual_times[i] = run_time
        
        # Extract bitstream and save CRC
        os.system(f"ffmpeg -i \"temp/{i}.mkv\" -map 0:v:0 -c:v copy \"temp/{i}.avif\"")
        crc = crc32(f"temp/{i}.avif")
        checksums[i] = crc
        time_str = seconds_to_str(run_time)
        crc_str = hex(crc)
        printf(f"Test {i} took {time_str}, bitstream CRC: {crc_str}")

    slowest_time = max(individual_times)
    fastest_time = min(individual_times)
    avg_time = total_time / num_runs
    slowest_variance = get_change(slowest_time, avg_time)
    fastest_variance = get_change(fastest_time, avg_time)
    slowest_diff = seconds_to_str(slowest_time - avg_time)
    fastest_diff = seconds_to_str(avg_time - fastest_time)

    # Check if all checksums match each other
    checksums_match = all(checksums[i] == checksums[i + 1] for i in range(num_runs - 1))
    printf(f"Checksum comparison: {checksums}")
    
    if checksums_match:
        printf("Consistency test passed")
    else:
        printf("Encoder produces inconsistent results")

    avg_time_str = seconds_to_str(avg_time)
    printf(f"Run variance: -{fastest_diff}({fastest_variance:.2f}%) avg:{avg_time_str} +{slowest_diff}({slowest_variance:.2f}%)")
    
    remove_dir("temp")
    printf(f"Benchmark completed for {name}\n")

def benchmark_all_binaries():
    printf("Iterating over binaries in the directory...")
    
    # Recursively iterate over binaries in the directory
    for dirpath, _, files in os.walk(binary_directory):
        for binary in files:
            binary_path = os.path.join(dirpath, binary)
            if os.path.isfile(binary_path) and binary == "SvtAv1EncApp.exe":
                folder_name = os.path.basename(dirpath)  # Get the folder name for the binary
                printf(f"Found binary: {binary} in folder: {folder_name}")
                
                # Create the temp directory before copying the executable
                create_dir("temp")
                
                shutil.copyfile(binary_path, os.path.join("temp", "SvtAv1EncApp.exe"))
                benchmark_encoder(os.path.join("temp", "SvtAv1EncApp.exe"), folder_name)  # Use the copied binary
            else:
                printf(f"Skipping non-executable or non-file: {binary}")

    remove_dir("temp")  # Clean up temp directory after all benchmarks are done

printf("Starting benchmarks for all binaries in the directory")
benchmark_all_binaries()
f.close()