Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/ruby-on-rails/55.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/video/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ruby on rails 使用回形针滑轨播放视频_Ruby On Rails_Video_Paperclip - Fatal编程技术网

Ruby on rails 使用回形针滑轨播放视频

Ruby on rails 使用回形针滑轨播放视频,ruby-on-rails,video,paperclip,Ruby On Rails,Video,Paperclip,我想设置视频上传,以便用户可以查看和播放它们。我是新手,有人知道怎么做吗?你可以看看 在包含视频的模型中,您需要正确的格式(ffmpeg)和视频验证: has_attached_file :attachment, styles: lambda { |a| a.instance.is_image? ? {:small => "x200>", :medium => "x300>", :large => "x400>"} : {:thum

我想设置视频上传,以便用户可以查看和播放它们。我是新手,有人知道怎么做吗?

你可以看看

在包含视频的模型中,您需要正确的格式(
ffmpeg
)和视频验证:

   has_attached_file :attachment,
          styles: lambda { |a| a.instance.is_image? ? {:small => "x200>", :medium => "x300>", :large => "x400>"}  : {:thumb => { :geometry => "100x100#", :format => 'jpg', :time => 10}, :medium => { :geometry => "300x300#", :format => 'jpg', :time => 10}}},
          :processors => lambda { |a| a.is_video? ? [ :ffmpeg ] : [ :thumbnail ] }
    validates_attachment_content_type :video, content_type: /\Avideo\/.*\Z/ 
根据评论更新:

 has_attached_file :video, styles: {
    :medium => {
      :geometry => "640x480",
      :format => 'mp4'
    },
    :thumb => { :geometry => "160x120", :format => 'jpeg', :time => 10}
  }, :processors => [:transcoder]

有一些实时代码可以实现这一点:

#文件
gem“曲别针ffmpeg”,“~>1.2.0”
#app/models/attachment.rb
类附件{geometry:“100x100#”,格式:'jpg',时间:10},中间:{geometry:“300x300#”,格式:'jpg',时间:10},
处理器:[:ffmpeg]
结束

你遇到的主要问题是电话

当你上传任何带有回形针的附件时,它必须在存储之前对其进行处理。处理过程将转换为正确的格式并调整大小(您也可以使用它做其他很酷的事情)

视频处理与图像处理稍有不同,首先需要对视频进行处理,以便服务器能够播放视频,然后还要从中提取一些屏幕截图

因此,您需要一个定制处理器,@Czanfar在其答案中发布的处理器要么是
ffmpeg
要么是
transcoder


我在这里也写了一个答案:


顺便说一下,这是我去看那些做回形针的人的时候:

多亏了我的回答,我才让它工作起来

确保安装了ffmpeg


像其他文件一样设置文件(遵循曲别针文档)并使用。因此生成轨道生成曲别针文章附件,然后在model/post.rb文件中添加,然后在post_参数中添加:附件,然后视图ffmpeg已贬值,因此我使用曲别针av转码库本地我得到一个黑色的视频屏幕,但视频播放按钮是可点击的,但没有什么-我想可能是因为需要加载ffmpeg或视频转换器?是的,您可能需要一个转换器或至少交叉浏览器解决方案。看看这篇文章,我必须同时添加这两个附件选项吗?还是只添加一个?谢谢,巴德,这是在斯德哥尔摩
#Gemfile
gem "paperclip-ffmpeg", "~> 1.2.0"

#app/models/attachment.rb
class Attachment < ActiveRecord::Base

   has_attached_file :attachment,
        styles: {:thumb => { geometry: "100x100#", format: 'jpg', time: 10}, medium: { gemometry: "300x300#", format: 'jpg', time: 10}},
        processors: [ :ffmpeg ]

end
brew install ffmpeg --with-fdk-aac --with-ffplay --with-freetype --with-frei0r --with-libass --with-libvo-aacenc --with-libvorbis --with-libvpx --with-opencore-amr --with-openjpeg --with-opus --with-rtmpdump --with-schroedinger --with-speex --with-theora --with-tools