Recherche avancée

Médias (0)

Mot : - Tags -/organisation

Aucun média correspondant à vos critères n’est disponible sur le site.

Autres articles (101)

  • HTML5 audio and video support

    13 avril 2011, par

    MediaSPIP uses HTML5 video and audio tags to play multimedia files, taking advantage of the latest W3C innovations supported by modern browsers.
    The MediaSPIP player used has been created specifically for MediaSPIP and can be easily adapted to fit in with a specific theme.
    For older browsers the Flowplayer flash fallback is used.
    MediaSPIP allows for media playback on major mobile platforms with the above (...)

  • Contribute to translation

    13 avril 2011

    You can help us to improve the language used in the software interface to make MediaSPIP more accessible and user-friendly. You can also translate the interface into any language that allows it to spread to new linguistic communities.
    To do this, we use the translation interface of SPIP where the all the language modules of MediaSPIP are available. Just subscribe to the mailing list and request further informantion on translation.
    MediaSPIP is currently available in French and English (...)

  • Prérequis à l’installation

    31 janvier 2010, par

    Préambule
    Cet article n’a pas pour but de détailler les installations de ces logiciels mais plutôt de donner des informations sur leur configuration spécifique.
    Avant toute chose SPIPMotion tout comme MediaSPIP est fait pour tourner sur des distributions Linux de type Debian ou dérivées (Ubuntu...). Les documentations de ce site se réfèrent donc à ces distributions. Il est également possible de l’utiliser sur d’autres distributions Linux mais aucune garantie de bon fonctionnement n’est possible.
    Il (...)

