{"id":1883,"date":"2016-09-11T14:57:32","date_gmt":"2016-09-11T06:57:32","guid":{"rendered":"http:\/\/www.magicandlove.com\/blog\/?p=1883"},"modified":"2016-09-11T14:57:32","modified_gmt":"2016-09-11T06:57:32","slug":"save-processing-screen-as-video-with-jcodec-new","status":"publish","type":"post","link":"http:\/\/www.magicandlove.com\/blog\/2016\/09\/11\/save-processing-screen-as-video-with-jcodec-new\/","title":{"rendered":"Save Processing screen as video with jCodec &#8211; new"},"content":{"rendered":"<p>It may not be easy for readers to get the old jcodec-0.1.5.jar for what I have done in the last post. I tried to work out for a newer solution but found that the latest version did change quite a lot. The latest <a href=\"https:\/\/github.com\/jcodec\/jcodec\">jcodec source is 0.2.0<\/a>. I built the latest two files for the Processing test<\/p>\n<ul>\n<li>jcodec-0.2.0.jar<\/li>\n<li>jcodec-javase-0.2.0.jar<\/li>\n<\/ul>\n<p>You can download a <a href=\"http:\/\/www.magicandlove.com\/software\/jcodec020.zip\">compressed file of the code folder<\/a> where you can drop and extract inside the Processing sketch folder. The Processing codes also change to reflect the class structure. Here it is.<br \/>\n&nbsp;<\/p>\n<pre lang=\"java\">\r\n\/\/ Save video file\r\nimport processing.video.*;\r\nimport org.jcodec.api.awt.AWTSequenceEncoder8Bit;\r\n\r\nimport java.awt.image.BufferedImage;\r\nimport java.io.File;\r\n\r\nimport org.slf4j.Logger;\r\nimport org.slf4j.LoggerFactory;\r\nimport org.apache.log4j.BasicConfigurator;\r\n\r\nstatic Logger log;\r\nCapture cap;\r\nAWTSequenceEncoder8Bit enc;\r\nString videoName;\r\nString audioName;\r\nboolean recording;\r\n\r\nvoid setup() {\r\n  size(640, 480);\r\n  background(0);\r\n  log = LoggerFactory.getLogger(this.getClass());\r\n  BasicConfigurator.configure();\r\n  cap = new Capture(this, width, height);\r\n  videoName = \"bear.mp4\";\r\n  recording = false;\r\n  int fRate = 25;\r\n  frameRate(fRate);\r\n  cap.start();\r\n  try {\r\n    enc = AWTSequenceEncoder8Bit.createSequenceEncoder8Bit(new File(dataPath(videoName)), fRate);\r\n  } \r\n  catch (IOException e) {\r\n    e.printStackTrace();\r\n  }\r\n}\r\n\r\nvoid draw() {\r\n  image(cap, 0, 0);\r\n  if (recording) {\r\n    BufferedImage bi = (BufferedImage) cap.getNative();\r\n    try {\r\n      enc.encodeImage(bi);\r\n    } \r\n    catch (IOException e) {\r\n      e.printStackTrace();\r\n    }\r\n  }\r\n}\r\n\r\nvoid captureEvent(Capture c) {\r\n  c.read();\r\n}\r\n\r\nvoid mousePressed() {\r\n  recording = !recording;\r\n  log.info(\"Recording : \" + recording);\r\n}\r\n\r\nvoid keyPressed() {\r\n  if (keyCode == 32) {\r\n    try {\r\n      enc.finish();\r\n    } \r\n    catch (IOException e) {\r\n      e.printStackTrace();\r\n    }\r\n  }\r\n}<\/pre>\n","protected":false},"excerpt":{"rendered":"<p>It may not be easy for readers to get the old jcodec-0.1.5.jar for what I have done in the last post. I tried to work out for a newer solution but found that the latest version did change quite a lot. The latest jcodec source is 0.2.0. I built the latest two files for the [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[89,79],"tags":[149,62],"class_list":["post-1883","post","type-post","status-publish","format-standard","hentry","category-research","category-software-2","tag-jcodec","tag-processing-org"],"_links":{"self":[{"href":"http:\/\/www.magicandlove.com\/blog\/wp-json\/wp\/v2\/posts\/1883","targetHints":{"allow":["GET"]}}],"collection":[{"href":"http:\/\/www.magicandlove.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/www.magicandlove.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/www.magicandlove.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/www.magicandlove.com\/blog\/wp-json\/wp\/v2\/comments?post=1883"}],"version-history":[{"count":1,"href":"http:\/\/www.magicandlove.com\/blog\/wp-json\/wp\/v2\/posts\/1883\/revisions"}],"predecessor-version":[{"id":1884,"href":"http:\/\/www.magicandlove.com\/blog\/wp-json\/wp\/v2\/posts\/1883\/revisions\/1884"}],"wp:attachment":[{"href":"http:\/\/www.magicandlove.com\/blog\/wp-json\/wp\/v2\/media?parent=1883"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/www.magicandlove.com\/blog\/wp-json\/wp\/v2\/categories?post=1883"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/www.magicandlove.com\/blog\/wp-json\/wp\/v2\/tags?post=1883"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}