【发布时间】:2014-03-20 12:29:35
【问题描述】:
我正在使用 Carrierwave 将视频文件上传到我的 Rails 应用程序。我的视频模型有一个属性“旋转”,我用它来存储视频的方向(例如,90、180、270 等)。
我想在我的上传器中设置“旋转”的值,我在其中确定视频是否旋转:
require 'mini_exiftool'
class VideoPathUploader < CarrierWave::Uploader::Base
process :encode
def encode
video = MiniExiftool.new(@file.path)
orientation = video.rotation
# save the orientation of the video record here ??
if orientation == 90
# rotate video
Rails.logger.debug "portrait video"
aspect_ratio = video.imageheight.to_f / video.imagewidth.to_f
encode_video(:mp4, custom: "-vf transpose=1", aspect: aspect_ratio)
else
aspect_ratio = video.imagewidth.to_f / video.imageheight.to_f
encode_video(:mp4, resolution: :same, aspect: aspect_ratio)
end
instance_variable_set(:@content_type, "video/mp4")
:set_content_type_mp4
end
如何在我的上传器中引用模型并更新其属性之一?
【问题讨论】:
标签: ruby-on-rails carrierwave uploader