from tools.download import downloadfrom tools.uncompressed import unzipimport subprocessimport osFFMPEG_BIN_PATH = 'ffmpeg/bin'def download_ffmpeg():file_name = 'ffmpeg-master-latest-win64-gpl-shared'url = f'https://github.com/BtbN/FFmpeg-Builds/releases/download/latest/{file_name}.zip'save_name = 'ffmpeg.zip'if os.path.exists(save_name):os.remove(save_name)download(url, save_name)unzip(save_name)os.rename(file_name, 'ffmpeg')os.remove(save_name)def ffmpeg_check(ffmpeg_bin_path=None):global FFMPEG_BIN_PATHif ffmpeg_bin_path is None:ffmpeg_bin_path = FFMPEG_BIN_PATHFFMPEG_BIN_PATH = os.path.abspath(ffmpeg_bin_path)if os.path.exists(os.path.join(FFMPEG_BIN_PATH, 'ffmpeg.exe')):# print('ffmpeg 已经下载')passelse:print('第一次运行,需下载 ffmpeg,请稍候...')download_ffmpeg()def ffmpeg_cmd(cmd_args):current_path = os.path.abspath(os.curdir)# print(current_path)os.chdir("../tools")ffmpeg_check()# print(os.path.abspath(os.curdir))os.chdir(current_path)# print(os.path.abspath(os.curdir))# cmd = 'SET PATH=%PATH%;"' + os.path.abspath(FFMPEG_BIN_PATH) + '" & ' + cmdcmd = '"' + os.path.abspath(os.path.join(FFMPEG_BIN_PATH, "ffmpeg.exe")) + '" ' + cmd_argsprint(cmd)# result = os.popen(cmd)# outline = result.read()# print(outline)# return outlineimport subprocessprocess = subprocess.Popen(cmd, stdout=subprocess.PIPE, stderr=subprocess.PIPE, shell=True)output, error = process.communicate()output_info = ""# 输出信息output_lines = output.decode('utf-8')if len(output_lines) > 0:output_lines += "\n"output_info += error.decode('utf-8')# print(output_info)return output_info# result = system_call(cmd)# print(result)# print(cmd)# val = os.system(cmd)# if val == 0:# print("Success")# else:# print("Fail..")def gen_mp4(image_file, audio_file, output_mp4_file):cmd = 'SET PATH=%PATH%;"' + FFMPEG_BIN_PATH + '" & 'ffmpeg_cmd = 'ffmpeg -r 15 -loop 1 -i "' + image_file + '" -i "' + audio_file + \'" -s 7680x3840 -pix_fmt yuvj420p -t 278 -vcodec libx264 "' + output_mp4_file + '"'print(ffmpeg_cmd)cmd = cmd + ffmpeg_cmd
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。