ffmpeg 无法扩展 drawtext

ffmpeg failing to expand drawtext

我想在我的视频上叠加一个 seconds:milliseconds 时间戳,但我已经为此苦思了几个小时,但没有任何结果。如果我写:

ffmpeg -f lavfi -i testsrc=duration=5:size=800x600:rate=30 -vf drawtext="fontfile=C\:/Windows/Fonts/arial.ttf:text='%{pts}': x=(w-tw)/2: y=h-(2*lh): fontcolor=white: box=1: boxcolor=0x00000000@1" -preset ultrafast output.mp4

%{pts} 不会展开,只会在框架上显示文字 {pts}

请注意,我已经阅读了大量有关此时间戳覆盖内容的网络指南(ffmpeg docs/guides/wikis、Whosebug、博客等),但是 none [=35] =] 工作:它只是覆盖文字文本。

一些上下文:

完整输出日志:

[E:\]ffmpeg -f lavfi -i testsrc=duration=5:size=800x600:rate=30 -vf drawtext="fontfile=C\:/Windows/Fonts/arial.ttf:text=%{pts}: x=(w-tw)/2: y=h-(2*lh): fontcolor=white: box=1: boxcolor=0x00000000@1" -preset ultrafast output.mp4
ffmpeg version N-76822-g12a419d Copyright (c) 2000-2015 the FFmpeg developers
  built with gcc 5.2.0 (GCC)
  configuration: --enable-gpl --enable-version3 --disable-w32threads --enable-avisynth --enable-bzlib --enable-fontconfig --enable-frei0r --enable-gnutls --enable-iconv --enable-libass --enable-libbluray --enable-libbs2b --enable-libcaca --enable-libdcadec --enable-libfreetype --enable-libgme --enable-libgsm --enable-libilbc --enable-libmodplug --enable-libmp3lame --enable-libopencore-amrnb --enable-libopencore-amrwb --enable-libopenjpeg --enable-libopus --enable-librtmp --enable-libschroedinger --enable-libsoxr --enable-libspeex --enable-libtheora --enable-libtwolame --enable-libvidstab --enable-libvo-aacenc --enable-libvo-amrwbenc --enable-libvorbis --enable-libvpx --enable-libwavpack --enable-libwebp --enable-libx264 --enable-libx265 --enable-libxavs --enable-libxvid --enable-libzimg --enable-lzma --enable-decklink --enable-zlib
  libavutil      55.  9.100 / 55.  9.100
  libavcodec     57. 16.100 / 57. 16.100
  libavformat    57. 19.100 / 57. 19.100
  libavdevice    57.  0.100 / 57.  0.100
  libavfilter     6. 15.100 /  6. 15.100
  libswscale      4.  0.100 /  4.  0.100
  libswresample   2.  0.101 /  2.  0.101
  libpostproc    54.  0.100 / 54.  0.100
Input #0, lavfi, from 'testsrc=duration=5:size=800x600:rate=30':
  Duration: N/A, start: 0.000000, bitrate: N/A
    Stream #0:0: Video: rawvideo (RGB[24] / 0x18424752), rgb24, 800x600 [SAR 1:1 DAR 4:3], 30 tbr, 30 tbn, 30 tbc
