这些是包含的流:
Stream #0:0[0x247]: Video: mpeg2video (Main) ([2][0][0][0] / 0x0002), yuv420p(tv, top first), 720x576 [SAR 64:45 DAR 16:9], 25 fps, 25 tbr, 90k tbn, 50 tbc
Stream #0:1[0x248](fra): Audio: mp2 ([3][0][0][0] / 0x0003), 48000 Hz, stereo, fltp, 192 kb/s
Stream #0:2[0x24c](fra,eng): Subtitle: dvb_teletext ([6][0][0][0] / 0x0006)
Stream #0:3[0x6c3](rus): Subtitle: dvb_subtitle ([6][0][0][0] / 0x0006)
Stream #0:4[0x6c4](eng): Subtitle: dvb_subtitle ([6][0][0][0] / 0x0006)
Stream #0:5[0x6c5](deu): Subtitle: dvb_subtitle ([6][0][0][0] / 0x0006)
Stream #0:6[0x6c6](dut): Subtitle: dvb_subtitle ([6][0][0][0] / 0x0006)
Stream #0:7[0x6c7](spa): Subtitle: dvb_subtitle ([6][0][0][0] / 0x0006)
Stream #0:8[0x6c8](rum): Subtitle: dvb_subtitle ([6][0][0][0] / 0x0006)
Stream #0:9[0x6c9](fra): Subtitle: dvb_subtitle ([6][0][0][0] / 0x0006)
我参考了我所关注的三个在线资源:
如何使用 ffmpeg 从视频中提取字幕?
https://trac.ffmpeg.org/wiki/ExtractSubtitles
https://newbedev.com/extract-every-audio-and-subtitles-from-a-video-with-ffmpeg
我尝试了里面的所有内容,包括
ffmpeg -txt_format text -i ...
建议。
结果通常类似于
Output #0, srt, to 'subs.srt':
Metadata:
encoder : Lavf58.29.100
Stream #0:0(fra,eng): Subtitle: subrip (srt)
Metadata:
encoder : Lavc58.54.100 srt
Stream mapping:
Stream #0:2 -> #0:0 (dvb_teletext (libzvbi_teletextdec) -> subrip (srt))
Press [q] to stop, [?] for help
size= 0kB time=00:00:00.00 bitrate=N/A speed= 0x
video:0kB audio:0kB subtitle:0kB other streams:0kB global headers:0kB muxing overhead: unknown
Output file is empty, nothing was encoded (check -ss / -t / -frames parameters if used)
或者,使用 .ass 目标,
Output #0, ass, to 'out.ass':
Metadata:
encoder : Lavf58.29.100
Stream #0:0(fra,eng): Subtitle: ass (ssa)
Metadata:
encoder : Lavc58.54.100 ssa
Stream mapping:
Stream #0:2 -> #0:0 (dvb_teletext (libzvbi_teletextdec) -> ass (ssa))
Press [q] to stop, [?] for help
size= 1kB time=00:00:00.00 bitrate=N/A speed= 0x
video:0kB audio:0kB subtitle:0kB other streams:0kB global headers:1kB muxing overhead: unknown
此处的文件不为空,但包含
[Script Info]
; Script generated by FFmpeg/Lavc58.54.100
ScriptType: v4.00+
PlayResX: 384
PlayResY: 288
[V4+ Styles]
Format: Name, Fontname, Fontsize, PrimaryColour, SecondaryColour, OutlineColour, BackColour, Bold, Italic, Underline, StrikeOut, ScaleX, ScaleY, Spacing, Angle, BorderStyle, Outline, Shadow, Alignment, MarginL, MarginR, MarginV, Encoding
Style: Default,Arial,16,&Hffffff,&Hffffff,&H0,&H0,0,0,0,0,100,100,0,0,1,1,0,2,10,10,10,0
[Events]
Format: Layer, Start, End, Style, Name, MarginL, MarginR, MarginV, Effect, Text
我试过字幕是否真的是空的。结果不是:mplayer 会显示它们。
我该怎么做才能正确提取它们?
答案1
流媒体是基于位图的字幕。
提取它们有 2 个步骤(在您的示例中为英文字幕):
1: ffmpeg -i input -map 0:4 -c dvdsub -f matroska subtitles.mkv
2: mkvextract subtitles.mkv tracks 0:sub
您将获得 2 个文件:子目录(索引文件)和子子(位图文件)