开发者

Capture Video Length with FFMPEG and Paperclip

开发者 https://www.devze.com 2023-01-28 22:39 出处:网络
I am trying to get the video length during the video upload.We are using SWFUpload to upload the file.Then paperclip to store it on S3.Our current process is loading the file into memory and then anal

I am trying to get the video length during the video upload. We are using SWFUpload to upload the file. Then paperclip to store it on S3. Our current process is loading the file into memory and then analyzing it. It explodes with large movies. I know I can re-download the file from S3 to my EC2 instance 开发者_Go百科afterwards.

I was wondering if there is a way to process the file before Paperclip takes it, so I can run the FFMPEG inspection on it.


You can do a before_save to process the temporary file before it is saved if you are not uploading straight to s3. That's probably the easiest way.

I would wonder do you really need to load the whole file using FFMPEG? All you need is the meta-data of the file. I wrote an app for audio that did something similar. You can get the filesize from Paperclip, if you can get the bitrate of the mpeg you can calculate the length of the file easily by dividing the filesize by the bitrate.

Use a before_save/before_create callback to get the bitrate from the file and store it as a field in the database. Generate the length dynamically from this value.

0

精彩评论

暂无评论...
验证码 换一张
取 消