如何使用ffmpeg在编码的视频中添加字幕?

时间:2019-11-12 12:28:58

标签: ffmpeg

我正在尝试使用此处before回答的选项将srt文件添加到视频中。默认情况下,我的输入文件中有标题。我以各种方式尝试在编码的视频中启用字幕。下面是我使用的命令。

ffmpeg  -i input.ts -i captions.srt -b:a 32000 -ar 48000  -force_key_frames 'expr:gte(t,n_forced*3)' -acodec libfaac -hls_flags single_file -hls_list_size 0 -hls_time 3 -vcodec libx264 -s 320x240 -b:v 512000 -maxrate 512000 -c:s mov_text outfile.ts

但是当我看到编码文件的mediainfo后,看不到标题。您可以看到我的命令的日志文件。

[mpegts @ 0x56412e67b0c0] max_analyze_duration 5000000 reached at 5024000 microseconds st:1
input.ts FPS 29.970030 1
Input #0, mpegts, from 'input.ts':
  Duration: 00:03:00.07, start: 1.400000, bitrate: 2172 kb/s
  Program 1
    Metadata:
      service_name    : Service01
      service_provider: FFmpeg
    Stream #0:0[0x100]: Video: mpeg2video (Main), 1 reference frame ([2][0][0][0] / 0x0002), yuv420p(tv), 704x480 [SAR 10:11 DAR 4:3], Closed Captions, max. 15000 kb/s, 
29.97 fps, 29.97 tbr, 90k tbn, 59.94 tbc
    Stream #0:1[0x101](eng): Audio: ac3 ([129][0][0][0] / 0x0081), 48000 Hz, stereo, fltp, 192 kb/s
Input #1, srt, from 'captions.srt':
  Duration: N/A, bitrate: N/A
    Stream #1:0: Subtitle: subrip
[graph 0 input from stream 0:0 @ 0x56412e678540] w:704 h:480 pixfmt:yuv420p tb:1/90000 fr:30000/1001 sar:10/11 sws_param:flags=2
[scaler for output stream 0:0 @ 0x56412e9caac0] w:320 h:240 flags:'bicubic' interl:0
[scaler for output stream 0:0 @ 0x56412e9caac0] w:704 h:480 fmt:yuv420p sar:10/11 -> w:320 h:240 fmt:yuv420p sar:1/1 flags:0x4
[graph 1 input from stream 0:1 @ 0x56412e9f74e0] tb:1/48000 samplefmt:fltp samplerate:48000 chlayout:0x3
[audio format for output stream 0:1 @ 0x56412e9f7b40] auto-inserting filter 'auto-inserted resampler 0' between the filter 'Parsed_anull_0' and the filter 'audio format 
for output stream 0:1'                                                                                                                                               
[auto-inserted resampler 0 @ 0x56412e9f9f20] ch:2 chl:stereo fmt:fltp r:48000Hz -> ch:2 chl:stereo fmt:s16 r:48000Hz
[libx264 @ 0x56412e9bb8c0] VBV maxrate specified, but no bufsize, ignored
[libx264 @ 0x56412e9bb8c0] using SAR=1/1
[libx264 @ 0x56412e9bb8c0] using cpu capabilities: MMX2 SSE2Fast SSSE3 SSE4.2
[libx264 @ 0x56412e9bb8c0] profile High, level 2.0
[mpegts @ 0x56412e9ba5a0] muxrate VBR, pcr every 2 pkts, sdt every 200, pat/pmt every 40 pkts
Output #0, mpegts, to 'my_encoded_all-3.ts':
  Metadata:
    encoder         : Lavf57.25.100
    Stream #0:0: Video: h264 (libx264), -1 reference frame, yuv420p, 320x240 [SAR 1:1 DAR 4:3], q=-1--1, 512 kb/s, 29.97 fps, 90k tbn, 29.97 tbc
    Metadata:
      encoder         : Lavc57.24.102 libx264
    Side data:
      unknown side data type 10 (24 bytes)
    Stream #0:1(eng): Audio: aac (libfaac), 48000 Hz, stereo, s16, 32 kb/s
    Metadata:
      encoder         : Lavc57.24.102 libfaac
    Stream #0:2(eng): Subtitle: subrip (srt), 320x240
        Metadata:
          encoder         : Lavc57.24.102 srt
    Stream mapping:
      Stream #0:0 -> #0:0 (mpeg2video (native) -> h264 (libx264))
      Stream #0:1 -> #0:1 (ac3 (native) -> aac (libfaac))
      Stream #1:0 -> #0:2 (subrip (srt) -> subrip (srt))
