video-gif-previewer 0.1.2.1 → 0.1.3.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: b2b325311e19a74076204cc56dbfd8815c3e4c2cd6653045ff2e7da1e78f0fc4
4
- data.tar.gz: ae351ad22913a542313c2bb94ebf2df684713cb23e48555bd0ff19831094388f
3
+ metadata.gz: ee961361f5876c75ef0109affe91f3beb440c756915bd1a9ef54aff44bd04fde
4
+ data.tar.gz: d038b99d923cbc64d4445d1ae88f69d891430042e2960d750225e41bec2170f9
5
5
  SHA512:
6
- metadata.gz: 790563509871a5209c51a05e65aebc513d2c7067e1b80da6ad70a2cc26dc1ff0ca9b02c9c0280d0df5b2069dd8eaea3629cdb5efd3c65cbad92ca2fdc4c2efe3
7
- data.tar.gz: 9c06563698db999a6d876c7d1175a08a475f7641d7889cae4aefc3fabac50268c2c142ff2e8d14145240d942a5a6cdcd3ebd98b79776f526a2083d40c5d41584
6
+ metadata.gz: 3d103901c922dc46b8c01ea8533aeec11596d653387aa5b9b1c4551ab75651184a421f6c2615d1e0884f975a37033c621777853cce27e2b86431ef1b275f98c4
7
+ data.tar.gz: 71b6475ba293135be873eec14caf814da0f3e11245173908b9edc934c81f2c0174b4fa497ebcef4e4c2685e4c789719c178ba3152908840be3a88bc1fc17f1f9
data/lib/gif_previewer.rb CHANGED
@@ -4,6 +4,8 @@ require 'timeout'
4
4
 
5
5
  class GifPreviewer < ActiveStorage::Previewer::VideoPreviewer
6
6
  MAX_PROCESSING_TIME = 60
7
+ LONG_FILE_DURATION = 1200
8
+ LONG_FILE_DEFAULT_START = 60
7
9
 
8
10
  def preview(**options)
9
11
  Rails.logger.info(msg: 'Downloading Blob', blob: @blob)
@@ -61,11 +63,11 @@ class GifPreviewer < ActiveStorage::Previewer::VideoPreviewer
61
63
  end
62
64
 
63
65
  def start_frame(file_duration:)
64
- if file_duration > 300
66
+ if file_duration > LONG_FILE_DURATION
65
67
  # if the file is fairly long (> 5m) start around ~1m into the file to avoid long processing
66
- 60
68
+ LONG_FILE_DEFAULT_START
67
69
  elsif file_duration > 10
68
- # if file is not super long, use file_duration to either pick a random place ~33% into the file
70
+ # if file is not super long, use file_duration to pick a random place ~33% into the file
69
71
  mid_frame = (file_duration.to_f / 3).floor
70
72
  mid_frame > 3 ? mid_frame : 3
71
73
  else
@@ -100,14 +102,33 @@ class GifPreviewer < ActiveStorage::Previewer::VideoPreviewer
100
102
  'end (to)': end_frame_num,
101
103
  )
102
104
  Timeout::timeout(MAX_PROCESSING_TIME) do
103
- draw self.class.ffmpeg_path,
104
- '-i', file.path,
105
- '-filter_complex', "fps=10,scale=360:-1[s]; [s]split[a][b]; [a]palettegen[palette]; [b][palette]paletteuse",
106
- '-f', 'gif',
107
- '-ss', start_frame_num.to_s,
108
- '-to', end_frame_num.to_s,
109
- '-',
110
- &block
105
+ if ENV.fetch('RAILS_VIDEO_GIF_FORCE_BASIC')
106
+ basic_gif_preview(file:, start_frame_num:, end_frame_num:, &block)
107
+ else
108
+ pallet_gif_preview(file:, start_frame_num:, end_frame_num:, &block)
109
+ end
111
110
  end
112
111
  end
112
+
113
+ def pallet_gif_preview(file:, start_frame_num:, end_frame_num:, &block)
114
+ draw self.class.ffmpeg_path,
115
+ '-i', file.path,
116
+ '-filter_complex', "fps=10,scale=360:-1[s]; [s]split[a][b]; [a]palettegen[palette]; [b][palette]paletteuse",
117
+ '-f', 'gif',
118
+ '-ss', start_frame_num.to_s,
119
+ '-to', end_frame_num.to_s,
120
+ '-',
121
+ &block
122
+ end
123
+
124
+ def basic_gif_preview(file:, start_frame_num:, end_frame_num:, &block)
125
+ draw self.class.ffmpeg_path,
126
+ '-i', file.path,
127
+ '-filter_complex', "fps=10",
128
+ '-f', 'gif',
129
+ '-ss', start_frame_num.to_s,
130
+ '-to', end_frame_num.to_s,
131
+ '-',
132
+ &block
133
+ end
113
134
  end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  class VideoGifPreviewer
4
- VERSION = '0.1.2.1'
4
+ VERSION = '0.1.3.1'
5
5
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: video-gif-previewer
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.2.1
4
+ version: 0.1.3.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Brian Haberer
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2025-05-16 00:00:00.000000000 Z
11
+ date: 2025-05-28 00:00:00.000000000 Z
12
12
  dependencies: []
13
13
  description: Generate rails active storage video previews as gifs
14
14
  email: bhaberer@gmail.com