Save image or animation in pyglet - python-2.7

I have an image saving issue. I need to take input of either a bmp, jpg, png, or gif and display it. The display part is fairly easy, the hard part is saving it. I want to take the user-supplied file and save it in a zipped directory that's going to be the save file for this project. I see that I can do pygletimage.save(filename) and get a png file. I'm fine with the format change for still images. The question is, how can I save a gif file easily in pyglet?

I use this function at every frame :
pyglet.image.get_buffer_manager().get_color_buffer().save(filename)
Here's the complete snippet. It saves whatever you display to numbered image files.
#---EXPORT --------------------------------------------------------
def save_a_frame(self):
file_num=str(self.frame_number).zfill(5)
file_t=str(self.chrono)
filename="frame-"+file_num+'-# '+file_t+'sec.png'
pyglet.image.get_buffer_manager().get_color_buffer().save(filename)
print 'image file writen : ',filename
def export_loop(self,dt):
constant_interval=1.0/PicPS
if self.chrono<END_TIME:
# update at a constant dt, regardless of real time
# so that even if refresh is slow no frame should be missing
# self.frame_draw(PicPS)
self.update(constant_interval)
self.frame_draw(dt)
self.frame_number+=1
self.save_a_frame()
else:
exit()

You can save each frame as a PNG via your pygletimage.save() method, then use the imagemagick command-line tool to combine those into a GIF like so:
convert -delay 10 -loop 0 frame_*.png animation.gif
See https://www.imagemagick.org/Usage/anim_basics/ for more information.

Related

Trying to encode a GIF file using giflib

I am given image data and color table I am trying to export it as a single frame GIF using giflib. I looked into the API, but can't get it to work. The program crashes even at the first function:
GifFileType image_out;
int errorCode = 0;
char* fileName = "SomeName.gif";
image_out = *EGifOpenFileName(fileName,true, &errorCode);
It is my understanding that I first need to open a file by specifying it's name and then update it with fileHandle. Then Fill in the screen description, the extension block the image data and add the 3B ending to the file. Then use EGifSpew to export the whole gif. The problem is that I can't even use EGifOpenFileName(); The program crashes at that line.
Can someone help me the API of giflib? This problem is getting really frustrating.
Thanks.
EDIT:
For the purposes of simple encoding I do not want to specify a color table and I just want to encode a single frame GIF.
The prototype is:
GifFileType *EGifOpenFileName(char *GifFileName, bool GifTestExistance, int *ErrorCode)
You should write as
GifFileType* image_out = EGifOpenFileName(fileName,true, &errorCode);
Note GifFileType is not POD type so you should NOT copy like that.

Save output to disk using FMOD

I am using FMOD to play some sounds and I would like to save the resulting mix to the disk.
I have been trying the system->recordStart(0, sound, true) path, but that saves the microphone input of the device.
In some way, I would like to redirect the speakers output to the disk
Thank you
Marc
To redirect everything that would go to the speakers to disk simply use the function System::setOutput and pass in a value of FMOD_OUTPUTTYPE_WAVWRITER. Make sure you call this function before you call System::init, when you are done call System::release and a wav file will appear next to your executable.
You can also specify the name and location of the output wav file by passing a full path via the System::init extradriverdata parameter.

generating thumbnails using CF8 cfimage tag - large filesize caused by image metadata

i'm building a small web app that will resize images to different pixel dimensions after they have been uploaded.
I am attempting to create 150px X 100px thumbnail from a 3mb jpg image, but am unable to get the filesize smaller than 68kb ( I would expect to generate a file between 4kb & 15kb file depending on compression type etc).
I have used the action="resize" method of the tag & also used the ImageResize() & imageScaleToFit() functions but all these methods keep the exif & IPTC meta data intact (I am assuming this is what is keeping the thumbnail file as large as it is).
If I use an image without any metadata it resizes the thumbnail to a small filesize as expected.
Is there anyway I can strip the exif & IPTC metadata from the image to reduce the thumbnail size using any of CF8's built in image functions?
you can use the Sanselan Java library to remove EXIF and IPTC metadata. Here is a code sample using the removeExifMetadata from this library:
<cfscript>
// setup and init the Sanselan library
SanselanPath = arrayNew(1);
arrayAppend(SanselanPath, expandPath("sanselan\sanselan-0.97-incubator.jar"));
javaloader = createObject("component", "javaloader.JavaLoader").init(SanselanPath);
// setup your source and destination image
pathToInFile = ExpandPath("myImage.jpg");
pathToOutFile = ExpandPath("MyImagewoEXIF.jpg");
inFile = javaloader.create("java.io.FileInputStream").init(pathToInFile);
outFile = javaloader.create("java.io.FileOutputStream").init(pathToOutFile);
// create the exifRewriter
exifRewriter = javaloader.create("org.apache.sanselan.formats.jpeg.exifRewrite.ExifRewriter").init();
// call the method removeExifMetadata
exifRewriter.removeExifMetadata(inFile,outFile);
outFile.close();
</cfscript>
You can do the same to remove IPTC meta data using iptc.JpegIptcRewriter and the removeIPTC method. You can verify using the CF functions ImageGetEXIFMetaData and ImageGetIPTCMetadata that everything has been removed.
Now I'm not sure that it will really reduce the file size, let me know :-)
You can create a new image the same dimensions as the thumbnail and use ImagePaste to paste in the thumbnail. ColdFusion does not preserve EXIF data with the paste operation.
If you wanted to, you could use the command line tool that is linked in the post that #Ciaran Archer linked above, and then write a bash command (*nix/Mac) or bat command (Windows) that runs the command and then use CFExecute to run that command. I have never really worked with CFImage before or image metadata so I couldn't give you the proper code, but what I said will probably have the best performance, because you are exporting commands to the filesystem is made to do (work with files).
Check this out:
Use
ImageWrite(imageObject,destination,0.9,true) returns small sized image (90% quality, overwrite="true")
instead of
ImageWrite(imageObject,destination,true,0.9) returns big sized image (quality="true" which is 1, overwrite="0.9" which is true)
Select quality ratio from 0 to 1 to reduce the file size.

Convert video file to TIFF with ffmpeg.dll or avcodec.dll? Is "on-the-fly" possible?

I want to create a program, which gets a video-file from Qt, converts that video file to TIFF-files and sends them to an algorithm which handles these TIFF-Files.
My questions:
is it possible with ffmpeg or avcodec not to convert a video-file to TIFF-files first on harddrive and send them to the algorithm after that, but to convert frame for frame and send it to the algorithm right away?
The more important question: Is it possible to do that not with an external process with ffmpeg.exe, but with ffmpeg.dll? Or is it only possible with avcodec.dll? (It doesn't have to be "on-the-fly" like at my point above) How can I create a ffmpeg.dll with header and lib?
for exporting tif :
http://www.repaire.net/forums/cinema-numerique/215306-projet-dencodage-dcp.html
Creating a tiff from second 29 in a mpeg, using ffmpeg dd201110 can be done like this:
ffmpeg -i 'test.mpg' -vframes 1 -compression_level 0 -ss 29 'test.tiff'
YMMV :-D
If you dont want to store the image as a file, take a look at ffmpeg-php
http://ffmpeg-php.sourceforge.net/
$movie->getFrame([Integer framenumber])
Returns a frame from the movie as an ffmpeg_frame object.
$frame->toGDImage()
Returns a truecolor GD image of the frame.
There may be C code underneath you can reuse..

Saving image to file with IImageEncoder

do you have a working code to share.
I’m trying to figure out how to save to a file an IBitmapImage image.
I need to resize existing .jpg file and it seems like the only API for Windows Mobile. I managed to load it convert it to IImage -> IBitmapImage -> IBasicBitmapOps and resize it finally, but I have no clue how to save it properly to a new file.
Use IBitmapImage::LockBits to get access to the image data via its BitmapData* lockedBitmapData parameter. Use the BitmapData to prepare a bitmap file info header, then write that one and the image data in BitmapData::Scan0 to a file using regular file writing with ::WriteFile or higher level ones if you use such.