Videos not loading with Paperclip Gem - ffmpeg in Rails

I can upload my images, however, when I try to upload a video, it publishes as a black screen with a play button not working. I don't know where I went wrong. Do I need a video player for this?

This might be a lightweight solution, however I am new to Rails. Any help is appreciated. Thank.

Publishing model

        class Post < ActiveRecord::Base

    belongs_to :user

    has_attached_file :image, :styles => { :medium => "300x300>", :thumb => "100x100>" }
    has_attached_file :video, :styles => {:medium => { :geometry => "300x300", :format => 'flv'},:thumb => {:geometry => "100x100#", :format => 'jpg', :time => 15}
    }, :processors => [:ffmpeg] 



    validates_attachment_content_type :image, :content_type => ["image/jpg", "image/jpeg", "image/png", "image/gif"]
    validates_attachment_content_type :video, :content_type => ["video/mp4", "video.mov", "video/mpeg","video/mpeg4", "image/jpg", "image/jpeg"]

    validates :description, presence: true
    validates :image, presence: false
    validates :video, presence: false

end

      

AddAttachmentImageToPosts Model

    class AddAttachmentVideoToPosts < ActiveRecord::Migration
  def self.up
     change_table :posts do |t|
      t.attachment :video
    end
  end

  def self.down
    drop_attached_file :posts, :video
  end
end

      

_Form message

  <div class="field">
    <%= f.label :image %>
    <%= f.file_field :image %>
  </div>


  <div class="field">
    <%= f.label :video %>
    <%= f.file_field :video %>
  </div></br>


  <div class="field">
    <%= f.label :description %>
    <%= f.text_field :description %>
  </div>

      

Messages Show

<div class="row">
    <div class="col-md-offset-4 col-med-8">
        <div class="panel panel-default">
        <div class="panel-heading center">
            <%= image_tag @post.image.url(:medium) %>
            <%= video_tag @post.video.url(:medium), controls: true, type: "video/mp4" %>
        </div>
        <div class="panel-body">
        <p><%= @post.description %></p>
        <p><strong><%= @post.user.name if @post.user %></strong></p>

    <% if @post.user == current_user %>
        <%= link_to edit_post_path(@post) do %>
        <span class="glyphicon glyphicon-edit"></span>
        Edit
      <% end %>
    <% end %>
    <%= link_to 'Back', posts_path %>
    </div>
</div>

      

+3


source to share





All Articles