假設我有這樣的影片格式:
Metadata:
CREATION_TIME : 2017-08-04T21:29:42Z
ENCODER : Lavf57.7.2
Duration: 00:24:45.83, start: 0.000000, bitrate: 1130 kb/s
Chapter #0:0: start 0.000000, end 90.048000
Metadata:
title : Chapter 1
Chapter #0:1: start 90.048000, end 741.074000
Metadata:
title : Chapter 2
Chapter #0:2: start 741.074000, end 1391.348000
Metadata:
title : Chapter 3
Chapter #0:3: start 1391.348000, end 1422.338000
Metadata:
title : Chapter 4
Chapter #0:4: start 1422.338000, end 1485.693000
Metadata:
title : Chapter 5
Stream #0:0: Video: h264 (High), yuv420p(tv, bt709, progressive), 960x720 [SAR 1:1 DAR 4:3], 23.98 fps, 23.98 tbr, 1k tbn, 47.95 tbc (default)
Stream #0:1(eng): Audio: aac (LC), 48000 Hz, stereo, fltp (default)
Metadata:
title : Stereo
Stream #0:2(jpn): Audio: aac (LC), 48000 Hz, stereo, fltp
Metadata:
title : Stereo
Stream #0:3(eng): Subtitle: ass (default) (forced)
Stream #0:4: Attachment: ttf
Metadata:
filename : FRAMD.TTF
mimetype : application/x-truetype-font
Stream #0:5: Attachment: ttf
Metadata:
filename : FRAMDCN.TTF
mimetype : application/x-truetype-font
Stream #0:6: Attachment: ttf
Metadata:
filename : FRAMDIT.TTF
mimetype : application/x-truetype-font
Stream #0:7: Attachment: ttf
Metadata:
filename : DEJAVUSERIF.TTF
mimetype : application/x-truetype-font
Stream #0:8: Attachment: ttf
Metadata:
filename : FRADM.TTF
mimetype : application/x-truetype-font
Stream #0:9: Attachment: ttf
Metadata:
filename : FRADMCN.TTF
mimetype : application/x-truetype-font
Stream #0:10: Attachment: ttf
Metadata:
filename : FRADMIT.TTF
mimetype : application/x-truetype-font
我想拍攝該影片的每一幀並將其轉換為圖像,但我想保留字幕。
我嘗試了這樣的命令:
ffmpeg -i file.mkv -r 1 -ss 120 -t 350 -map 0:0 images/output_%05d.png
這讓我得到了我想要的範圍內的幀(-ss..-t
),但是每當我嘗試添加-map 0:3
(字幕流)的一些變化時,我得到
Automatic encoder selection failed for output stream #0:1. Default encoder for format image2 (codec none) is probably disabled. Please choose an encoder manually.
為流 0:1 選擇編碼器時發生錯誤
我也嘗試過像這樣的變體
ffmpeg -i file.mkv -r 1 -ss 120 -t 350 -map 0:0 -attach ~/Library/Fonts/DejaVuSans.ttf -metadata:s:0 mimetype=application/x-truetype-font images/output_%05d.png
這也只是簡單地寫出了 PNG 檔案——沒有字幕。
我在這裡缺少什麼?
答案1
ffmpeg
當我了解到它不執行字幕渲染後我就明白了。我不得不使用過濾subtitles
器,這意味著ffmpeg
用重新編譯--enable-libass
。
最終命令如下圖所示:
ffmpeg -i file.mkv -r 1 -map 0:0 -vf "subtitles=file.mkv" images/output_%05d.png