carrierwave-video不处理视频

时间:2018-05-08 21:39:55

标签: ruby-on-rails video ruby-on-rails-5 carrierwave

我正在尝试转码视频文件并将其上传到s3。为此,我尝试使用carrierwave-video gem进行转码。对于上传我使用的是载波并进行后台处理我使用的是带有activejob和sidekiq组合的carrierwave-backgrounder。转码后,视频文件应上传到S3。但是,我遇到的问题是载波视频不转码视频文件,但视频文件仍以原始格式加载到s3。我不明白错误导致它不能转码的地方。谁能告诉我在制作载波视频转码文件方面我缺少什么?

VideoUploader

class VideoUploader < CarrierWave::Uploader::Base

  # Include RMagick or MiniMagick support:
  # include CarrierWave::RMagick
  # include CarrierWave::MiniMagick

  include CarrierWave::MimeTypes
  process :set_content_type

  include CarrierWave::Video
  process encode_video: [:mp4, resolution: "640x480", watermark: {}]

  include ::CarrierWave::Backgrounder::Delay

  # Choose what kind of storage to use for this uploader:
  # storage :file
  storage :fog

  # Override the directory where uploaded files will be stored.
  # This is a sensible default for uploaders that are meant to be mounted:
  def store_dir
    "uploads/#{model.class.to_s.underscore}/#{mounted_as}/#{model.id}"
  end
end

movie.rb

class Movie < ApplicationRecord
        mount_uploader :video, VideoUploader
        process_in_background :video

        validates :title, presence: true, length: { minimum: 1, maximum: 30 },
                                                                                uniqueness: { case_sensitive: false }
        validates :year, presence: true, numericality: { only_integer: true }
        validates :plot, presence: true, length: { minimum: 1, maximum: 1000 }
        validates :video, presence: true

end

movies_controller.rb(创建)

def create
    movie = Movie.new(movie_params)

                if movie.save
                        VideoProcesserJob.perform_later(movie.id)
                        render json: movie, status: 201
                else
                        render json: { errors: movie.errors }, status: 422
                end
        end

VideoProcesserJob.rb

class VideoProcesserJob < ApplicationJob
  queue_as :default

  def perform(movie_id)
    movie = Movie.find(movie_id)
  end
end

0 个答案:

没有答案