Fast movie creation using MATLAB and ffmpeg - matlab

I have some time series data that I would like to create into movies. The data could be 2D (about 500x10000) or 3D (500x500x10000). For 2D data, the movie frames are simply line plot using plot, and for 3D data, we can use surf, imagesc, contour etc. Then we create a video file using these frames in MATLAB, then compress the video file using ffmpeg.
To do it fast, one would try not to render all the images to display, nor save the data to disk then read it back again during the process. Usually, one would use getframe or VideoWriter to create movie in MATLAB, but they seem to easily get tricky if one tries not to display the figures to screen. Some even suggest plotting in hidden figures, then saving them as images to disk as .png files, then compress them using ffmpeg (e.g. with x265 encoder into .mp4). However, saving the output of imagesc in my iMac took 3.5s the first time, then 0.5s after. I also find it not fast enough to save so many files to disk only to ask ffmpeg to read them again. One could hardcopy the data as this suggests, but I am not sure whether it works regardless of the plotting method (e.g. plot, surf etc.), and how one would transfer data over to ffmpeg with minimal disk access.
This is similiar to this, but immovie is too slow. This post 3 is similar, but advocates writing images to disk then reading them (slow IO).

maybe what you're trying to do is to convert your data into an image by doing the same kind of operation that surf, or imagesc or contour is doing and then writing it to a file directly, that would keep all the data in the memory until writing is needed.
I had little experience with real images that could also work here:
I saw that calling imshow took lot of time, but changing the CData of a presetted figure created by the imshow function took around 5ms, so, maybe you could set a figure using any of the function you like, and then update the underlying XData, YData etc. so that the figure will update in the same fashion?
best of luck!

Related

How to plot vector (not rastered as pixels) graphics in opencv

Being used to Matlab and its great capabilities of drawing vector graphics, I am looking for something similar in OpenCV. OpenCV drawing functions seem to raster the lines or points at pixel level. Currently, I am dumping the data into text, copy-paste to Matlab and doing all the plots. I also thought about using Matlab engine to pass it the parameters and running plots, but it seems to be too much mess for simple debug operation.
I want to be able to do the following:
Zoom in, out of the image
Draw a line/point which is re-rastered each time I do zoom, like in Matlab.
Currently, I found image watch plugin to take care of zooming, but it does not help with the second part.
Any idea?
OpenCV has a lot of capabilities to process an image but only minimal ones for displaying the result. It has nothing that can display vector graphics like Matlab. When I need to see polygons on image (or just polygons) I am dumping them to file and using third party viewer (usually Giv viewer).

How to make a 3D plot in paraview with a time-axis?

After some simulations with fenics, I saved the results in vtk format, so that I can load it in ParaView. The results are 1D-data, that are time-dependent. In the end, it should look like these example figures, I found in some papers:
This means one axis for space coordinates, one for the time and one for the actual data. ParaView shows me my data and with "warp by scalar" I get the desired result, however only for exactly one time step. Animating works too, but I do not want to create a video for 1D-data, when it looks much nicer in one 3D plot.
How can I add the time as additional axis in ParaView?
This, I am afraid, is not supported currently. It's certainly a nice feature, however. I'd suggest making a feature request on the ParaView Bug Tracker

how to generation animation as mpg or speed up gif in matlab

I am plotting a randomly walking points on the figure and trying to capture the motion at each step by getframe. After I collect all the frames, I output the result as avi with movie2avi, but the output file was so big to fit into my presentation. I am looking for a way to export the movie to mp4, anyone have any idea? I also try to use the 3rd party movie2gif, it save the size to huge extent but when I play the gif, it looks so unsmooth
In later versions of Matlab (e.g. 2012) it is done by creating and writing a video object. For example, the following code generates movie of a randomly moving circle. You can adjust the speed of the movie with the FrameRate and the size with the Quality properties. For more details see the Matlab documentation.
vobj=VideoWriter('MyMovieFile', 'Motion JPEG AVI');
vobj.FrameRate=4;
vobj.Quality=75
open(vobj);
for i=1:100
plot(rand,rand,'o')
F=getframe(gcf);
writeVideo(vobj, F);
cla(gca)
end
close(vobj)

faster imread with matlab for images with small portion of data

I'm trying to track objects in separated frames of a video. If I do a background subtraction before storing the images the size of the images will be much smaller (like one fifth). so I was wondering if I can also read these images faster since most of the pixels are zero. Still simple imread didn't make any difference.
I also tried the pixelregion option for loading only the location of objects and that didn't work either since there are like ten objects in each frame.
It may be faster to store the frames as a video file, rather than individual images. Then you can read them using vision.VideoFileReader from the Computer Vision System Toolbox.

iphone: Use Core Plot with large number of data point, or another graphing solution?

I am wanting to use core plot but before I work on implementing it, I am wondering how it performs with a large number of data points. Some of the data we want to display on a line graph has around 5000 data points.
Can core plot show all of this data on screen without having to scroll to see more data? Will it load this many points fairly quickly? Does core plot cache larger graphs like this?
Any comments about this would be great.
Can core plot show all of this data on screen without having to scroll to see more data?
Sure, the scale of your plot space and axes is independent of the number of data points.
Will it load this many points fairly quickly?
It depends on what format you're starting with (Core Plot supports several ways of getting data), the device you're using, and how you define "fairly quickly". My gut feeling is that loading the data won't be your bottleneck no matter what format you use--drawing 5000 points will. You'll probably have to try it to see if it will meet your needs.
Does core plot cache larger graphs like this?
It caches the data in an efficient format and there are methods to add and remove data points without reloading everything. It does not cache the bitmap explicitly. Core Plot uses Core Animation to handle all of the graphical elements, so it takes advantage of the caching and optimizations built into CA.