Opened 6 years ago

Last modified 17 hours ago

#2874 open enhancement

Export image2 file name as frame metadata

Reported by: jlubeck Owned by:
Priority: wish Component: avformat
Version: git-master Keywords: drawtext image2
Cc: alexandre.schmidt@gmail.com, anthony@derobert.net Blocked By:
Blocking: Reproduced by developer: yes
Analyzed by developer: no

Description

I'm creating a timelapse which I would love to include the "timecode" of when each picture was taken.

Currently, the timecode option creates one for everyframe of the video.

Also, using text='\%T' seems to work only for real-time streams.

I have files named:
2013-08-16_001032.jpg
2013-08-16_002045.jpg
2013-08-16_003024.jpg
2013-08-16_004043.jpg
and so on... That is year-month-date_hourminutesecond.jpg

I'm currently using the following:

% ffmpeg -y -i "2013-08-14_%*.jpg" -vf "drawtext=fontfile=/Library/Fonts/AppleGothic?.ttf: text=%{n}:expansion=normal: r=25: x=(w-tw)/2: y=h-(2*lh): fontcolor=white: box=1: boxcolor=0x00000000@1" output.m4v

And it is printing a new number on each frame. It would be great if instead of %{n} we could use something to grab the filename, or even better, meta data from the jpg to be able to format the timestamp. But just with the file name would be great.

ffmpeg version 1.2.1

Thanks!

Attachments (2)

2019.12.03_22.26.52.jpg (53.2 KB) - added by jlubeck 44 hours ago.
2019.12.04_00.45.06.jpg (45.5 KB) - added by jlubeck 43 hours ago.
With exif data

Download all attachments as: .zip

Change History (22)

comment:1 Changed 6 years ago by cehoyos

  • Keywords drawtext added
  • Priority changed from normal to wish

What metadata are you referring to? / Please provide a sample input file.

comment:2 Changed 6 years ago by jlubeck

I don't know if meta data is the right word. I meant the information that any file has on an operating system. Like "Created Date", "Modified Date", etc

comment:3 Changed 6 years ago by cehoyos

Could you elaborate more on the use case? I thought what is interesting is the actual frame metadata of the file (like image creation time or image orientation or song name) and not information that the operating system provides for the file. Note that input generally does not have to be a file.

comment:4 follow-ups: Changed 6 years ago by jlubeck

Oh yes, actual frame metadata would be great if someone was getting pictures from an actual camera. It is not my actual use case though, but whoever handles this enhancement could go way past my personal requirement.

My current use case is that I made a script that captures a screenshot of my desktop every n seconds.

At the end of the day, all the screenshots are compiled into a video with FFMPEG.

What I would like is to print into the video the date/time of each frame.

comment:5 in reply to: ↑ 4 Changed 6 years ago by cehoyos

  • Component changed from avfilter to avformat
  • Keywords image2 added
  • Reproduced by developer set
  • Status changed from new to open
  • Summary changed from AVFilter: drawtext: Draw text with information of current image file to Export image2 file name as frame metadata
  • Version changed from unspecified to git-master

Replying to jlubeck:

Oh yes, actual frame metadata would be great if someone was getting pictures from an actual camera. It is not my actual use case though, but whoever handles this enhancement could go way past my personal requirement.

This works with current FFmpeg.

My current use case is that I made a script that captures a screenshot of my desktop every n seconds.

At the end of the day, all the screenshots are compiled into a video with FFMPEG.

What I would like is to print into the video the date/time of each frame.

This sounds as if it would be simpler to use ffmpeg for the screen capture.

Adding the current file name as frame metadata should fix your problem.

comment:6 follow-up: Changed 6 years ago by jlubeck

I'm sorry, I don't know if I understood you correctly. You say I can already do what I need?
Could you share an example?

Thank you very much for your help

comment:7 in reply to: ↑ 6 Changed 6 years ago by cehoyos

Replying to jlubeck:

I'm sorry, I don't know if I understood you correctly. You say I can already do what I need?