Sur d’autres sites (5791)

  • How do I get videos to upload using carrierwave-video ?

    10 juillet 2016, par Eric

    I tried to follow the instructions on github to upload using carrierwave-video, but get an error that says the file or directory mmpeg -i doesn’t exist.

    The upload path for images is correct, just not the video one.

    I added all of the following code necessary to help solve the error and minified as much as I possibly could.

    This is the video uploader code using carrierwave :

    class VideoUploader < CarrierWave::Uploader::Base

     include CarrierWave::Video
     storage :file

     version :mp4 do
       process :encode_video => [:mp4, resolution: "100x100"]
     end

     def store_dir
       "uploads/#{model.class.to_s.underscore}/#{mounted_as}/#{model.id}"
     end
    end

    This is the movie controller code that handles uploading of videos :

    class MoviesController < ApplicationController
      include MoviesHelper

      def index
         mode "index"
      end

      def show
         mode "show"
      end

      def new
         mode "new"
      end

      def edit
         mode "edit"
      end

      def create
         mode "create"
      end

      def update
         mode "update"
      end

      def destroy
         mode "destroy"
      end

      def review
         mode "review"
      end

      def approve
         mode "approve"
      end

      def deny
         mode "deny"
      end
    end

    This is the model data for the movie that goes with it :

    class Movie < ActiveRecord::Base
     attr_accessible :created_on, :description, :maintenance, :reviewed, :subplaylist_id, :title, :user_id, :video, :remote_video_url
     belongs_to :user
     belongs_to :subplaylist
     mount_uploader :video, VideoUploader
    end

    This is where the movie is supposed to be displayed but it is not working :

    <% provide(:title, "Movie: Where movies are made!") %>
    <% provide(:keywords, "movies, video") %>
    <% provide(:description, "This is the place where users showcase their wonderful video talent.") %>
    <p>&lt;%= notice %></p>
    <h1 class="pageheader">&lt;%= @movie.title %></h1>
    <br />
    <p class="pagetext">&lt;%= video_tag(@movie.video_url.to_s, controls: true, class: "imagebox") %></p>
    <p class="pagetext">&lt;%= @movie.description %></p>
    <p class="pagetext">Created on: &lt;%= @movie.created_on.strftime("%B-%d-%Y") %></p>
    <p class="pagetext">Owner: &lt;%= getType(@movie.user) %>&lt;%= link_to @movie.user.vname, user_path(@movie.user) %></p>
    <br />
    <p class="pagetext">&lt;%= link_to 'Back', mainplaylist_subplaylist_path(@subplaylist.mainplaylist, @movie.subplaylist) %></p>

    This is where the movie new action is :

    &lt;% provide(:title, "Movie: Create new movies here!") %>
    &lt;% provide(:description, "New movies are uploaded only to the site when the movie gets approved.") %>
    <h1 class="pagetextheader">New movie</h1>
    &lt;%= render 'form' %>
    <p class="pagetext">&lt;%= link_to 'Back', mainplaylist_subplaylist_path(@subplaylist.mainplaylist, @subplaylist) %></p>

    This is where the movies forum parameters are :

    &lt;%= form_for([@subplaylist, @movie], :html=>{:multipart => true}) do |f| %>
     &lt;% if @movie.errors.any? %>
       <div>
         <h2>&lt;%= pluralize(@movie.errors.count, "error") %> prohibited this movie from being saved:</h2>

         <ul>
         &lt;% @movie.errors.full_messages.each do |msg| %>
           <li>&lt;%= msg %></li>
         &lt;% end %>
         </ul>
       </div>
     &lt;% end %>
     <br />
     <div class="pagetext">
       &lt;%= f.label :title %><br />
       &lt;%= f.text_field :title %>
     </div>
     <div class="pagetext">
       &lt;%= f.file_field :video %>
     </div>
     <div class="pagetext">
       &lt;%= f.label :remote_video_url, "or video URL" %><br />
       &lt;%= f.text_field :remote_video_url %>
     </div>
     <div class="pagetext">
       &lt;%= f.label :description %><br />
       &lt;%= f.text_area :description %>
     </div>
     <div class="pagetext">
       &lt;%= f.submit %>
     </div>
     <br />
    &lt;% end %>

    This is the movies helper code :

    module MoviesHelper

      def mode(type)
         code = auto_logout
         if(code == true)
            sign_out
            redirect_to root_path
         else
            #Check if Maintenance is turned_on
            allmode = Maintenancemode.find_by_id(1)
            moviemode = Maintenancemode.find_by_id(19)
            mode_turned_on = (allmode.maintenance_on || moviemode.maintenance_on)
            #Determine if any maintenance is on
            if(mode_turned_on)
               #Determine if we are a regular user
               regularUser = (!current_user || !current_user.admin?)
               if(regularUser)
                  #Determine which maintenance mode is on
                  if(allmode.maintenance_on)
                     redirect_to maintenance_path
                  else
                     redirect_to movies_maintenance_path
                  end
               else
                  switch type
               end
            else
               switch type
            end
         end
      end

      private
         def getType(user)
            if(user.admin)
               value = "$"
            else
               typeFound = Usertype.find_by_user_id(user.id)
               if(typeFound)
                  type = typeFound.privilege
                  if(type == "Reviewer")
                     value = "^"
                  elsif(type == "Banned")
                     value = "!"
                  else
                     value = "~"
                  end
               else
                  value = "~"
               end
            end
            return value
         end

         def movieApproved
            movieFound = Movie.find_by_id(params[:movie_id])
            if(movieFound)
               movieFound.reviewed = true
               pouch = Pouch.find_by_user_id(movieFound.user_id)
               pointsForMovie = 10
               pouch.amount += pointsForMovie
               @pouch = pouch
               @pouch.save
               @movie = movieFound
               @movie.save
    #            MovieMailer.movie_approved(@movie, pointsForMovie).deliver
               redirect_to movies_review_path
            else
               render "public/404"
            end
         end

         def movieDenied
            movieFound = Movie.find_by_id(params[:movie_id])
            if(movieFound)
               #Retrieve the user who owns this pet first
               #userEmail = petFound.user.email
               #Send mail to user with link to edit the pet they sent
               @movie = movieFound
               MovieMailer.movie_denied(@movie).deliver
               redirect_to movies_review_path
            else
               render "public/404"
            end
         end

         def createMovie(subplaylistFound)
            newMovie = subplaylistFound.movies.new
            @subplaylist = subplaylistFound
            @movie = newMovie
         end

         def saveMovie(subplaylistFound, logged_in)
            newMovie = subplaylistFound.movies.new(params[:movie])
            newMovie.user_id = logged_in.id
            currentTime = Time.now
            newMovie.created_on = currentTime
            @movie = newMovie
            if(@movie.save)
               @subplaylist = subplaylistFound
    #            MovieMailer.review_movie(@movie).deliver
               flash[:success] = "#{@movie.title} is currently being reviewed please check back later."
               redirect_to subplaylist_movie_path(@subplaylist, @movie)
            else
               render "new"
            end
         end

         def switch(type)
            if(type == "index") #Admin only
               logged_in = current_user
               if(logged_in)
                  if(logged_in.admin)
                     allMovies = Movies.order("created_on desc").page(params[:page]).per(10)
                     @movies = allMovies
                  else
                     redirect_to root_path
                  end
               else
                  redirect_to root_path
               end
            elsif(type == "show")
               movieFound = Movie.find_by_id(params[:id])
               if(movieFound)
                  subplaylistFound = Subplaylist.find_by_id(params[:subplaylist_id])
                  if(subplaylistFound)
                     if(movieFound.reviewed)
                        @subplaylist = subplaylistFound
                        @movie = movieFound
                     else
                        logged_in = current_user
                        if(logged_in)
                           userMatch = ((logged_in.id == movieFound.user_id) || logged_in.admin)
                           if(userMatch)
                              @subplaylist = subplaylistFound
                              @movie = movieFound
                           else
                              redirect_to root_path
                           end
                        else
                           redirect_to root_path
                        end
                     end
                  else
                     redirect_to root_path
                  end
               else
                  render "public/404"
               end
            elsif(type == "new")
               logged_in = current_user
               if(logged_in)
                  subplaylistFound = Subplaylist.find_by_id(params[:subplaylist_id])
                  if(subplaylistFound)
                     if(subplaylistFound.collab_mode)
                        createMovie(subplaylistFound)
                     else
                        userMatch = (logged_in.id == subplaylistFound.user_id)
                        if(userMatch)
                           createMovie(subplaylistFound)
                        else
                           redirect_to root_path
                        end
                     end
                  else
                     render "public/404"
                  end
               else
                  redirect_to root_path
               end
            elsif(type == "create")
               logged_in = current_user
               if(logged_in)
                  subplaylistFound = Subplaylist.find_by_id(params[:subplaylist_id])
                  if(subplaylistFound)
                     if(subplaylistFound.collab_mode)
                        saveMovie(subplaylistFound, logged_in)
                     else
                        userMatch = (logged_in.id == subplaylistFound.user_id)
                        if(userMatch)
                           saveMovie(subplaylistFound, logged_in)
                        else
                           redirect_to root_path
                        end
                     end
                  else
                     render "public/404"
                  end
               else
                  redirect_to root_path
               end
            elsif(type == "edit")
               logged_in = current_user
               if(logged_in)
                  movieFound = Movie.find_by_id(params[:id])
                  if(movieFound)
                     userMatch = (logged_in.id == movieFound.user_id)
                     if(userMatch)
                        subplaylistFound = Subplaylist.find_by_id(movieFound.subplaylist_id)
                        if(subplaylistFound)
                           @subplaylist = subplaylistFound
                           @movie = movieFound
                        else
                           render "public/404"
                        end
                     else
                        redirect_to root_path
                     end
                  else
                     render "public/404"
                  end
               else
                  redirect_to root_path
               end
            elsif(type == "update")
               logged_in = current_user
               if(logged_in)
                  movieFound = Movie.find_by_id(params[:id])
                  if(movieFound)
                     userMatch = (logged_in.id == movieFound.user_id)
                     if(userMatch)
                        subplaylistFound = Subplaylist.find_by_id(movieFound.subplaylist_id)
                        if(subplaylistFound)
                           @movie = movieFound
                           if(@movie.update_attributes(params[:movie]))
                              @subplaylist = subplaylistFound
                              flash[:success] = 'Movie was successfully updated.'
                              redirect_to subplaylist_movie_path(@subplaylist, @movie)
                           else
                              render "edit"
                           end
                        else
                           render "public/404"
                        end
                     else
                        redirect_to root_path
                     end
                  else
                     render "public/404"
                  end
               else
                  redirect_to root_path
               end
            elsif(type == "destroy")
               logged_in = current_user
               if(logged_in)
                  movieFound = Movie.find_by_id(params[:id]) #Need to move this below the admin section to protect it
                  if(movieFound)
                     if(logged_in.admin)
                        subplaylistFound = Subplaylist.find_by_id(movieFound.subplaylist_id)
                        if(subplaylistFound)
                           @movie = movieFound
                           @subplaylist = subplaylistFound
                           @movie.destroy
                           redirect_to mainplaylist_subplaylist_path(@subplaylist.mainplaylist, @subplaylist)
                        else
                           render "public/404"
                        end
                     else
                        redirect_to root_path
                     end
                  else
                     render "public/404"
                  end
               else
                  redirect_to root_path
               end
            elsif(type == "review") #Admin
               logged_in = current_user
               if(logged_in)
                  if(logged_in.admin)
                     allMovies = Movie.all
                     moviesToReview = allMovies.select{|movie| !movie.reviewed}
                     @movies = Kaminari.paginate_array(moviesToReview).page(params[:page]).per(10)
                  else
                     typeFound = Usertype.find_by_user_id(logged_in.id)
                     if(typeFound.privilege == "Reviewer")
                        allMovies = Movie.all
                        moviesToReview = allMovies.select{|movie| !movie.reviewed}
                        @movies = Kaminari.paginate_array(moviesToReview).page(params[:page]).per(10)
                     else
                        redirect_to root_path
                     end
                  end
               else
                  redirect_to root_path
               end
            elsif(type == "approve") #Admin
               logged_in = current_user
               if(logged_in)
                  if(logged_in.admin)
                     movieApproved
                  else
                     typeFound = Usertype.find_by_user_id(logged_in.id)
                     if(typeFound.privilege == "Reviewer")
                        movieApproved
                     else
                        redirect_to root_path
                     end
                  end
               else
                  redirect_to root_path
               end
            elsif(type == "deny") #Admin
               logged_in = current_user
               if(logged_in)
                  if(logged_in.admin)
                     movieDenied
                  else
                     typeFound = Usertype.find_by_user_id(logged_in.id)
                     if(typeFound.privilege == "Reviewer")
                        movieDenied
                     else
                        redirect_to root_path
                     end
                  end
               else
                  redirect_to root_path
               end
            end
         end
    end

    This is the subplaylists show code :

    &lt;% provide(:title, "Subplaylist: The place where users videos gets uploaded to!") %>
    &lt;% provide(:keywords, "user, video, uploaded") %>
    &lt;% provide(:description, "Allows the categorization of various videos that the user submitted successfully.") %>
    <p>&lt;%= notice %></p>
    <h1 class="pageheader">&lt;%= @subplaylist.title %></h1>
    <br />
    <p class="pagetext">&lt;%= @subplaylist.description %></p>
    <br />
    <div class="pagebox">&lt;%= paginate @movies %></div>





    <br />
    <div class="pagetext">
      &lt;% @movies.each_with_index do |movie, index| %>
         <div class="container">
            <div class="inner">
               <div class="inner">&lt;%= link_to movie.title, subplaylist_movie_path(@subplaylist, movie) %></div>
               &lt;% if current_user &amp;&amp; (current_user.id == movie.user_id || current_user.admin? )%>
                  <div class="inner">&lt;%= button_to 'Edit', edit_subplaylist_movie_path(@subplaylist, movie), method: :get %></div>
                  <div class="inner">&lt;%= button_to 'Destroy', [@subplaylist, movie], method: :delete, data: { confirm: 'Are you sure?' } %></div>
               &lt;% end %>
               <p>&lt;%= video_tag movie.video_url(:thumb).to_s, controls: true %></p>
            </div>
            <br />
            <p>Created on: &lt;%= movie.created_on.strftime("%B-%d-%Y") %></p>
            <p>Owner: &lt;%= getType(movie.user) %>&lt;%= link_to movie.user.vname, user_path(movie.user) %></p>
         </div>
         &lt;% if ((index + 1) % 3) == 0 %>
            <br />
            <br />
         &lt;% end %>
      &lt;% end %>
    </div>
    <br />
    &lt;% if current_user %>
      <p class="pagetext">&lt;%= link_to "New Movie", new_subplaylist_movie_path(@subplaylist) %></p>
      <br />
    &lt;% end %>
    <p class="pagetext">&lt;%= link_to 'Back', user_mainplaylist_path(@mainplaylist.user.vname, @subplaylist.mainplaylist.title) %></p>

    This is the subplaylists model :

    class Subplaylist &lt; ActiveRecord::Base
      attr_accessible :title, :description, :collab_mode
      belongs_to :user
      belongs_to :mainplaylist
      has_many :movies, :foreign_key => "subplaylist_id", :dependent => :destroy
      VALID_NAME = /\A[A-Za-z][A-Za-z1-9][A-Za-z1-9 ]+\z/
      validates :title, presence: true, format: {with: VALID_NAME}
      validates :description, presence: true
    end

    This is the subplaylists controller code :

    class SubplaylistsController &lt; ApplicationController
      include SubplaylistsHelper

      def index
         mode "index"
      end

      def show
         mode "show"
      end

      def new
         mode "new"
      end

      def edit
         mode "edit"
      end

      def create
         mode "create"
      end

      def update
         mode "update"
      end

      def destroy
         mode "destroy"
      end
    end

    This is the subplaylist helper code :

    module SubplaylistsHelper

      def mode(type)
         code = auto_logout
         if(code == true)
            sign_out
            redirect_to root_path
         else
            #Check if Maintenance is turned_on
            allmode = Maintenancemode.find_by_id(1)
            subplaylistmode = Maintenancemode.find_by_id(18)
            mode_turned_on = (allmode.maintenance_on || subplaylistmode.maintenance_on)
            #Determine if any maintenance is on
            if(mode_turned_on)
               #Determine if we are a regular user
               regularUser = (!current_user || !current_user.admin?)
               if(regularUser)
                  #Determine which maintenance mode is on
                  if(allmode.maintenance_on)
                     redirect_to maintenance_path
                  else
                     redirect_to subplaylists_maintenance_path
                  end
               else
                  switch type
               end
            else
               switch type
            end
         end
      end

      private
         def getType(user)
            if(user.admin)
               value = "$"
            else
               typeFound = Usertype.find_by_user_id(user.id)
               if(typeFound)
                  type = typeFound.privilege
                  if(type == "Reviewer")
                     value = "^"
                  elsif(type == "Banned")
                     value = "!"
                  else
                     value = "~"
                  end
               else
                  value = "~"
               end
            end
            return value
         end

         def switch(type)
            if(type == "show")
               subplaylistFound = Subplaylist.find_by_id(params[:id])
               if(subplaylistFound)
                  mainplaylistFound = Mainplaylist.find_by_title(params[:mainplaylist_id])
                  if(mainplaylistFound)
                     playlistMatch = (subplaylistFound.mainplaylist_id == mainplaylistFound.id)
                     if(playlistMatch)
                        @mainplaylist = mainplaylistFound
                        @subplaylist = subplaylistFound
                        subplaylistMovies = @subplaylist.movies.all
                        reviewedMovies = subplaylistMovies
                        if(subplaylistMovies.count > 0)
                           reviewedMovies = subplaylistMovies.select{|movie| movie.reviewed}
                        end
                        @movies = Kaminari.paginate_array(reviewedMovies).page(params[:page]).per(10)
                     else
                        redirect_to root_path
                     end
                  else
                     render "public/404"
                  end
               else
                  redirect_to root_path
               end
            elsif(type == "destroy")
               logged_in = current_user
               if(logged_in)
                  subplaylistFound = Subplaylist.find_by_id(params[:id]) #Need to move this below the admin section to protect it
                  if(subplaylistFound)
                     if(logged_in.admin)
                        mainplaylistFound = Mainplaylist.find_by_id(subplaylistFound.mainplaylist_id)
                        if(mainplaylistFound)
                           @subplaylist = subplaylistFound
                           @mainplaylist = mainplaylistFound
                           @subplaylist.destroy
                           redirect_to mainplaylist_subplaylists_path(@mainplaylist)
                        else
                           render "public/404"
                        end
                     else
                        redirect_to root_path
                     end
                  else
                     render "public/404"
                  end
               else
                  redirect_to root_path
               end
            end
         end
    end

    This is the User model :

    class User &lt; ActiveRecord::Base
      attr_accessible :email, :first_name, :last_name, :login_id, :vname, :password, :password_confirmation, :avatar
      has_secure_password
      mount_uploader :avatar, AvatarUploader
      before_save { |user| user.email = user.email.downcase }
      before_save { |user| user.first_name = user.first_name.humanize }

      #key
      has_one :sessionkey, :foreign_key => "user_id", :dependent => :destroy
      has_one :usertype, :foreign_key => "user_id", :dependent => :destroy

      #Video section
      has_many :mainplaylists, :foreign_key => "user_id", :dependent => :destroy
      has_many :subplaylists, :foreign_key => "user_id", :dependent => :destroy
      has_many :movies, :foreign_key => "user_id", :dependent => :destroy

      #validates :first_name, presence: true
      VALID_EMAIL_REGEX = /\A[\w+\-.]+@[a-z\d\-.]+\.[a-z]+\z/i
      VALID_NAME_REGEX = /\A[a-z][a-z][a-z]+\z/i
      VALID_VNAME_REGEX = /\A[A-Za-z][A-Za-z][A-Za-z][A-Za-z0-9 ]+([-][A-Za-z0-9 ]+)?\z/
      VALID_PASSWORD_REGEX = /\A[A-Za-z0-9!][A-Za-z0-9!][A-Za-z0-9!][A-Za-z0-9!][A-Za-z0-9!][A-Za-z0-9!]+\z/
      validates :first_name, presence: true, format: { with: VALID_NAME_REGEX}
      validates :last_name, presence: true, format: { with: VALID_NAME_REGEX}
      validates :email, presence: true, format: { with: VALID_EMAIL_REGEX}
      validates :login_id, presence: true, format: { with: VALID_VNAME_REGEX}, uniqueness: { case_sensitive: false}
      validates :vname, presence: true, format: { with: VALID_VNAME_REGEX}, uniqueness: { case_sensitive: false}
      validates :password, length: {minimum: 6}#, format: { with: VALID_PASSWORD_REGEX}
      validates :password_confirmation, presence: true #, format: { with: VALID_PASSWORD_REGEX}

      def to_param
         vname
      end
    end

    This is the sessionkey model :

    class Sessionkey &lt; ActiveRecord::Base
     belongs_to :user
    end

    This is the usertype model :

    class Usertype &lt; ActiveRecord::Base
     attr_accessible :privilege, :user_id #Only priviledge will be changeable
     belongs_to :user
    end

    This is the error message :

    No such file or directory - ffmpeg -i /home/eric/Projects/Local/Lduelingpets/Trial/public/uploads/tmp/1466811951-3149-2702/mp4_TrialMovies.mp4
  • Revision 8d3d2b76f3 : Tx size selection enhancements (1) Refines the modeling function and uses that

    22 juin 2013, par Deb Mukherjee

    Changed Paths :
     Modify /vp9/common/vp9_blockd.h


     Modify /vp9/encoder/vp9_encodeframe.c


     Modify /vp9/encoder/vp9_onyx_if.c


     Modify /vp9/encoder/vp9_onyx_int.h


     Modify /vp9/encoder/vp9_rdopt.c



    Tx size selection enhancements

    (1) Refines the modeling function and uses that to add some speed
    features. Specifically, intead of using a flag use_largest_txfm as
    a speed feature, an enum tx_size_search_method is used, of which
    two of the types are USE_FULL_RD and USE_LARGESTALL. Two other
    new types are added :
    USE_LARGESTINTRA (use largest only for intra)
    USE_LARGESTINTRA_MODELINTER (use largest for intra, and model for
    inter)

    (2) Another change is that the framework for deciding transform type
    is simplified to use a heuristic count based method rather than
    an rd based method using txfm_cache. In practice the new method
    is found to work just as well - with derf only -0.01 down.
    The new method is more compatible with the new framework where
    certain rd costs are based on full rd and certain others are
    based on modeled rd or are not computed. In this patch the existing
    rd based method is still kept for use in the USE_FULL_RD mode.
    In the other modes, the count based method is used.
    However the recommendation is to remove it eventually since the
    benefit is limited, and will remove a lot of complications in
    the code

    (3) Finally a bug is fixed with the existing use_largest_txfm speed feature
    that causes mismatches when the lossless mode and 4x4 WH transform is
    forced.

    Results on derf :
    USE_FULL_RD : +0.03% (due to change in the tables), 0% encode time reduction
    USE_LARGESTINTRA : -0.21%, 15% encode time reduction (this one is a
    pretty good compromise)
    USE_LARGESTINTRA_MODELINTER : -0.98%, 22% encode time reduction
    (currently the benefit of modeling is limited for txfm size selection,
    but keeping this enum as a placeholder) .
    USE_LARGESTALL : -1.05%, 27% encode-time reduction (same as existing
    use_largest_txfm speed feature).

    Change-Id : I4d60a5f9ce78fbc90cddf2f97ed91d8bc0d4f936

  • How do I get videos to upload using ruby on rails carrierwave-video ?

    9 juillet 2016, par Eric

    Updated as of July 9, 2016

    I tried to follow the instructions on the github website for the video uploader process using carrierwave-video gem but get an error that says the file or directory mmpeg -i doesn’t exist.

    The upload path for images functions correctly, just not the video one.

    I have added all of the following code necessary to help solve the error and minified as much as i possibly could.

    Video uploader code using carrierwave

    class VideoUploader < CarrierWave::Uploader::Base

     include CarrierWave::Video
     storage :file

     version :mp4 do
       process :encode_video => [:mp4, resolution: "100x100"]
     end

     def store_dir
       "uploads/#{model.class.to_s.underscore}/#{mounted_as}/#{model.id}"
     end
    end

    Here is the movie controller code that handles uploading of videos

    class MoviesController &lt; ApplicationController
      include MoviesHelper

      def index
         mode "index"
      end

      def show
         mode "show"
      end

      def new
         mode "new"
      end

      def edit
         mode "edit"
      end

      def create
         mode "create"
      end

      def update
         mode "update"
      end

      def destroy
         mode "destroy"
      end

      def review
         mode "review"
      end

      def approve
         mode "approve"
      end

      def deny
         mode "deny"
      end
    end

    Here is the model data for the movie that goes with it

    class Movie &lt; ActiveRecord::Base
     attr_accessible :created_on, :description, :maintenance, :reviewed, :subplaylist_id, :title, :user_id, :video, :remote_video_url
     belongs_to :user
     belongs_to :subplaylist
     mount_uploader :video, VideoUploader
    end

    Here is where the movie is supposed to be displayed but it is not working

    &lt;% provide(:title, "Movie: Where movies are made!") %>
    &lt;% provide(:keywords, "movies, video") %>
    &lt;% provide(:description, "This is the place where users showcase their wonderful video talent.") %>
    <p>&lt;%= notice %></p>
    <h1 class="pageheader">&lt;%= @movie.title %></h1>
    <br />
    <p class="pagetext">&lt;%= video_tag(@movie.video_url.to_s, controls: true, class: "imagebox") %></p>
    <p class="pagetext">&lt;%= @movie.description %></p>
    <p class="pagetext">Created on: &lt;%= @movie.created_on.strftime("%B-%d-%Y") %></p>
    <p class="pagetext">Owner: &lt;%= getType(@movie.user) %>&lt;%= link_to @movie.user.vname, user_path(@movie.user) %></p>
    <br />
    <p class="pagetext">&lt;%= link_to 'Back', mainplaylist_subplaylist_path(@subplaylist.mainplaylist, @movie.subplaylist) %></p>

    Here is where the movie new action is

    &lt;% provide(:title, "Movie: Create new movies here!") %>
    &lt;% provide(:description, "New movies are uploaded only to the site when the movie gets approved.") %>
    <h1 class="pagetextheader">New movie</h1>
    &lt;%= render 'form' %>
    <p class="pagetext">&lt;%= link_to 'Back', mainplaylist_subplaylist_path(@subplaylist.mainplaylist, @subplaylist) %></p>

    Here is where the movies forum parameters are

    &lt;%= form_for([@subplaylist, @movie], :html=>{:multipart => true}) do |f| %>
     &lt;% if @movie.errors.any? %>
       <div>
         <h2>&lt;%= pluralize(@movie.errors.count, "error") %> prohibited this movie from being saved:</h2>

         <ul>
         &lt;% @movie.errors.full_messages.each do |msg| %>
           <li>&lt;%= msg %></li>
         &lt;% end %>
         </ul>
       </div>
     &lt;% end %>
     <br />
     <div class="pagetext">
       &lt;%= f.label :title %><br />
       &lt;%= f.text_field :title %>
     </div>
     <div class="pagetext">
       &lt;%= f.file_field :video %>
     </div>
     <div class="pagetext">
       &lt;%= f.label :remote_video_url, "or video URL" %><br />
       &lt;%= f.text_field :remote_video_url %>
     </div>
     <div class="pagetext">
       &lt;%= f.label :description %><br />
       &lt;%= f.text_area :description %>
     </div>
     <div class="pagetext">
       &lt;%= f.submit %>
     </div>
     <br />
    &lt;% end %>

    Here is the movies helper code

    module MoviesHelper

      def mode(type)
         code = auto_logout
         if(code == true)
            sign_out
            redirect_to root_path
         else
            #Check if Maintenance is turned_on
            allmode = Maintenancemode.find_by_id(1)
            moviemode = Maintenancemode.find_by_id(19)
            mode_turned_on = (allmode.maintenance_on || moviemode.maintenance_on)
            #Determine if any maintenance is on
            if(mode_turned_on)
               #Determine if we are a regular user
               regularUser = (!current_user || !current_user.admin?)
               if(regularUser)
                  #Determine which maintenance mode is on
                  if(allmode.maintenance_on)
                     redirect_to maintenance_path
                  else
                     redirect_to movies_maintenance_path
                  end
               else
                  switch type
               end
            else
               switch type
            end
         end
      end

      private
         def getType(user)
            if(user.admin)
               value = "$"
            else
               typeFound = Usertype.find_by_user_id(user.id)
               if(typeFound)
                  type = typeFound.privilege
                  if(type == "Reviewer")
                     value = "^"
                  elsif(type == "Banned")
                     value = "!"
                  else
                     value = "~"
                  end
               else
                  value = "~"
               end
            end
            return value
         end

         def movieApproved
            movieFound = Movie.find_by_id(params[:movie_id])
            if(movieFound)
               movieFound.reviewed = true
               pouch = Pouch.find_by_user_id(movieFound.user_id)
               pointsForMovie = 10
               pouch.amount += pointsForMovie
               @pouch = pouch
               @pouch.save
               @movie = movieFound
               @movie.save
    #            MovieMailer.movie_approved(@movie, pointsForMovie).deliver
               redirect_to movies_review_path
            else
               render "public/404"
            end
         end

         def movieDenied
            movieFound = Movie.find_by_id(params[:movie_id])
            if(movieFound)
               #Retrieve the user who owns this pet first
               #userEmail = petFound.user.email
               #Send mail to user with link to edit the pet they sent
               @movie = movieFound
               MovieMailer.movie_denied(@movie).deliver
               redirect_to movies_review_path
            else
               render "public/404"
            end
         end

         def createMovie(subplaylistFound)
            newMovie = subplaylistFound.movies.new
            @subplaylist = subplaylistFound
            @movie = newMovie
         end

         def saveMovie(subplaylistFound, logged_in)
            newMovie = subplaylistFound.movies.new(params[:movie])
            newMovie.user_id = logged_in.id
            currentTime = Time.now
            newMovie.created_on = currentTime
            @movie = newMovie
            if(@movie.save)
               @subplaylist = subplaylistFound
    #            MovieMailer.review_movie(@movie).deliver
               flash[:success] = "#{@movie.title} is currently being reviewed please check back later."
               redirect_to subplaylist_movie_path(@subplaylist, @movie)
            else
               render "new"
            end
         end

         def switch(type)
            if(type == "index") #Admin only
               logged_in = current_user
               if(logged_in)
                  if(logged_in.admin)
                     allMovies = Movies.order("created_on desc").page(params[:page]).per(10)
                     @movies = allMovies
                  else
                     redirect_to root_path
                  end
               else
                  redirect_to root_path
               end
            elsif(type == "show")
               movieFound = Movie.find_by_id(params[:id])
               if(movieFound)
                  subplaylistFound = Subplaylist.find_by_id(params[:subplaylist_id])
                  if(subplaylistFound)
                     if(movieFound.reviewed)
                        @subplaylist = subplaylistFound
                        @movie = movieFound
                     else
                        logged_in = current_user
                        if(logged_in)
                           userMatch = ((logged_in.id == movieFound.user_id) || logged_in.admin)
                           if(userMatch)
                              @subplaylist = subplaylistFound
                              @movie = movieFound
                           else
                              redirect_to root_path
                           end
                        else
                           redirect_to root_path
                        end
                     end
                  else
                     redirect_to root_path
                  end
               else
                  render "public/404"
               end
            elsif(type == "new")
               logged_in = current_user
               if(logged_in)
                  subplaylistFound = Subplaylist.find_by_id(params[:subplaylist_id])
                  if(subplaylistFound)
                     if(subplaylistFound.collab_mode)
                        createMovie(subplaylistFound)
                     else
                        userMatch = (logged_in.id == subplaylistFound.user_id)
                        if(userMatch)
                           createMovie(subplaylistFound)
                        else
                           redirect_to root_path
                        end
                     end
                  else
                     render "public/404"
                  end
               else
                  redirect_to root_path
               end
            elsif(type == "create")
               logged_in = current_user
               if(logged_in)
                  subplaylistFound = Subplaylist.find_by_id(params[:subplaylist_id])
                  if(subplaylistFound)
                     if(subplaylistFound.collab_mode)
                        saveMovie(subplaylistFound, logged_in)
                     else
                        userMatch = (logged_in.id == subplaylistFound.user_id)
                        if(userMatch)
                           saveMovie(subplaylistFound, logged_in)
                        else
                           redirect_to root_path
                        end
                     end
                  else
                     render "public/404"
                  end
               else
                  redirect_to root_path
               end
            elsif(type == "edit")
               logged_in = current_user
               if(logged_in)
                  movieFound = Movie.find_by_id(params[:id])
                  if(movieFound)
                     userMatch = (logged_in.id == movieFound.user_id)
                     if(userMatch)
                        subplaylistFound = Subplaylist.find_by_id(movieFound.subplaylist_id)
                        if(subplaylistFound)
                           @subplaylist = subplaylistFound
                           @movie = movieFound
                        else
                           render "public/404"
                        end
                     else
                        redirect_to root_path
                     end
                  else
                     render "public/404"
                  end
               else
                  redirect_to root_path
               end
            elsif(type == "update")
               logged_in = current_user
               if(logged_in)
                  movieFound = Movie.find_by_id(params[:id])
                  if(movieFound)
                     userMatch = (logged_in.id == movieFound.user_id)
                     if(userMatch)
                        subplaylistFound = Subplaylist.find_by_id(movieFound.subplaylist_id)
                        if(subplaylistFound)
                           @movie = movieFound
                           if(@movie.update_attributes(params[:movie]))
                              @subplaylist = subplaylistFound
                              flash[:success] = 'Movie was successfully updated.'
                              redirect_to subplaylist_movie_path(@subplaylist, @movie)
                           else
                              render "edit"
                           end
                        else
                           render "public/404"
                        end
                     else
                        redirect_to root_path
                     end
                  else
                     render "public/404"
                  end
               else
                  redirect_to root_path
               end
            elsif(type == "destroy")
               logged_in = current_user
               if(logged_in)
                  movieFound = Movie.find_by_id(params[:id]) #Need to move this below the admin section to protect it
                  if(movieFound)
                     if(logged_in.admin)
                        subplaylistFound = Subplaylist.find_by_id(movieFound.subplaylist_id)
                        if(subplaylistFound)
                           @movie = movieFound
                           @subplaylist = subplaylistFound
                           @movie.destroy
                           redirect_to mainplaylist_subplaylist_path(@subplaylist.mainplaylist, @subplaylist)
                        else
                           render "public/404"
                        end
                     else
                        redirect_to root_path
                     end
                  else
                     render "public/404"
                  end
               else
                  redirect_to root_path
               end
            elsif(type == "review") #Admin
               logged_in = current_user
               if(logged_in)
                  if(logged_in.admin)
                     allMovies = Movie.all
                     moviesToReview = allMovies.select{|movie| !movie.reviewed}
                     @movies = Kaminari.paginate_array(moviesToReview).page(params[:page]).per(10)
                  else
                     typeFound = Usertype.find_by_user_id(logged_in.id)
                     if(typeFound.privilege == "Reviewer")
                        allMovies = Movie.all
                        moviesToReview = allMovies.select{|movie| !movie.reviewed}
                        @movies = Kaminari.paginate_array(moviesToReview).page(params[:page]).per(10)
                     else
                        redirect_to root_path
                     end
                  end
               else
                  redirect_to root_path
               end
            elsif(type == "approve") #Admin
               logged_in = current_user
               if(logged_in)
                  if(logged_in.admin)
                     movieApproved
                  else
                     typeFound = Usertype.find_by_user_id(logged_in.id)
                     if(typeFound.privilege == "Reviewer")
                        movieApproved
                     else
                        redirect_to root_path
                     end
                  end
               else
                  redirect_to root_path
               end
            elsif(type == "deny") #Admin
               logged_in = current_user
               if(logged_in)
                  if(logged_in.admin)
                     movieDenied
                  else
                     typeFound = Usertype.find_by_user_id(logged_in.id)
                     if(typeFound.privilege == "Reviewer")
                        movieDenied
                     else
                        redirect_to root_path
                     end
                  end
               else
                  redirect_to root_path
               end
            end
         end
    end

    Here is the subplaylists show code

    &lt;% provide(:title, "Subplaylist: The place where users videos gets uploaded to!") %>
    &lt;% provide(:keywords, "user, video, uploaded") %>
    &lt;% provide(:description, "Allows the categorization of various videos that the user submitted successfully.") %>
    <p>&lt;%= notice %></p>
    <h1 class="pageheader">&lt;%= @subplaylist.title %></h1>
    <br />
    <p class="pagetext">&lt;%= @subplaylist.description %></p>
    <br />
    <div class="pagebox">&lt;%= paginate @movies %></div>





    <br />
    <div class="pagetext">
      &lt;% @movies.each_with_index do |movie, index| %>
         <div class="container">
            <div class="inner">
               <div class="inner">&lt;%= link_to movie.title, subplaylist_movie_path(@subplaylist, movie) %></div>
               &lt;% if current_user &amp;&amp; (current_user.id == movie.user_id || current_user.admin? )%>
                  <div class="inner">&lt;%= button_to 'Edit', edit_subplaylist_movie_path(@subplaylist, movie), method: :get %></div>
                  <div class="inner">&lt;%= button_to 'Destroy', [@subplaylist, movie], method: :delete, data: { confirm: 'Are you sure?' } %></div>
               &lt;% end %>
               <p>&lt;%= video_tag movie.video_url(:thumb).to_s, controls: true %></p>
            </div>
            <br />
            <p>Created on: &lt;%= movie.created_on.strftime("%B-%d-%Y") %></p>
            <p>Owner: &lt;%= getType(movie.user) %>&lt;%= link_to movie.user.vname, user_path(movie.user) %></p>
         </div>
         &lt;% if ((index + 1) % 3) == 0 %>
            <br />
            <br />
         &lt;% end %>
      &lt;% end %>
    </div>
    <br />
    &lt;% if current_user %>
      <p class="pagetext">&lt;%= link_to "New Movie", new_subplaylist_movie_path(@subplaylist) %></p>
      <br />
    &lt;% end %>
    <p class="pagetext">&lt;%= link_to 'Back', user_mainplaylist_path(@mainplaylist.user.vname, @subplaylist.mainplaylist.title) %></p>

    Here is the subplaylists model

    class Subplaylist &lt; ActiveRecord::Base
      attr_accessible :title, :description, :collab_mode
      belongs_to :user
      belongs_to :mainplaylist
      has_many :movies, :foreign_key => "subplaylist_id", :dependent => :destroy
      VALID_NAME = /\A[A-Za-z][A-Za-z1-9][A-Za-z1-9 ]+\z/
      validates :title, presence: true, format: {with: VALID_NAME}
      validates :description, presence: true
    end

    Here is the subplaylists controller code

    class SubplaylistsController &lt; ApplicationController
      include SubplaylistsHelper

      def index
         mode "index"
      end

      def show
         mode "show"
      end

      def new
         mode "new"
      end

      def edit
         mode "edit"
      end

      def create
         mode "create"
      end

      def update
         mode "update"
      end

      def destroy
         mode "destroy"
      end
    end

    Here is the subplaylist helper code

    module SubplaylistsHelper

      def mode(type)
         code = auto_logout
         if(code == true)
            sign_out
            redirect_to root_path
         else
            #Check if Maintenance is turned_on
            allmode = Maintenancemode.find_by_id(1)
            subplaylistmode = Maintenancemode.find_by_id(18)
            mode_turned_on = (allmode.maintenance_on || subplaylistmode.maintenance_on)
            #Determine if any maintenance is on
            if(mode_turned_on)
               #Determine if we are a regular user
               regularUser = (!current_user || !current_user.admin?)
               if(regularUser)
                  #Determine which maintenance mode is on
                  if(allmode.maintenance_on)
                     redirect_to maintenance_path
                  else
                     redirect_to subplaylists_maintenance_path
                  end
               else
                  switch type
               end
            else
               switch type
            end
         end
      end

      private
         def getType(user)
            if(user.admin)
               value = "$"
            else
               typeFound = Usertype.find_by_user_id(user.id)
               if(typeFound)
                  type = typeFound.privilege
                  if(type == "Reviewer")
                     value = "^"
                  elsif(type == "Banned")
                     value = "!"
                  else
                     value = "~"
                  end
               else
                  value = "~"
               end
            end
            return value
         end

         def switch(type)
            if(type == "show")
               subplaylistFound = Subplaylist.find_by_id(params[:id])
               if(subplaylistFound)
                  mainplaylistFound = Mainplaylist.find_by_title(params[:mainplaylist_id])
                  if(mainplaylistFound)
                     playlistMatch = (subplaylistFound.mainplaylist_id == mainplaylistFound.id)
                     if(playlistMatch)
                        @mainplaylist = mainplaylistFound
                        @subplaylist = subplaylistFound
                        subplaylistMovies = @subplaylist.movies.all
                        reviewedMovies = subplaylistMovies
                        if(subplaylistMovies.count > 0)
                           reviewedMovies = subplaylistMovies.select{|movie| movie.reviewed}
                        end
                        @movies = Kaminari.paginate_array(reviewedMovies).page(params[:page]).per(10)
                     else
                        redirect_to root_path
                     end
                  else
                     render "public/404"
                  end
               else
                  redirect_to root_path
               end
            elsif(type == "destroy")
               logged_in = current_user
               if(logged_in)
                  subplaylistFound = Subplaylist.find_by_id(params[:id]) #Need to move this below the admin section to protect it
                  if(subplaylistFound)
                     if(logged_in.admin)
                        mainplaylistFound = Mainplaylist.find_by_id(subplaylistFound.mainplaylist_id)
                        if(mainplaylistFound)
                           @subplaylist = subplaylistFound
                           @mainplaylist = mainplaylistFound
                           @subplaylist.destroy
                           redirect_to mainplaylist_subplaylists_path(@mainplaylist)
                        else
                           render "public/404"
                        end
                     else
                        redirect_to root_path
                     end
                  else
                     render "public/404"
                  end
               else
                  redirect_to root_path
               end
            end
         end
    end

    Here is the User model

    class User &lt; ActiveRecord::Base
      attr_accessible :email, :first_name, :last_name, :login_id, :vname, :password, :password_confirmation, :avatar
      has_secure_password
      mount_uploader :avatar, AvatarUploader
      before_save { |user| user.email = user.email.downcase }
      before_save { |user| user.first_name = user.first_name.humanize }

      #key
      has_one :sessionkey, :foreign_key => "user_id", :dependent => :destroy
      has_one :usertype, :foreign_key => "user_id", :dependent => :destroy

      #Video section
      has_many :mainplaylists, :foreign_key => "user_id", :dependent => :destroy
      has_many :subplaylists, :foreign_key => "user_id", :dependent => :destroy
      has_many :movies, :foreign_key => "user_id", :dependent => :destroy

      #validates :first_name, presence: true
      VALID_EMAIL_REGEX = /\A[\w+\-.]+@[a-z\d\-.]+\.[a-z]+\z/i
      VALID_NAME_REGEX = /\A[a-z][a-z][a-z]+\z/i
      VALID_VNAME_REGEX = /\A[A-Za-z][A-Za-z][A-Za-z][A-Za-z0-9 ]+([-][A-Za-z0-9 ]+)?\z/
      VALID_PASSWORD_REGEX = /\A[A-Za-z0-9!][A-Za-z0-9!][A-Za-z0-9!][A-Za-z0-9!][A-Za-z0-9!][A-Za-z0-9!]+\z/
      validates :first_name, presence: true, format: { with: VALID_NAME_REGEX}
      validates :last_name, presence: true, format: { with: VALID_NAME_REGEX}
      validates :email, presence: true, format: { with: VALID_EMAIL_REGEX}
      validates :login_id, presence: true, format: { with: VALID_VNAME_REGEX}, uniqueness: { case_sensitive: false}
      validates :vname, presence: true, format: { with: VALID_VNAME_REGEX}, uniqueness: { case_sensitive: false}
      validates :password, length: {minimum: 6}#, format: { with: VALID_PASSWORD_REGEX}
      validates :password_confirmation, presence: true #, format: { with: VALID_PASSWORD_REGEX}

      def to_param
         vname
      end
    end

    Here is the sessionkey model

    class Sessionkey &lt; ActiveRecord::Base
     belongs_to :user
    end

    Here is the usertype model

    class Usertype &lt; ActiveRecord::Base
     attr_accessible :privilege, :user_id #Only priviledge will be changeable
     belongs_to :user
    end

    Error message

    No such file or directory - ffmpeg -i /home/eric/Projects/Local/Lduelingpets/Trial/public/uploads/tmp/1466811951-3149-2702/mp4_TrialMovies.mp4