video-gif-previewer 0.1.2 → 0.1.3

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: 292c2cc47f8ede9e3a0ee23a79e971599be7de0cffc81602f2e494a5e13daeb7
4
- data.tar.gz: 6de21e7755a025814b7343df160ce7348715ed4a47c3aeedf001aea74991de76
3
+ metadata.gz: b015e3b3e0ccb4c9dc91ce011c219ab3b920fe4675fbb9249dc2f470044a5658
4
+ data.tar.gz: a6af13b82e337777122b49dec038fbeec9a444315e38ecad9de816be38eb65dc
5
5
  SHA512:
6
- metadata.gz: df66a6f10b8b7ce17f854f550d1485de29aaea08358f4f193622dc8aafb69aaeb6dc4d12262067c7309bbf284740f936b131551cb45656d35d846ccc068276bb
7
- data.tar.gz: fa832e3f7318c9939d68f73e3bdec938e1ef2c3a239d44b1965af24ad9f390f099aa5a996c45afd56757d60a1917489ed993a41d9caba1e9ff0dfa99537845b0
6
+ metadata.gz: 6c8aec9d500f8d838c8a6804e6a2c3c783ebfb6f33df4d345b4ba25fce50df33e708af879be383fe829027daea672560c6607cfec682f230a9c15a3079ac4074
7
+ data.tar.gz: 63b27323f2f4ea277efd36d6c66e7d7a8b14fd276146a8fdd1c16d4022a7d5c069eac8a3911df6b5dcf6fa5323b72d17dc9370d25ed43881e3ef8c5ff2e9ec27
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)
@@ -60,12 +62,16 @@ class GifPreviewer < ActiveStorage::Previewer::VideoPreviewer
60
62
  `#{ffprobe_path} -v error -show_entries format=duration -of default=noprint_wrappers=1:nokey=1 #{input_file.path}`.to_f.floor.to_i
61
63
  end
62
64
 
63
- # Use file_duration to either pick a random place ~33% into the file, or if the file is too short, use 0
64
65
  def start_frame(file_duration:)
65
- if file_duration > 10
66
+ if file_duration > LONG_FILE_DURATION
67
+ # if the file is fairly long (> 5m) start around ~1m into the file to avoid long processing
68
+ LONG_FILE_DEFAULT_START
69
+ elsif file_duration > 10
70
+ # if file is not super long, use file_duration to pick a random place ~33% into the file
66
71
  mid_frame = (file_duration.to_f / 3).floor
67
72
  mid_frame > 3 ? mid_frame : 3
68
73
  else
74
+ # if the file is too short, just start from 0
69
75
  0
70
76
  end
71
77
  end
@@ -96,14 +102,29 @@ class GifPreviewer < ActiveStorage::Previewer::VideoPreviewer
96
102
  'end (to)': end_frame_num,
97
103
  )
98
104
  Timeout::timeout(MAX_PROCESSING_TIME) do
99
- draw self.class.ffmpeg_path,
100
- '-i', file.path,
101
- '-filter_complex', "fps=10,scale=360:-1[s]; [s]split[a][b]; [a]palettegen[palette]; [b][palette]paletteuse",
102
- '-f', 'gif',
103
- '-ss', start_frame_num.to_s,
104
- '-to', end_frame_num.to_s,
105
- '-',
106
- &block
105
+ basic_gif_preview(file:, start_frame_num:, end_frame_num:, &block)
107
106
  end
108
107
  end
108
+
109
+ def pallet_gif_preview(file:, start_frame_num:, end_frame_num:, &block)
110
+ draw self.class.ffmpeg_path,
111
+ '-i', file.path,
112
+ '-filter_complex', "fps=10,scale=360:-1[s]; [s]split[a][b]; [a]palettegen[palette]; [b][palette]paletteuse",
113
+ '-f', 'gif',
114
+ '-ss', start_frame_num.to_s,
115
+ '-to', end_frame_num.to_s,
116
+ '-',
117
+ &block
118
+ end
119
+
120
+ def basic_gif_preview(file:, start_frame_num:, end_frame_num:, &block)
121
+ draw self.class.ffmpeg_path,
122
+ '-i', file.path,
123
+ '-filter_complex', "fps=10",
124
+ '-f', 'gif',
125
+ '-ss', start_frame_num.to_s,
126
+ '-to', end_frame_num.to_s,
127
+ '-',
128
+ &block
129
+ end
109
130
  end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  class VideoGifPreviewer
4
- VERSION = '0.1.2'
4
+ VERSION = '0.1.3'
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
4
+ version: 0.1.3
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-04-16 00:00:00.000000000 Z
11
+ date: 2025-05-17 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