20221204使用ffmpeg给视频加硬字幕

20221204使用ffmpeg给视频加硬字幕
2022/12/4 18:17


测试:
中文字幕的编码格式如果是ANSI格式的,肯定出错!^_
可选UTF-8或者UNICODE格式。

[Parsed_subtitles_0 @ 00000000028d34c0] Error decoding: Invalid data found when processing input (ignored)
[srt @ 00000000028c1580] Invalid UTF-8 in decoded subtitles text; maybe missing -sub_charenc option
[Parsed_subtitles_0 @ 00000000028d34c0] Error decoding: Invalid data found when processing input (ignored)
[srt @ 00000000028c1580] Invalid UTF-8 in decoded subtitles text; maybe missing -sub_charenc option
[Parsed_subtitles_0 @ 00000000028d34c0] Error decoding: Invalid data found when processing input (ignored)
[srt @ 00000000028c1580] Invalid UTF-8 in decoded subtitles text; maybe missing -sub_charenc option
[Parsed_subtitles_0 @ 00000000028d34c0] Error decoding: Invalid data found when processing input (ignored)
[srt @ 00000000028c1580] Invalid UTF-8 in decoded subtitles text; maybe missing -sub_charenc option
[Parsed_subtitles_0 @ 00000000028d34c0] Error decoding: Invalid data found when processing input (ignored)
[srt @ 00000000028c1580] Invalid UTF-8 in decoded subtitles text; maybe missing -sub_charenc option
[Parsed_subtitles_0 @ 00000000028d34c0] Error decoding: Invalid data found when processing input (ignored)
[srt @ 00000000028c1580] Invalid UTF-8 in decoded subtitles text; maybe missing -sub_charenc option
[Parsed_subtitles_0 @ 00000000028d34c0] Error decoding: Invalid data found when processing input (ignored)
[srt @ 00000000028c1580] Invalid UTF-8 in decoded subtitles text; maybe missing -sub_charenc option
[Parsed_subtitles_0 @ 00000000028d34c0] Error decoding: Invalid data found when processing input (ignored)
[srt @ 00000000028c1580] Invalid UTF-8 in decoded subtitles text; maybe missing -sub_charenc option
[Parsed_subtitles_0 @ 00000000028d34c0] Error decoding: Invalid data found when processing input (ignored)
[srt @ 00000000028c1580] Invalid UTF-8 in decoded subtitles text; maybe missing -sub_charenc option
[Parsed_subtitles_0 @ 00000000028d34c0] Error decoding: Invalid data found when processing input (ignored)
[srt @ 00000000028c1580] Invalid UTF-8 in decoded subtitles text; maybe missing -sub_charenc option
[Parsed_subtitles_0 @ 00000000028d34c0] Error decoding: Invalid data found when processing input (ignored)
[srt @ 00000000028c1580] Invalid UTF-8 in decoded subtitles text; maybe missing -sub_charenc option
[Parsed_subtitles_0 @ 00000000028d34c0] Error decoding: Invalid data found when processing input (ignored)
[srt @ 00000000028c1580] Invalid UTF-8 in decoded subtitles text; maybe missing -sub_charenc option
[Parsed_subtitles_0 @ 00000000028d34c0] Error decoding: Invalid data found when processing input (ignored)
[AVFilterGraph @ 00000000026eef80] Error initializing filter 'subtitles' with args '1.srt:force_style=Alignment=6,PrimaryColour=&H80ff00,Fontsize=18,MarginL=5,M
arginV=5'
Error initializing complex filters.
Invalid data found when processing input

L:\SRT\BBC.Horizon.2014.Should.I.Eat.Meat.The.Big.Health.Dilemma.720p.HDTV.x264.AAC.MVGroup.org.mkv>ffmpeg -i "1.mkv" -lavfi "subtitles=1.srt:force_style='Align
ment=6,PrimaryColour=&H80ff00,Fontsize=18,MarginL=5,MarginV=5'" -crf 1 -c:a copy "99.mp4" >> 99.txt
ffmpeg version git-2020-06-28-4cfcfb3 Copyright (c) 2000-2020 the FFmpeg developers
  built with gcc 9.3.1 (GCC) 20200621
  configuration: --enable-gpl --enable-version3 --enable-sdl2 --enable-fontconfig --enable-gnutls --enable-iconv --enable-libass --enable-libdav1d --enable-libb
