1. Generating thumbnails of images and videos
- Posted by DD Jul 21, 2009
- 1140 views
- Last edited Jul 22, 2009
How would i go about generating thumbnails from images and videos? What i need to do is get a set of thumbs from a source video for display and to save to disk. The program needs to work on Windows XP, Vista, and 7, and needs to support any video container and codec a user is likely to run into; .mp4, wmv, avi, mov, and such. Is there examples of this in your archives or can anyone give example code on doing this?
2. Re: Generating thumbnails of images and videos
- Posted by ghaberek (admin) Jul 22, 2009
- 1176 views
ffmpeg to the rescue! (I really like this program.)
This will export a single frame at the 3 second mark to a file called Image1.jpg.
Option | Description |
---|---|
-i | Input file |
-an | Disable audio recording |
-ss | Seek to position |
-r | Frame rate (fps) |
-vframes | Number of frames |
-y | Force overwrite of output file(s) |
-Greg
3. Re: Generating thumbnails of images and videos
- Posted by DD Jul 22, 2009
- 1182 views
ffmpeg to the rescue! (I really like this program.)
This will export a single frame at the 3 second mark to a file called Image1.jpg.
Option | Description |
---|---|
-i | Input file |
-an | Disable audio recording |
-ss | Seek to position |
-r | Frame rate (fps) |
-vframes | Number of frames |
-y | Force overwrite of output file(s) |
-Greg
Thanks, ghaberek, this seems a lot easyer than i had expected! Few questions though; Is ffmpeg available as a single windows .exe? Is it possible to package it with a single .exe euprogram? Also, is it possible to specify the snapshot position as a percentage or get the length in seconds of the video so one can be calculated?
4. Re: Generating thumbnails of images and videos
- Posted by ghaberek (admin) Jul 22, 2009
- 1152 views
Is ffmpeg available as a single windows .exe?
Yes. There are "static" and "shared" builds of ffmpeg. Static builds are single, large .exe files, while shared builds are smaller .exe files with several .dll dependancies.
Is it possible to package it with a single .exe euprogram?
You would have provide the ffmpeg.exe file separately. Most programs nowadays include several dozen/hundred/thousand files and are packaged and distributed with some sort of installer, like NSIS.
Also, is it possible to specify the snapshot position as a percentage or get the length in seconds of the video so one can be calculated?
If you call ffmpeg with only an input file, like ffmpeg -i "video file.avi" you'll get an output like this:
Input #0, avi, from 'video file.avi': Duration: 00:12:34.00, start: 0.000000, bitrate: 4067 kb/s Stream #0.0: Video: msvideo1, rgb555, 1372x900, 15.00 tb(r) Stream #0.1: Audio: pcm_s16le, 22050 Hz, mono, s16, 352 kb/s At least one output file must be specified
You can grab the Duration from this output and calculate a percentage of it on your own.
-Greg
5. Re: Generating thumbnails of images and videos
- Posted by GeorgeWalters Jul 23, 2009
- 1110 views
Greg, can this program make a thumbnail of a single larger pic? If not do you know of a good one?
6. Re: Generating thumbnails of images and videos
- Posted by ghaberek (admin) Jul 23, 2009
- 1146 views
Greg, can this program make a thumbnail of a single larger pic? If not do you know of a good one?
ImageMagick is a great tool for making thumbnails.
It can also operate on several images at once:
convert *.jpg[125x125] thumb%03d.jpg (this is faster)
I also use GD and CxImage in my applications.
-Greg
7. Re: Generating thumbnails of images and videos
- Posted by GeorgeWalters Jul 23, 2009
- 1144 views
- Last edited Jul 24, 2009
Greg, can this program make a thumbnail of a single larger pic? If not do you know of a good one?
ImageMagick is a great tool for making thumbnails.
It can also operate on several images at once:
convert *.jpg[125x125] thumb%03d.jpg (this is faster)
I also use GD and CxImage in my applications.
-Greg
Thanks Greg. I'll take a look.
George
8. Re: Generating thumbnails of images and videos
- Posted by DD Jul 25, 2009
- 1157 views
Thanks for the help so far, have a few more requirements. My BBcode is a bit rusty, but ill try and make this a formatted nice list for ya
- Is it possible to resize the video snapshots to thumbnail size directly from FFMPEG, or will they need a run through something else to shrink them?
- How do i generate thumbnails from JPEG images? You have mentioned ImageMagick but its HUGE, a 34 meg dependency is not usable in this case.
- I also need to get the image size from the original image.
- How do i display thumbnails in a Win32lib app, preferably from JPEG data contained in a sequence (or memory location)?
- FFMPEG at 9 megs is no lightweight either, is there anything smaller? Considering the number of codecs supported, it would be acceptable if there is no alternative.
- The app must be standalone, no installers or extra files unless they can be packaged within the single .exe app
- Also, the app is dealing with somewhat sensitive data, the thumbnails should not need to be written to temp files. Is this doable?
Since i need a prototype of the app ASAP, at least the last two requirements can be ignored if they are not possible in EU in favour of just getting the thing to work. Just means Ill have to develop the final app in VC. I hate VC.
9. Re: Generating thumbnails of images and videos
- Posted by kinz Jul 25, 2009
- 1118 views
Thanks for the help so far, have a few more requirements. My BBcode is a bit rusty, but ill try and make this a formatted nice list for ya
- Is it possible to resize the video snapshots to thumbnail size directly from FFMPEG, or will they need a run through something else to shrink them?
- How do i generate thumbnails from JPEG images? You have mentioned ImageMagick but its HUGE, a 34 meg dependency is not usable in this case.
- I also need to get the image size from the original image.
- How do i display thumbnails in a Win32lib app, preferably from JPEG data contained in a sequence (or memory location)?
- FFMPEG at 9 megs is no lightweight either, is there anything smaller? Considering the number of codecs supported, it would be acceptable if there is no alternative.
- The app must be standalone, no installers or extra files unless they can be packaged within the single .exe app
- Also, the app is dealing with somewhat sensitive data, the thumbnails should not need to be written to temp files. Is this doable?
Since i need a prototype of the app ASAP, at least the last two requirements can be ignored if they are not possible in EU in favour of just getting the thing to work. Just means Ill have to develop the final app in VC. I hate VC.
Try please this:
http://www.fookes.com/downloads.php?product=ezthumbs
kinz
10. Re: Generating thumbnails of images and videos
- Posted by DD Jul 25, 2009
- 1088 views
Yes, this seems to be approximately what i am trying to accomplish, just simpler and with video support and some other custom features. The ezthumbs product cannot be integrated into my app, so it will not be useful for this purpose. As such, I still need answers to my previous posting.
11. Re: Generating thumbnails of images and videos
- Posted by mic_ Jul 25, 2009
- 1122 views
Here's something I wrote a little more than a year ago to go through all JPG images in the current directory, generate thumbnails for each of them, save the thumbnails in a directory named "thumbs" and create a html file that displays all the tumbnails. It uses CxImage to load and save the images.
include cximage.ew include file.e include machine.e include get.e include misc.e constant INITIALDIR = current_dir() constant s = dir(INITIALDIR&"\\*.JPG") constant fn = open("thumbs\\index.html","wb") atom image -- Initialize the CXI library if not CXI_Init() then abort(0) end if puts(fn,"<html><head><title>Thumbs</title></head><body><table><tr>") for i=1 to length(s) do if length(s[i][D_NAME])>4 then -- Load an image from file image = CXI_LoadImage(INITIALDIR&"\\"&s[i][D_NAME], CXI_FORMAT_UNKNOWN, 0) -- Abort if the image couldn't be loaded if not image then abort(0) end if CXI_Resize(image, 240, 160, CXI_GOOD_RESIZE) CXI_SetJpegQuality(image,90) puts(fn,"<td><a href=\""&s[i][D_NAME]&"\"><img src=\""&s[i][D_NAME][1..length(s[i][D_NAME])-4]&"-tmb.jpg"&"\"></img></a></td>") if remainder(i,4)=0 then puts(fn,"</tr>\n<tr>") end if -- Save a copy of the image as JPEG if CXI_SaveImage(image, INITIALDIR&"\\thumbs\\"&s[i][D_NAME][1..length(s[i][D_NAME])-4]&"-tmb.jpg", CXI_FORMAT_JPG) then end if puts(1,s[i][D_NAME]&"\n") printf(1,"Image dimensions: %dx%d\n",{CXI_GetWidth(image),CXI_GetHeight(image)}) printf(1,"Bits per pixel: %d\n\n",CXI_GetBpp(image)) -- Destroy the resources allocated for the image CXI_FreeImage(image) end if end for puts(fn,"</tr></table></body></html>")
12. Re: Generating thumbnails of images and videos
- Posted by DD Jul 25, 2009
- 1124 views
Here's something I wrote a little more than a year ago to go through all JPG images in the current directory, generate thumbnails for each of them, save the thumbnails in a directory named "thumbs" and create a html file that displays all the tumbnails. It uses CxImage to load and save the images.
include cximage.ew include file.e include machine.e include get.e include misc.e constant INITIALDIR = current_dir() constant s = dir(INITIALDIR&"\\*.JPG") constant fn = open("thumbs\\index.html","wb") atom image -- Initialize the CXI library if not CXI_Init() then abort(0) end if puts(fn,"<html><head><title>Thumbs</title></head><body><table><tr>") for i=1 to length(s) do if length(s[i][D_NAME])>4 then -- Load an image from file image = CXI_LoadImage(INITIALDIR&"\\"&s[i][D_NAME], CXI_FORMAT_UNKNOWN, 0) -- Abort if the image couldn't be loaded if not image then abort(0) end if CXI_Resize(image, 240, 160, CXI_GOOD_RESIZE) CXI_SetJpegQuality(image,90) puts(fn,"<td><a href=\""&s[i][D_NAME]&"\"><img src=\""&s[i][D_NAME][1..length(s[i][D_NAME])-4]&"-tmb.jpg"&"\"></img></a></td>") if remainder(i,4)=0 then puts(fn,"</tr>\n<tr>") end if -- Save a copy of the image as JPEG if CXI_SaveImage(image, INITIALDIR&"\\thumbs\\"&s[i][D_NAME][1..length(s[i][D_NAME])-4]&"-tmb.jpg", CXI_FORMAT_JPG) then end if puts(1,s[i][D_NAME]&"\n") printf(1,"Image dimensions: %dx%d\n",{CXI_GetWidth(image),CXI_GetHeight(image)}) printf(1,"Bits per pixel: %d\n\n",CXI_GetBpp(image)) -- Destroy the resources allocated for the image CXI_FreeImage(image) end if end for puts(fn,"</tr></table></body></html>")
It appears that CxImage adds yet another DLL dependency to the project, and as such will not be suitable for the final app. Nonetheless, i need a prototype and do not have the time to recode the app in Visual C, so it will have to do for now to make the prototype release.
How then do i display the thumbnail in the GUI, which is built with win32lib?
13. Re: Generating thumbnails of images and videos
- Posted by mic_ Jul 25, 2009
- 1078 views
There's already a thread about displaying images using win32lib and cximage.
14. Re: Generating thumbnails of images and videos
- Posted by DD Jul 25, 2009
- 1132 views
There's already a thread about displaying images using win32lib and cximage.
Thanks, that appears to be exactly what i need. CxImage mentions the possibility of saving an image directly to a memory location, but says that thats not yet implemented. Is it possible to do that as well?
Also, I found a suggestion that it may be possible to append arbitrary files to a .exe and have the application 'extract' that data to the files at run time. This would eliminate the dependencies problem by allowing me to distribute ffmpeg.exe and cximage.dll as part of the application's .exe. Can this be done with a .exe generated by EU? This would allow releasing the app weeks or months ahead of schedule, as it would not have to be recoded in another language.
15. Re: Generating thumbnails of images and videos
- Posted by mic_ Jul 26, 2009
- 1158 views
I've got a new version of the CxImage wrapper that lets you save to memory, something like this:
constant ptr = allocate(4) atom pEncodedData integer bufferSize bufferSize = CXI_SaveImage(image, ptr, CXI_FORMAT_JPG) if bufferSize > 0 then pEncodedData = peek4u(ptr) else -- Error end if
It also adds functions to generate a HBITMAP directly from a loaded image, to create thumbnails with correct aspect ratio, and to apply various filters like rotation, blur, gamma, dither..
It hasn't been properly tested or documented yet so I'll upload it to the archive later, but in the meantime you can find it here
16. Re: Generating thumbnails of images and videos
- Posted by ghaberek (admin) Jul 27, 2009
- 1113 views
I'm curious as to why you need a single, stand-alone exe file. I've been down that road before, and each time I've determined it was a moot, if not impossible request. Modern applications often have dozens, hundreds, or even thousands of dependencies (DLL files). Asking for a laundry list of features stuffed into a single executable seems like a rather tall request IMHO.
You may want to look into the GDI+ Flat API, with which you should be able gain the functionality CxImage with native Windows DLLs. I don't think it's been wrapped in Euphoria yet. It's made up of "about 600 functions", a couple dozen structures, and about a hundred constants.
You may be able to use DirectShow to obtain thumbnails from videos, but that seems to be a COM library, so you'd have to use EuCOM. I have no idea where to even begin with that.
-Greg