ffmpeg库编译加文字,使用ffmpeg添加文字字幕

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.

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 :

Encoder (codec id 94210) not found for output stream #0.2

When I launch

ffmpeg -codecs

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 will not work with -c copy

The order of -c copy -c:s mov_text is important. You are telling FFmpeg:

Video: copy, Audio: copy, Subtitle: copy

Subtitle: mov_text

If you reverse them, you are telling FFmpeg:

Subtitle: mov_text

Video: copy, Audio: copy, Subtitle: copy

Alternatively you could just use -c:v copy -c:a copy -c:s mov_text in any

order.

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值