How to add the timestamp as a part of the generated image file name in ffmpeg

ffmpegfilenames

I am trying to extract png images from a video using ffmpeg and add the timestamp as a part of the generated image file name.

Please see the below command I am using for the same

ffmpeg -vcodec mpeg2video -f mpegts -i test_movie.ts -f image2 -vf "drawtext=fontfile=/Library/Fonts/Tahoma.ttf: timecode='$(date +%H\\:%M\\:%S).00': r=30: x=(w-tw)/2: y=h-(2*lh): fontcolor=white: box=1: boxcolor=0x00000000@1" -vsync vfr -pattern_type glob ./compare_multiple_$(gdate +%H\_%M\_%S_%3N).png

But this is not appending the filename properly. It gives an error as shown below:

[image2 @ 0x7ff01301f600] Could not get frame filename number 2 from
pattern './compare_multiple_10_09_58_490.png' (either set updatefirst
or use a pattern like %03d within the filename pattern)
av_interleaved_write_frame(): Invalid argument frame= 10 fps=0.0
q=-0.0 Lsize=N/A time=00:00:00.12 bitrate=N/A video:1047kB audio:0kB
subtitle:0kB other streams:0kB global headers:0kB muxing overhead:
unknown Conversion failed!

Best Answer

You were close, but the problem is pointed to right from the error message: Your pattern ./compare_multiple_$(gdate +%H\_%M\_%S_%3N).png is incorrect.

In the documenation, when they use "N" in the pattern, "N" is symbolic for the 'integer of your choosing', and in your case, it looks like you want that to be 3. So use %3d instead of %3N and you should be good to go.

Related Question