使用模型生成视频和字幕

# 处理图片和封面
cp -ar /home/jcleng/work/book/.vscode/iimmgg/* /home/jcleng/下载/001/mv/

# 先把音频转视频
# ffmpeg -i spk_1751439780.wav -vn -c:a aac -b:a 128k spk_1751439780.mp4

# 使用index-tts文本转语音,和润色
mystring="李一桐曝女推在土耳其一起洗澡,李一桐网速太快啦,书卷一梦剧最出圈的三人捅,房顶上的蜈蚣名场面都知道。她还悄悄说这次女子推理社团综土耳其之旅和戚薇,田曦薇,张艺凡,李雪琴还建了澡堂搭子群,5个人在一个洗浴间的奇妙经历,友谊有了质的飞跃"

docker run --entrypoint= -it --rm \
  -v /home/jcleng/work/mywork/index-tts/:/app/index-tts \
  -e HF_ENDPOINT="https://hf-mirror.com" \
  -e PYTHONPATH=/app/index-tts/indextts: \
  --name=indexttsbash registry.cn-hangzhou.aliyuncs.com/joybo/index-tts:latest \
  python indextts/cli.py "$mystring" \
  --voice tests/sample_prompt.wav \
  --config checkpoints/config.yaml \
  --force \
  --output outputs/output.wav

# 生成字幕(会下载语音模型)
# https://github.com/baxtree/subaligner
docker pull registry.cn-hangzhou.aliyuncs.com/jcleng/baxtree-subaligner

cp /home/jcleng/work/mywork/index-tts/outputs/output.wav /home/jcleng/下载/001/mv/

docker run --rm -v `pwd`:`pwd` \
  -v /home/jcleng/work/mywork/subaligner:/root/.cache/whisper \
  -w `pwd` -it registry.cn-hangzhou.aliyuncs.com/jcleng/baxtree-subaligner \
  subaligner -m script -v output.wav -s subtitle.txt -o subtitle_realy.srt -ml zho -sil zho

# 对没有subtitle.txt的媒体生成srt;subtitle.txt是每一句都要还行
subaligner -m transcribe -v output.wav -ml zho -mr whisper -mf medium -o subtitle_aligned.srt

# 生成视频
# https://github.com/jifengg/ffmpeg-script
node /home/jcleng/work/mywork/ffmpeg-script/ffmpeg.img2video.js -display cover -width 1080 -height 1920 -repeat -i "/home/jcleng/下载/001/mv/"

# 增加bgm
# 截取bgm
ffmpeg -i bgm.mp3 -ss 00:02:41 -to 00:04:00 -c copy hot_output.mp3
# 最后输出
ffmpeg -i output.mp4 -i /home/jcleng/下载/001/onceimg/hot_output.mp3 \
    -filter_complex "[1:a]volume=0.2[bgm];[0:a][bgm]amix=inputs=2:duration=first" \
    -c:v copy \
    output_with_mixed_audio.mp4

### 字幕加高
        filters_lain += `[${last_output_label}]subtitles=force_style='MarginV=50,PrimaryColour=&H00FFFF&':filename='${subtitle_file.replace(/\\/g, '/').replace(/:/g, '\\:')}'[${output_label}];`;
  • reimg.php

<?php

function resizeAndCover($sourcePath, $destPath, $targetWidth = 1080, $targetHeight = 1920)
{
    // 获取图像信息
    $info = getimagesize($sourcePath);
    $originalWidth = $info[0];
    $originalHeight = $info[1];
    $mime = $info['mime'];

    // 创建原始图像资源
    switch ($mime) {
        case 'image/jpeg':
            $sourceImage = imagecreatefromjpeg($sourcePath);
            break;
        case 'image/png':
            $sourceImage = imagecreatefrompng($sourcePath);
            break;
        case 'image/gif':
            $sourceImage = imagecreatefromgif($sourcePath);
            break;
        default:
            throw new Exception("不支持的图片格式");
    }

    // 计算 cover 模式下的缩放比例
    $scale = max($targetWidth / $originalWidth, $targetHeight / $originalHeight);
    $scaledWidth = (int)($originalWidth * $scale);
    $scaledHeight = (int)($originalHeight * $scale);

    // 创建缩放后的临时图像
    $resizedImage = imagecreatetruecolor($scaledWidth, $scaledHeight);
    imagecopyresampled(
        $resizedImage,
        $sourceImage,
        0,
        0,
        0,
        0,
        $scaledWidth,
        $scaledHeight,
        $originalWidth,
        $originalHeight
    );

    // 创建最终裁剪图像(1080x1920)
    $croppedImage = imagecreatetruecolor($targetWidth, $targetHeight);

    // 居中裁剪
    $x = ($scaledWidth - $targetWidth) / 2;
    $y = ($scaledHeight - $targetHeight) / 2;
    imagecopy($croppedImage, $resizedImage, 0, 0, $x, $y, $targetWidth, $targetHeight);

    // 保存结果
    imagejpeg($croppedImage, $destPath, 90); // 质量设为 90,可选

    // 释放资源
    imagedestroy($sourceImage);
    imagedestroy($resizedImage);
    imagedestroy($croppedImage);
}

// 示例调用
try {
    $path_arr = [
        '/home/jcleng/下载/001/onceimg/1.png',
        '/home/jcleng/下载/001/onceimg/2.png',
        '/home/jcleng/下载/001/onceimg/3.png',
        // '/home/jcleng/下载/001/onceimg/4.png',
    ];
    $outdirname = '/home/jcleng/下载/001/mv/';
    foreach ($path_arr  as $key => $path) {
        resizeAndCover($path, $outdirname . "/thumb{$key}.jpg");
        echo "图片处理完成";
    }
} catch (Exception $e) {
    echo "错误: " . $e->getMessage();
}
  • fishaudio太慢了

docker run -itd --network=host \
  -v `pwd`:`pwd` \
  -w `pwd` \
  --name=fishspeech \
  swr.cn-north-4.myhuaweicloud.com/ddn-k8s/docker.io/fishaudio/fish-speech:v1.5.0