realtime sketch output video capture
in
Share your Work
•
8 months ago
I just corrected a stupid error and got my third attempt at realtime sketch capture to work. I haven't tested it much at all and the code is still a little raw, but I am very pleased with the performance and convenience.
My previous attempts:
attempt one
attempt two
This third version is much more convenient because it captures directly to compressed video instead of an image sequence and, now that I have OpenGL PBOs working, using it seems to cause very little framerate penalty. I have only tested it with 720 so far though.
The process involves adding a file to the sketch you would like to capture. The code creates a temporary file and continuously overwrites it with the raw pixel data of the most recent frame. The actual video encoding is done by ffmpeg which is run via another Processing sketch that reads the same temporary file that is being written to and pipes the data to the ffmpeg process. Your PATH environment variable has to inlude ffmpeg's bin folder for this to work.
capSend.pde (put this with the sketch you want to capture)
capEncode.pde (run your sketch using capSend.pde, then this to start capturing, click to stop)
The encoding sketch is basically an ffmpeg command line that I have tailored for Vimeo. The output video filenames are hard coded and it will overwrite them without asking unless you rename them. I have only tested this on Windows and Processing 1.5.1 because those are what I use most of the time (it wont work on the 2.0 betas). I'm kind of waiting for a stable 2.0 release before trying it with that. It shouldn't be hard to convert.
The command lines could probably be less hackish if this was run on Mac or Linux. I have the option to record the currently playing audio along with the video which should be possible with just one command line but I had to do them separately and combine them after the capture because the audio would not allow the process to end and close the file properly. On Linux I'm assuming you could send the process SIGINT with the kill command and it would close correctly. Also on Windows I'm using this audio capture thing. I don't know if you can capture line in via ffmpeg on Windows, but I think you can on Linux. Anyway I have the audio disabled by default in the code.
If you try it don't forget to make sure the width(ww) and height(hh) and save and temp locations match in both files. Width and height are set to 1280 and 720 by default. The temp location defaults to C:\p5temp and the save location to a folder called test in the sketch path. I'd be happy to hear if it does or doesn't work and how it performs on your system; Also, any suggestions for the code.
My previous attempts:
attempt one
attempt two
This third version is much more convenient because it captures directly to compressed video instead of an image sequence and, now that I have OpenGL PBOs working, using it seems to cause very little framerate penalty. I have only tested it with 720 so far though.
The process involves adding a file to the sketch you would like to capture. The code creates a temporary file and continuously overwrites it with the raw pixel data of the most recent frame. The actual video encoding is done by ffmpeg which is run via another Processing sketch that reads the same temporary file that is being written to and pipes the data to the ffmpeg process. Your PATH environment variable has to inlude ffmpeg's bin folder for this to work.
capSend.pde (put this with the sketch you want to capture)
capEncode.pde (run your sketch using capSend.pde, then this to start capturing, click to stop)
The encoding sketch is basically an ffmpeg command line that I have tailored for Vimeo. The output video filenames are hard coded and it will overwrite them without asking unless you rename them. I have only tested this on Windows and Processing 1.5.1 because those are what I use most of the time (it wont work on the 2.0 betas). I'm kind of waiting for a stable 2.0 release before trying it with that. It shouldn't be hard to convert.
The command lines could probably be less hackish if this was run on Mac or Linux. I have the option to record the currently playing audio along with the video which should be possible with just one command line but I had to do them separately and combine them after the capture because the audio would not allow the process to end and close the file properly. On Linux I'm assuming you could send the process SIGINT with the kill command and it would close correctly. Also on Windows I'm using this audio capture thing. I don't know if you can capture line in via ffmpeg on Windows, but I think you can on Linux. Anyway I have the audio disabled by default in the code.
If you try it don't forget to make sure the width(ww) and height(hh) and save and temp locations match in both files. Width and height are set to 1280 and 720 by default. The temp location defaults to C:\p5temp and the save location to a folder called test in the sketch path. I'd be happy to hear if it does or doesn't work and how it performs on your system; Also, any suggestions for the code.