Opened 5 years ago

Closed 15 months ago

#7946 closed enhancement (invalid)

drawtext %{metadata:key} can only pull manually entered tags

Reported by: electron.rotoscope Owned by:
Priority: minor Component: ffmpeg
Version: unspecified Keywords: drawtext metadata
Cc: Blocked By:
Blocking: Reproduced by developer: no
Analyzed by developer: no

Description

Summary of the bug:

ffmpeg's drawtext filter supports text expansion for metadata, but it only seems to be able to read keys that show up in ffprobe packet outputs prepended by "TAG:", which are rare. (I can only find them if I manually insert them via a concat list)
It would be useful to be able to access other packet metadata (e.g. size of current packet) the same way %{n} and %{pts} work.

How to reproduce:
Running the latest ffmpeg on windows, if I don't create a "file_packet_metadata" line in a concat list, there's nothing the %{metadata} can access. It can't access any of the other information that shows up with ffprobe -show_packets

C:\ffmpeg>echo file 'C:\ffmpeg\testfile.mov' > catjustfile.txt

C:\ffmpeg>ffprobe -f concat -safe 0 -show_packets -read_intervals "%+#1" catjustfile.txt
ffprobe version N-93994-gd81913e680 Copyright (c) 2007-2019 the FFmpeg developers
  built with gcc 8.3.1 (GCC) 20190414
  configuration: --enable-gpl --enable-version3 --enable-sdl2 --enable-fontconfig --enable-gnutls --enable-iconv --enable-libass --enable-libdav1d --enable-libbluray --enable-libfreetype --enable-libmp3lame --enable-libopencore-amrnb --enable-libopencore-amrwb --enable-libopenjpeg --enable-libopus --enable-libshine --enable-libsnappy --enable-libsoxr --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-libvorbis --enable-libvo-amrwbenc --enable-libmysofa --enable-libspeex --enable-libxvid --enable-libaom --enable-libmfx --enable-amf --enable-ffnvcodec --enable-cuvid --enable-d3d11va --enable-nvenc --enable-nvdec --enable-dxva2 --enable-avisynth --enable-libopenmpt
  libavutil      56. 28.100 / 56. 28.100
  libavcodec     58. 52.102 / 58. 52.102
  libavformat    58. 27.103 / 58. 27.103
  libavdevice    58.  7.100 / 58.  7.100
  libavfilter     7. 55.100 /  7. 55.100
  libswscale      5.  4.101 /  5.  4.101
  libswresample   3.  4.100 /  3.  4.100
  libpostproc    55.  4.100 / 55.  4.100
Input #0, concat, from 'catjustfile.txt':
  Duration: N/A, start: 0.000000, bitrate: 57 kb/s
    Stream #0:0(eng): Video: prores (Proxy) (apco / 0x6F637061), yuv422p10le(tv, smpte170m/unknown/unknown, progressive), 64x64, 57 kb/s, 25 fps, 25 tbr, 25 tbn, 25 tbc
    Metadata:
      creation_time   : 2019-06-06T23:17:35.000000Z
      handler_name    : Apple Video Media Handler
      encoder         : Apple ProRes 422 (Proxy)
[PACKET]
codec_type=video
stream_index=0
pts=0
pts_time=0.000000
dts=0
dts_time=0.000000
duration=1
duration_time=0.040000
convergence_duration=N/A
convergence_duration_time=N/A
size=288
pos=1569
flags=K_
[/PACKET]

C:\ffmpeg>ffmpeg -f concat -safe 0 -i catjustfile.txt -vf "drawtext=text='%{metadata\:manualkey\:notfound}'" -vframes 1 -y "out1.png"
ffmpeg version N-93994-gd81913e680 Copyright (c) 2000-2019 the FFmpeg developers
  built with gcc 8.3.1 (GCC) 20190414
  configuration: --enable-gpl --enable-version3 --enable-sdl2 --enable-fontconfig --enable-gnutls --enable-iconv --enable-libass --enable-libdav1d --enable-libbluray --enable-libfreetype --enable-libmp3lame --enable-libopencore-amrnb --enable-libopencore-amrwb --enable-libopenjpeg --enable-libopus --enable-libshine --enable-libsnappy --enable-libsoxr --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-libvorbis --enable-libvo-amrwbenc --enable-libmysofa --enable-libspeex --enable-libxvid --enable-libaom --enable-libmfx --enable-amf --enable-ffnvcodec --enable-cuvid --enable-d3d11va --enable-nvenc --enable-nvdec --enable-dxva2 --enable-avisynth --enable-libopenmpt
  libavutil      56. 28.100 / 56. 28.100
  libavcodec     58. 52.102 / 58. 52.102
  libavformat    58. 27.103 / 58. 27.103
  libavdevice    58.  7.100 / 58.  7.100
  libavfilter     7. 55.100 /  7. 55.100
  libswscale      5.  4.101 /  5.  4.101
  libswresample   3.  4.100 /  3.  4.100
  libpostproc    55.  4.100 / 55.  4.100
