Probleme mit sehr großen komprimierten Wörterbüchern in Python
Posted: 12 Feb 2025, 00:54
Ich habe derzeit ein sehr seltsames und spezifisches Problem. Wie viele von uns dachte, erstelle ich derzeit ein -Video zu ASCII -Konverter ( in Farbe bitte ), dies gibt eine sehr große aus. TXT -Datei, die ich für die automatische Komprimierung entschieden habe (die Dateien waren 5 GB). Hinweis: Ich habe ZStandard für die Komprimierung ausgewählt.
Ich speichere die Daten als Name, Daten, Intervall und Musik , aber wenn ich extrahiert habe >. Das Intervall (oder das Rahmenintervall) wird ursprünglich als Ganzzahl gespeichert, und ich weiß, dass es als int gespeichert ist, weil es gestern buchstäblich gearbeitet hat. Aber heute gibt es als Wörterbuch ... die Schleife aus wie
Ich kann die Datei übrigens nicht überprüfen, weil sie zu groß ist (Notizblock, Notizblock ++, Glogg, VSCODE)
Code: Select all
def save_movie(interval):
import os
import json
import base64
# Get the name of the movie from the user
name = input("Name: ")
# Read the .mp3 file as binary data and convert to Base64
print("Encoding music")
with open(os.path.join("Converter", "music.mp3"), 'rb') as file:
blob_data = file.read()
blob_data_base64 = base64.b64encode(blob_data).decode('utf-8')
# Create a dictionary to store all the data
print("Creating storage for data")
with open("Converter/temp/.~lock.temp.json#","r") as file:
movie_data = {
'name': name,
'data': file.read(),
'interval': interval,
'music': blob_data_base64
}
# Save to either a .json or .txt file
print("Creating file")
file_extension = 'zst'
file_name = f"{name}.{file_extension}"
print("Compressing")
ideal_level = ideal_ratio(len(movie_data["data"]))
level = choose_compression_level(ideal_level)
print("")
d = parallel_zstd_compress(json.dumps(movie_data,indent=4),level)
# Write the dictionary to the desired file format
print("Saving")
with open(os.path.join("Converter/saves",file_name), 'wb') as file:
file.write(d)
print(f"Movie saved to {file_name}")
def extract_movie(json_file_path):
import json
import base64
import os
print("Beginning extraction")
with open(f"Converter/saves/{json_file_path}", 'rb') as file:
movie_data = decompress_chunk(file.read())
print("Done, getting Data...")
movie_data = movie_data.decode('utf-8')
movie_data = json.loads(movie_data)
# Extract the movie data
name = movie_data['name']
data_json = movie_data['data']
interval = movie_data['interval']
music_base64 = movie_data['music']
print("Done. Decoding music")
# Convert the Base64-encoded music back to binary data
print("-Decoding music")
music_data = base64.b64decode(music_base64)
# Recreate the .mp3 file from the binary data
print("-Saving music")
music_file_path = "Converter/music.mp3"
os.makedirs(os.path.dirname(music_file_path), exist_ok=True)
with open(music_file_path, 'wb') as music_file:
music_file.write(music_data)
print("Done, preparing movie...")
# Convert the JSON movie data back to a Python list
movie_data_list = json.loads(data_json)
print(f"Movie '{name}' extracted.")
# Return the extracted data
return {
'data': movie_data_list,
'interval': interval,
}
Code: Select all
for index, element in enumerate(ASCII_movie.items()):
# Calculate the expected time for the current frame
expected_time = start_time + index * frames_interval
< /code>
Hier ist der Fehler < /p>
Traceback (most recent call last):
File "C:\Users\stard\OneDrive\Documents\code\COnverter\theASCII.py", line 355, in
browse()
File "C:\Users\stard\OneDrive\Documents\code\COnverter\theASCII.py", line 342, in browse
view(data,interval)
File "C:\Users\stard\OneDrive\Documents\code\COnverter\theASCII.py", line 303, in view
expected_time = start_time + index * frames_interval
~~~~~~^~~~~~~~~~~~~~~~~
TypeError: unsupported operand type(s) for *: 'int' and 'dict'