luray --enable-libfreetype --enable-libmp3lame --enable-libopencore-amrnb --enable-libopencore-amrwb --enable-libopenjpeg --enable-libopus --enable-libshine --e
nable-libsnappy --enable-libsoxr --enable-libsrt --enable-libtheora --enable-libtwolame --enable-libvpx --enable-libwavpack --enable-libwebp --enable-libx264 --
enable-libx265 --enable-libxml2 --enable-libzimg --enable-lzma --enable-zlib --enable-gmp --enable-libvidstab --enable-libvmaf --enable-libvorbis --enable-libvo
-amrwbenc --enable-libmysofa --enable-libspeex --enable-libxvid --enable-libaom --enable-libgsm --disable-w32threads --enable-libmfx --enable-ffnvcodec --enable
-cuda-llvm --enable-cuvid --enable-d3d11va --enable-nvenc --enable-nvdec --enable-dxva2 --enable-avisynth --enable-libopenmpt --enable-amf
  libavutil      56. 55.100 / 56. 55.100
  libavcodec     58. 93.100 / 58. 93.100
  libavformat    58. 47.100 / 58. 47.100
  libavdevice    58. 11.100 / 58. 11.100
  libavfilter     7. 86.100 /  7. 86.100
  libswscale      5.  8.100 /  5.  8.100
  libswresample   3.  8.100 /  3.  8.100
  libpostproc    55.  8.100 / 55.  8.100
Input #0, matroska,webm, from '1.mkv':
  Metadata:
    encoder         : libebml v1.3.0 + libmatroska v1.4.1
    creation_time   : 2014-08-19T07:06:49.000000Z
  Duration: 00:59:03.92, start: 0.000000, bitrate: 2653 kb/s
    Stream #0:0(eng): Video: h264 (High), yuv420p(progressive), 1280x720 [SAR 1:1 DAR 16:9], 25 fps, 25 tbr, 1k tbn, 50 tbc (default)
    Metadata:
      _STATISTICS_WRITING_APP: mkvmerge v7.1.0 ('Good Love') 32bit built on Jul 27 2014 12:59:18
      _STATISTICS_WRITING_APP-eng: mkvmerge v7.1.0 ('Good Love') 32bit built on Jul 27 2014 12:59:18
      _STATISTICS_WRITING_DATE_UTC: 2014-08-19 07:06:49
      _STATISTICS_WRITING_DATE_UTC-eng: 2014-08-19 07:06:49
      _STATISTICS_TAGS: BPS DURATION NUMBER_OF_FRAMES NUMBER_OF_BYTES
      _STATISTICS_TAGS-eng: BPS DURATION NUMBER_OF_FRAMES NUMBER_OF_BYTES
      BPS             : 2517029
      BPS-eng         : 2517029
      DURATION        : 00:59:03.920000000
      DURATION-eng    : 00:59:03.920000000
      NUMBER_OF_FRAMES: 88598
      NUMBER_OF_FRAMES-eng: 88598
      NUMBER_OF_BYTES : 1115019080
      NUMBER_OF_BYTES-eng: 1115019080
    Stream #0:1(eng): Audio: aac (LC), 48000 Hz, stereo, fltp (default)
    Metadata:
      _STATISTICS_WRITING_APP: mkvmerge v7.1.0 ('Good Love') 32bit built on Jul 27 2014 12:59:18
      _STATISTICS_WRITING_APP-eng: mkvmerge v7.1.0 ('Good Love') 32bit built on Jul 27 2014 12:59:18
      _STATISTICS_WRITING_DATE_UTC: 2014-08-19 07:06:49
      _STATISTICS_WRITING_DATE_UTC-eng: 2014-08-19 07:06:49
      _STATISTICS_TAGS: BPS DURATION NUMBER_OF_FRAMES NUMBER_OF_BYTES
      _STATISTICS_TAGS-eng: BPS DURATION NUMBER_OF_FRAMES NUMBER_OF_BYTES
      BPS             : 133893
      BPS-eng         : 133893
      DURATION        : 00:59:03.915000000
      DURATION-eng    : 00:59:03.915000000
      NUMBER_OF_FRAMES: 166121
      NUMBER_OF_FRAMES-eng: 166121
      NUMBER_OF_BYTES : 59313396
      NUMBER_OF_BYTES-eng: 59313396
    Stream #0:2(eng): Subtitle: subrip
    Metadata:
      BPS             : 104
      BPS-eng         : 104
      DURATION        : 00:58:35.000000000
      DURATION-eng    : 00:58:35.000000000
      NUMBER_OF_FRAMES: 923
      NUMBER_OF_FRAMES-eng: 923
      NUMBER_OF_BYTES : 46083
      NUMBER_OF_BYTES-eng: 46083
      _STATISTICS_WRITING_APP: mkvmerge v7.1.0 ('Good Love') 32bit built on Jul 27 2014 12:59:18
      _STATISTICS_WRITING_APP-eng: mkvmerge v7.1.0 ('Good Love') 32bit built on Jul 27 2014 12:59:18
      _STATISTICS_WRITING_DATE_UTC: 2014-08-19 07:06:49
      _STATISTICS_WRITING_DATE_UTC-eng: 2014-08-19 07:06:49
      _STATISTICS_TAGS: BPS DURATION NUMBER_OF_FRAMES NUMBER_OF_BYTES
      _STATISTICS_TAGS-eng: BPS DURATION NUMBER_OF_FRAMES NUMBER_OF_BYTES