Input #0, concat, from 'catjustfile.txt':
  Duration: N/A, start: 0.000000, bitrate: 57 kb/s
    Stream #0:0(eng): Video: prores (Proxy) (apco / 0x6F637061), yuv422p10le(tv, smpte170m/unknown/unknown, progressive), 64x64, 57 kb/s, 25 fps, 25 tbr, 25 tbn, 25 tbc
    Metadata:
      creation_time   : 2019-06-06T23:17:35.000000Z
      handler_name    : Apple Video Media Handler
      encoder         : Apple ProRes 422 (Proxy)
Stream mapping:
  Stream #0:0 -> #0:0 (prores (native) -> png (native))
Press [q] to stop, [?] for help
Fontconfig error: Cannot load default config file
[Parsed_drawtext_0 @ 000000000064c6c0] Using "C:/Windows/fonts/mingliu.ttc"
Output #0, image2, to 'out1.png':
  Metadata:
    encoder         : Lavf58.27.103
    Stream #0:0(eng): Video: png, rgb48be, 64x64, q=2-31, 200 kb/s, 25 fps, 25 tbn, 25 tbc
    Metadata:
      creation_time   : 2019-06-06T23:17:35.000000Z
      handler_name    : Apple Video Media Handler
      encoder         : Lavc58.52.102 png
frame=    1 fps=0.0 q=-0.0 Lsize=N/A time=00:00:00.04 bitrate=N/A speed= 2.5x
video:0kB audio:0kB subtitle:0kB other streams:0kB global headers:0kB muxing overhead: unknown

C:\ffmpeg>echo file 'C:\ffmpeg\testfile.mov' > catmanualentry.txt && echo file_packet_metadata manualkey=manualentry >> catmanualentry.txt

C:\ffmpeg>ffprobe -f concat -safe 0 -show_packets -read_intervals "%+#1" catmanualentry.txt
ffprobe version N-93994-gd81913e680 Copyright (c) 2007-2019 the FFmpeg developers
  built with gcc 8.3.1 (GCC) 20190414
  configuration: --enable-gpl --enable-version3 --enable-sdl2 --enable-fontconfig --enable-gnutls --enable-iconv --enable-libass --enable-libdav1d --enable-libbluray --enable-libfreetype --enable-libmp3lame --enable-libopencore-amrnb --enable-libopencore-amrwb --enable-libopenjpeg --enable-libopus --enable-libshine --enable-libsnappy --enable-libsoxr --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-libvorbis --enable-libvo-amrwbenc --enable-libmysofa --enable-libspeex --enable-libxvid --enable-libaom --enable-libmfx --enable-amf --enable-ffnvcodec --enable-cuvid --enable-d3d11va --enable-nvenc --enable-nvdec --enable-dxva2 --enable-avisynth --enable-libopenmpt
  libavutil      56. 28.100 / 56. 28.100
  libavcodec     58. 52.102 / 58. 52.102
  libavformat    58. 27.103 / 58. 27.103
  libavdevice    58.  7.100 / 58.  7.100
  libavfilter     7. 55.100 /  7. 55.100
  libswscale      5.  4.101 /  5.  4.101
  libswresample   3.  4.100 /  3.  4.100
  libpostproc    55.  4.100 / 55.  4.100
Input #0, concat, from 'catmanualentry.txt':
  Duration: N/A, start: 0.000000, bitrate: 57 kb/s
    Stream #0:0(eng): Video: prores (Proxy) (apco / 0x6F637061), yuv422p10le(tv, smpte170m/unknown/unknown, progressive), 64x64, 57 kb/s, 25 fps, 25 tbr, 25 tbn, 25 tbc
    Metadata:
      creation_time   : 2019-06-06T23:17:35.000000Z
      handler_name    : Apple Video Media Handler
      encoder         : Apple ProRes 422 (Proxy)
[PACKET]
codec_type=video
stream_index=0
pts=0
pts_time=0.000000
dts=0
dts_time=0.000000
duration=1
duration_time=0.040000
convergence_duration=N/A
convergence_duration_time=N/A
size=288
pos=1569
flags=K_
TAG:manualkey=manualentry
[SIDE_DATA]
side_data_type=Strings Metadata
[/SIDE_DATA]
[/PACKET]