File 'output.mp4' already exists. Overwrite ? [y/N] y
No pixel format specified, yuv444p for H.264 encoding chosen.
Use -pix_fmt yuv420p for compatibility with outdated media players.
[libx264 @ 00000000003f83c0] using SAR=1/1
[libx264 @ 00000000003f83c0] using cpu capabilities: MMX2 SSE2Fast SSSE3 Cache64 SlowShuffle
[libx264 @ 00000000003f83c0] profile High 4:4:4 Predictive, level 3.1, 4:4:4 8-bit
[libx264 @ 00000000003f83c0] 264 - core 148 r2638 7599210 - H.264/MPEG-4 AVC codec - Copyleft 2003-2015 - http://www.videolan.org/x264.html - options: cabac=0 ref=1 deblock=0:0:0 analyse=0:0 me=dia subme=0 psy=1 psy_rd=1.00:0.00 mixed_ref=0 me_range=16 chroma_me=1 trellis=0 8x8dct=0 cqm=0 deadzone=21,11 fast_pskip=1 chroma_qp_offset=6 threads=3 lookahead_threads=1 sliced_threads=0 nr=0 decimate=1 interlaced=0 bluray_compat=0 constrained_intra=0 bframes=0 weightp=0 keyint=250 keyint_min=25 scenecut=0 intra_refresh=0 rc=crf mbtree=0 crf=23.0 qcomp=0.60 qpmin=0 qpmax=69 qpstep=4 ip_ratio=1.40 aq=0
Output #0, mp4, to 'output.mp4':
  Metadata:
    encoder         : Lavf57.19.100
    Stream #0:0: Video: h264 (libx264) ([33][0][0][0] / 0x0021), yuv444p, 800x600 [SAR 1:1 DAR 4:3], q=-1--1, 30 fps, 15360 tbn, 30 tbc
    Metadata:
      encoder         : Lavc57.16.100 libx264
Stream mapping:
  Stream #0:0 -> #0:0 (rawvideo (native) -> h264 (libx264))
Press [q] to stop, [?] for help
frame=  150 fps= 61 q=-1.0 Lsize=     185kB time=00:00:05.00 bitrate= 303.2kbits/s
video:184kB audio:0kB subtitle:0kB other streams:0kB global headers:0kB muxing overhead: 0.755086%
[libx264 @ 00000000003f83c0] frame I:1     Avg QP:20.00  size: 18409
[libx264 @ 00000000003f83c0] frame P:149   Avg QP:16.11  size:  1135
[libx264 @ 00000000003f83c0] mb I  I16..4: 100.0%  0.0%  0.0%
[libx264 @ 00000000003f83c0] mb P  I16..4:  0.7%  0.0%  0.0%  P16..4:  5.1%  0.0%  0.0%  0.0%  0.0%    skip:94.2%
[libx264 @ 00000000003f83c0] coded y,u,v intra: 5.0% 3.3% 2.8% inter: 1.1% 1.0% 0.9%
[libx264 @ 00000000003f83c0] i16 v,h,dc,p: 81%  6%  2% 11%
[libx264 @ 00000000003f83c0] kb/s:299.93

[E:\]

去掉 %{pts} 两边的撇号(按照 aergistal 的建议),并将百分号用双引号括起来,像这样。

ffmpeg -f lavfi -i testsrc=duration=5:size=800x600:rate=30 -vf drawtext=
"fontfile=C\:/Windows/Fonts/arial.ttf:text="%"{pts}:x=(w-tw)/2:y=h-(2*lh):
fontcolor=white:box=1:boxcolor=0x00000000@1" -preset ultrafast output.mp4

(我还删除了 -vf 参数中的空格,因为它们不是必需的。)

你看,Unix shell 以及 Windows 命令行对命令进行了一些更改,这就是为什么你需要像这样重复反斜杠:\。这可能会变得复杂和混乱。每个平台都略有不同,因此如果不进行一些试验,很难为您提供可行的解决方案。目前我无法使用有效的 ffmpeg 安装访问 Windows 命令行,因此我无法测试此解决方案。但我知道百分号 % 被特殊对待。它似乎被您的命令行吞噬了,这就是为什么您会在框架上看到文字 {pts} 的原因。

请查看这个 Whosebug 答案

编辑:由于 OP 补充说他将 TCC/LE 用作 shell,我建议将百分号加倍,如下所示:

ffmpeg -f lavfi -i testsrc=duration=5:size=800x600:rate=30 -vf drawtext=
"fontfile=C\:/Windows/Fonts/arial.ttf:text=%%{pts}:x=(w-tw)/2:y=h-(2*lh):
fontcolor=white:box=1:boxcolor=0x00000000@1" -preset ultrafast output.mp4

上面提到的 Whosebug 回答中也讨论了这个解决方案。