我想使用 Shrine gem 上传视频文件、转码并从视频中生成缩略图。
我正在尝试将 Erik Dahlstrand 的Shrine-Rails-example从照片转换为视频。我在创建视频上传器时遇到问题。我将此代码基于Video is not of allowed type (allowed types: video/mp4), Shrine, Rails
require "streamio-ffmpeg"
class VideoUploader < Shrine
ALLOWED_TYPES = %w[video/mp4 video/quicktime video/x-msvideo video/mpeg]
plugin :processing
plugin :versions
plugin :determine_mime_type
plugin :cached_attachment_data
plugin :remove_attachment
plugin :add_metadata
plugin :validation_helpers
plugin :derivation_endpoint, prefix: "derivations/video"
add_metadata do |io, context|
movie = Shrine.with_file(io) { |file| FFMPEG::Movie.new(file.path) }
{ "duration" => movie.duration,
"bitrate" => movie.bitrate,
"resolution" => movie.resolution,
"frame_rate" => movie.frame_rate }
end
movie.screenshot("video_thumb_007.jpg", seek_time: 5, resolution: '320x240')
metadata_method :duration
Attacher.validate do
validate_max_size 100.megabyte, message: "is too large (max is 100 MB)"
validate_mime_type_inclusion ALLOWED_TYPES
end
end
我收到此错误:
/var/folders/mm/_j8x4k2176jcv31zvbc497_c0000gp
/T/shrine20190607-24438-4f3jz2.m4v: No such file or directory
事实上,该位置没有文件。那么等待上传时文件存储在哪里?
此外,使用演示将照片上传到 AWS(生产环境),对象存储在存储桶中名为“照片”的文件夹中。Shrine 显然使用表名来命名文件夹。是否可以创建替代和嵌套文件夹名称?
谢谢 - 似乎是一个了不起的宝石!试图更好地理解它!
谢谢