2014-10-01 5 views
2

좋아, 이제는 클립 클립을 사용하여 이미지와 비디오를 업로드했습니다. 궁금 해서요. 비디오를 레일에 저장하는 간단한 방법이 있습니까? 나는 파일을 업로드하기 위해 양식을 만들었고, 나는 그것을 저장해야하는 특정 유형이 있는지 궁금합니다. (분명히 문자열이 아니라, 그 선을 따라). 나는 단순히 세 가지 파일 유형 모두를 가진 비디오 플레이어를 원합니다. (ogg, mp4, wav). 데이터베이스의 각 행에 저장됩니다.레일에 비디오 파일 저장하기

답변

4

아마도 paperclip-ffmpeg을보고 싶을 것입니다. 나는 클립 스타일으로 다른 형식을 저장합니다. 이것은 예를 들어 썸네일과 같이 다양한 크기를 생성하기 위해 이미지를 처리하는 일반적인 클립 클립 이미지 업로드와 매우 비슷하게 보입니다.

면책 조항 : 이렇게하면 서버에 ffmpeg를 설치해야합니다. Mac을 사용하고 자작농을 사용하는 경우이 링크가 유용합니다. http://www.renevolution.com/how-to-install-ffmpeg-on-mac-os-x/

아래 예에서 데이터베이스의 첨부 파일이 data으로 설정되어 있다고 가정 해 보겠습니다.

마이그레이션을 실행하여 테이블에 적절한 열을 추가하십시오.

> rails g migration add_data_to_videos data:attachment 

다음 모델에서.

# Validations 
validates_attachment_presence :data 
validates_attachment_size :data, less_than: 100.megabytes # if you want a max file size 
validates_attachment_content_type :data, content_type: /\Avideo\/.*\Z/ # or you can specify individual content types you want to allow 

has_attached_file :data, 
    url: '/videos/:id/:style/:basename.:extension', # whatever you want 
    styles: { 
    poster: { size: '640x480', format: 'jpg' }, # this takes a snapshot of the video to have as your poster 
    v_large_webm: { geometry: '640x480', format: 'webm' }, # your webm format 
    v_large_mp4: { geometry: '640x480', format: 'mp4' } # your mp4 format 
    }, 
    processors: [:ffmpeg], 
    auto_rotate: true 

이렇게 설정하면 이미지가있는 클립 클립을 사용하는 것과 매우 유사합니다.

# To display the video (HTML5 way using HAML) 
%video{controls: '', height: 'auto', width: '100%', poster: @video.data.url(:poster)} 
    %source{src: @video.data.url(:v_large_mp4), type: 'video/mp4'} 
    %source{src: @video.data.url(:v_large_webm), type: 'video/webm'} 
    Your browser does not support the video tag. 

백그라운드 작업을 사용하여 처리하는 것이 좋습니다. 아마 DelayedJob.

관련 문제