分辨率和其他参数都不一致的 2 段 视频合并,拼接

@echo off
setlocal enabledelayedexpansion
chcp 65001 >nul

set "TMPDIR=%~dp0_tmp_concat"
set "LIST=%~dp0list.txt"
set "CONCATLIST=%TMPDIR%\concat.txt"
set "OUT=%~dp0out.mp4"

if exist "%OUT%" del /f /q "%OUT%"
if exist "%TMPDIR%" rmdir /s /q "%TMPDIR%"
mkdir "%TMPDIR%"
if exist "%LIST%" del "%LIST%"
if exist "%CONCATLIST%" del "%CONCATLIST%"

set /a idx=0

echo [1/2] 正在统一转码...
for %%f in (*.mp4) do (
    if /i not "%%~nxf"=="out.mp4" (
        set /a idx+=1
        set "num=000!idx!"
        set "num=!num:~-4!"
        echo 处理: %%f
        ffmpeg -y -i "%%f" -vf "scale=1280:720:force_original_aspect_ratio=decrease,pad=1280:720:(ow-iw)/2:(oh-ih)/2,setsar=1,fps=30" -c:v libx264 -crf 23 -preset medium -c:a aac -b:a 192k -ar 48000 -ac 2 "%TMPDIR%\!num!.mp4"
        if errorlevel 1 (
            echo [错误] 转码失败: %%f
            goto :fail
        )
        rem 带 file 的原始文件名列表
        echo file "%%f">> "%LIST%"
        rem 实际合并用的编号列表
        echo file '!num!.mp4'>> "%CONCATLIST%"
    )
)

if not exist "%CONCATLIST%" (
    echo [错误] 没有找到可处理的 mp4 文件。
    goto :fail
)

echo [2/2] 正在合并...
ffmpeg -y -f concat -safe 0 -i "%CONCATLIST%" -c copy "%OUT%"
if errorlevel 1 (
    echo [错误] 合并失败。
    goto :fail
)

echo.
echo 完成: %OUT%
echo 列表保留: %LIST%
del /f /q "%TMPDIR%\*.mp4"
rmdir /s /q "%TMPDIR%" 2>nul
pause
exit /b 0

:fail
echo.
echo 已中止,临时目录保留在: %TMPDIR%
echo 列表位置: %LIST%
pause
exit /b 1

list.txt 这个列表里的原始文件参数不一致,别直接拿它跑 concat 合并,它只是记录;实际合并用的是临时编号列表。

posted @ 2026-12-01 17:23  飞翔的a  阅读(9)  评论(0)    收藏  举报