[Parsed_subtitles_0 @ 00000000028234c0] Shaper: FriBidi 1.0.9 (SIMPLE)
[srt @ 00000000027f06c0] UTF16 is automatically converted to UTF8, do not specify a character encoding
[Parsed_subtitles_0 @ 00000000028234c0] Using font provider directwrite
Stream mapping:
  Stream #0:0 (h264) -> subtitles
  subtitles -> Stream #0:0 (libx264)
  Stream #0:1 -> #0:1 (copy)
Press [q] to stop, [?] for help
[Parsed_subtitles_0 @ 00000000026630c0] Shaper: FriBidi 1.0.9 (SIMPLE)
[srt @ 00000000088dfbc0] UTF16 is automatically converted to UTF8, do not specify a character encoding
[Parsed_subtitles_0 @ 00000000026630c0] Using font provider directwrite
[libx264 @ 00000000026f00c0] using SAR=1/1
[libx264 @ 00000000026f00c0] using cpu capabilities: MMX2 SSE2Fast SSSE3 SSE4.2 AVX FMA3 BMI2 AVX2
[libx264 @ 00000000026f00c0] profile High, level 3.1, 4:2:0, 8-bit
[libx264 @ 00000000026f00c0] 264 - core 160 - H.264/MPEG-4 AVC codec - Copyleft 2003-2020 - http://www.videolan.org/x264.html - options: cabac=1 ref=3 deblock=1
:0:0 analyse=0x3:0x113 me=hex subme=7 psy=1 psy_rd=1.00:0.00 mixed_ref=1 me_range=16 chroma_me=1 trellis=1 8x8dct=1 cqm=0 deadzone=21,11 fast_pskip=1 chroma_qp_
offset=-2 threads=22 lookahead_threads=3 sliced_threads=0 nr=0 decimate=1 interlaced=0 bluray_compat=0 constrained_intra=0 bframes=3 b_pyramid=2 b_adapt=1 b_bia
s=0 direct=1 weightb=1 open_gop=0 weightp=2 keyint=250 keyint_min=25 scenecut=40 intra_refresh=0 rc_lookahead=40 rc=crf mbtree=1 crf=1.0 qcomp=0.60 qpmin=0 qpma
x=69 qpstep=4 ip_ratio=1.40 aq=1:1.00
Output #0, mp4, to '99.mp4':
  Metadata:
    encoder         : Lavf58.47.100
    Stream #0:0: Video: h264 (libx264) (avc1 / 0x31637661), yuv420p, 1280x720 [SAR 1:1 DAR 16:9], q=-1--1, 25 fps, 12800 tbn, 25 tbc (default)
    Metadata:
      encoder         : Lavc58.93.100 libx264
    Side data:
      cpb: bitrate max/min/avg: 0/0/0 buffer size: 0 vbv_delay: N/A
    Stream #0:1(eng): Audio: aac (LC) (mp4a / 0x6134706D), 48000 Hz, stereo, fltp (default)
    Metadata:
      _STATISTICS_WRITING_APP: mkvmerge v7.1.0 ('Good Love') 32bit built on Jul 27 2014 12:59:18
      _STATISTICS_WRITING_APP-eng: mkvmerge v7.1.0 ('Good Love') 32bit built on Jul 27 2014 12:59:18
      _STATISTICS_WRITING_DATE_UTC: 2014-08-19 07:06:49
      _STATISTICS_WRITING_DATE_UTC-eng: 2014-08-19 07:06:49
      _STATISTICS_TAGS: BPS DURATION NUMBER_OF_FRAMES NUMBER_OF_BYTES
      _STATISTICS_TAGS-eng: BPS DURATION NUMBER_OF_FRAMES NUMBER_OF_BYTES
      BPS             : 133893
      BPS-eng         : 133893
      DURATION        : 00:59:03.915000000
      DURATION-eng    : 00:59:03.915000000
      NUMBER_OF_FRAMES: 166121
      NUMBER_OF_FRAMES-eng: 166121
      NUMBER_OF_BYTES : 59313396
      NUMBER_OF_BYTES-eng: 59313396
