Paperclip Video Upload

后端 未结 2 1847
南笙
南笙 2021-01-06 09:40

I\'m trying to enable video upload in my post. Can\'t get it to display the video. The video gets uploaded, I can confirm that while i manage to right click on the video ar

相关标签:
2条回答
  • 2021-01-06 09:46

    You should use video tag, not iframe (only video tag has autoplay options). Check here what formats are supported by what browser: http://caniuse.com/#search=video

    If you want crossbrowser solution, try VideoJS - http://www.videojs.com/ Here you can get a Rails plugin - https://github.com/seanbehan/videojs_rails

    0 讨论(0)
  • 2021-01-06 10:09

    Paperclip Video Upload:

    I had the same issue just this past week - Try this!

    Video model:
        has_attached_file :video, styles: {
            :medium => {
              :geometry => "640x480",
              :format => 'mp4'
            },
            :thumb => { :geometry => "160x120", :format => 'jpeg', :time => 10}
        }, :processors => [:transcoder]
        validates_attachment_content_type :video, content_type: /\Avideo\/.*\Z/
    

    Make sure you already bundled:

    gem 'paperclip', '~> 4.3.1'
    gem 'aws-sdk', '< 2.0'
    gem 'paperclip-av-transcoder'
    gem "paperclip-ffmpeg", "~> 1.2.0"
    

    Run the paperclip migration:

    rails g paperclip model video
    

    Be sure to add in post_controller.rb:

    private
    
        def bscenes_params
            params.require(:post).permit(:video)
        end
    

    Upload form:

    <%= f.file_field :video %>
    

    Show page:

    <%= video_tag bscene.video.url(:medium), controls: true, style: "max-width: 100%;" %>
    

    At this point you should get this error:

    Av::UnableToDetect (Unable to detect any supported library):
    

    Go to your terminal and type in:

    brew options ffmpeg
    

    Then run the following to install ffmpeg:

    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
    

    Restart your server and try to upload a video now! Hope this helps - Happy coding :)

    0 讨论(0)
提交回复
热议问题