使用ffmpeg和windows命令行批处理NOT LINUX连接/加入MP4文件

jul*_*rne 2 windows video ffmpeg concatenation batch-file

我写了一个批处理脚本,试图采用一个运行12秒的通用介绍性标题视频(MP4)并将其附加到其他4个MP4视频的开头(相同的视频,但每个都有不同的语言音轨)

根据这里的ffmpeg语法:http://ffmpeg.org/trac/ffmpeg/wiki/How%20to%20concatenate%20%28join,%20merge%29%20media%20files concat demuxer需要从一个文本文件中运行看起来像这样:

# this is a comment
file '/path/to/file1'
file '/path/to/file2'
file '/path/to/file3'
Run Code Online (Sandbox Code Playgroud)

我相信我的脚本中的所有内容都会一直运行,直到加入文件为止.但我得到这个错误:

[concat @ 04177d00] Line 2: unknown keyword ''C:\Users\Joe\1May\session3\readyforfinalconversion\frenchfile.mp4'
filelistFrench.txt: Invalid data found when processing input
[concat @ 03b70a80] Line 2: unknown keyword ''C:\Users\Joe\1May\session3\readyforfinalconversion\spanishfile.mp4'
filelistSpanish.txt: Invalid data found when processing input
[concat @ 0211b960] Line 2: unknown keyword ''C:\Users\Joe\1May\session3\readyforfinalconversion\basquefile.mp4'
filelistBasque.txt: Invalid data found when processing input
[concat @ 03a20a80] Line 2: unknown keyword ''C:\Users\Joe\1May\session3\readyforfinalconversion\Englishfile.mp4'
filelistEnglish.txt: Invalid data found when processing input
Run Code Online (Sandbox Code Playgroud)

我相信问题在于我正在创建的文本文件.请原谅我的无知,但有时像我这样的新脚本制作者对开发人员的术语感到困惑,可能会从字面上理解.

因此,当我查看他们提供的示例文本文件时,我是否正确认为这是我的文本文件应该是什么样子?

# this is a comment
Titlefile.mp4 'C:\Users\Joe\1May\session3\readyforfinalconversion\Titlefile.mp4'
Englishfile.mp4 'C:\Users\Joe\1May\session3\readyforfinalconversion\Englishfile.mp4'
Run Code Online (Sandbox Code Playgroud)

再一次,我是不是太字面了?报价是否正确?斜线是否正确?在示例中,它们提供路径中的斜杠/而不是普通的Windows \.我将提供整个脚本,以防它有所帮助.

@echo off

setlocal EnableDelayedExpansion

rem Create an array of languages
set i=0
for %%a in (French Spanish Basque English) do (
   set /A i+=1
   set term[!i!]=%%a
)

rem Get the title video file name from user

set /p titlevideofilename=What is the title video file 

name?

rem create a path variable for the title video file

set pathtotitlevideo=%~dp0%titlevideofilename%

rem Get the names of the different language video files to append to the title video
rem create a path variable for each different language video files

for /L %%i in (1,1,4) do (
   set /p language[%%i]=what is the name of the !term

[%%i]! file you want to append after the title video?
   set pathtofile[%%i]=%~dp0!language[%%i]!
)

rem create data file for ffmpeg based on variable data

for /L %%i in (1,1,4) do (
    echo # this is a comment>>filelist!term[%

%i]!.txt
    echo file '%pathtotitlevideo%'>>filelist!term[%

%i]!.txt
    echo file '!pathtofile[%%i]!'>>filelist!term[%

%i]!.txt
)

cls

rem join files using ffmpeg concat option

for /L %%i in (1,1,4) do (
   c:\ffmpeg\ffmpeg\bin\ffmpeg.exe -loglevel error -f 

concat -i filelist!term[%%i]!.txt -c copy !language[%

%i]!.!term[%%i]!.withtitle.mp4
)

endlocal

:eof
exit
Run Code Online (Sandbox Code Playgroud)

编辑
感谢@foxidrive让我看看它的简洁性...我突然发现,显然我不够文字.我做了这3个更改并且脚本现在完美地运行1:"文件"在那里示例字面意思是"文件"2:需要使用单引号而不是双引号,如在那里示例中所示.3:使用"\"而不是"/",因为它们在那里有例子.

所以现在我创建文本文件的代码如下所示:

rem create data file for ffmpeg based on variable data

for /L %%i in (1,1,4) do (
    echo # this is a comment>>filelist!term[%

%i]!.txt
    echo file '%pathtotitlevideo%'>>filelist!term[%

%i]!.txt
    echo file '!pathtofile[%%i]!'>>filelist!term[%

%i]!.txt
)
Run Code Online (Sandbox Code Playgroud)

所以现在我的文本文件如下所示:

# this is a comment    
file 'C:\Users\Joe\1May\session3\readyforfinalconversion\Titlefile.mp4'
file 'C:\Users\Joe\1May\session3\readyforfinalconversion\Englishfile.mp4'
Run Code Online (Sandbox Code Playgroud)

fox*_*ive 8

从阅读您的问题,我建议配置文件可能如下所示:

# this is a comment
file 'C:\Users\Joe\1May\session3\readyforfinalconversion\Titlefile.mp4'
file 'C:\Users\Joe\1May\session3\readyforfinalconversion\Englishfile.mp4'
Run Code Online (Sandbox Code Playgroud)

对于Windows,它可能需要围绕路径\文件名而不是单引号使用双引号.尝试两种方式.