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

标签 windows video batch-file ffmpeg concatenation

我编写了一个批处理脚本,试图获取一个运行 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'

我相信我的脚本中的所有内容在加入文件之前似乎都在正常工作。但是我得到这个错误:

[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

我认为问题在于我正在创建的文本文件。请原谅我 n00b 的无知,但有时像我这样的新脚本制作者会对开发人员术语感到困惑,并且可能会按字面意思理解。

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

# this is a comment
Titlefile.mp4 'C:\Users\Joe\1May\session3\readyforfinalconversion\Titlefile.mp4'
Englishfile.mp4 'C:\Users\Joe\1May\session3\readyforfinalconversion\Englishfile.mp4'

再一次,我是不是太直白了?报价是否正确?斜线是否正确?在示例中,他们提供的路径中的斜杠是/而不是普通窗口\。如果有帮助,我会提供整个脚本。

@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

编辑
感谢@foxidrive 让我看到了它的简单性……我突然想到,显然我不够直白。我做了这 3 处更改,脚本现在可以完美运行 1:示例中的"file"字面意思是"file" 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
)

所以现在我的文本文件看起来像这样:

# this is a comment    
file 'C:\Users\Joe\1May\session3\readyforfinalconversion\Titlefile.mp4'
file 'C:\Users\Joe\1May\session3\readyforfinalconversion\Englishfile.mp4'

最佳答案

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

# this is a comment
file 'C:\Users\Joe\1May\session3\readyforfinalconversion\Titlefile.mp4'
file 'C:\Users\Joe\1May\session3\readyforfinalconversion\Englishfile.mp4'

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

关于windows - 使用 ffmpeg 和 Windows 命令行批处理 NOT LINUX 连接/加入 MP4 文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18474312/

相关文章:

C# 如何从进程中检索代码然后运行它?

java - 通过 CMD/Registry 禁用 IPv4

C - 在 Windows 上编写在 UNIX 上编译,反之亦然

xcode - MP4 类型的 NSURL 出现 fatal error

video - FFmpeg:使用淡入/淡出效果向视频添加多个叠加层。命令有效,但图像(覆盖)未显示在视频中

python - 批量运行 python 脚本并等待执行返回

batch-file - 批处理 - 如果在日志文件中找到内容,则将其写入另一个日志文件,否则不执行任何操作

windows - 应用程序在启动时崩溃 - 如何获取崩溃转储文件?

android - FFMPEG:多个图像帧+1个音频=1个视频

c# - 杀死资源管理器进程