Class: Photein::Video

Inherits:
MediaFile show all
Defined in:
lib/photein/video.rb

Constant Summary collapse

SUPPORTED_FORMATS =
%w(
  .mov
  .mp4
  .webm
).freeze
OPTIMIZATION_FORMAT_MAP =
{
  desktop: { '.mov'  => '.mp4' },
  web: { '.mov'  => '.mp4' }
}.freeze
BITRATE_THRESHOLD =
{
  desktop: 8388608, # 1MB/s
  web:     2097152, # 0.25MB/s
}.freeze
TARGET_CRF =
{
  desktop: '28',
  web:     '35',
}.freeze

Constants inherited from MediaFile

MediaFile::DATE_FORMAT, MediaFile::NORMAL_EXTNAME_MAP

Instance Attribute Summary

Attributes inherited from MediaFile

#path

Instance Method Summary collapse

Methods inherited from MediaFile

for, #import, #initialize

Constructor Details

This class inherits a constructor from Photein::MediaFile

Instance Method Details

#optimize(tempfile:, lib_type:) ⇒ Object



36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
# File 'lib/photein/video.rb', line 36

def optimize(tempfile:, lib_type:)
  return if lib_type == :master
  return if video.bitrate < BITRATE_THRESHOLD[lib_type]

  Photein.logger.info("transcoding #{tempfile}")
  return if Photein::Config.dry_run

  video.transcode(
    tempfile.to_s,
    [
      '-map_metadata', '0', # https://video.stackexchange.com/a/26076
      '-movflags',     'use_metadata_tags',
      '-c:v',          'libx264',
      '-crf',          TARGET_CRF[lib_type],
    ],
    &method(:display_progress_bar)
  )
end