from fastapi import FastAPI import uvicorn import nest_asyncio from fastapi.middleware.cors import CORSMiddleware from datetime import datetime app = FastAPI() origins = ["*"] app.add_middleware(CORSMiddleware, allow_origins=origins, allow_credentials=True, allow_methods=["*"], allow_headers=["*"]) preset = "fast" @app.get("/sync") def lip_sync(audio:str, image:str, tmpdir:str): #dir = datetime.now().strftime('%Y%m%d%H%M%S%f') dir = "/data/digital/files/videos/" + tmpdir print("start....audio=" + audio + ", image=" + image + ", tmpdir=" + tmpdir) #os.system("python inference.py --driven_audio %s --source_image %s --enhancer gfpgan --result_dir %s --size 256 --preprocess crop" %(audio,image,dir)) os.system("python inference.py --driven_audio %s --source_image %s --result_dir %s --size 256 --preprocess full --still" %(audio,image,dir)) #os.system("python inference.py --driven_audio %s --source_image %s --enhancer gfpgan --result_dir %s --size 256 --preprocess full --still" %(audio,image,dir)) resultVideo = os.listdir(dir)[0] print("end....return video: " + resultVideo) os.system("chown -R $group:$user " + dir) os.system("ffmpeg -i " + dir + "/" + resultVideo + " -vcodec h264 " + dir + "/temp.mp4") os.system("rm -rf " + dir + "/" + resultVideo) os.system("mv " + dir + "/temp.mp4 " + dir + "/" + resultVideo) return resultVideo; if __name__ == "__main__": PORT = 37860 nest_asyncio.apply() uvicorn.run(app, host="0.0.0.0", port=PORT)
标签:调用,--,image,system,SadTalker,API,audio,os,dir From: https://www.cnblogs.com/zhangzhijian/p/18221698