Motion-JPEG from APL
8 posts
• Page 1 of 1
Motion-JPEG from APL
I wish to create an animation of a zoom into a Mandelbrot image.
Using Dyalog APL/W I have succeeded by repeatedly replacing one bitmapped image by another under ⎕WC and have produce a very smooth animation, but it is limited to being run under Windows. https://www.youtube.com/watch?v=7aUOAklV2AM
The simplest animation under HTML-5 that I have come across (so far) is Motion-Jpeg. A MPEG file is basically (if I have understood it correctly) a simple header (hight, width and frame rate), followed by a series of JPEG images. Such a file can be played easily onto a browser running HTML5.
I could possibly create a series of 16,000 BMP (or PNG/GIF) files from my bitmaps, convert them to JPEG files via a utility, and then get APL to merge these JPEG files into a single MJPEG file. Each of the 16,000+ BMP files becoming a single frame of the MPEG.
If would be far nicer to get the APL to convert the bitmap data straight into a JPEG "stream" without creating the 16,000 BMP files.
Since Dyalog does not support JPEG formats I might use ⎕NA to access a utility such as GDIPlus / Libgdiplus. (Libgdiplus is the Mono library that provides a GDI+-compatible API on non-Windows operating systems).
GDIPlus support an image format that can be read to and from many image file formats. I should even be able to create a GDI "image" directly within APL. From there creating JPEG output and a MJPEG file should be relatively straight forward.
I have in the past written many calls to programs via ⎕NA calls, and know how hard it is to work out all the parameters that have to be set up with the correct data types using the available documentation and the correct header (.h) files.
If anyone here had any experience in using GDIPlus from Dyalog, and can pass on any tips, I would be vary grateful.
Or if you can suggest a simpler way of creating "movie" files directly from APL. (Stop Go Animation?)
Thanking you for any suggestions
Ray
Using Dyalog APL/W I have succeeded by repeatedly replacing one bitmapped image by another under ⎕WC and have produce a very smooth animation, but it is limited to being run under Windows. https://www.youtube.com/watch?v=7aUOAklV2AM
The simplest animation under HTML-5 that I have come across (so far) is Motion-Jpeg. A MPEG file is basically (if I have understood it correctly) a simple header (hight, width and frame rate), followed by a series of JPEG images. Such a file can be played easily onto a browser running HTML5.
I could possibly create a series of 16,000 BMP (or PNG/GIF) files from my bitmaps, convert them to JPEG files via a utility, and then get APL to merge these JPEG files into a single MJPEG file. Each of the 16,000+ BMP files becoming a single frame of the MPEG.
If would be far nicer to get the APL to convert the bitmap data straight into a JPEG "stream" without creating the 16,000 BMP files.
Since Dyalog does not support JPEG formats I might use ⎕NA to access a utility such as GDIPlus / Libgdiplus. (Libgdiplus is the Mono library that provides a GDI+-compatible API on non-Windows operating systems).
GDIPlus support an image format that can be read to and from many image file formats. I should even be able to create a GDI "image" directly within APL. From there creating JPEG output and a MJPEG file should be relatively straight forward.
I have in the past written many calls to programs via ⎕NA calls, and know how hard it is to work out all the parameters that have to be set up with the correct data types using the available documentation and the correct header (.h) files.
If anyone here had any experience in using GDIPlus from Dyalog, and can pass on any tips, I would be vary grateful.
Or if you can suggest a simpler way of creating "movie" files directly from APL. (Stop Go Animation?)
Thanking you for any suggestions
Ray
Ray Cannon
Please excuse any smelling pisstakes.
Please excuse any smelling pisstakes.
-
ray - Posts: 238
- Joined: Wed Feb 24, 2010 12:24 am
- Location: Blackwater, Camberley. UK
Re: Motion-JPEG from APL
Ray, I wish I could spend more time on this because it sounds like a fun weekend project. But at the moment life is throwing wrenches and I'll have to shelve it for a while. In the meantime, if you want to get something done, I suggest you take a look at ffmpeg (ffmpeg.org). It's an all-in-one executable which can do whatever you can think of around video formats. One of the things it can do is take a list of bitmaps in a directory (in just about any format, I believe) and make a movie out of them, in whichever format you want. ffmpeg's syntax is known to be complex but I believe Chat GPT and friends can help you there.
https://trac.ffmpeg.org/wiki/Slideshow
https://trac.ffmpeg.org/wiki/Slideshow
-
StefanoLanzavecchia - Posts: 113
- Joined: Fri Oct 03, 2008 9:37 am
Re: Motion-JPEG from APL
Thank you for this information Stefano, ffmpeg appears to be exactly the type of information I was looking for. I had not thought about asking ChatGP for help with it.
I will let you know how successful my efforts are.
I will let you know how successful my efforts are.
Ray Cannon
Please excuse any smelling pisstakes.
Please excuse any smelling pisstakes.
-
ray - Posts: 238
- Joined: Wed Feb 24, 2010 12:24 am
- Location: Blackwater, Camberley. UK
Re: Motion-JPEG from APL
I have now created a 5 min 36 second mp4 file from 1000 PNG files using ffmpeg thanks to Stefano's suggestion.
I used MakePNG to create the each of the PNG images from my bitmap data and wrote that to file called zoomNNNN.png, numbering each file in order.
Then ChatGP was given
"I have a set of PNG files in D:\APL and want to use C:\FFmpeg\ffmpg.exe to create a mp4 file from them"
Because my files were actually called zoom0001.png etc I had to add the "zoom" into the result that ChatGP had returned (.... D:\APL\%04d.png ....)
I then ran as a command line:
C:\FFmpeg\ffmpeg.exe -framerate 30 -i D:\APL\zoom%04d.png -c:v libx264 -r 30 -pix_fmt yuv420p C:\temp\output.mp4
An that worked!
So thank you Stefano, and Chat GP.
Once I have added some music, I will post the MP4 movie of the Mandelbrot zoom on YouTube and leave a link here.
I am open to suggestions of what music would be suitable. Maybe I should ask ChatGP!
I used MakePNG to create the each of the PNG images from my bitmap data and wrote that to file called zoomNNNN.png, numbering each file in order.
Then ChatGP was given
"I have a set of PNG files in D:\APL and want to use C:\FFmpeg\ffmpg.exe to create a mp4 file from them"
Because my files were actually called zoom0001.png etc I had to add the "zoom" into the result that ChatGP had returned (.... D:\APL\%04d.png ....)
I then ran as a command line:
C:\FFmpeg\ffmpeg.exe -framerate 30 -i D:\APL\zoom%04d.png -c:v libx264 -r 30 -pix_fmt yuv420p C:\temp\output.mp4
An that worked!
So thank you Stefano, and Chat GP.
Once I have added some music, I will post the MP4 movie of the Mandelbrot zoom on YouTube and leave a link here.
I am open to suggestions of what music would be suitable. Maybe I should ask ChatGP!
Ray Cannon
Please excuse any smelling pisstakes.
Please excuse any smelling pisstakes.
-
ray - Posts: 238
- Joined: Wed Feb 24, 2010 12:24 am
- Location: Blackwater, Camberley. UK
Re: Motion-JPEG from APL
I have now created an MP4 video of my Mandelbrot zoom complete with audio.
The Audio I have chosen is the opening theme from Interstellar by Hans Zimmer. I am currently building a WAV file directly in APL from the score. (I'm about 1/3 complete.)
The ffmpeg command I have used is:
Here's what each part of the command does:
C:\FFmpeg\ffmpeg.exe: Specifies the path to the FFmpeg executable.
-i D:\APL\zoom%04d.png: Specifies the input PNG files located in the directory
%04d is a placeholder that represents a sequential numbering pattern for the PNG files (e.g., 0001.png, 0002.png, etc.).
-stream_loop -1: Specifies the following input is to be repeated endlessly
-i C:\Users\ray_c\Documents\MyDWS\Interstellar.wav: Specifies where the input WAV file is located.
-shortest: This will stop after the shorter of the video and the audio.
-c:v libx264: Sets the video codec to libx264 (H.264 codec). This codec is widely supported and produces good-quality output.
-r 30: Sets the output frame rate to 30 frames per second.
-pix_fmt yuv420p: Sets the pixel format to yuv420p, which is widely compatible with different players and platforms.
C:\output\output.mp4: Specifies the output directory and filename for the resulting MP4 file.
The Audio I have chosen is the opening theme from Interstellar by Hans Zimmer. I am currently building a WAV file directly in APL from the score. (I'm about 1/3 complete.)
The ffmpeg command I have used is:
- Code: Select all
C:\FFmpeg\ffmpeg.exe -i D:\APL\zoom%04d.png -stream_loop -1 -i C:\Users\ray_c\Documents\MyDWS\Interstellar.wav -shortest -c:v libx264 -r 30 -pix_fmt yuv420p C:\temp\output.mp4
Here's what each part of the command does:
C:\FFmpeg\ffmpeg.exe: Specifies the path to the FFmpeg executable.
-i D:\APL\zoom%04d.png: Specifies the input PNG files located in the directory
%04d is a placeholder that represents a sequential numbering pattern for the PNG files (e.g., 0001.png, 0002.png, etc.).
-stream_loop -1: Specifies the following input is to be repeated endlessly
-i C:\Users\ray_c\Documents\MyDWS\Interstellar.wav: Specifies where the input WAV file is located.
-shortest: This will stop after the shorter of the video and the audio.
-c:v libx264: Sets the video codec to libx264 (H.264 codec). This codec is widely supported and produces good-quality output.
-r 30: Sets the output frame rate to 30 frames per second.
-pix_fmt yuv420p: Sets the pixel format to yuv420p, which is widely compatible with different players and platforms.
C:\output\output.mp4: Specifies the output directory and filename for the resulting MP4 file.
Ray Cannon
Please excuse any smelling pisstakes.
Please excuse any smelling pisstakes.
-
ray - Posts: 238
- Joined: Wed Feb 24, 2010 12:24 am
- Location: Blackwater, Camberley. UK
Re: Motion-JPEG from APL
Here (as promised) is my final movie, an MP4 file on YouTube, "Zoom into cherry Blossom"
The Mandelbrot set is centred at ¯1.626083578674037 ¯0.00417344815218.
The Music is by Hans Zimmer from the film Interstellar.
https://youtu.be/jGW-YevMwj4
Many thanks to Stefano for his suggestion to use FFMPEG.
Ray
The Mandelbrot set is centred at ¯1.626083578674037 ¯0.00417344815218.
The Music is by Hans Zimmer from the film Interstellar.
https://youtu.be/jGW-YevMwj4
Many thanks to Stefano for his suggestion to use FFMPEG.
Ray
Ray Cannon
Please excuse any smelling pisstakes.
Please excuse any smelling pisstakes.
-
ray - Posts: 238
- Joined: Wed Feb 24, 2010 12:24 am
- Location: Blackwater, Camberley. UK
Re: Motion-JPEG from APL
Nicely done!
-
StefanoLanzavecchia - Posts: 113
- Joined: Fri Oct 03, 2008 9:37 am
Re: Motion-JPEG from APL
Well done and thank you Ray.
And a fine holiday season to you.
And a fine holiday season to you.
-
Phil Last - Posts: 628
- Joined: Thu Jun 18, 2009 6:29 pm
- Location: Wessex
8 posts
• Page 1 of 1
Return to Windows: GUI, COM/OLE/ActiveX
Who is online
Users browsing this forum: No registered users and 0 guests
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group