0.0
No commit activity in last 3 years
No release in over 3 years
timestamp_maker is a command-line tool that adds timestamp on assets/videos based on their creation time.
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
 Dependencies

Development

~> 5.14
~> 13.0

Runtime

~> 2.0
~> 1.0
= 0.0.6
 Project Readme

timestamp_maker

timestamp_maker is a command-line tool that adds timestamp on assets/videos based on their creation time.

It looks up the following metadata (ex. EXIF) of the file:

  1. Creation time

  2. GPS coordinate

  3. Time offset

badge

Prerequisite

  1. FFmpeg with both Fontconfig and FreeType enabled

  2. ImageMagick

  3. tzdata

By default, ImageMagick uses Helvetica font. You should either install it or use --font-familiy to speicy another font in your system.

Installation

gem install timestamp_maker

Usage

Quick Start

timestamp assets/in.jpg assets/out-1.jpg
out 1
timestamp assets/in.mp4 assets/out-1.gif
out 1

Customize Appearance

timestamp \
  --format '臺北時間:%Y/%m/%d %H:%M:%S' \
  --font-padding 2 \
  --font-family 'Noto Sans Mono CJK TC' \
  --font-size 16 \
  --font-color black \
  --background-color '#FFFFFFB7' \
  --coordinate-origin bottom-right \
  -x 6 -y 6 \
  assets/in.jpg assets/out-2.jpg
out 2

Customize Time

timestamp \
  --time-zone America/New_York \
  --time '2017-03-12T01:59:56-05:00' \
  assets/in.mp4 assets/out-2.gif
out 2

It handles daylight saving time for you. :)

Run timestamp --help for more information.

Configure TimestampMaker instance

timestamp -r ./config.rb in.mp4 out.mp4
config.rb
TimestampMaker.instance =
  TimestampMaker.new(mime_recognizer: @my_recognizer)

API

require 'timestamp_maker'

TimestampMaker.new.add_timestamp(input_path, output_path)

The snippet above is equivalent to:

require 'timestamp_maker'

TimestampMaker.new.add_timestamp(
  input_path, output_path,
  format: '%Y-%m-%d %H:%M:%S',
  time: nil,
  font_size: 32,
  font_family: 'Sans',
  font_color: 'white',
  background_color: '#000000B3',
  time_zone: nil,
  coordinate_origin: 'top-left',
  x: 32,
  y: 32,
  font_padding: 8
)

Customize MIME Type Recognizer

class FileMime
  def recognize(path)
    command = %W[file --brief --mime-type #{path}]
    stdout_string, status = Open3.capture2(*command)
    stdout_string
  end
end
TimestampMaker.new(mime_recognizer: FileMime.new)

Customize Timezone Lookuper

By default, timestamp_maker uses wheretz to find IANA timezone by given latitude/longitude offline.

Unfortunately, wheretz is not under active maintenance and its' database would outdate some day. We can replae wheretz to other more reliable tools like GeoName, for example:

require 'timestamp_maker/time_zone_lookupers/geo_name'
TM = TimestampMaker
lookup = TM::TimeZoneLookupers::GeoName.new(username: 'YOUR_USERNAME')
TM.new(
  handlers: [
    TM::Handlers::ImageMagick.new(time_zone_lookuper: lookup),
    TM::Handlers::Ffmpeg.new(time_zone_lookuper: lookup)
  ]
)