[Parsed_subtitles_0 @ 00000000026630c0] fontselect: (Arial, 400, 0) -> ArialMT, 0, ArialMT
[Parsed_subtitles_0 @ 00000000026630c0] Glyph 0x751C not found, selecting one more font for (Arial, 400, 0)
[Parsed_subtitles_0 @ 00000000026630c0] fontselect: (Arial, 400, 0) -> MicrosoftYaHeiUI, 1, MicrosoftYaHeiUI
[h264 @ 0000000002680f80] Reference 8 >= 7time=00:26:23.21 bitrate=24863.0kbits/s speed=2.79x
[h264 @ 0000000002680f80] error while decoding MB 8 30, bytestream 6013
[h264 @ 0000000002680f80] concealing 1241 DC, 1241 AC, 1241 MV errors in P frame
frame=88598 fps= 70 q=-1.0 Lsize=10740018kB time=00:59:03.90 bitrate=24826.4kbits/s speed=2.82x
video:10678139kB audio:57923kB subtitle:0kB other streams:0kB global headers:0kB muxing overhead: 0.036845%
[libx264 @ 00000000026f00c0] frame I:605   Avg QP: 0.56  size:328623
[libx264 @ 00000000026f00c0] frame P:26903 Avg QP: 1.54  size:206527
[libx264 @ 00000000026f00c0] frame B:61090 Avg QP: 3.58  size: 84783
[libx264 @ 00000000026f00c0] consecutive B-frames:  3.6% 11.5%  5.3% 79.6%
[libx264 @ 00000000026f00c0] mb I  I16..4: 17.4% 35.0% 47.6%
[libx264 @ 00000000026f00c0] mb P  I16..4:  6.4% 11.1% 14.8%  P16..4: 29.4% 17.2% 14.9%  0.0%  0.0%    skip: 6.2%
[libx264 @ 00000000026f00c0] mb B  I16..4:  1.1%  2.7%  3.4%  B16..8: 38.0% 12.2%  7.2%  direct:10.0%  skip:25.4%  L0:48.3% L1:39.8% BI:11.9%
[libx264 @ 00000000026f00c0] 8x8 transform intra:35.4% inter:33.0%
[libx264 @ 00000000026f00c0] coded y,uvDC,uvAC intra: 95.3% 93.0% 88.3% inter: 53.2% 51.4% 46.0%
[libx264 @ 00000000026f00c0] i16 v,h,dc,p: 21% 18% 20% 41%
[libx264 @ 00000000026f00c0] i8 v,h,dc,ddl,ddr,vr,hd,vl,hu: 24% 23% 20%  4%  5%  5%  6%  6%  6%
[libx264 @ 00000000026f00c0] i4 v,h,dc,ddl,ddr,vr,hd,vl,hu: 23% 23% 13%  6%  9%  7%  7%  6%  6%
[libx264 @ 00000000026f00c0] i8c dc,h,v,p: 49% 21% 19% 11%
[libx264 @ 00000000026f00c0] Weighted P-Frames: Y:1.4% UV:0.7%
[libx264 @ 00000000026f00c0] ref P L0: 67.0% 12.0% 14.2%  6.8%  0.0%
[libx264 @ 00000000026f00c0] ref B L0: 85.2% 11.6%  3.2%
[libx264 @ 00000000026f00c0] ref B L1: 97.8%  2.2%
[libx264 @ 00000000026f00c0] kb/s:24683.21

