{"id":952,"date":"2012-04-10T21:21:19","date_gmt":"2012-04-10T13:21:19","guid":{"rendered":"http:\/\/www.magicandlove.com\/blog\/?p=952"},"modified":"2012-04-10T21:24:13","modified_gmt":"2012-04-10T13:24:13","slug":"directshow-for-processing","status":"publish","type":"post","link":"http:\/\/www.magicandlove.com\/blog\/2012\/04\/10\/directshow-for-processing\/","title":{"rendered":"DirectShow for Processing"},"content":{"rendered":"<p>I adopt the <a href=\"http:\/\/www.humatic.de\/htools\/dsj.htm\">DirectShow Java Wrapper<\/a> to work in Processing with two classes, one for movie playback and one for video capture. At this moment, there are just two Java classes, not an individual library yet. Since it is for DirectShow, it is of course in Windows platform. You have to package the <strong>dsj.jar<\/strong> and the <strong>dsj.dll<\/strong> (32bit or 64bit according to your platform) into your <strong>code<\/strong> folder.<br \/>\n&nbsp;<br \/>\n<strong>The DMovie class for movie playback<\/strong><\/p>\n<pre lang=\"java\">\r\nimport de.humatic.dsj.*;\r\nimport java.awt.image.BufferedImage;\r\n\r\nclass DMovie implements java.beans.PropertyChangeListener {\r\n\r\n  private DSMovie movie;\r\n  public int width, height;\r\n\r\n  DMovie(String _s) {\r\n    movie = new DSMovie(dataPath(_s), DSFiltergraph.DD7, this);\r\n    movie.setVolume(1.0);\r\n    movie.setLoop(false);\r\n    movie.play();\r\n    width = movie.getDisplaySize().width;\r\n    height = movie.getDisplaySize().height;\r\n  }\r\n\r\n  public PImage updateImage() {\r\n    PImage img = createImage(width, height, RGB);\r\n    BufferedImage bimg = movie.getImage();\r\n    bimg.getRGB(0, 0, img.width, img.height, img.pixels, 0, img.width);\r\n    img.updatePixels();\r\n    return img;\r\n  }\r\n\r\n  public void loop() {\r\n    movie.setLoop(true);\r\n    movie.play();\r\n  }\r\n  \r\n  public void play() {\r\n    movie.play();\r\n  }\r\n  \r\n  public void propertyChange(java.beans.PropertyChangeEvent e) {\r\n    switch (DSJUtils.getEventType(e)) {\r\n    }\r\n  }\r\n}\r\n<\/pre>\n<p>&nbsp;<br \/>\n<strong>Sample code that uses the DMovie class<\/strong><\/p>\n<pre lang=\"java\">\r\nDMovie mov;\r\n\r\nvoid setup()\r\n{\r\n  size(1280, 692);\r\n  background(0);\r\n  mov = new DMovie(\"Hugo.mp4\");\r\n  mov.loop();\r\n  frameRate(25);\r\n}\r\n\r\nvoid draw()\r\n{\r\n  image(mov.updateImage(), 0, 0);\r\n}\r\n<\/pre>\n<p>&nbsp;<br \/>\n<strong>The DCapture class that performs video capture with the available webcam<\/strong><\/p>\n<pre lang=\"java\">\r\nimport de.humatic.dsj.*;\r\nimport java.awt.image.BufferedImage;\r\n\r\nclass DCapture implements java.beans.PropertyChangeListener {\r\n\r\n  private DSCapture capture;\r\n  public int width, height;\r\n\r\n  DCapture() {\r\n    DSFilterInfo[][] dsi = DSCapture.queryDevices();\r\n    capture = new DSCapture(DSFiltergraph.DD7, dsi[0][0], false, \r\n    DSFilterInfo.doNotRender(), this);\r\n    width = capture.getDisplaySize().width;\r\n    height = capture.getDisplaySize().height;\r\n  }\r\n\r\n  public PImage updateImage() {\r\n    PImage img = createImage(width, height, RGB);\r\n    BufferedImage bimg = capture.getImage();\r\n    bimg.getRGB(0, 0, img.width, img.height, img.pixels, 0, img.width);\r\n    img.updatePixels();\r\n    return img;\r\n  }\r\n\r\n  public void propertyChange(java.beans.PropertyChangeEvent e) {\r\n    switch (DSJUtils.getEventType(e)) {\r\n    }\r\n  }\r\n}\r\n<\/pre>\n<p><strong>Sample code that uses the DCapture class<\/strong><\/p>\n<pre lang=\"java\">\r\nDCapture cap;\r\n\r\nvoid setup() \r\n{\r\n  size(640, 480);\r\n  background(0);\r\n  cap = new DCapture();\r\n}\r\n\r\nvoid draw()\r\n{\r\n  image(cap.updateImage(), 0, 0, cap.width, cap.height);\r\n}\r\n<\/pre>\n","protected":false},"excerpt":{"rendered":"<p>I adopt the DirectShow Java Wrapper to work in Processing with two classes, one for movie playback and one for video capture. At this moment, there are just two Java classes, not an individual library yet. Since it is for DirectShow, it is of course in Windows platform. You have to package the dsj.jar and [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[79,66],"tags":[102,62],"class_list":["post-952","post","type-post","status-publish","format-standard","hentry","category-software-2","category-testing","tag-directshow","tag-processing-org"],"_links":{"self":[{"href":"http:\/\/www.magicandlove.com\/blog\/wp-json\/wp\/v2\/posts\/952","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=952"}],"version-history":[{"count":3,"href":"http:\/\/www.magicandlove.com\/blog\/wp-json\/wp\/v2\/posts\/952\/revisions"}],"predecessor-version":[{"id":954,"href":"http:\/\/www.magicandlove.com\/blog\/wp-json\/wp\/v2\/posts\/952\/revisions\/954"}],"wp:attachment":[{"href":"http:\/\/www.magicandlove.com\/blog\/wp-json\/wp\/v2\/media?parent=952"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/www.magicandlove.com\/blog\/wp-json\/wp\/v2\/categories?post=952"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/www.magicandlove.com\/blog\/wp-json\/wp\/v2\/tags?post=952"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}