FFmpeg 合併行車紀錄器影片

近日偶得出外行程,忽然想將其中一段記錄下來,以供日後參考,想到行車記錄器上都有,就找到相應時間的影片全複製到電腦裡了。只是,這類影片都是分段記錄,每段幾百MB幾分鐘,一段一段看實在很麻煩。要如何將它們合併成一段呢?

記得很久以前也做過影片合併的事,用的也是 ffmpeg,但當時沒記下來,現在又得重來一次了。找著找著,試著試著,每一篇都說這樣可行,我依樣畫葫蘆偏就不行。後來終於看到這一篇能用的,而且他是把待處理影片檔名列表全放進一個文字檔裡,再由文字檔帶入參數中,一行指令就解決更好用,這回該記下來了,只要影片格式相同,都能用這方式。


一、影片列表

先螢幕列表確認無誤:
…:/影片> ls *.MOV
FILE2613.MOV FILE2614.MOV FILE2615.MOV FILE2616.MOV FILE2617.MOV FILE2618.MOV FILE2619.MOV

將列表轉向寫入文件:(文件名稱自取,此名為 files)
…:/影片> ls *.MOV > files

列表文件內容,依據格式需求稍做修改:(列表文件名稱為前項自取的 files)

修改結果須符合參數引入格式:

二、執行指令

ffmpeg -f concat -i files -c copy output.mov

三、合併結果


合併前各單檔長度 5 分鐘。(本範例檔為起始檔,長度不足)


合併後單檔長度 32 分鐘。

四、指令參數說明

-f:force 設定格式

(以下資料來自http://ffmpeg.org/ffmpeg-formats.html#concat-1
3.4 concat

Virtual concatenation script demuxer.

This demuxer reads a list of files and other directives from a text file and demuxes them one after the other, as if all their packets had been muxed together.

The timestamps in the files are adjusted so that the first file starts at 0 and each next file starts where the previous one finishes. Note that it is done globally and may cause gaps if all streams do not have exactly the same length.

All files must have the same streams (same codecs, same time base, etc.).

The duration of each file is used to adjust the timestamps of the next file: if the duration is incorrect (because it was computed using the bit-rate or because the file is truncated, for example), it can cause artifacts. The duration directive can be used to override the duration stored in each file.

-i:input 指定輸入檔

ffmpeg reads from an arbitrary number of input “files” (which can be regular files, pipes, network streams, grabbing devices, etc.), specified by the “-i” option,…

-c:codec 設定編碼

(copy 是只複製不重編碼,速度較快。)
An empty stream specifier matches all streams. For example, “-codec copy” or
“-codec: copy” would copy all the streams without reencoding.

Stream copy is a mode selected by supplying the “copy” parameter to the
-codec option. It makes ffmpeg omit the decoding and encoding step for the
specified stream, so it does only demuxing and muxing.

發佈留言

發佈留言必須填寫的電子郵件地址不會公開。 必填欄位標示為 *