L:\SRT\BBC.Horizon.2014.Should.I.Eat.Meat.The.Big.Health.Dilemma.720p.HDTV.x264.AAC.MVGroup.org.mkv>dir
 驱动器 L 中的卷是 3TB-L清空
 卷的序列号是 7606-C4C9

 

 

 

 

 


https://blog.csdn.net/ternence_hsu/article/details/108437008
ffmpeg 硬压字幕的实现

常用的字幕格式
webvtt、ass、srt

硬压字幕参数
ffmpeg -i “imput.mp4” -lavfi “subtitles=subtitles.srt:force_style=‘Alignment=0,OutlineColour=&H100000000,BorderStyle=3,Outline=1,Shadow=0,Fontsize=18,MarginL=5,MarginV=25’” -crf 1 -c:a copy “output.mp4”
ffmpeg -i "imput.mp4" -lavfi "subtitles=subtitles.srt:force_style='Alignment=0,OutlineColour=&H100000000,BorderStyle=3,Outline=1,Shadow=0,Fontsize=18,MarginL=5,MarginV=25'" -crf 1 -c:a copy "output.mp4"

参数:
01.Name             风格(Style)的名称. 区分大小写. 不能包含逗号.
02.Fontname         使用的字体名称, 区分大小写.
03.Fontsize         字体的字号
04.PrimaryColour    设置主要颜色, 为蓝-绿-红三色的十六进制代码相排列, BBGGRR. 为字幕填充颜色
05.SecondaryColour  设置次要颜色, 为蓝-绿-红三色的十六进制代码相排列, BBGGRR. 在卡拉OK效果中由次要颜色变为主要颜色.
06.OutlineColour    设置轮廓颜色, 为蓝-绿-红三色的十六进制代码相排列, BBGGRR.
07.BackColour       设置阴影颜色, 为蓝-绿-红三色的十六进制代码相排列, BBGGRR. ASS的这些字段还包含了alpha通道信息. (AABBGGRR), 注ASS的颜色代码要在前面加上&H
08.Bold             -1为粗体, 0为常规
09.Italic           -1为斜体, 0为常规
10.Underline       [-1 或者 0] 下划线
11.Strikeout       [-1 或者 0] 中划线/删除线
12.ScaleX          修改文字的宽度. 为百分数
13.ScaleY          修改文字的高度. 为百分数
14.Spacing         文字间的额外间隙. 为像素数
15.Angle           按Z轴进行旋转的度数, 原点由alignment进行了定义. 可以为小数
16.BorderStyle     1=边框+阴影, 3=纯色背景. 当值为3时, 文字下方为轮廓颜色的背景, 最下方为阴影颜色背景.
17.Outline         当BorderStyle为1时, 该值定义文字轮廓宽度, 为像素数, 常见有0, 1, 2, 3, 4.
18.Shadow          当BorderStyle为1时, 该值定义阴影的深度, 为像素数, 常见有0, 1, 2, 3, 4.
19.Alignment       定义字幕的位置. 字幕在下方时, 1=左对齐, 2=居中, 3=右对齐. 1, 2, 3加上4后字幕出现在屏幕上方. 1, 2, 3加上8后字幕出现在屏幕中间. 例: 11=屏幕中间右对齐. Alignment对于ASS字幕而言, 字幕的位置与小键盘数字对应的位置相同.
20.MarginL         字幕可出现区域与左边缘的距离, 为像素数
21.MarginR         字幕可出现区域与右边缘的距离, 为像素数
22.MarginV         垂直距离

参考:
https://stackoverflow.com/questions/57869367/ffmpeg-subtitles-alignment-and-position
http://www.mamicode.com/info-detail-1764596.html


https://blog.csdn.net/luanjinlu/article/details/78141744
[ffmpeg]加硬字幕

ffmpeg -i demo.mp4 -vf ass=subtitle.ass output.mp4
ffmpeg -i demo.mp4 -vf subtitles=sample.srt out.mp4


https://p3terx.com/archives/add-captions-to-your-videos-with-ffmpeg.html
使用 FFmpeg 为视频添加字幕

ffmpeg -i input.mkv -vf subtitles=subtitles.srt output.mkv
ffmpeg -i input.mkv -vf subtitles=input.mkv output.mp4
ffmpeg -i input.mkv -vf subtitles=input.mkv:si=1 output.mp4

ffmpeg -i subtitles.srt subtitles.ass
ffmpeg -i input.mkv -vf ass=subtitles.ass output.mp4

评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值