Reputation: 836
I am trying to overlay a seconds:milliseconds
timestamp on my video, but I have been breaking my head over this for some hours without any result. If I write:
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
the %{pts}
does not get expanded, and only shows the literal text {pts}
on the frame.
Please note that I have read a ton of guides around the web (ffmpeg docs/guides/wikis, stackoverflow, blogs, etc.) on this timestamp overlay stuff, but none of the solutions/syntaxes work: it simply overlays the literal text.
Some context:
ffmpeg
Zeranoe build version git-12a419d (2015-11-23)The full output log:
[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:\]
Upvotes: 2
Views: 2581
Reputation: 28727
Remove the apostrophes around %{pts}
(as proposed by aergistal), and also wrap the percent sign in double quotes, like this.
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
(I also removed the spaces in the -vf parameter, because they are not neccessary.)
You see, the Unix shell but also the Windows commandline make some changes to the commands, and that's why you needed to repeat the backslash like this: \\
. This can get complicated and confusing. Each platform is a little bit different, so it's difficult to give you a working solution without some experimenting. Currently I don't have access to a Windows commandline with a working ffmpeg installation, so I could not test this solution. But I know that percent signs %
are treated specially. It seems that it got eaten by your command line, and that's why you see a literal {pts}
overlaid on the frame.
Please see this StackOverflow answer Is there a way to prevent percent expansion of env variable in Windows command line?
Edit: As the OP added that he used TCC/LE as shell, I proposed doubling the percent sign, like this:
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
This solution was also discussed in the StackOverflow answer mentioned above.
Upvotes: 2