Scheming a neon piece…
Easy Processing > Illustrator Export (bonus SVG export)
After a long time playing with ideas for an easy Processing to Illustrator tool that would allow fancy coding to be piped directly into Illustrator for further layout (and was vector-based the whole way through – no terrible rasterization allowed), I now have a really easy solution that doesn’t involve any fancy code, external libraries, or command-line nonsense. The process:
1. Write your code as usual, but add PDF export
2. Run once and use File > Place… to insert the PDF into your AI document (do not simply open the document, as changes will not be reflected) — NOTE: be sure “Link” is clicked when placing
3. The resulting PDF, placed into the document as a single unit
4. Make changes in Processing and re-save the pdf – here we reduce the number of lines from 1,000 to 10
5. Back in AI, you will be prompted to update the pdf – easy! No need to ask it, simply moving between programs updates your work
6. Awesome, done.
A dead end for this process was SVG export from Processing, which is not super easy (surprisingly). Here’s my hack that uses Inkscape’s command line tools:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 |
import processing.pdf.*; String filename = "test.pdf"; boolean deletePDF = false; void setup() { size(11*72, 17*72); // pretend we're creating a normal pdf beginRecord(PDF, filename); // do some stuff here! for (int i=0; i<1000; i++) { line(random(0,width), random(0,height), random(0,width), random(0,height)); } endRecord(); // convert to svg // via: http://www.inkscapeforum.com/viewtopic.php?f=5&t=5391 String[] outputFile = split(filename, '.'); runUnixCommand("/Applications/Inkscape.app/Contents/Resources/script --without-gui " + sketchPath + "/" + filename + " --export-plain-svg=" + sketchPath + "/" + outputFile[0] + ".svg", sketchPath); // if specified, delete the original pdf if (deletePDF) { runUnixCommand("rm " + filename + " -f", sketchPath); } // X11 will still be running, so you'll have to quit it by hand... } void runUnixCommand(String commandToRun, String dir) { File workingDir = new File(dir); // where to do it - should be full path String returnedValues; // value to return any results // run the command! try { Process p = Runtime.getRuntime().exec(commandToRun, null, workingDir); int i = p.waitFor(); if (i == 0) { BufferedReader stdInput = new BufferedReader(new InputStreamReader(p.getInputStream())); while ( (returnedValues = stdInput.readLine ()) != null) { println(returnedValues); } } else { BufferedReader stdErr = new BufferedReader(new InputStreamReader(p.getErrorStream())); while ( (returnedValues = stdErr.readLine ()) != null) { println(returnedValues); } } } catch (Exception e) { println("Error running command!"); println(e); } } |
Creating Video With Processing and FFMPEG
Max/MSP users: look familiar?
For the past week I have been wrangling with getting ffmpeg (the open-source, command line video utility) to run in a Processing sketch and preserve the hard edges of graphical and/or intentionally pixelly video. It now works!
Details are listed in the code itself, but it is most important to note that the codec is likely the most important factor in getting good quality. The “png” codec is great, but will create rather large files; mjpeg (MotionJPEG) also works well for graphics and hard edges (pixellated images, etc); H.264 is all-around good for photgraphic images.
The sketch below runs ffmpeg’s commands within Processing (as covered before) and exports a video from a series of still files. Processing’s built-in video library seems ok, but offers little in the way of control as compared to ffmpeg. Questions or suggestions are welcomed – feel free to use but please give credit!
UPDATE:
While I really don’t know why, the previous sketch seems to break with a Java IOException error. It appears that ffmpeg can’t be found, but the solution is simple: specify the path to your ffmpeg install. For example:
/usr/local/bin/ffmpeg filename.mov etc...
The “-c:v” option to specify the codec is also updated to “-vcodec” and “-acodec”
[ download the updated sketch here ]
Installing ffmpeg (and LAME) on Mac Snow Leopard and Lion
A video still created programmatically; thousands of these can be combined into video using the ffmpeg library – faster and cleaner than a clunky Final Cut project
UPDATE 2: I ran into an error trying to install ffmpeg using these instructions yesterday. However, installing using MacPorts worked like a charm! I suggest following the instructions for installing LAME first, then use MacPorts to install ffmpeg using the following command:
1 |
sudo port install ffmpeg |
UPDATE: Having switched recently to Lion, the install below didn’t quite work. With a small tweak, it appears to be ok – see below for details.
Well, it might not be Lion (doing live musical performance with my laptop makes me leary of new operating systems) but after finding little recent info on installing ffmpeg on a Mac, I’ve put together this basic outline. For someone who isn’t great at installing libraries using Terminal, it wasn’t completely straightforward, but it works! You will need the Apple Developer Tools to make this work (so far as I can tell).
UPDATE: I did a fresh install of XCode and had to do one small addition to get everything to compile. For details, see this post.
This tutorial is based on the tutorial by Stephen Jungels, with some explanation and consolidation targeted at noobs (like myself). Definite hat tip, Stephen!
The basic steps are as follows, full details after the break:
- Install Git
- Download LAME
- Download ffmpeg
- Find or create folder to install to
- Install LAME
- Install ffmpeg
- Test
Continue reading “Installing ffmpeg (and LAME) on Mac Snow Leopard and Lion”