No, you don't want frame metadata (as you explained in comment:4) , you want the filename (which is available within the demuxer but not currently exported as metadata) or as an alternative other file information that is currently not available within ffmpeg.

comment:8 Changed 6 years ago by jlubeck

Oh, ok. Thanks for clearing that up. I figured later that the enhancement wouldn't still be open if I could do it now.

Thanks again!

comment:9 in reply to: ↑ 4 ; follow-up: Changed 6 years ago by EkriirkE

Replying to jlubeck:

Oh yes, actual frame metadata would be great if someone was getting pictures from an actual camera. It is not my actual use case though, but whoever handles this enhancement could go way past my personal requirement.

My current use case is that I made a script that captures a screenshot of my desktop every n seconds.

At the end of the day, all the screenshots are compiled into a video with FFMPEG.

What I would like is to print into the video the date/time of each frame.

I have a similar case; I have these cheap WiFi? security cameras that write jpgs to an FTP, the JPGs have the camera MAC, alias, and timestamp in the filename. It would be fantastic to get the source frame's file name overlaid on a compiled video.

comment:10 in reply to: ↑ 9 Changed 6 years ago by acidsoulbr

Replying to EkriirkE:

I have a similar case; I have these cheap WiFi? security cameras that write jpgs to an FTP, the JPGs have the camera MAC, alias, and timestamp in the filename. It would be fantastic to get the source frame's file name overlaid on a compiled video.

Looking for a way to use source frame's file name as overlay text, I found this proposal. I am exactly in the same case of having a cheap WiFi? security camera that writes jpgs to an FTP, the JPGs have the camera MAC address, alias (cam name), and timestamp of acquired image in the filename - all things that I would find cool to have in the overlay text.

comment:11 Changed 4 years ago by AlexSmith

  • Cc alexandre.schmidt@gmail.com added

comment:12 Changed 4 years ago by derobert

  • Cc anthony@derobert.net added

comment:13 Changed 7 days ago by AlexSmith

While this is not marked as solved, a handy solution is to define a tag within each image with the desired value. In this case, I'm defining tag ImageDescription? to contain the path to each file found. Like this:

find -name "*.JPG" -exec exif --tag="ImageDescription" --ifd=0 --set-value="{}" --output="{}" "{}" \;

Or, if you need more control over what's being saved to the metatag, you can use:

find -name "*.JPG" | while read f; do exif --tag="ImageDescription?" --ifd=0 --set-value="$f" --output="$f" "$f"; done

Then issuing something ffmpeg like this:

ffmpeg -f image2 -pattern_type glob -framerate 12 -i '/path/to/some/dir/*.JPG' -s 1920x1080 -b:v 3M -filter_complex drawtext="fontsize=h/20:fontcolor=white:fontfile=/usr/share/fonts/truetype/freefont/FreeSans.ttf:text='%{metadata\:DateTime\:notfound}':x=0:y=100",drawtext="fontsize=h/20:fontcolor=white:fontfile=/usr/share/fonts/truetype/freefont/FreeSans.ttf:text='%{metadata\:ImageDescription\:NA}':x=0:y=250" foo.avi

The above will use drawtext for two things:

  1. Drawing the contents of DateTime? metadata.
  2. Drawing the contents of ImageDescription? metadata.

Hope this helps someone out there.

comment:14 in reply to: ↑ description Changed 7 days ago by AlexSmith

Replying to jlubeck:

It would be great if instead of %{n} we could use something to grab the filename, or even better, meta data from the jpg to be able to format the timestamp. But just with the file name would be great.

It is possible to read the image's metadata and draw it on top of each frame by using the 'drawtext=' filter. For example, to read the DateTime? metadata from each frame, one can use:

drawtext="text='%{metadata\:DateTime\:def_value}'"

Currently there's no way to print the input file name, unless some additional steps are taken, like shown here: https://trac.ffmpeg.org/ticket/2874#comment:13

ffmpeg version 3.4.6-0ubuntu0.18.04.1

comment:15 follow-up: Changed 3 days ago by jlubeck