Press [q] to stop, [?] for help
[scaler for output stream 0:0 @ 0x56412e9caac0] w:704 h:480 fmt:yuv420p sar:40/33 -> w:320 h:240 fmt:yuv420p sar:4/3 flags:0x4
No more output streams to write to, finishing.e=00:02:58.85 bitrate= 658.4kbits/s speed=13.2x
frame= 5377 fps=385 q=-1.0 Lsize=   16672kB time=00:59:16.18 bitrate=  38.4kbits/s speed= 255x
video:11401kB audio:1410kB subtitle:446kB other streams:0kB global headers:0kB muxing overhead: 25.753614%
Input file #0 (input.ts):
  Input stream #0:0 (video): 5380 packets read (40279443 bytes); 5377 frames decoded; 
  Input stream #0:1 (audio): 5625 packets read (4320000 bytes); 5625 frames decoded (8640000 samples); 
  Total: 11005 packets (44599443 bytes) demuxed
Input file #1 (captions.srt):
  Input stream #1:0 (subtitle): 10972 packets read (447147 bytes); 10972 frames decoded; 
  Total: 10972 packets (447147 bytes) demuxed
Output file #0 (output.ts):
  Output stream #0:0 (video): 5377 frames encoded; 5377 packets muxed (11675098 bytes); 
  Output stream #0:1 (audio): 8438 frames encoded (8640000 samples); 8439 packets muxed (1444109 bytes); 
  Output stream #0:2 (subtitle): 10972 frames encoded; 10972 packets muxed (456619 bytes); 
  Total: 24788 packets (13575826 bytes) muxed
[libx264 @ 0x56412e9bb8c0] frame I:81    Avg QP:15.08  size: 16370
[libx264 @ 0x56412e9bb8c0] frame P:2312  Avg QP:17.77  size:  3393
[libx264 @ 0x56412e9bb8c0] frame B:2984  Avg QP:22.38  size:   839
[libx264 @ 0x56412e9bb8c0] consecutive B-frames: 20.6% 13.2%  9.4% 56.8%
[libx264 @ 0x56412e9bb8c0] mb I  I16..4: 11.6% 37.0% 51.4%
[libx264 @ 0x56412e9bb8c0] mb P  I16..4:  1.2%  3.2%  2.4%  P16..4: 33.7% 18.0% 15.7%  0.0%  0.0%    skip:25.6%
[libx264 @ 0x56412e9bb8c0] mb B  I16..4:  0.2%  0.3%  0.2%  B16..8: 30.7%  9.2%  3.2%  direct: 5.1%  skip:51.1%  L0:33.6% L1:44.5% BI:21.9%
[libx264 @ 0x56412e9bb8c0] final ratefactor: 16.76
[libx264 @ 0x56412e9bb8c0] 8x8 transform intra:43.0% inter:49.8%
[libx264 @ 0x56412e9bb8c0] coded y,uvDC,uvAC intra: 77.9% 85.1% 68.8% inter: 22.9% 21.7% 6.0%
[libx264 @ 0x56412e9bb8c0] i16 v,h,dc,p: 30% 38%  5% 26%
[libx264 @ 0x56412e9bb8c0] i8 v,h,dc,ddl,ddr,vr,hd,vl,hu: 21% 23% 18%  4%  5%  7%  6%  7%  8%
[libx264 @ 0x56412e9bb8c0] i4 v,h,dc,ddl,ddr,vr,hd,vl,hu: 28% 23% 11%  5%  6%  8%  6%  7%  6%
[libx264 @ 0x56412e9bb8c0] i8c dc,h,v,p: 46% 24% 21%  8%
[libx264 @ 0x56412e9bb8c0] Weighted P-Frames: Y:4.2% UV:2.6%
[libx264 @ 0x56412e9bb8c0] ref P L0: 73.3% 10.9% 11.1%  4.5%  0.1%
[libx264 @ 0x56412e9bb8c0] ref B L0: 92.1%  6.3%  1.6%
[libx264 @ 0x56412e9bb8c0] ref B L1: 97.4%  2.6%

我发现编码没有问题,但看不到输出编码视频中启用的字幕。我在VLC播放器中播放过。没有字幕的音轨。

我们不能在编码时在视频中添加字幕吗?

在实现这一目标方面的任何帮助将不胜感激。

0 个答案:

没有答案