C:\ffmpeg>ffmpeg -f concat -safe 0 -i catmanualentry.txt -vf "drawtext=text='%{metadata\:manualkey\:notfound}'" -vframes 1 -y "out2.png"
ffmpeg version N-93994-gd81913e680 Copyright (c) 2000-2019 the FFmpeg developers
  built with gcc 8.3.1 (GCC) 20190414
  configuration: --enable-gpl --enable-version3 --enable-sdl2 --enable-fontconfig --enable-gnutls --enable-iconv --enable-libass --enable-libdav1d --enable-libbluray --enable-libfreetype --enable-libmp3lame --enable-libopencore-amrnb --enable-libopencore-amrwb --enable-libopenjpeg --enable-libopus --enable-libshine --enable-libsnappy --enable-libsoxr --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-libvorbis --enable-libvo-amrwbenc --enable-libmysofa --enable-libspeex --enable-libxvid --enable-libaom --enable-libmfx --enable-amf --enable-ffnvcodec --enable-cuvid --enable-d3d11va --enable-nvenc --enable-nvdec --enable-dxva2 --enable-avisynth --enable-libopenmpt
  libavutil      56. 28.100 / 56. 28.100
  libavcodec     58. 52.102 / 58. 52.102
  libavformat    58. 27.103 / 58. 27.103
  libavdevice    58.  7.100 / 58.  7.100
  libavfilter     7. 55.100 /  7. 55.100
  libswscale      5.  4.101 /  5.  4.101
  libswresample   3.  4.100 /  3.  4.100
  libpostproc    55.  4.100 / 55.  4.100
Input #0, concat, from 'catmanualentry.txt':
  Duration: N/A, start: 0.000000, bitrate: 57 kb/s
    Stream #0:0(eng): Video: prores (Proxy) (apco / 0x6F637061), yuv422p10le(tv, smpte170m/unknown/unknown, progressive), 64x64, 57 kb/s, 25 fps, 25 tbr, 25 tbn, 25 tbc
    Metadata:
      creation_time   : 2019-06-06T23:17:35.000000Z
      handler_name    : Apple Video Media Handler
      encoder         : Apple ProRes 422 (Proxy)
Stream mapping:
  Stream #0:0 -> #0:0 (prores (native) -> png (native))
Press [q] to stop, [?] for help
Fontconfig error: Cannot load default config file
[Parsed_drawtext_0 @ 000000000057e740] Using "C:/Windows/fonts/mingliu.ttc"
Output #0, image2, to 'out2.png':
  Metadata:
    encoder         : Lavf58.27.103
    Stream #0:0(eng): Video: png, rgb48be, 64x64, q=2-31, 200 kb/s, 25 fps, 25 tbn, 25 tbc
    Metadata:
      creation_time   : 2019-06-06T23:17:35.000000Z
      handler_name    : Apple Video Media Handler
      encoder         : Lavc58.52.102 png
frame=    1 fps=0.0 q=-0.0 Lsize=N/A time=00:00:00.04 bitrate=N/A speed=1.48x
video:0kB audio:0kB subtitle:0kB other streams:0kB global headers:0kB muxing overhead: unknown

Attachments (3)

testfile.mov (8.6 KB ) - added by electron.rotoscope 5 years ago.
source video (nothing special, just 1 sec of white)
out1.png (339 bytes ) - added by electron.rotoscope 5 years ago.
result of untagged concat list
out2.png (371 bytes ) - added by electron.rotoscope 5 years ago.
result of tagged concat list

Download all attachments as: .zip

Change History (8)

by electron.rotoscope, 5 years ago

Attachment: testfile.mov added

source video (nothing special, just 1 sec of white)

by electron.rotoscope, 5 years ago

Attachment: out1.png added

result of untagged concat list

by electron.rotoscope, 5 years ago

Attachment: out2.png added

result of tagged concat list

comment:1 by electron.rotoscope, 5 years ago

I suppose it would have been clearer if the third command above was

ffmpeg -f concat -safe 0 -i catjustfile.txt -vf "drawtext=text='%{metadata\:size\:notfound}'" -vframes 1 -y "out1.png"

but it's the same result

comment:2 by Elon Musk, 5 years ago

Resolution: invalid
Status: newclosed

the metadata feature of drawtext filter works as designed, it pulls TAGs only.

comment:3 by colemarc, 15 months ago

Resolution: invalid
Status: closedreopened

So I would like to know how to put the following info into a text parameter of a drawtext filter:
1 if the frame is a keyframe
0 if it is not

Currently I have this:

drawtext=text='%{n}%{pts\:hms} %{metadata\:key_frame\:NAkf} %{pict_type} %{metadata\:lavfi.scd.score\:NAscore}'

but key_frame is not recognized, neither is iskey, nor key.

in reply to:  3 comment:4 by electron.rotoscope, 15 months ago

Whether something's a keyframe or not is shown by the pict_type tag, which you already have. I think what comment number 2 had meant is that "metadata" in the sense that it's used by the "metadata" tag in drawtext refers specifically to tags, not intrinsic descriptions; it's for things like GPS coordinates and camera serial number, not things like pixel height.

Replying to colemarc:

So I would like to know how to put the following info into a text parameter of a drawtext filter:
1 if the frame is a keyframe
0 if it is not

Currently I have this:

drawtext=text='%{n}%{pts\:hms} %{metadata\:key_frame\:NAkf} %{pict_type} %{metadata\:lavfi.scd.score\:NAscore}'

but key_frame is not recognized, neither is iskey, nor key.

comment:5 by Elon Musk, 15 months ago

Resolution: invalid
Status: reopenedclosed

This is not support channel.

Note: See TracTickets for help on using tickets.