Am I living in the Matrix and this is all in my head? I can't believe I got a reply from this ticket that I made 6 years ago and I needed to do again, but now for a work thing instead of a hobby! I'm freaking out. Let me try what you mentioned on https://trac.ffmpeg.org/ticket/2874#comment:13 (as unfortunately the images that are being delivered to me have no metadata associated so I can't use the DateTime? thing)

comment:16 in reply to: ↑ 15 Changed 3 days ago by AlexSmith

In the last days I've been trying to find out how metatags are populated when image2 reads the input files. My idea is to add a new parameter containing the input filename, so it could be used by drawtext filter. But man... What a pain! Wish me luck! Maybe I can patch image2 so that it can send this info to other filters and make it happen.

Changed 44 hours ago by jlubeck

Changed 43 hours ago by jlubeck

With exif data

comment:17 follow-up: Changed 43 hours ago by jlubeck

Hey Alex, I just attached 2 jpgs. The first one is an original that comes from my camera. The second is one which I added the DateTime? field with exif. I can see the field with exif as well. But ffmpeg and ffprobe don't show any metadata at all. Any idea what might be wrong? I don't have access to the files I used 6 years ago, so I can't remember what was going on back then. But if I mentioned medatada, I'm sure I was at least getting SOMETHING. I'd appreciate any help!

comment:18 in reply to: ↑ 17 Changed 31 hours ago by AlexSmith

Hi, jlubeck!

Make sure you're using exif the right way. For example:

exif -c --tag="DateTime" --ifd=0 --set-value="2011-12-13 14:15:16" --output="/tmp/new.jpg" /tmp/2019.12.03_22.26.52.jpg

Note -c was necessary here as your original image appears to not have an EXIF header.

After this, we can see the frame with ffprobe:

$ ffprobe -i new.jpg -show_frames
[FRAME]
media_type=video
stream_index=0
key_frame=1
pkt_pts=0
pkt_pts_time=0.000000
pkt_dts=0
pkt_dts_time=0.000000
best_effort_timestamp=0
best_effort_timestamp_time=0.000000
pkt_duration=1
pkt_duration_time=0.040000
pkt_pos=N/A
pkt_size=54705
width=1280
height=720
pix_fmt=yuvj420p
sample_aspect_ratio=1:1
pict_type=I
coded_picture_number=0
display_picture_number=0
interlaced_frame=0
top_field_first=0
repeat_pict=0
color_range=pc
color_space=bt470bg
color_primaries=unknown
color_transfer=unknown
chroma_location=center
TAG:XResolution=     72:1      
TAG:YResolution=     72:1      
TAG:ResolutionUnit=    2
TAG:DateTime=2011-12-13 14:15:16     <<<-------
TAG:YCbCrPositioning=    1
TAG:ExifVersion= 48,  50,  49,  48
TAG:ComponentsConfiguration=  1,   2,   3,   0
TAG:FlashpixVersion= 48,  49,  48,  48
TAG:ColorSpace=65535
TAG:PixelXDimension=      0
TAG:PixelYDimension=      0
[/FRAME]

This is what interests us:

TAG:DateTime=2011-12-13 14:15:16

Then we can use this tag with drawtext. For example:

ffmpeg -f image2 -i new.jpg -filter_complex drawtext="fontsize=50:fontcolor=white:fontfile=/usr/share/fonts/truetype/freefont/FreeSans.ttf:borderw=2:bordercolor=black:text='%{metadata\:DateTime\:notfound}':x=100:y=100" out.avi

Hope that helps...

comment:19 Changed 18 hours ago by jlubeck

Dude... DUDE!! You are THE BEST. You finally resolved an issue I had after 6 years!!
Thank you so much man

I don't know if the ticket itself should be solved, as it would be nice to have the filter get the filename directly without having to resort to external tools. But still, Alex, from the bottom of my heart. Thank you!!

comment:20 Changed 17 hours ago by AlexSmith

I'm happy to help you, my friend! If you don't mind, I'd leave the ticket opened until we find a way to make filename available as a meta for drawtext filter. That would be desirable for all people using image2.

Note: See TracTickets for help on using tickets.