Opened 11 years ago

Closed 4 years ago

Last modified 4 years ago

#2874 closed enhancement (fixed)

Export image2 file name as frame metadata

Reported by: Jan Owned by: Alexandre Heitor Schmidt
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 Jan 4 years ago.
2019.12.04_00.45.06.jpg (45.5 KB ) - added by Jan 4 years ago.
With exif data

Download all attachments as: .zip

Change History (26)

comment:1 by Carl Eugen Hoyos, 11 years ago

Keywords: drawtext added
Priority: normalwish

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

comment:2 by Jan, 11 years ago

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 by Carl Eugen Hoyos, 11 years ago

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 by Jan, 11 years ago

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.

in reply to:  4 comment:5 by Carl Eugen Hoyos, 11 years ago

Component: avfilteravformat
Keywords: image2 added
Reproduced by developer: set
Status: newopen
Summary: AVFilter: drawtext: Draw text with information of current image fileExport image2 file name as frame metadata
Version: unspecifiedgit-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 by Jan, 11 years ago

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

in reply to:  6 comment:7 by Carl Eugen Hoyos, 11 years ago

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 by Jan, 11 years ago

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!

in reply to:  4 ; comment:9 by EkriirkE, 10 years ago

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.

in reply to:  9 comment:10 by ACiDSouL-BR, 10 years ago

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 by Alexandre Heitor Schmidt, 8 years ago

Cc: alexandre.schmidt@gmail.com added

comment:12 by Anthony DeRobertis, 8 years ago

Cc: anthony@derobert.net added

comment:13 by Alexandre Heitor Schmidt, 4 years ago

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.

in reply to:  description comment:14 by Alexandre Heitor Schmidt, 4 years ago

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 by Jan, 4 years ago

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)

in reply to:  15 comment:16 by Alexandre Heitor Schmidt, 4 years ago

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.

by Jan, 4 years ago

Attachment: 2019.12.03_22.26.52.jpg added

by Jan, 4 years ago

Attachment: 2019.12.04_00.45.06.jpg added

With exif data

comment:17 by Jan, 4 years ago

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!

in reply to:  17 comment:18 by Alexandre Heitor Schmidt, 4 years ago

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 by Jan, 4 years ago

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 by Alexandre Heitor Schmidt, 4 years ago

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.

comment:21 by Alexandre Heitor Schmidt, 4 years ago

Owner: set to Alexandre Heitor Schmidt

I submitted a patch to the development team:

http://ffmpeg.org/pipermail/ffmpeg-devel/2019-December/254369.html
https://patchwork.ffmpeg.org/patch/16798/

Let's see if it is accepted.

comment:22 by Jan, 4 years ago

Oh wow, that would be great!

comment:24 by Alexandre Heitor Schmidt, 4 years ago

Resolution: fixed
Status: openclosed

The patch was applied: ae436cc5e4d75c1a7deefb2b30820486e2f3d8af

We can close this ticket now.

Last edited 4 years ago by Carl Eugen Hoyos (previous) (diff)
Note: See TracTickets for help on using tickets.