我正在使用carrierwave-video gem 通过我的Rails 应用程序上传视频。当我尝试上传视频时,出现以下错误:
使用 FFmpeg 转码失败。检查 ffmpeg 安装并验证视频没有损坏或缩短。原始错误:nil 不是符号。
我相信我的 ffmpeg 安装是成功的,因为如果我可以成功运行以下命令:
qt-faststart input.mp4 output.mp4
仔细查看我的日志,视频文件的参数似乎是正确的,但是当应用程序尝试创建视频记录时,我有两个回滚:
Started POST "/videos" for 127.0.0.1 at 2013-09-27 11:42:04 -0400
Processing by VideosController#create as HTML
Parameters: {"utf8"=>"✓", "authenticity_token"=>"5lMoFtM5Rrdu4Ra8ut8rD3jYv3FJ0cxo38QW5ATw9ZQ=", "video"=>{"project_id"=>"4", "step_id"=>"22", "saved"=>"true", "embed_url"=>"", "video_path"=>#<ActionDispatch::Http::UploadedFile:0x007f84702436b8 @original_filename="2013-08-02 17.19.02.mp4", @content_type="video/mp4", @headers="Content-Disposition: form-data; name=\"video[video_path]\"; filename=\"2013-08-02 17.19.02.mp4\"\r\nContent-Type: video/mp4\r\n", @tempfile=#<File:/var/folders/dc/c0nfvwy96lq7p4ll94mklnmr0000gp/T/RackMultipart20130927-1871-173l2g7>>}, "button"=>""}
User Load (0.6ms) SELECT "users".* FROM "users" WHERE "users"."id" = 1 LIMIT 1
Project Load (0.3ms) SELECT "projects".* FROM "projects" WHERE "projects"."id" = $1 LIMIT 1 [["id", "4"]]
(0.2ms) BEGIN
(0.2ms) ROLLBACK
(0.2ms) BEGIN
(0.1ms) ROLLBACK
#<ActiveModel::Errors:0x007f847058fd08 @base=#<Video id: nil, embed_url: "", project_id: 4, step_id: 22, saved: true, created_at: nil, updated_at: nil, thumbnail_url: nil, image_id: nil, video_path: nil>, @messages={:video_path=>["Failed to transcode with FFmpeg. Check ffmpeg install and verify video is not corrupt or cut short. Original error: nil is not a symbol"]}>
Completed 406 Not Acceptable in 616ms (ActiveRecord: 1.6ms)
有没有人遇到过类似的问题,如果有,你是怎么解决的?
视频.rb:
class Video < ActiveRecord::Base
# maybe we should add a title attribute to the video?
attr_accessible :position, :project_id, :step_id, :image_id, :saved, :embed_url, :thumbnail_url, :video_path
mount_uploader :video_path, VideoPathUploader
...
def set_success(format, opt)
self.success = true
end
end
video_path_uploader.rb
class VideoPathUploader < CarrierWave::Uploader::Base
include CarrierWave::Video
include CarrierWave::Video::Thumbnailer
process encode_video: [:mp4, callbacks: { after_transcode: :set_success } ]
# Include RMagick or MiniMagick support:
# include CarrierWave::RMagick
# include CarrierWave::MiniMagick
# 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
version :thumb do
process thumbnail: [{format: 'png', quality: 10, size: 158, strip: false, logger: Rails.logger}]
def full_filename for_file
png_name for_file, version_name
end
end
version :square_thumb do
process thumbnail: [{format: 'png', quality: 10, size: 105, strip: false, logger: Rails.logger}]
def full_filename for_file
png_name for_file, version_name
end
end
end