改变视频文件二进制值而不影响播放的方法
作者:互联网
本质是视频文件二进制值后追加特殊符号(如换行符、制表符)的二进制值
import hashlib import os def getFilesByDir(target_path, include_str=None, filter_strs=None): """ 获取指定目录下所有的文件(不包含以__开头和结尾的文件)或指定格式的文件,若不同目录存在相同文件名,只返回第1个文件的路径 :param target_path: 查找的目录路径 :param include_str: 获取包含字符串的名称,不区分大小写 :param filter_strs: 过滤包含字符串的名称,区分大小写 """ if filter_strs is None: filter_strs = [] files = [] names = os.listdir(target_path) for name in names: path = os.path.abspath(os.path.join(target_path, name)) if os.path.isfile(path): # 寻找包含指定字符串的文件名 if include_str is not None and include_str.upper() not in name.upper(): continue # 寻找不包含filter_strs中的字符 for filter_str in filter_strs: if filter_str in name: break else: files.append(path) #递归获取子文件夹里的文件 # else: files += getFilesByDir(path, include_str=include_str, filter_strs=filter_strs) return files def editBineryOfFiles(files): for i in range(len(files)): with open(files[i][:files[i].rindex('\\')+1] + str(i) + '.mp4', 'wb') as f: with open(files[i], 'rb') as tf: f.write(tf.read()) f.write(b'\n') target_path = 'D:/' files = getFilesByDir(target_path, '') editBineryOfFiles(files)
标签:files,include,二进制,filter,strs,str,视频文件,path,播放 来源: https://www.cnblogs.com/uuuxxllj/p/16631933.html