This isn't exactly a tool or library yet, but I thought this was the place to post it.
Saving the following code as a pde and adding it to a sketch should allow the sketch output to be captured to an image sequence without any further modification to the sketch itself. After adding the file, running the sketch should produce an extra, minimized window. When the window is "de-minimized" sketch output should be recorded, minimizing should stop recording.
This is in very early development, but should work with some quirks. I've experimented with various image formats and methods of saving them and found that Targa(tga) files work best for what I'm doing. Some formats produce more slowdown in the sketch and general strangeness in the output especially for larger image sizes. I think the problems may have something to do with the image writing functions not being entirely compatible with threading. This is the first time I've tried threading so I really don't know.
I had a little trouble making videos out of the image sequence to, but eventually found a decent process for H264:
Encode to lossless video with ffmpeg using QuickTime "Animation" codec:
ffmpeg -i %06d.tga -vcodec qtrle output.mov
Apparently libx264, the library ffmpeg uses to encode H264, only handles the YUV colorspace so it messes up the color on images in RGB format. I had this problem and others trying to use ffmpeg to go directly from image sequence or my mov to H264 encoding. I streamed the mov through VLC to an H264 encoded mp4 instead. Replace the bitrate part of the output string with crf=18 or so.
I appreciate people trying it out and giving feedback.
Saving the following code as a pde and adding it to a sketch should allow the sketch output to be captured to an image sequence without any further modification to the sketch itself. After adding the file, running the sketch should produce an extra, minimized window. When the window is "de-minimized" sketch output should be recorded, minimizing should stop recording.
This is in very early development, but should work with some quirks. I've experimented with various image formats and methods of saving them and found that Targa(tga) files work best for what I'm doing. Some formats produce more slowdown in the sketch and general strangeness in the output especially for larger image sizes. I think the problems may have something to do with the image writing functions not being entirely compatible with threading. This is the first time I've tried threading so I really don't know.
- PApplet p = this ;
- {
- import javax.imageio.ImageIO;
- import java.awt. image .RenderedImage;
- import java.awt.event.WindowEvent;
- import java.awt.event.WindowStateListener;
- import java.awt.Color;
- import processing.app.Base;
- new ThreadWriter();
- // new Thread(
- // new Runnable() {
- // boolean running = true;
- // public void run() {
- // while(running) {
- // if(frameCount==1) {
- // p.registerDraw(new ThreadWriter());
- // running = false;
- // }
- // }
- // }
- // }
- // ).start();
- }
- public class ThreadWriter implements WindowStateListener {
- int vidRate;
- int ind;
- long fTime;
- File render;
- Frame f;
- String stopped = "p5cap : stopped" ;
- String recording = "p5cap : " ;
- int sz;
- ThreadWriter() {
- vidRate = 0;
- // Base.initPlatform();
- f = setupFrame();
- f.addWindowStateListener( this );
- }
- Frame setupFrame() {
- Frame frame = new Frame();
- frame.setSize(200,200);
- frame.setTitle(stopped);
- frame.setExtendedState(frame.ICONIFIED);
- frame.setLocation( screen . width -200,0);
- frame.setBackground( new Color(255,0,0));
- frame. setVisible ( true );
- return frame;
- }
- public void windowStateChanged(WindowEvent e) {
- if (e.getNewState()==1) {
- p.unregisterDraw( this );
- f.setTitle(stopped);
- }
- if (e.getNewState()==0) {
- if (render== null ) render = new File(p.sketchPath( "render" ));
- if (!render.exists()) render.mkdir();
- fTime = System.nanoTime();
- p.registerDraw( this );
- }
- }
- public void draw () {
- // println(Thread.activeCount());
- double cTime = System.nanoTime()-fTime;
- if (cTime >= vidRate*.001) {
- new Thread (
- new Runnable() {
- public void run() {
- // p.save(render.getAbsolutePath()+"/"+nf(ind++,6)+".tiff");
- p.g. save (render.getAbsolutePath()+ "/" + nf (ind++,6)+ ".tga" );
- // try {
- // ImageIO.write((RenderedImage)p.g.getImage(), "png",
- // createOutput("render/"+nf(ind++,6)+".png"));
- // ImageIO.write((RenderedImage)p.g.getImage(), "jpg",
- // new File(render.getAbsolutePath()+"/"+nf(ind++,6)+".jpg"));
- // }
- // catch(IOException e){println(e);}
- fTime = System.nanoTime();
- }
- }
- ).start();
- }
- // new Thread(
- // new Runnable() {
- // public void run() {
- // sz = Base.calcFolderSize(new File(p.sketchPath("render")));
- // sz /= 1048576; // sz/1024/1024 MB
- // f.setTitle(recording+sz+"MB");
- // }
- // }
- // ).start();
- }
- }
I had a little trouble making videos out of the image sequence to, but eventually found a decent process for H264:
Encode to lossless video with ffmpeg using QuickTime "Animation" codec:
ffmpeg -i %06d.tga -vcodec qtrle output.mov
Apparently libx264, the library ffmpeg uses to encode H264, only handles the YUV colorspace so it messes up the color on images in RGB format. I had this problem and others trying to use ffmpeg to go directly from image sequence or my mov to H264 encoding. I streamed the mov through VLC to an H264 encoded mp4 instead. Replace the bitrate part of the output string with crf=18 or so.
I appreciate people trying it out and giving feedback.
2