使用ffmpeg添加文字字幕 [英] Use ffmpeg to add text subtitles
问题描述
我正在使用ffmpeg将文本字幕添加到.mp4容器中:
I am trying to add text subtitles to an .mp4 container using ffmpeg:
ffmpeg -i input.mp4 -i input.srt -map 0.0 -map 0.1 -map 1.0 output.mp4
当我试图运行这行,它给我一个错误:
When I am trying to run this line, it gives me an error :
流映射的十一行必须匹配输出流的数量。
Nmber of stream maps must match number of output streams.
如果我尝试将mp4更改为mkv(尽管mp4支持文字字幕),如下所示:
If I try to change the mp4 to mkv (although mp4 supports text subtitles), like this:
ffmpeg -i input.mp4 -i input.srt -map 0.0 -map 0.1 -map 1.0 output.mkv
它正确地映射了流,但发出错误:
It correctly maps the streams, but gives an error :
编码器(编解码器编号94210)未找到输出流#0.2
Encoder (codec id 94210) not found for output stream #0.2
当我启动
ffmpeg -codecs
我可以看到作为解码器和编码器支持srt编解码器,但是我不知道用于mp4和mkv子编码的是什么,以及是否需要单独切换或编译。
I can see that srt codec is supported as decoder and encoder, however I am not sure what is used for mp4 and mkv subs encoding, and whether I need to switch it on or compile separately.
推荐答案
ffmpeg -i infile.mp4 -i infile.srt -c copy -c:s mov_text outfile.mp4
-vf subtitles = infile.srt
不适用于 -c copy
-c copy -c:s mov_text
的顺序很重要。你正在告诉FFmpeg:
The order of -c copy -c:s mov_text
is important. You are telling FFmpeg:
- 视频:复制,音频:复制,副标题:复制
- 小标题:mov_text
如果你扭转他们,你告诉FFmpeg:
If you reverse them, you are telling FFmpeg:
- 副标题:mov_text
- 视频:复制,音频:复制,副标题:复制
或者你可以使用任何
订单中的 -c:v copy -c:copy -c:s mov_text
这篇关于使用ffmpeg添加文字字幕的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!