# Attachment\_fu

**URL:** <https://www.ruby-forum.com/t/attachment-fu/176067>\
**Category:** Rails\
**Created:** [September 24, 2009, 10:20am UTC](https://www.ruby-forum.com/t/attachment-fu/176067 "2009-09-24T10:20:24Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Abhishek\_shukla](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/7cd45c/32.png) [@Abhishek\_shukla](https://www.ruby-forum.com/u/Abhishek_shukla)\
**Post date:** [September 24, 2009, 10:20am UTC](https://www.ruby-forum.com/t/attachment-fu/176067/1 "2009-09-24T10:20:24Z")

</div>

Hello,  
I have a functionality where i need to upload an image, So for that i am  
using attachment\_fu + acts\_as\_state\_machine,. and every thing is  
working  
fine. But now from the view front i want to display as an thumbnail  
image  
just like youtube but the problem is that how do i crop a image from a  
video?

Thanks for any help

Thanks  
Abhis

---

<div class="post-metadata">

**Author:** ![Abhishek\_shukla](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/7cd45c/32.png) [@Abhishek\_shukla](https://www.ruby-forum.com/u/Abhishek_shukla)\
**Post date:** [September 24, 2009, 5:12pm UTC](https://www.ruby-forum.com/t/attachment-fu/176067/2 "2009-09-24T17:12:36Z")

</div>

Abhishek shukla wrote:

> Hello,  
> I have a functionality where i need to upload an image, So for that i am  
> using attachment\_fu + acts\_as\_state\_machine,. and every thing is  
> working  
> fine. But now from the view front i want to display as an thumbnail  
> image  
> just like youtube but the problem is that how do i crop a image from a  
> video?

Is your question on actually getting a frame from a video file, or  
cropping an image?

As far as grabbing a frame that might depend on what video format you’re  
using. For example QuickTime provides methods for getting/setting a  
poster frame. So from the Quicktime API you would use a message to  
QTMovie:

- (NSImage \*)posterImage.

In case no posterImage has been set then you could fall back to getting  
some other frame using the message:

- (NSImage \*)frameImageAtTime:(QTTme)time

Now, obviously that’s the internals of QuickTime, but the point I’m  
making is that I’m not sure that attachement\_fu itself is going to help  
you. I’m sure there is probably an open source tool that can provide  
access to these features.

Maybe ffmpeg would help:  
[http://ffmpeg.org/](http://ffmpeg.org/)

---

<div class="post-metadata">

**Author:** ![Abhishek\_shukla](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/7cd45c/32.png) [@Abhishek\_shukla](https://www.ruby-forum.com/u/Abhishek_shukla)\
**Post date:** [September 24, 2009, 5:24pm UTC](https://www.ruby-forum.com/t/attachment-fu/176067/3 "2009-09-24T17:24:47Z")

</div>

Robert W. wrote:

> Maybe ffmpeg would help:  
> [http://ffmpeg.org/](http://ffmpeg.org/)

An excerpt from the ffmpeg docs:

For extracting images from a video:

ffmpeg -i foo.avi -r 1 -s WxH -f image2 foo-%03d.jpeg

This will extract one video frame per second from the video and will  
output them in files named `foo-001.jpeg', `foo-002.jpeg’, etc. Images  
will be rescaled to fit the new WxH values.

If you want to extract just a limited number of frames, you can use the  
above command in combination with the -vframes or -t option, or in  
combination with -ss to start extracting from a certain point in time.  
…  
…  
`-ss position' Seek to given time position in seconds. hh:mm:ss[.xxx] syntax is also supported. ... ... `-vframes number’  
Set the number of video frames to record.

This looks to me like it should work well for your needs.

---

<div class="post-metadata">

**Author:** ![Abhishek\_shukla](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/7cd45c/32.png) [@Abhishek\_shukla](https://www.ruby-forum.com/u/Abhishek_shukla)\
**Post date:** [September 25, 2009, 1:15pm UTC](https://www.ruby-forum.com/t/attachment-fu/176067/4 "2009-09-25T13:15:05Z")

</div>

Thanks robert for sharing the ideas will defiantly implement it.

On Thu, Sep 24, 2009 at 8:54 PM, Robert W. \<
