Python Video Ikun

打乱视频帧

import os
import random
 
folder_path = './'  # 文件夹路径,这里假设为当前文件夹
 
for filename in os.listdir(folder_path):
    if filename.endswith('.jpg'):
        # 生成随机数作为新文件名
        new_filename = str(random.randint(10000, 99999)) + '.jpg'
        # 重命名文件
        os.rename(os.path.join(folder_path, filename), os.path.join(folder_path, new_filename))
 
重命名
 
import os
from PIL import Image
import random
 
# 获取当前文件夹路径
current_folder = os.getcwd()
 
# 获取当前文件夹下的所有jpg文件
jpg_files = [f for f in os.listdir(current_folder) if f.endswith('.jpg')]
 
# 遍历每个jpg文件
for file in jpg_files:
    # 打开图片
    img = Image.open(file)
 
    # 获取图片尺寸
    width, height = img.size
 
    # 计算需要打乱的像素数量
    shuffle_pixels = int(width * height / 2)
 
    # 随机打乱像素
    for i in range(shuffle_pixels):
        x = random.randint(0, width - 1)
        y = random.randint(0, height - 1)
        r, g, b = img.getpixel((x, y))
        r_new = random.randint(0, 255)
        g_new = random.randint(0, 255)
        b_new = random.randint(0, 255)
        img.putpixel((x, y), (r_new, g_new, b_new))
 
    # 生成新的文件名
    new_file = "shuffled_" + file
 
    # 保存图片
    img.save(new_file, "JPEG")
    print(new_file, "JPEG")
 
# 输出提示信息
print("所有jpg图片已经被打乱三分之一像素并保存为新的jpg文件!")
 
打乱图片像素
傻逼CC协约