ruby-av / paperclip-av-transcoder

Audio/Video Transcoder for Paperclip using FFMPEG/Avconv
MIT License
136 stars 82 forks source link

Accessing file metadata using '<attachment>_meta' #42

Closed jclemans closed 8 years ago

jclemans commented 8 years ago
You may optionally add `<attachment>_meta` to your model and it will get populated with information about the processed video.

What does this mean? Where and how does this need to be added to the model in order to work? There is a lack of context in the documentation on this subject. The way this is written looks like it has something to do with view markup, which seems contradictory to the instructions. I've looked at the source code and searched for any examples utilizing this feature, but can't make heads or tails of it. Can anyone provide additional detail on how to access file metadata using this gem? I really would like to be able to access an mp4 file's duration metadata.

If anyone can answer this question I would be more than happy to update the README to help others using this gem.

Edit: As a workaround I found an ffmpeg command that will grab the video duration from the metadata after it has been uploaded and saved. I set up an after_save callback on my video model that uses this to save the duration to the db. duration = ffprobe -i #{file_path} -show_entries format=duration -v quiet -of csv="p=0"

owahab commented 8 years ago

The message can use a lot of enhancements indeed. Here's what I was trying to explain: If your model example has an attachment field named :avatar, create a new migration to add avatar_meta to example database table (ideally would be called examples). Then paperclip-av-transcoder will add meta data related to the uploaded file to avatar_meta.

Please feel free to quote and rephrase.

jclemans commented 8 years ago

Thank you so much for answering this question quickly! So an example migration would look something like this:

def change
    add_column :users, :avatar_meta, :string
end

Is :string the correct type to store the meta as in this case?

owahab commented 8 years ago

Since meta data is usually a hash, it's better to use hstore, json or jsonb field types.