启动

import argparse
import json
import sys

from image_to_video import run_start

if __name__ == '__main__':
    parser = argparse.ArgumentParser()
    parser.add_argument('--work_dir', type=str, help='工作目录')
    parser.add_argument('--video_scale', type=str, help='视频尺寸')
    parser.add_argument('--tts_config', type=str, help='tts以及字幕配置')
    parser.add_argument('--bgm_file_config', type=str, help='背景音乐配置')
    parser.add_argument('--image_list', type=str, help='图片列表')
    parser.add_argument('--template', type=str, help='方法模版')

    args = parser.parse_args()

    work_dir = args.work_dir
    video_scale = args.video_scale

    # Parse the JSON strings into Python dictionaries
    print(args.tts_config)
    tts_config = json.loads(args.tts_config)
    bgm_file_config = json.loads(args.bgm_file_config)
    image_list = json.loads(args.image_list)
    template = json.loads(args.template)

    run_start(work_dir, tts_config, bgm_file_config, video_scale, image_list, template)
    print("主图视频Done! ")

    print("OK")  # 返回"OK"作为成功信息

    sys.exit(0)  # 返回成功状态给Shell
python3 command_start_image_to_video.py \\
    --work_dir "./tmp" \\
    --video_scale "800,800" \\
    --tts_config "{\\"tts_enable\\": true, \\"txt_content\\": \\"我超爱这个小黄鸭泡泡枪!每次按下一键启动,就像进入了缤纷泡泡的世界。泡泡多而且不漏液,翻转也不怕,玩得我好开心。晚上闪烁灯光还能带来梦幻光效,真的是我最喜欢的玩具了,玩得好嗨!\\", \\"voice_type\\": \\"BV050_streaming\\", \\"people_voice_output_file\\": \\"\\", \\"subtitle\\": { \\"subtitle_enable\\": true, \\"font_file_name\\": \\"AlibabaPuHuiTi-3-85-Bold.ttf\\", \\"font_color\\": \\"orange\\", \\"font_size\\": 50, \\"font_stroke_color\\": \\"black\\", \\"font_stroke_wide\\": 1, \\"shadow\\": true, \\"shadow_color\\": \\"black\\", \\"outside_shadow_shift_x\\": \\"3\\", \\"outside_shadow_shift_y\\": \\"3\\" }}" \\
    --bgm_file_config "{\\"bgm_enable\\": true, \\"bgm_file\\": \\"lively\\"}" \\
    --image_list "[\\"<https://p6-item.ecombdimg.com/img/ecom-shop-material/jTfkqxza_m_0ea96199d125335f78fb1509850afa86_sx_314864_www800-800~tplv-5mmsx3fupr-resize_q:1080:1080:q90.png\\>", \\"<https://p3-item.ecombdimg.com/img/ecom-shop-material/jTfkqxza_m_7733871679a06ddd867f1d2f632c8bfa_sx_262201_www800-800~tplv-5mmsx3fupr-resize_q:1080:1080:q90.png\\>", \\"<https://p3-item.ecombdimg.com/img/ecom-shop-material/jTfkqxza_m_7733871679a06ddd867f1d2f632c8bfa_sx_262201_www800-800~tplv-5mmsx3fupr-resize_q:1080:1080:q90.png\\>", \\"<https://p3-item.ecombdimg.com/img/ecom-shop-material/jTfkqxza_m_f20d90c31e12374b40d522d5ede2971c_sx_314832_www800-800~tplv-5mmsx3fupr-resize_q:1080:1080:q90.png\\>", \\"<https://p3-item.ecombdimg.com/img/ecom-shop-material/jTfkqxza_m_5d391e57087f325c6736fb6181229a61_sx_152317_www800-800~tplv-5mmsx3fupr-resize_q:1080:1080:q90.png\\"]"> \\
    --template "[{\\"method\\": \\"resize_after_slider\\", \\"direction\\": \\"left\\", \\"duration\\": \\"3\\"}, {\\"method\\": \\"resize_after_slider\\", \\"direction\\": \\"right\\", \\"duration\\": \\"3\\"}, {\\"method\\": \\"resize_after_slider\\", \\"direction\\": \\"top\\", \\"duration\\": \\"3\\"}, {\\"method\\": \\"resize_after_slider\\", \\"direction\\": \\"bottom\\", \\"duration\\": \\"3\\"}, {\\"method\\": \\"zoom_scale\\", \\"zoom_type\\": \\"in\\", \\"duration\\": \\"3\\"}]"

在node中启动执行

@ApiOperation({ summary: '测试主图视频生成' })
    @Post('testVideo')
    async testVideo(@Body() body: any): Promise<any> {
        // eslint-disable-next-line @typescript-eslint/no-var-requires
        const shell = require('shelljs');
        console.log(body);

        console.log(`cd /Users/wcy/PycharmProjects/image-to-video-pre/src &&
          python3 command_start_image_to_video.py \\\\
    --work_dir "${body.work_dir}" \\\\
    --video_scale "${body.video_scale}" \\\\
    --tts_config '${JSON.stringify(body.tts_config)}' \\\\
    --bgm_file_config '${JSON.stringify(body.bgm_file_config)}' \\\\
    --image_list '${JSON.stringify(body.image_list)}' \\\\
    --template '${JSON.stringify(body.template)}'
        `);

        // 执行生成主图视频代码
        const { result } = shell.exec(`cd /Users/wcy/PycharmProjects/image-to-video-pre/src && 
         python3 command_start_image_to_video.py \\\\
    --work_dir "${body.work_dir}" \\\\
    --video_scale "${body.video_scale}" \\\\
    --tts_config '${JSON.stringify(body.tts_config)}' \\\\
    --bgm_file_config '${JSON.stringify(body.bgm_file_config)}' \\\\
    --image_list '${JSON.stringify(body.image_list)}' \\\\
    --template '${JSON.stringify(body.template)}'

        `);
        console.log(`result testVideo ${result}`)
    }