This question does not appear to be about a specific programming problem, a software algorithm, or software tools primarily used by programmers. If you believe the question would be on-topic on another Stack Exchange site, you can leave a comment to explain where the question may be able to be answered.
Closed 4 years ago.
The community reviewed whether to reopen this question last year and left it closed:
Original close reason(s) were not resolved
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
接受
或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
发布评论
评论(9)
注意:此解决方案将字幕作为单独的可选(且用户控制的)字幕轨道添加到视频中。
-vf subtitles=infile.srt
不适用于-c copy
-c copy -c:s mov_text
的顺序很重要。你告诉 FFmpeg:如果你颠倒它们,你就是告诉 FFmpeg:
或者你可以使用
-c:v 复制 -c:a 复制 -c:s mov_text
在任何命令。
NOTE: This solution adds the subtitles to the video as a separate optional (and user-controlled) subtitle track.
-vf subtitles=infile.srt
will not work with-c copy
The order of
-c copy -c:s mov_text
is important. You are telling FFmpeg:If you reverse them, you are telling FFmpeg:
Alternatively you could just use
-c:v copy -c:a copy -c:s mov_text
in anyorder.
注意:此解决方案将字幕“刻录”到视频中,以便视频的每个观看者都将被迫看到它们。
如果您的 ffmpeg 在编译时启用了 libass,您可以直接执行
以下操作 :例如,对于 Ubuntu 20.10,您可以检查
ffmpeg --version
是否具有--enable-libass
。否则,您可以使用
libass
库(确保您的 ffmpeg 安装有配置--enable-libass
中的库)。首先将字幕转换为
.ass
格式:然后使用视频滤镜添加它们:
NOTE: This solution "burns the subtitles" into the video, so that every viewer of the video will be forced to see them.
If your ffmpeg has libass enabled at compile time, you can directly do:
This is the case e.g. for Ubuntu 20.10, you can check if
ffmpeg --version
has--enable-libass
.Otherwise, you can the
libass
library (make sure your ffmpeg install has the library in the configuration--enable-libass
).First convert the subtitles to
.ass
format:Then add them using a video filter:
您正在尝试将字幕混合为字幕流。这很简单,但 MP4(或 M4V)和 MKV 使用不同的语法。在这两种情况下,您都必须指定视频和音频编解码器,或者如果您只想添加字幕,则只需复制流。
MP4:
MKV:
You are trying to mux subtitles as a subtitle stream. It is easy but different syntax is used for MP4 (or M4V) and MKV. In both cases you must specify video and audio codec, or just copy stream if you just want to add subtitle.
MP4:
MKV:
MKV 容器几乎支持任何视频和音频编解码器,还支持字幕和 DVD 菜单。因此,您只需使用带有字幕的 MKV 容器将编解码器从输入视频复制到输出视频即可。首先,您应该将 SRT 转换为 ASS 字幕格式
并将 ASS 字幕嵌入视频
也适用于 VMW 文件。
请参阅 wiki 页面容器格式比较
MKV container supports video and audio codecs Virtually anything and also supports subtitles and DVD menus. So you can just copy codecs from input video to output video with MKV container with subtitles. First you should convert SRT to ASS subtitle format
and embed ASS subtitles to video
Also worked with VMW file.
see the wiki page Comparison of container formats
ffmpeg 支持
mov_text
字幕编码器,它是 MP4 容器中唯一支持的字幕编码器,并且可以通过 iTunes、Quicktime、iOS 等播放。您的行将显示为:
ffmpeg -i input.mp4 -i input.srt -map 0:0 -map 0:1 -map 1:0 -c:s mov_text 输出.mp4
ffmpeg supports the
mov_text
subtitle encoder which is about the only one supported in an MP4 container and playable by iTunes, Quicktime, iOS etc.Your line would read:
ffmpeg -i input.mp4 -i input.srt -map 0:0 -map 0:1 -map 1:0 -c:s mov_text output.mp4
我尝试使用 MP4Box 来完成此任务,但它无法处理我正在处理的 M4V。我成功使用 ffmpeg 使用以下命令行将 SRT 嵌入为软字幕:
ffmpeg -i input.m4v -i input.srt -vcodec copy -acodec copy -scodec copy -map 0:0 -map 0:1 -map 1:0 -y output.mkv
像你一样,我必须使用 MKV 输出文件 - 我无法创建 M4V 文件。
I tried using MP4Box for this task, but it couldn't handle the M4V I was dealing with. I had success embedding the SRT as soft subtitles with ffmpeg with the following command line:
ffmpeg -i input.m4v -i input.srt -vcodec copy -acodec copy -scodec copy -map 0:0 -map 0:1 -map 1:0 -y output.mkv
Like you I had to use an MKV output file - I wasn't able to create an M4V file.
我将提供一个简单而通用的答案,适用于任意数量的音频和 srt 字幕并且尊重可能包含 mkv 容器的元数据。因此,它甚至会添加 matroska 可能包含的图像作为附件(尽管不是其他类型的 AFAIK)并将它们转换为曲目;你将无法观看,但它们会在那里(你可以将它们解复用)。啊,如果 mkv 也有章节 mp4。
正如您所看到的,这都是关于
-map 0
的,它告诉 FFmpeg 添加所有曲目,其中包括元数据、章节、附件等。无法识别的“轨道”(mkv允许附加任何类型的文件),它将以错误结束。如果您经常这样做,您可以创建一个简单的批处理
mkv2mp4.bat
,以创建与 mkv 名称相同的 mp4。如果有错误控制、不同的输出名称等会更好,但你明白了。现在您只需运行
它就会创建“带字幕的视频等.mp4”,其中包含最多的信息。
I will provide a simple and general answer that works with any number of audios and srt subtitles and respects the metadata that may include the mkv container. So it will even add the images the matroska may include as attachments (though not another types AFAIK) and convert them to tracks; you will not be able to watch but they will be there (you can demux them). Ah, and if the mkv has chapters the mp4 too.
As you can see, it's all about the
-map 0
, that tells FFmpeg to add all the tracks, which includes metadata, chapters, attachments, etc. If there is an unrecognized "track" (mkv allows to attach any type of file), it will end with an error.You can create a simple batch
mkv2mp4.bat
, if you usually do this, to create an mp4 with the same name as the mkv. It would be better with error control, a different output name, etc., but you get the point.Now you can simply run
And it will create "Video with subtitles etc.mp4" with the maximum of information included.
简单示例:
仅替换 linux 变量
Simple Example:
Only replace the linux variables
这就是 mkv 如此优秀的容器的原因,尤其是现在它已经成熟了:
This is the reason why mkv is such a good container, especially now that it's mature: