我正在使用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
如何在我的上传器中引用模型并更新其中一个属性?
答案 0 :(得分:0)
在我的上传器中引用视频记录,我只需要调用modeL:
orientation = video.rotation model.rotation = orientation