class VideoUploader < Shrine
plugin :processing
plugin :versions
plugin :delete_raw # delete processed chunks after they're uploaded
process(:store) do |io, context|
raw_video = io.download
mp4 = Tempfile.new(["video", ".mp4"], binmode: true)
movie = FFMPEG::Movie.new(raw_video.path)
movie.transcode(mp4.path)
raw_video.delete # delete the downloaded raw video
hls_path, chunk_paths = generate_hls(mp4) # custom method
versions = {hls: File.open(hls_path)}
chunk_paths.each_with_index do |path, idx|
versions[:"#{chunk}_#{idx}"] = File.open(path)
end
versions # hash of files that will be uploaded
end
def generate_location(io, context)
case context[:version]
when :hls
# return location where this HLS playlist should be uploaded to
when /chunk_\d+/
# return location where this chunk should be uploaded to
else
super
end
end
end
--
You received this message because you are subscribed to the Google Groups "Shrine" group.
To unsubscribe from this group and stop receiving emails from it, send an email to ruby-shrine+unsubscribe@googlegroups.com.
To post to this group, send email to ruby-...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/ruby-shrine/3b0d2297-5510-4612-acfa-a7fe9dcc946d%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
To unsubscribe from this group and stop receiving emails from it, send an email to ruby-shrine...@googlegroups.com.