| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354 |
- #!/usr/bin/env python3
- # -*- coding: utf-8 -*-
- import requests
- import base64
- import os
- # ===================== 配置 =====================
- API_URL = "http://183.252.196.135:6001"
- INPUT_FILE = "/Users/alien/Desktop/Digital_Human/coco.mp4"
- # 输出文件名由调用脚本决定,这里使用动态命名
- import sys
- if len(sys.argv) > 1:
- OUTPUT_FILE = sys.argv[1]
- else:
- OUTPUT_FILE = "/Users/alien/Desktop/Digital_Human/back/video/result.mp4"
- BG_COLOR = "black"
- CROP_TO_PERSON = True
- CROP_MARGIN = 50
- # =================================================
- def main():
- print("🚀 开始处理视频...")
- # 读取视频并转 base64
- with open(INPUT_FILE, 'rb') as f:
- video_base64 = base64.b64encode(f.read()).decode('utf-8')
- # 发送请求(自动裁剪 + 背景颜色)
- response = requests.post(
- f"{API_URL}/v1/video/greenscreen",
- json={
- "video_base64": video_base64,
- "downsample_ratio": 0.25,
- "bg_color": BG_COLOR,
- "crop_to_person": CROP_TO_PERSON,
- "margin": CROP_MARGIN,
- "return_base64": True
- },
- timeout=600
- )
- # 获取结果
- result = response.json()
- video_bytes = base64.b64decode(result['video_base64'])
- # 直接保存到你指定的目录
- with open(OUTPUT_FILE, 'wb') as f:
- f.write(video_bytes)
- print(f"\n🎉 处理完成!")
- print(f"✅ 文件已保存到:{OUTPUT_FILE}")
- if __name__ == "__main__":
- main()
|