簡體   English   中英

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

[英]Concatenate / Join MP4 files using ffmpeg and windows command line batch NOT LINUX

我編寫了一個批處理腳本,試圖獲取一個運行 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

我相信問題在於我正在創建的文本文件。 請原諒我的無知,但有時像我這樣的新腳本制作者會對開發人員術語感到困惑,並且可能會從字面上理解。

因此,當我查看他們提供的示例文本文件時,我認為這就是我的文本文件應該是什么樣子的想法是否正確?

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

再說一遍,我是不是太直白了? 報價是否正確? 斜線是否正確? 在示例中,他們提供的路徑中的斜杠是 / 而不是普通的 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

編輯
感謝@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
)

所以現在我的文本文件看起來像這樣:

# 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

步驟1:創建一個文件,例如C:\\ iAmAFile.txt,其中包含以下內容並保存

file 'C:\video1.flv'
file 'C:\video2.flv'

第2步:下載FFmpeg http://ffmpeg.zeranoe.com/builds/win32/static/ffmpeg-20140716-git-faafd1e-win32-static.7z 解壓縮它,轉到該文件夾​​,你會發現一個ff.prompt.bat文件,就像命令提示符打開它一樣。

在此輸入圖像描述

第3步:現在應用教程命令(Concat demuxer更可靠,它不會破壞編碼器/解碼器只是復制) https://trac.ffmpeg.org/wiki/How%20to%20concatenate%20(join,%20merge )%20media%20files#分路

> ffmpeg -f concat -i C:\iAmAFile.txt -c copy C:\output.flv

完成

多平台解決方案,使用 python:

(不完整的片段)

combined = 'combined.mp4'
tempf = 'tempfile'
s = ''
for f in sys.argv[1:]:
    s += f"file '{f}'\n"
open(tempf, 'w').write(s)
cmd = f'ffmpeg -f concat -safe 0 -i {tempf} -c copy {combined}'
os.system(cmd)

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM