Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import codeanticode.syphon.*;
- import java.io.*;
- String ffmpegInstall = "/opt/local/bin/"; // you may need to specify the location that ffmpeg is installed**
- String exportFilename = "out.mov"; // MUST INCLUDE EXTENSION (mov, mp4, or see ffmpeg doc for list)
- int frameWidth = 1280; // size for exported video
- int frameHeight = 720;
- int fps = 30; // frames per second for resulting video
- String codec = "mpeg4";
- String commandToRun;
- PGraphics canvas;
- SyphonClient client;
- public void setup() {
- size(1280, 720, P3D);
- println("Available Syphon servers:");
- println(SyphonClient.listServers());
- // Create syhpon client to receive frames
- // from the first available running server:
- client = new SyphonClient(this);
- // A Syphon server can be specified by the name of the application that it contains it,
- // its name, or both:
- // Only application name.
- //client = new SyphonClient(this, "SendFrames");
- // Both application and server names
- //client = new SyphonClient(this, "SendFrames", "Processing Syphon");
- // Only server name
- //client = new SyphonClient(this, "", "Processing Syphon");
- // An application can have several servers:
- //client = new SyphonClient(this, "Quartz Composer", "Raw Image");
- //client = new SyphonClient(this, "Quartz Composer", "Scene");
- background(0);
- }
- public void draw() {
- if (client.available()) {
- canvas = client.getGraphics(canvas);
- image(canvas, 0, 0, width, height);
- saveFrame("/Volumes/tempdisk/frame.tif");
- // commandToRun = ffmpegInstall + "ffmpeg -y -r " + fps + " -i /Volumes/tempdisk/frame.tif -vcodec " + codec + " " + exportFilename; // command that runs ffmpeg
- commandToRun = ffmpegInstall + "ffmpeg -y -r " + fps + " -i /Volumes/tempdisk/frame.tif -vcodec " + codec + " " + "-preset ultrafast -vf setsar=1:1 -q 1 -an -f rawvideo udp://239.0.1.22:1234";
- UnixCommand(commandToRun);
- }
- }
- void keyPressed() {
- if (key == ' ') {
- client.stop();
- } else if (key == 'd') {
- println(client.getServerName());
- }
- }
- void UnixCommand(String commandToRun) {
- File workingDir = new File(sketchPath(""));
- String returnedValues;
- 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) {
- // enable this option if you want to get updates when the process succeeds
- // println(" " + returnedValues);
- }
- }
- else {
- BufferedReader stdErr = new BufferedReader(new InputStreamReader(p.getErrorStream()));
- while ( (returnedValues = stdErr.readLine ()) != null) {
- // print information if there is an error or warning (like if a file already exists, etc)
- println(" " + returnedValues);
- }
- }
- }
- // if there is an error, let us know
- catch (Exception e) {
- println("Error, sorry!");
- println(" " + e);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment