OpenGL - Create video output file - file

I want to be able to use OpenGL to create a video output file instead of the usual display on screen output. I am thinking by not using glutPostRedisplay() or (SFML version, which is something like this:) window.Display(), and somehow using glReadPixels() instead.
glReadPixels puts the pixel content into an array in memory (as you might already know) but how can I convert that into a frame, and string several frames together in a video file? And what format would the video file be in, so that I can play it?
I should explain why I want to do this: A lot of physics simulations can take a very long time to calculate enough information to display one frame, so it's better to leave it running overnight and play the video file the next morning. You wouldn't want to keep coming back every 5 minutes to see what had happened.

glutPostRedisplay is part of GLUT and not something specific to OpenGL.
You normally do offscreen rendering using either a PBuffer or using a hidden window and a framebuffer object.
Converting a image into a video can be done in various ways. For example you could utilize FFmpeg using image2pipe as input format and write the raw image data to the ffmpeg process standard input. A much simpler scheme would be to dump each frame into a separate image file. Using libpng is straightforward. You can then merge the individual images into a video.
However when doing physics simulation you should not dump the final rendering into a file. Instead you should store the simulation data for later playback, as you then can adjust rendering parameters without having to re-simulate everything. And you will have to make adjustments to the renderer!

Related

how to convert jpegs to video with fixed fps?

I have a series of jpegs,I would like to pack and compress them to a Video.
I use tool mpeg streamclip, but it double the whole play time.
If I have 300 jpegs, set fixed fps 30, I expect to get a video of 10s length . but using stream clip I get a 20s long video.
One answer is to get someone who understands programming. The programming APIs (application interfaces, the way client programs call libraries) to the lig libraries like ffmeg have ways in which frame rate can be controlled, and it's usually quite a simple matter to modify a program to produce fewer intermediate frames if you are creating a video from a list of JPEGs.
But the best answer is probably to find a tool that supports what you want to do. That's not a question to ask a programmer especially. Ask someone who knows about video editing. (It would take me about two days to write such a tool from scratch on top of my own JPEG codec and ffmpeg, so obviously I can't do it in response to this question, but that's roughly the level of work you're looking at).

Creating a GdkPixbuf from raw Bitmap data

I am trying to port a Clean graphics library (specifically, ObjectIO) to Linux with GDK. The library consists of a non-OS-specific part, which I don't want to touch because of compatibility issues, and an OS-specific part which I can touch.
One of the functions I have to implement is one that takes raw data from a .bmp file and has to build a GdkPixbuf from this. This function has to be written in C.
I am aware of the function gdk_pixbuf_new_from_file(), but I do not get the file name (and can't change that, as it's in the non-OS-specific part of the library). I only get the raw data.
I saw this manual entry, and I guess I could use gdk_pixbuf_new_from_data(), but this requires that you know the row stride of the image, of which I'm unsure how to get it.
Is there a way to get the row stride from the file? If not, the only possibility I see is to create a temporary file with the data and then call gdk_pixbuf_new_from_file() - but that would be really ugly.
You want to use the function:
int stride = cairo_format_stride_for_width(CAIRO_FORMAT_RGB24, ImageWidth);

How to resize an image using libpng?

I am looking for an advice how to resize an image using libpng in C. I have already written a function, which makes png image from the structure. I want to make my image bigger: for example 1 pixel is extended to 9 pixels (3x3). Is there any function which would be able to do that?
No, libpng is an I/O library that deals with reading and writing the PNG image format.
Resizing an image has nothing to do with any on-disk file format, it's a pure image operation that generally happens in-memory.
You should look at some general-purpose image-processing library, or just do it yourself. The particular resize you mention is easy enough, just read a single pixel and write it 9 times to the output. Then use libpng's functions to save the new image.

Audio (mp3) editing in C

What I wish to do is to "split" an .mp3 into two separate files, taking duration as an argument to specify how long the first file should be.
However, I'm not entirely sure how to achieve this in C. Is there a particular library that could help with this? Thanks in advance.
I think you should use the gstreamer framework for this purpose. So you can write an application where you can use existing plugins to do this job. I am not sure of this but you can give it a try. Check out http://gstreamer.freedesktop.org/
For queries related to gstreamer: http://gstreamer-devel.966125.n4.nabble.com/
If you don't find any library in the end, then understand the header of a mp3 file and divide the original file into any number of parts and add individual headers to them. Its not gonna be easy but its possible.
It can be as simple as cutting the file at a position determined by the mp3 bitrate and duration requested. But:
your file should be CBR - that method won't work on ABR or VBR files, because they have different densityes
your player should be robust enough not to break if it gets partial mp3 frame at a start. Most of the playback libraries will handle mp3s split that way very gracefully.
If you need more info, just ask, I am on the mobile and can get you more info later.
If you want to be extra precise when cutting, you can use some library to parse mp3 frame headers, and then write frames that you need. That way, and the way mentioned before, you'll get only frame alignment as a minimum, and you have to live with thaty and that's 40ms.
If that isn't enough, you must decode mp3 to PCM, split at sample boundary, then recompress to mp3 again.
Good luck
P.s.
When you say split, I hope you don't expect them to play one after another with no audible 'artifacts'. Mp3 frames aren't self-sufficient, as they carry information from the frame before.

Display PostScript in WPF

I'd like to display some sheet music in my WPF application which was generated by Lilypond. Lilypond can make postscript and PNG files - I've got the latter working, but I'd much prefer the former so that the music can be resized nicely. Is there a way to do that?
Simplest, but perhaps distasteful to many, would be to shell-out and use an external program render the postscript to png. You'd probably want to display some generic "working, please wait" message, as making an accurate progress-bar would be quite a chore.
Alternately, ghostscript can be used as a library and can read the PS from memory and render to memory, potentially saving some disk-access.

Resources