Rails アプリを使用して動画をアップロードするために、carrierwave-video gem を使用しています。動画をアップロードしようとすると、次のエラーが表示されます。
FFmpeg でのトランスコードに失敗しました。ffmpeg のインストールを確認し、ビデオが破損していないこと、または途切れていないことを確認します。元のエラー: nil はシンボルではありません。
次のコマンドを正常に実行できれば、ffmpeg のインストールは成功したと思います。
qt-faststart input.mp4 output.mp4
ログを詳しく見ると、ビデオ ファイルのパラメーターは正しいようですが、アプリがビデオ レコードを作成しようとすると、2 つのロールバックが発生します。
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