- xml - AJAX/Jquery XML 解析
- 具有多重继承的 XML 模式
- .net - 枚举序列化 Json 与 XML
- XML 简单类型、简单内容、复杂类型、复杂内容
我正在使用 carrierwave 将电影上传到 amazon s3,效果非常好。
现在我想在上传时或上传后给电影加水印,我不知道,最好的方法是什么?
我试过这个:
movie_controller.rb
Action 上传视频
movie = FFMPEG::Movie.new(@vid.video.url)
puts "........................................"
puts movie.inspect
if @vid.save
只是为了查明视频是否是从 stremio 中捕获的。
但后来我得到了找不到电影的错误,问题是它没有在 amazon s3 存储桶中查找,它在我的本地服务器上查找
No such file or directory - the file '/uploads/tmp/1462954331-3471-8766/VID-20160424-WA0013.mp4' does not exist
解决方案是什么?或者我应该在载波 uploader 中执行此操作?
更新:
当我在 .save 操作之后执行此操作时,它会查看 amazon s3 存储桶 .. 但还会说电影不存在。但如果我直接在浏览器中调用它,它就会显示出来。
更新代码:
#Laedt ein Video hoch
def uploadMovie
@user = User.find_by_id session[:user_id]
#Holt alle Channels für die er eine Berechtigung hat (Eingeloggter user)
@user = User.find_by_id session[:user_id]
@knowledgeproviderList = @user.knowledgeprovider
@channels = Channel.where(knowledgeprovider_id: @knowledgeproviderList.pluck(:id))
@vid = Movie.new(movies_params)
@channel = Channel.find(params[:vid][:channel_id])
@vid.channel = @channel
#Fügt dem Movie einen Tag hinzu
createTag params
createCategory params
if @vid.save
flash[:notice] = t("flash.saved")
#movie = FFMPEG::Movie.new(@vid.video.url)
#puts "........................................"
#puts movie.inspect
redirect_to :action => :add
else
redirect_to :action => :add
end
end
更新错误:
movie = FFMPEG::Movie.new(@vid.video.current_path)
options = {watermark: "mages/header.png", resolution: "640x360", watermark_filter: { position: "RT", padding_x: 10, padding_y: 10 } }
movie.transcode("movie.flv", options)
更新:在 uploader 中添加代码:
process :watermark_movie
def watermark_movie
if self.file.path
options = {watermark: "images/header.png", resolution: "640x360", watermark_filter: { position: "RT", padding_x: 10, padding_y: 10 } }
self.model.file = FFMPEG::Movie.new(self.file.path).transcode("#{root}/#{cache_dir}/#{self.cache_id}/file.mp4", options)
end
end
错误:
multi_json (1.12.0) lib/multi_json/adapter.rb:19:in `load'
multi_json (1.12.0) lib/multi_json.rb:122:in `load'
streamio-ffmpeg (2.0.0) lib/ffmpeg/movie.rb:28:in `initialize'
app/uploaders/movie_uploader.rb:40:in `new'
app/uploaders/movie_uploader.rb:40:in `watermark_movie'
carrierwave (0.11.2) lib/carrierwave/uploader/processing.rb:84:in `block in process!'
carrierwave (0.11.2) lib/carrierwave/uploader/processing.rb:76:in `each'
carrierwave (0.11.2) lib/carrierwave/uploader/processing.rb:76:in `process!'
carrierwave_backgrounder (0.4.2) lib/backgrounder/delay.rb:14:in `process!'
carrierwave (0.11.2) lib/carrierwave/uploader/callbacks.rb:18:in `block in with_callbacks'
carrierwave (0.11.2) lib/carrierwave/uploader/callbacks.rb:18:in `each'
carrierwave (0.11.2) lib/carrierwave/uploader/callbacks.rb:18:in `with_callbacks'
carrierwave (0.11.2) lib/carrierwave/uploader/cache.rb:134:in `cache!'
carrierwave (0.11.2) lib/carrierwave/mount.rb:329:in `cache'
carrierwave (0.11.2) lib/carrierwave/mount.rb:163:in `video='
carrierwave (0.11.2) lib/carrierwave/orm/activerecord.rb:39:in `video='
activerecord (4.2.1) lib/active_record/attribute_assignment.rb:54:in `public_send'
activerecord (4.2.1) lib/active_record/attribute_assignment.rb:54:in `_assign_attribute'
activerecord (4.2.1) lib/active_record/attribute_assignment.rb:41:in `block in assign_attributes'
actionpack (4.2.1) lib/action_controller/metal/strong_parameters.rb:183:in `each_pair'
actionpack (4.2.1) lib/action_controller/metal/strong_parameters.rb:183:in `each_pair'
activerecord (4.2.1) lib/active_record/attribute_assignment.rb:35:in `assign_attributes'
activerecord (4.2.1) lib/active_record/core.rb:559:in `init_attributes'
activerecord (4.2.1) lib/active_record/core.rb:281:in `initialize'
activerecord (4.2.1) lib/active_record/inheritance.rb:61:in `new'
activerecord (4.2.1) lib/active_record/inheritance.rb:61:in `new'
app/controllers/movies_controller.rb:71:in `uploadMovie'
actionpack (4.2.1) lib/action_controller/metal/implicit_render.rb:4:in `send_action'
actionpack (4.2.1) lib/abstract_controller/base.rb:198:in `process_action'
actionpack (4.2.1) lib/action_controller/metal/rendering.rb:10:in `process_action'
actionpack (4.2.1) lib/abstract_controller/callbacks.rb:20:in `block in process_action'
activesupport (4.2.1) lib/active_support/callbacks.rb:117:in `call'
activesupport (4.2.1) lib/active_support/callbacks.rb:117:in `call'
activesupport (4.2.1) lib/active_support/callbacks.rb:555:in `block (2 levels) in compile'
activesupport (4.2.1) lib/active_support/callbacks.rb:505:in `call'
activesupport (4.2.1) lib/active_support/callbacks.rb:505:in `call'
activesupport (4.2.1) lib/active_support/callbacks.rb:92:in `_run_callbacks'
activesupport (4.2.1) lib/active_support/callbacks.rb:776:in `_run_process_action_callbacks'
activesupport (4.2.1) lib/active_support/callbacks.rb:81:in `run_callbacks'
actionpack (4.2.1) lib/abstract_controller/callbacks.rb:19:in `process_action'
actionpack (4.2.1) lib/action_controller/metal/rescue.rb:29:in `process_action'
actionpack (4.2.1) lib/action_controller/metal/instrumentation.rb:32:in `block in process_action'
activesupport (4.2.1) lib/active_support/notifications.rb:164:in `block in instrument'
activesupport (4.2.1) lib/active_support/notifications/instrumenter.rb:20:in `instrument'
activesupport (4.2.1) lib/active_support/notifications.rb:164:in `instrument'
actionpack (4.2.1) lib/action_controller/metal/instrumentation.rb:30:in `process_action'
actionpack (4.2.1) lib/action_controller/metal/params_wrapper.rb:250:in `process_action'
activerecord (4.2.1) lib/active_record/railties/controller_runtime.rb:18:in `process_action'
actionpack (4.2.1) lib/abstract_controller/base.rb:137:in `process'
actionview (4.2.1) lib/action_view/rendering.rb:30:in `process'
actionpack (4.2.1) lib/action_controller/metal.rb:196:in `dispatch'
actionpack (4.2.1) lib/action_controller/metal/rack_delegation.rb:13:in `dispatch'
actionpack (4.2.1) lib/action_controller/metal.rb:237:in `block in action'
actionpack (4.2.1) lib/action_dispatch/routing/route_set.rb:74:in `call'
actionpack (4.2.1) lib/action_dispatch/routing/route_set.rb:74:in `dispatch'
actionpack (4.2.1) lib/action_dispatch/routing/route_set.rb:43:in `serve'
actionpack (4.2.1) lib/action_dispatch/journey/router.rb:43:in `block in serve'
actionpack (4.2.1) lib/action_dispatch/journey/router.rb:30:in `each'
actionpack (4.2.1) lib/action_dispatch/journey/router.rb:30:in `serve'
actionpack (4.2.1) lib/action_dispatch/routing/route_set.rb:819:in `call'
rack (1.6.4) lib/rack/etag.rb:24:in `call'
rack (1.6.4) lib/rack/conditionalget.rb:38:in `call'
rack (1.6.4) lib/rack/head.rb:13:in `call'
actionpack (4.2.1) lib/action_dispatch/middleware/params_parser.rb:27:in `call'
actionpack (4.2.1) lib/action_dispatch/middleware/flash.rb:260:in `call'
rack (1.6.4) lib/rack/session/abstract/id.rb:225:in `context'
rack (1.6.4) lib/rack/session/abstract/id.rb:220:in `call'
actionpack (4.2.1) lib/action_dispatch/middleware/cookies.rb:560:in `call'
activerecord (4.2.1) lib/active_record/query_cache.rb:36:in `call'
activerecord (4.2.1) lib/active_record/connection_adapters/abstract/connection_pool.rb:649:in `call'
activerecord (4.2.1) lib/active_record/migration.rb:378:in `call'
actionpack (4.2.1) lib/action_dispatch/middleware/callbacks.rb:29:in `block in call'
activesupport (4.2.1) lib/active_support/callbacks.rb:88:in `call'
activesupport (4.2.1) lib/active_support/callbacks.rb:88:in `_run_callbacks'
activesupport (4.2.1) lib/active_support/callbacks.rb:776:in `_run_call_callbacks'
activesupport (4.2.1) lib/active_support/callbacks.rb:81:in `run_callbacks'
actionpack (4.2.1) lib/action_dispatch/middleware/callbacks.rb:27:in `call'
actionpack (4.2.1) lib/action_dispatch/middleware/reloader.rb:73:in `call'
actionpack (4.2.1) lib/action_dispatch/middleware/remote_ip.rb:78:in `call'
actionpack (4.2.1) lib/action_dispatch/middleware/debug_exceptions.rb:17:in `call'
web-console (2.3.0) lib/web_console/middleware.rb:20:in `block in call'
web-console (2.3.0) lib/web_console/middleware.rb:18:in `catch'
web-console (2.3.0) lib/web_console/middleware.rb:18:in `call'
actionpack (4.2.1) lib/action_dispatch/middleware/show_exceptions.rb:30:in `call'
railties (4.2.1) lib/rails/rack/logger.rb:38:in `call_app'
railties (4.2.1) lib/rails/rack/logger.rb:20:in `block in call'
activesupport (4.2.1) lib/active_support/tagged_logging.rb:68:in `block in tagged'
activesupport (4.2.1) lib/active_support/tagged_logging.rb:26:in `tagged'
activesupport (4.2.1) lib/active_support/tagged_logging.rb:68:in `tagged'
railties (4.2.1) lib/rails/rack/logger.rb:20:in `call'
actionpack (4.2.1) lib/action_dispatch/middleware/request_id.rb:21:in `call'
rack (1.6.4) lib/rack/methodoverride.rb:22:in `call'
rack (1.6.4) lib/rack/runtime.rb:18:in `call'
activesupport (4.2.1) lib/active_support/cache/strategy/local_cache_middleware.rb:28:in `call'
rack (1.6.4) lib/rack/lock.rb:17:in `call'
actionpack (4.2.1) lib/action_dispatch/middleware/static.rb:113:in `call'
rack (1.6.4) lib/rack/sendfile.rb:113:in `call'
railties (4.2.1) lib/rails/engine.rb:518:in `call'
railties (4.2.1) lib/rails/application.rb:164:in `call'
rack (1.6.4) lib/rack/lock.rb:17:in `call'
rack (1.6.4) lib/rack/content_length.rb:15:in `call'
rack (1.6.4) lib/rack/handler/webrick.rb:88:in `service'
/home/felix/.rvm/rubies/ruby-2.0.0-p643/lib/ruby/2.0.0/webrick/httpserver.rb:138:in `service'
/home/felix/.rvm/rubies/ruby-2.0.0-p643/lib/ruby/2.0.0/webrick/httpserver.rb:94:in `run'
/home/felix/.rvm/rubies/ruby-2.0.0-p643/lib/ruby/2.0.0/webrick/server.rb:295:in `block in start_thread'
更新 -- 电影 uploader
# encoding: utf-8
class MovieUploader < CarrierWave::Uploader::Base
# Include RMagick or MiniMagick support:
# include CarrierWave::RMagick
include CarrierWave::MiniMagick
include CarrierWave::Video
include CarrierWave::Video::Thumbnailer
include CarrierWave::Backgrounder::Delay
require 'rubygems'
require 'streamio-ffmpeg'
# Choose what kind of storage to use for this uploader:
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
process :watermark_movie
def watermark_movie
puts "ssssssssssssssssssssssssssssssssss"
puts self.file.inspect
if self.file.path
options = {watermark: "http://felix-hohlwegler.de/holz-soft/include/designs/design13/images/header.png", resolution: "640x360", watermark_filter: { position: "RT", padding_x: 10, padding_y: 10 } }
self.model.file = FFMPEG::Movie.new(self.file.path).transcode("#{root}/#{cache_dir}/#{self.cache_id}/file.mp4", options)
end
end
version :thumb do
process thumbnail: [{format: 'png', quality: 10, size: 1200, strip: false, seek: 10, logger: Rails.logger}]
def full_filename for_file
png_name for_file, version_name
end
end
def png_name for_file, version_name
%Q{#{version_name}_#{for_file.chomp(File.extname(for_file))}.png}
end
# Add a white list of extensions which are allowed to be uploaded.
# For images you might use something like this:
def extension_white_list
%w(mov avi mkv mpeg mpeg2 mp4 3gp)
end
end
最佳答案
我们在处理音频的应用程序中做了类似的事情。显然,我们不使用视频或水印,但我们使用 streamio-ffmpeg 进行一些转码。
与其在 Controller 中编写与水印相关的代码,不如将该功能移至 uploader 。例如,我们的 convert_to_mp3
方法可能是您的水印方法。看起来这可能会解决您的问题。
# encoding: utf-8
require 'streamio-ffmpeg'
class FileUploader < CarrierWave::Uploader::Base
# Choose what kind of storage to use for this uploader:
storage :fog
before :store, :remember_cache_id
after :store, :delete_tmp_dir
# 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
# Process files as they are uploaded:
process :convert_to_mp3
def convert_to_mp3
if self.file.path
if self.file.extension == 'm4a' || self.file.extension == 'wav' || self.file.extension == 'aac'
self.model.file = FFMPEG::Movie.new(self.file.path).transcode("#{root}/#{cache_dir}/#{self.cache_id}/file.mp3", options_string)
end
end
end
def options_string
if self.file.extension == 'm4a'
"-acodec libmp3lame -write_xing 0"
elsif self.file.extension == 'aac'
"-acodec libmp3lame -write_xing 0"
elsif self.file.extension == 'wav'
"-acodec libmp3lame -write_xing 0"
end
end
# Add a white list of extensions which are allowed to be uploaded.
# For images you might use something like this:
def extension_white_list
%w(mp3 m4a wav)
end
def cache_id
@cache_id
end
def remember_cache_id(new_file)
@cache_id_was = cache_id
end
def delete_tmp_dir(new_file)
# make sure we don't delete other things accidentally by checking the name pattern
if @cache_id_was.present? && @cache_id_was =~ /\A[\d]{8}\-[\d]{4}\-[\d]+\-[\d]{4}\z/
FileUtils.rm_rf(File.join(root, cache_dir, @cache_id_was))
end
end
end
关于ruby-on-rails - Rails 在上传时使用 stremio-ffmpeg gem 给电影加水印,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37156802/
当我输入时: gem env 在我的 Windows 系统上,它会生成以下信息: RubyGems Environment: - RUBYGEMS VERSION: 1.3.5 - RUBY
我记得我用过 gem install rails安装 Rails,但今天当我想安装另一个 gem 时,输入 gem install ruby-recaptcha 它失败了,说: You don't h
我有一个要重命名的 gem 。它是published on RubyGems。我最担心的是人们想要更新它。 我看到了两条路,但是我真的很想听听重命名 gem 的人是如何做到的。 1.把旧的变成一个元包
$ gem install passenger Fetching: passenger-4.0.5.gem (100%) ERROR: While executing gem ... (Gem::F
我刚刚用 gem update mime-types 更新了 mime-types gem . gem list显示 mime-types (1.16)在更新之前。更新后gem list显示 mime
如果我构建了一个私有(private) gem(例如,在我的公司内部托管),然后我想在我正在构建的另一个 gem(不是应用程序!)中重用该 gem,我该怎么做? 我应该在哪里放置我的依赖项并告诉我的新
我正在编写一个具有多个 gem 依赖项的 gem,其中一个依赖于破坏新版本向后兼容性的 gem。这让我开始思考——我不希望我正在构建的 gem 变成“那个 gem”,让人们难以更新他们的应用程序。我也
我目前正在构建一个需要 mysql2 gem 的 RoR 项目。我成功安装了 gem 。因为它出现在我的 gem 列表中。 [root@vc2cmmka035538n simple_cms]# gem
我试图在 XP 上构建 capybara-webkit。我关注了this操作说明。它说要进行捆绑安装: $ cd ruby193\capybara-webkit $ bundle install
是否有可能为 Ruby 提供类似“本地”gem 存储库的东西? 我正在开发一个没有管理员权限的自定义 Linux 发行版。 Ruby 安装在机器上 (v.1.8.7),但显然没有安装“gem”或“bu
我是使用 gems 的新手,所以如果我的事实有误,请原谅我。 我想将 Bundler 从 v1.3.5 更新到最新版本 (v1.5.3),所以我尝试这样做: sudo gem install bund
如何使用 gem install 同时安装多个 gem,同时指定我想要的版本? 例子: gem install akami -v 1.2.0 --ignore-dependencies gem in
我正在尝试在 XP 上构建 capybara-webkit。我关注 this instruction .我说: 8) Clone latest version of capybara-webkit f
我正在尝试设置我自己的私有(private) gem 服务器,它应该为我的 gem 提供服务并显示 rdoc。正如我所读,默认的 gem 服务器应该能够做到这一点。由于我不希望除了我自己的所有 gem
假设我的 gem 是 VideoPlayer。文件夹结构是: VideoPlayer/ /bin vidplay.rb /lib VideoPlayer
如何避免 gem 清理特定错误。我在执行 gem 清理时看到以下错误。 Gem::InstallError: gem-wrappers 未安装在 GEM_HOME 中 gem cleanup Clea
我写了一个 gem elastic-beanstalk这将在 rails 项目文件结构中使用,以及在 rails 目录和文件不可用(无需解压缩等)的独立 CI 环境中使用。即正在运行的 Bamboo
运行“sudo gem list --local”和“gem list --local”给我不同的结果。我的 gem 路径设置为我的主文件夹,并且仅包含来自“gem list --local”的 ge
最初,我发布了 Stack Overflow 问题 Ruby on Rails gems... Re-open models (现已删除)。但我认为这个问题太令人困惑了……我会根据我的发现尝试提出不同
我使用 OS X El Capitan 10.11.6 首先,我在安装 pod 时遇到问题,按照本网站中的步骤进行操作后能够找到问题..终端拼出问题是我安装后的 ruby v 2.2.2当我尝试安
我是一名优秀的程序员,十分优秀!