def goto_out_dir(self): # p5 = self.outTxt['text'] p5 = self.fc_out.get_text() if not p5 or not os.path.exists(p5): utils.showinfo("输出路径设置不对") else: utils.open_dir(p5)
def process(self, dc, astr=''): set_title = self.set_title2 input_list = dc["list"] output_dir = dc["output_dir"] + os.sep utils.make_dir(output_dir) temp_dir = output_dir + 'tempDir' + os.sep utils.make_dir(temp_dir) utils.hide_file(temp_dir) keep_parent_select = dc["keep_parent_select"] final_png = "" total = len(input_list) count = 0 msg_str = " {0}/{1} {2}" for i in range(total): count = count + 1 input_file = input_list[i] p = Path(input_file) # 保留上层目录结构 # 排除根目录 path_root = "{0}{1}".format(p.drive, os.sep) path_parent = str(Path(p.parent).name) if keep_parent_select and not path_root == path_parent: output_sub_dir = "{0}{1}{2}".format(output_dir, path_parent, os.sep) utils.make_dir(output_sub_dir) output_file = "{0}{1}{2}".format(output_sub_dir, p.stem, ".jpg") else: output_file = "{0}{1}{2}".format(output_dir, p.stem, ".jpg") # 任务信息 mstr = msg_str.format(count, total, p.name) set_title(mstr) # 拼接 ffmpeg 参数 arr = [ "ffmpeg -y -i", '"{}"'.format(input_file), '-hide_banner', '"{}"'.format(output_file) ] ff.execute(" ".join(arr)) final_png = output_file set_title("操作结束!") # 自动打开目录 if final_png: utils.open_dir(output_dir) self.t1 = "" self.lock_btn(False)
def build_sdl(rewrite=False): """ Build SDL :param rewrite: if True delete old SDL build and build again """ with open_dir(config.work_dir), open_dir(config.sdl_build_dir, rewrite): log_build_dir = config.sdl_build_dir + "log4cxx_build/" log_build_arch_dir = log_build_dir + arch() run('''export THIRD_PARTY_INSTALL_PREFIX={}; export THIRD_PARTY_INSTALL_PREFIX_ARCH={}; cmake {} && make install VERBOSE=1 '''.format( log_build_dir, log_build_arch_dir, config.sdl_clone_dir))
def right_click_call(self, _): """ 右键点击 行动按钮 """ fp = self.txt['text'] if not fp: utils.showinfo('你还没有选择文件/目录') return if not os.path.exists(fp): utils.showinfo('文件/目录 不存在 "{}"'.format(fp)) return if self.is_folder: utils.open_dir(fp) else: utils.open_file(fp, True)
def prepare_test_run(rewrite=False): """ Copy all files, required to execute test run to special directory :param rewrite: it True delete old tests_run_dir and copy files again """ with open_dir(config.test_run_dir, rewrite): run("cp -r {} {}".format(config.atf_build_dir + "modules/", config.test_run_dir)) run("cp -r {} {}".format(config.atf_build_dir + "data/", config.test_run_dir)) run("cp -r {} {}".format(config.atf_build_dir + "StartSDL.sh", config.test_run_dir)) run("cp -r {} {}".format(config.atf_build_dir + "StopSDL.sh", config.test_run_dir)) run("cp -r {} {}".format(config.atf_build_dir + "WaitClosingSocket.sh", config.test_run_dir)) run("cp -r {} {}".format(config.atf_build_dir + "start.sh", config.test_run_dir)) run("cp -r {} {}".format(config.atf_build_dir + "interp", config.test_run_dir)) run("cp -r {} {}".format(config.scripts_clone_dir + "/*", config.test_run_dir)) run("cp -r {} {}".format(config.sdl_build_dir + "bin", config.test_run_dir + "SDL_bin")) logger_library_path = config.sdl_build_dir + \ "log4cxx_build/" + arch() + "/lib/" run("cp -r {} {}".format(logger_library_path + "/*", config.test_run_dir + "SDL_bin/"))
def build_atf(rewrite=False): """ Build ATF :param rewrite: if True, delete all build atf files and build again """ with open_dir(config.work_dir), cd(config.atf_build_dir): if rewrite: run("git reset --hard && git clean -dfx") qmake_path = config.qt_path + "/bin/qmake" qmake_lib = config.qt_path + "/lib/" run('''export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:{}; export QMAKE={}; make'''.format(qmake_lib, qmake_path))
def btn_click(self, event): """点击按钮""" w = event.widget if utils.is_right_click(event.num): # 鼠标右键键 if w == self.btn_refresh: self.show_devices_force() elif w == self.btn_apk: self.show_apk_info(utils.clipboard_get(), True) elif w == self.btn_wifi: win_wifi_connect.connect_one() else: # 鼠标左键 if w == self.btn_refresh: self.show_devices() elif w == self.btn_apk: self.show_apk_info() elif w == self.btn_folder: f = setting_atool.last_screen_shot s = str(f) if os.path.exists(f): utils.open_file(f, True) # 如果有文件记录 则定位到文件 else: s = str(setting_atool.output_dir) success = utils.open_dir(s) if not success: utils.showinfo("文件夹不存在,请查看设置") utils.clipboard_set(s) # 将路径拷贝到剪贴板中 # wifi链接 elif w == self.btn_wifi: if not utils.lift_and_check(self.win_wifi): self.win_wifi = win_wifi_connect.WifiConnect() # 遥控器 elif w == self.btn_remote: util_atool.show_remote() # 设置 elif w == self.btn_setting: if not utils.lift_and_check(self.win_pref): self.win_pref = win_preferences.Main()
def open_folder(self): # open_file() dir_name = open_dir() self.dir_name = dir_name if dir_name: self.images.clear() self.file_name.clear() files_list = os.listdir(dir_name) files_list = sorted(files_list) for file in files_list: if check_image_file(file): self.file_name.append(file) # image = QPixmap(dir_name + "/" + file) image = cv2.imread(dir_name + "/" + file) self.images.append(image) print("{} is loaded.".format(file)) self.num_images = len(self.images) self.loaded = True self.load_image_on_scene()
def processConcat(self, dc, astr=''): setTitle = self.setTitle2 list1 = dc["list1"] list2 = dc["list2"] fast_mode_select = dc["fast_mode_select"] outputDir = dc["output_dir"] + os.sep tempDir = outputDir + 'tempDir' + os.sep # 保持长度一致 minLen = min(len(list1), len(list2)) list1 = list1[0:minLen] list2 = list2[0:minLen] finalMP4 = "" pStr = "" # set param=-c:v libx264 -s 1920x1080 -r 24 -b:v 6144k -b:a 128k -ar 44100 -ac 2 -preset slower -threads 8 FFStr = '''ffmpeg -y -i "{input}" -c:v libx264 -s {v_size} -crf 18 -r {fps} -b:a 128k -ar 44100 -ac 2 -threads 8 "{output}"''' FFConcat = '''ffmpeg -y -f concat -safe 0 -i "{0}" -c copy "{1}"''' seq = ('input', 'output', 'v_size', 'fps') utils.make_dir(tempDir) utils.hide_file(tempDir) total = len(list1) count = 0 msgStr = " ({0}/{1}) {2}" print(list1) status = [] for i in range(len(list1)): count = count + 1 status.append('') fileA = list1[i] fileB = list2[i] arr = utils.get_file_names(fileA) fnameA = arr[1] # ftypeA = arr[2] ftempA = tempDir + "-" + fnameA + ".mp4" arr = utils.get_file_names(fileB) fnameB = arr[1] # ftypeB = arr[2] ftempB = tempDir + "-" + fnameB + ".mp4" fullName = fnameA + '__' + fnameB finalMP4 = outputDir + fullName + ".mp4" subTxt = tempDir + "concat_" + fullName + ".txt" # 任务信息 mstr = msgStr.format(count, total, fullName) setTitle(mstr) # 读取第一个视频的 尺寸和帧频作为基准 # !!!所有的视频都会进行一次转码 dc = dict.fromkeys(seq, "") dcinfo = ff.get_video_info(fileA, False) dc['fps'] = dcinfo['fps'] if dcinfo['fps'] else '24' dc['v_size'] = dcinfo['v_size'] if dcinfo['v_size'] else '1920x1080' # 检查视频参数是否相同 isSame = False if fast_mode_select: isSame = ff.compare_video(fileA, fileB) # 生成concat.txt, 并转换片头/片尾 subs = [] sub = "file '{0}'\n" if not isSame: # 转第一个视频 mstr = msgStr.format(count, total, "转换 第一个视频……") setTitle(mstr) status[i] = '10%' self.updateCenter(status) dc['input'] = fileA dc['output'] = ftempA pStr = FFStr.format(**dc) ff.execute(pStr) # 转第二个视频 mstr = msgStr.format(count, total, "转换 第二个视频……") setTitle(mstr) status[i] = '50%' self.updateCenter(status) dc['input'] = fileB dc['output'] = ftempB pStr = FFStr.format(**dc) ff.execute(pStr) subs.append(sub.format(ftempA)) subs.append(sub.format(ftempB)) else: mstr = msgStr.format(count, total, "参数相同,跳过转换,直接拼接!") setTitle(mstr) subs.append(sub.format(fileA)) subs.append(sub.format(fileB)) # 写入concat文件 utils.write_txt(subTxt, subs) # 拼接视频 mstr = msgStr.format(count, total, "拼接中……") setTitle(mstr) status[i] = '90%' self.updateCenter(status) pStr = FFConcat.format(subTxt, finalMP4) ff.execute(pStr) # print(pStr) sstr = '成功' if os.path.exists(finalMP4) else '失败' status[i] = sstr self.updateCenter(status) # 移除 concat.txt 和 mp4 utils.remove_file(subTxt) utils.remove_file(ftempA) utils.remove_file(ftempB) setTitle("操作结束!") setTitle("") # 自动打开目录 if finalMP4: utils.open_dir(outputDir) self.t1 = "" self.lockBtn(False)
def process(self, dc, _): set_title = self.start_btn.update_query lists = dc["input_files"] output_dir = dc["output_dir"] + os.sep output_dir = str(Path(output_dir)) + os.sep temp_dir = output_dir + 'tempDir' + os.sep utils.make_dir(temp_dir) utils.hide_file(temp_dir) pt_file = dc["pt_file"] pw_file = dc["pw_file"] frame_file = dc["frame_file"] watermark_file = dc["watermark_file"] number_file = dc["number_file"] number_file_2 = dc["number_file_2"] number_file_3 = dc["number_file_3"] pt_select = dc['pt_select'] pw_select = dc['pw_select'] need_frame = dc["frame_select"] need_watermark = dc["watermark_select"] need_number = dc['number_select'] need_number_2 = dc['number_select_2'] need_number_3 = dc['number_select_3'] # double_fix_select = dc["double_fix_select"] # fast_mode_select = False # fast_mode_select = dc['fast_mode_select'] rad_var = dc['fps'] if rad_var == 2: fps = '24' elif rad_var == 3: fps = '25' elif rad_var == 4: fps = '30' else: fps = '0' # 30m方案特殊处理 select_30m = utils.str_to_bool(dc["select_30m"]) if select_30m: pt_out_file = temp_dir + "--pt.mpg" pw_out_file = temp_dir + "--pw.mpg" else: pt_out_file = temp_dir + "--pt.mp4" pw_out_file = temp_dir + "--pw.mp4" pf = '' if pt_select: pf = "加片头" if pw_select: pf += "加片尾" if need_frame: pf += ",加幕布" if need_watermark: pf += ",加水印" if need_number: pf += ",加备案号" pf = pf.strip(', ') self.titlePrefix = pf frame_size = '0x0' water_size = '0x0' number_size = '0x0' number_size_2 = '0x0' number_size_3 = '0x0' if need_frame and frame_file: frame_size = utils.get_image_size2(frame_file) if need_watermark and watermark_file: water_size = utils.get_image_size2(watermark_file) if need_number and number_file: number_size = utils.get_image_size2(number_file) if need_number_2 and number_file_2: number_size_2 = utils.get_image_size2(number_file_2) if need_number_3 and number_file_3: number_size_3 = utils.get_image_size2(number_file_3) # 片头持续时间 pt_second = 0 if pt_select and pt_file: print(pt_file) tdc = ff.get_video_info(pt_file, False) # 匹配 尺寸和fps pt_second = tdc['duration'] if tdc["duration"] else '0' pt_second = float(pt_second) # 片尾持续时间 pw_second = 0 if pw_select and pw_file: tdc = ff.get_video_info(pw_file, False) # 匹配 尺寸和fps pw_second = tdc['duration'] if tdc["duration"] else '0' pw_second = float(pw_second) seq = (['index', -1], ['total', 0], ['rawMP4', ''], ['output_dir', ''], ['temp_dir', ''], ['pt_second', 0], ['pw_second', 0], ['pt_out_file', ''], ['pw_out_file', ''], ['frame_size', ''], ['water_size', ''], ['need_number', False], ['number_file', ''], ['number_size', ''], ['number_join_str', ''], ['number_join_short_str', ''], ['fps', 24]) # one_dc = dict.fromkeys(seq, "") one_dc = {} for key_value in seq: one_dc.setdefault(key_value[0], key_value[1]) one_dc['total'] = len(lists) one_dc['output_dir'] = output_dir one_dc['temp_dir'] = temp_dir one_dc['pt_second'] = pt_second one_dc['pw_second'] = pw_second one_dc['pt_second'] = pt_second one_dc['pt_out_file'] = pt_out_file one_dc['pw_out_file'] = pw_out_file one_dc['fps'] = fps if need_frame and frame_file: one_dc['frame_size'] = frame_size if need_watermark and watermark_file: one_dc['water_size'] = water_size for i in range(len(lists)): one_dc['index'] = i one_dc['rawMP4'] = lists[i] if need_number: one_dc['number_join_str'] = '' one_dc['number_join_short_str'] = '' one_dc['need_number'] = need_number one_dc['number_file'] = number_file one_dc['number_size'] = number_size self.once_complex(dc, one_dc) if need_number_2: one_dc['number_join_str'] = '爱奇艺备案号' one_dc['number_join_short_str'] = '爱奇艺' one_dc['need_number'] = need_number_2 one_dc['number_file'] = number_file_2 one_dc['number_size'] = number_size_2 self.once_complex(dc, one_dc) if need_number_3: one_dc['number_join_str'] = '腾讯备案号' one_dc['number_join_short_str'] = '腾讯' one_dc['need_number'] = need_number_3 one_dc['number_file'] = number_file_3 one_dc['number_size'] = number_size_3 self.once_complex(dc, one_dc) # 没有备案号任务 只执行一次 if not need_number and \ not need_number_2 and \ not need_number_3: one_dc['need_number'] = False # one_dc['number_file'] = number_file # one_dc['number_size'] = number_size # one_dc['number_join_str'] = '' # one_dc['number_join_short_str'] = '' self.once_complex(dc, one_dc) # 删除临时文件 utils.remove_file(pt_out_file) utils.remove_file(pw_out_file) print("完成!\n输出目录:" + output_dir) set_title("操作结束!") set_title("") # 自动打开目录 if self.final_video and os.path.exists(self.final_video): utils.open_file(self.final_video, True) else: utils.open_dir(output_dir) self.t1 = "" self.lock_btn(False) # 检查并执行关机 self.cb_shutdown.shutdown()
def process(self, dc, a_str=''): set_title = self.start.update_query input_list = dc["list"] output_dir = dc["output_dir"] + os.sep temp_dir = output_dir + 'tempDir' + os.sep utils.make_dir(temp_dir) utils.hide_file(temp_dir) s2bool = utils.str_to_bool keep_parent_select = s2bool(dc["keep_parent_select"]) keep_meta_select = s2bool(dc["keep_meta_select"]) # format1_select = s2bool(dc["format1_select"]) format2_select = s2bool(dc["format2_select"]) format3_select = s2bool(dc["format3_select"]) pt_select = dc["pt_select"] pw_select = dc["pw_select"] pt_second = dc["pt_second"] / 1000 pw_second = dc["pw_second"] / 1000 need_remain = dc["need_remain"] if format2_select: ext = ".m4a" param_a = "" elif format3_select: ext = ".wav" param_a = "" else: ext = ".mp3" param_a = " -acodec libmp3lame -ac 2 -ar 44100 -b:a 128k" final_mp4 = "" total = len(input_list) count = 0 msg_str = " {0}/{1} {2}" for i in range(total): count = count + 1 input_file = input_list[i] p = Path(input_file) # 保留上层目录结构 # 排除根目录 path_root = "{0}{1}".format(p.drive, os.sep) path_parent = str(Path(p.parent).name) if keep_parent_select and not path_root == path_parent: output_sub_dir = "{0}{1}{2}".format(output_dir, path_parent, os.sep) utils.make_dir(output_sub_dir) output_file = "{0}{1}{2}".format(output_sub_dir, p.stem, ext) else: output_file = "{0}{1}{2}".format(output_dir, p.stem, ext) # 任务信息 set_title(msg_str.format(count, total, p.name)) # 读取视频参数 tdc = ff.get_video_info(input_file, False) # v_size = tdc["v_size"] if tdc["v_size"] else "1920x1080" # fps = tdc["fps"] if tdc["fps"] else "24" # tdc["fps"] = fps duration = float(tdc['duration']) if tdc["duration"] else 0 duration = float(duration) second = duration if not duration: set_title('读取视频参数失败,不处理该视频') continue need_execute = False time_start = 0 time_to = 0 if pt_select and pt_second != 0: if pt_second < second: time_start = pt_second need_execute = True else: set_title('片头时长超过视频时长,不进行片头修剪!!!') if pw_select and pw_second != 0: if need_remain: time_to = second - pw_second else: time_to = pw_second if time_to > time_start: need_execute = True else: time_to = 0 set_title('片尾时长在起始时间之前,不进行片尾修剪!!!') if need_execute: set_title('正在转换 修剪部分……') if time_start != 0: ss = ' -ss {}'.format(time_start) else: ss = '' if time_to != 0: to = ' -to {}'.format(time_to) else: to = '' # 拼接 ffmpeg 参数 if keep_meta_select: param = 'ffmpeg -y -i "{in_file}"{param_a}{ss}{to} ' \ '-vn -hide_banner "{out_file}"' else: param = 'ffmpeg -y -i "{in_file}"{param_a}{ss}{to} -map_metadata -1 ' \ '-vn -hide_banner "{out_file}"' param = param.format(in_file=input_file, out_file=output_file, param_a=param_a, ss=ss, to=to) ff.execute(param) final_mp4 = output_file set_title("操作结束!") # 自动打开目录 if final_mp4: utils.open_dir(output_dir) self.t1 = "" self.lock_btn(False)
def process(self, dc, astr=''): set_title = self.set_title2 lists = dc["input_files"] radio_select_var = dc["radio_select_var"] output_dir = dc["output_dir"] + os.sep pt_select = dc["pt_select"] pw_select = dc["pw_select"] pt_second = dc["pt_second"] / 1000 pw_second = dc["pw_second"] / 1000 need_remain = dc["need_remain"] fast_select = dc["fast_select"] # 视频尺寸超过 1920x1080 10px 以内自动进行裁剪 size_cut_select = dc["size_cut_select"] add_param_str = "-vf crop=1920:1080:0:0 -threads 8 -hide_banner" if size_cut_select else "" add_param_str_mov = '-vf "crop=1920:1080:0:0,scale=2*trunc(iw/2):-2,setsar=1" -threads 8 -hide_banner' if size_cut_select else '' # 对符合要求的 mov 进行特殊处理 # -vf "crop=1920:1080:0:0,scale=2*trunc(iw/2):-2,setsar=1" mov_param = "-profile:v high -pix_fmt yuv420p" vaild_sizes = [ '1920x1080', '1280x720', '960x540', '640x360', '1080x1920', '720x1280', '540x960', '360x640' ] total = len(lists) count = 0 final_mp4 = "" msg_str = " {0}/{1} {2}" cut_info_str = "{0}" can_fast = False is_mov = False for i in range(len(lists)): count += 1 raw_mp4 = lists[i] if not os.path.exists(raw_mp4): continue p = Path(raw_mp4) suffix = str(p.suffix).lower() temp_mp4 = output_dir + str(p.stem) + ".mp4" is_mov = True if suffix == ".mov" else False # 任务信息 mstr = msg_str.format(count, total, p.name) set_title(mstr) final_mp4 = temp_mp4 # 匹配 尺寸和fps tdc = ff.get_video_info(raw_mp4, False) v_size = tdc["v_size"] if tdc["v_size"] else "1920x1080" fps = tdc["fps"] if tdc["fps"] else "24" tdc["fps"] = fps duration = float(tdc['duration']) if tdc["duration"] else 0 duration = float(duration) second = duration if not duration: set_title(cut_info_str.format('读取视频参数失败,不处理该视频')) continue # 码率 部分 # crf 不为 0 ff对象则不应用 v_bit_rate等参数 vb_str = "" if radio_select_var == 1: # 自动 tdc["crf"] = 18 can_fast = True elif radio_select_var == 2: # 4m vb_str = "4M" can_fast = False elif radio_select_var == 3: # 6m vb_str = "6M" can_fast = False elif radio_select_var == 4: # 8m vb_str = "8M" can_fast = False elif radio_select_var == 5: # 10m vb_str = "10M" can_fast = False elif radio_select_var == 6: # 30m vb_str = "30M" can_fast = False # 尺寸 部分 tdc["v_size"] = v_size s_arr = v_size.split("x") s_w = int(s_arr[0]) s_h = int(s_arr[1]) need_w = s_w > 1920 and s_w <= 1940 need_h = s_h > 1080 and s_h <= 1100 need_result = need_w or need_h if size_cut_select and need_result: tdc["v_size"] = "1920x1080" if is_mov: tdc["other_param_add"] = mov_param + " {}".format( add_param_str_mov) else: if 'other_param_add' in tdc and tdc[ "other_param_add"] != '': tdc["other_param_add"] += " {}".format(add_param_str) else: tdc["other_param_add"] = add_param_str can_fast = False else: # 指定 mov 的 尺寸才进行特殊处理 if is_mov and vaild_sizes.count(v_size) != 0: tdc["other_param_add"] = mov_param # 时长 部分 need_execute = False time_start = 0 time_to = 0 if pt_select and pt_second != 0: if pt_second < second: time_start = pt_second need_execute = True else: set_title(cut_info_str.format('片头时长超过视频时长,不进行片头修剪!!!')) if pw_select and pw_second != 0: if need_remain: time_to = second - pw_second else: time_to = pw_second if time_to > time_start: need_execute = True else: time_to = 0 set_title(cut_info_str.format('片尾时长在起始时间之前,不进行片尾修剪!!!')) if need_execute: if can_fast and fast_select: if suffix == ".mp4": set_title(cut_info_str.format('正在快速修剪!!!')) if "other_param_add" in tdc: tdc['other_param_add'] += " -c copy -copyts" else: tdc['other_param_add'] = "-c copy -copyts" else: set_title(cut_info_str.format('正在转换 修剪部分……')) # # else: # set_title(cut_info_str.format('输入的时长都不正确,不进行片头片尾的修剪!!!')) obj = ff.create_obj() obj.input_file = raw_mp4 obj.output_file = temp_mp4 obj.time_start = time_start obj.time_to = time_to obj.set_video_info(tdc, vb_str) # if fast_select: # obj.other_param = '-c copy -copyts -threads 8' # else: # obj.other_param = '-copyts -threads 8' obj.execute() # self.update_status(i, ss) set_title("操作结束!") set_title("") self.t1 = "" self.lock_btn(False) # 自动打开目录 if final_mp4: utils.open_dir(output_dir)