You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
69 lines
2.1 KiB
Python
69 lines
2.1 KiB
Python
import os, shutil, config
|
|
import ffmpeg
|
|
from tqdm import tqdm
|
|
|
|
def is_av1(filepath):
|
|
try:
|
|
probe = ffmpeg.probe(filepath)
|
|
for stream in probe['streams']:
|
|
if stream['codec_type'] == 'video' and 'codec_name' in stream:
|
|
if stream['codec_name'] == 'av1':
|
|
return True
|
|
except ffmpeg.Error as e:
|
|
print(f"Error probing {filepath}: {e}")
|
|
return "Fucked"
|
|
return False
|
|
|
|
def save_last_checked(filepath):
|
|
with open(".last_checked", "w") as f:
|
|
f.write(filepath)
|
|
|
|
def get_last_checked():
|
|
if os.path.exists(".last_checked"):
|
|
with open(".last_checked", "r") as f:
|
|
return f.read().strip()
|
|
return None
|
|
|
|
def init_list(videos):
|
|
last_checked = get_last_checked()
|
|
if last_checked:
|
|
for video in videos:
|
|
if os.path.basename(video['filepath']) == last_checked:
|
|
return videos[videos.index(video) + 1:]
|
|
return videos
|
|
|
|
def reencode_videos_av1():
|
|
conn, cursor = config.get_local_db_connection()
|
|
cursor.execute("SELECT filepath, id, codec FROM videos WHERE status != 'missing' AND filepath IS NOT NULL ORDER BY size ASC;")
|
|
videos = cursor.fetchall()
|
|
|
|
os.makedirs("fucked", exist_ok=True)
|
|
|
|
videos = init_list(videos)
|
|
|
|
with tqdm(videos, desc="Checking videos", unit="file") as pbar:
|
|
for video in videos:
|
|
pbar.update(1)
|
|
|
|
if pbar.n % 100 == 0:
|
|
save_last_checked(os.path.basename(video['filepath']))
|
|
|
|
if video['codec'] == 'av1':
|
|
continue
|
|
|
|
input_path = video['filepath']
|
|
isav1 = is_av1(input_path)
|
|
|
|
if isav1 == "Fucked":
|
|
print(f"🚫 Error probing {input_path}")
|
|
shutil.move(input_path, "fucked/" + os.path.basename(input_path))
|
|
continue
|
|
|
|
if isav1 == False:
|
|
continue
|
|
|
|
cursor.execute("UPDATE videos SET codec = %s WHERE id = %s", ('av1', video['id']))
|
|
conn.commit()
|
|
|
|
if __name__ == "__main__":
|
|
reencode_videos_av1() |