{"id":645,"date":"2009-12-09T15:58:28","date_gmt":"2009-12-09T19:58:28","guid":{"rendered":"http:\/\/www.uvm.edu\/~waw\/blog\/?p=645"},"modified":"2009-12-09T15:58:28","modified_gmt":"2009-12-09T19:58:28","slug":"i-created-a-red5-application","status":"publish","type":"post","link":"https:\/\/blog.uvm.edu\/waw\/2009\/12\/09\/i-created-a-red5-application\/","title":{"rendered":"I created a Red5 Application"},"content":{"rendered":"<p>Working with Red5 is like pulling teeth.<\/p>\n<p>Trying to see if I can spawn an ffmpeg instance after uploading a live video capture.<\/p>\n<p>First step was to see if I could edit\/copy any existing application, us to get the recipe. the oflaDemo application is he usual kick off for such things, but it is in fact a very simplistic demo and not exactly what I had in mind. All it really does is list the media files in the streams folder, and report back to the Flash client.<\/p>\n<p>A better example appeared to be Carl Sziebert&#8217;s server side stream-recording:<\/p>\n<p>http:\/\/sziebert.net\/posts\/server-side-stream-recording-updated\/<\/p>\n<p>He gives us the Java code (and ActionScript, too). It seems to interact with Red5 a lower level than the base ActionScript NetConnection tools. This, I hope, will allow me to follow <code>stream.saveAs(streamName, false); <\/code>with something like <code>child = Runtime.getRuntime().exec(command);<\/code>.<\/p>\n<p>But first, how to compile and install a new app?<\/p>\n<p>I got the red5 sample code using<br \/>\n<code>svn checkout http:\/\/red5.googlecode.com\/svn\/java\/example\/trunk\/<\/code>.<\/p>\n<p>I duplicated the oflaDemo folder inside folder trunk, and renamed it Recorder<\/p>\n<p>I replaced the Application.java and StreamManager.java files in \/src\/org\/red5\/demos\/oflaDemo with the sziebert code. renamed enclsing folder \/src\/org\/red5\/demos\/Recorder<\/p>\n<p>set working directory to trunk\/Recorder, setenv RED5_HOME to correct path, and invoked ant to compile. Looked in dist folder for Recorder.war, renamed it as Recorder.zip, unzipped, and moved result to Red5\/webapps<\/p>\n<p>in webapps.Recorder.WEB-INF, edited red5-web.properties, red5-web.xml, and web.xml to replace references to org\/red5\/demos\/oflaDemo with net\/sziebert\/tutorials<\/p>\n<p>restarted red5, tried my old Flash client (modified to connect to server address xxx.yyy.zzz.qqq\/Recoder ), worked as it did before.<\/p>\n<p>After looking again at my ActionScript Flash client, I see that I already have:<\/p>\n<blockquote><p>\n<code>function doCloseRecord() {<br \/>\n\t\/\/ after we have hit \"Stop\" recording and after the buffered video data has been<br \/>\n\t\/\/ sent to the Flash Media Server close the publishing stream<br \/>\n\tnsPublish.close();<br \/>\n\tnsPublish.publish(\"null\");<br \/>\n\tWait.text=\"Done!\";<br \/>\n}<\/code>\n<\/p><\/blockquote>\n<p>So, turns out I know exactly when my stream has finished uploading, and it is safe to launch ffmpeg. I really didn&#8217;t need sziebert&#8217;s low-level stuff. I just needed  to rewrite Application.java to include a method which I could name &#8216;launchexternal&#8217;  which execs a shell command. Then, my ActionScript code becomes<\/p>\n<blockquote><p>\n<code><br \/>\nfunction Fault(f:Event ){<br \/>\n    trace(\"There was a problem: \" + f.toString());<br \/>\n}<\/p>\n<p>function Result(result:Object) {<br \/>\n\ttrace(\"result from launchexternal \"+ result);<br \/>\n};<br \/>\nvar res = new Responder(Result,Fault);<\/p>\n<p>function doCloseRecord() {<br \/>\n\t\/\/ after we have hit \"Stop\" recording and after the buffered video data has been<br \/>\n\t\/\/ sent to the Flash Media Server close the publishing stream<br \/>\n\tnsPublish.close();<br \/>\n\tnsPublish.publish(\"null\");<br \/>\n\tWait.text=\"Done!\";<br \/>\n\tnc.call(\"launchexternal\",res);<br \/>\n}<\/code>\n<\/p><\/blockquote>\n<p>Fault and Result are functions that return results from the Responder object, The responder object gets passed to the nc.call method, and the results of launchexternal are returned<\/p>\n<p>At first blush, then, my new Application java starts to look like this<\/p>\n<blockquote><p>\n<code><br \/>\npublic string launchexternal() {<br \/>\n \t\tlog.info(\"wrecorder launchexternal\");<br \/>\n\t\tSystem.out.println(\"wrecorder launchexternal\");<br \/>\n\t\ttry {<br \/>\n\t\t\tString[] commands = new String[]{\"ls\", \"-lt\", \"..\"};<br \/>\n\t\t\tProcess child = Runtime.getRuntime().exec(commands);<br \/>\n\t\t\tInputStream in = child.getInputStream();<br \/>\n\t\t\tint c;<br \/>\n\t\t\twhile ((c = in.read()) != -1) {<br \/>\n\t\t\t\tSystem.out.println((char)c);<br \/>\n\t\t\t}<br \/>\n\t\t\tin.close();<br \/>\n\t\t} catch (IOException e) {<br \/>\n    }<br \/>\n\t\treturn true;<br \/>\n\t}<\/code>\n<\/p><\/blockquote>\n<p>By gosh, it worked, and the results of the ls command were spewed across the console from which I launched red5<\/p>\n<p>But was it an asynchronous background process? Further research into Runtime.getRuntime().exec suggested it was depreciated in favor of ProcessBuilder.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Working with Red5 is like pulling teeth. Trying to see if I can spawn an ffmpeg instance after uploading a live video capture. First step was to see if I could edit\/copy any existing application, us to get the recipe. &hellip; <a href=\"https:\/\/blog.uvm.edu\/waw\/2009\/12\/09\/i-created-a-red5-application\/\">Continue reading <span class=\"meta-nav\">&rarr;<\/span><\/a><\/p>\n","protected":false},"author":7,"featured_media":0,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[152203,8025,8026,141],"tags":[],"class_list":["post-645","post","type-post","status-publish","format-standard","hentry","category-electronicarts","category-scriptingprogramming","category-systems-and-servers","category-video"],"_links":{"self":[{"href":"https:\/\/blog.uvm.edu\/waw\/wp-json\/wp\/v2\/posts\/645","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/blog.uvm.edu\/waw\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/blog.uvm.edu\/waw\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/blog.uvm.edu\/waw\/wp-json\/wp\/v2\/users\/7"}],"replies":[{"embeddable":true,"href":"https:\/\/blog.uvm.edu\/waw\/wp-json\/wp\/v2\/comments?post=645"}],"version-history":[{"count":3,"href":"https:\/\/blog.uvm.edu\/waw\/wp-json\/wp\/v2\/posts\/645\/revisions"}],"predecessor-version":[{"id":648,"href":"https:\/\/blog.uvm.edu\/waw\/wp-json\/wp\/v2\/posts\/645\/revisions\/648"}],"wp:attachment":[{"href":"https:\/\/blog.uvm.edu\/waw\/wp-json\/wp\/v2\/media?parent=645"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/blog.uvm.edu\/waw\/wp-json\/wp\/v2\/categories?post=645"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/blog.uvm.edu\/waw\/wp-json\/wp\/v2\/tags?post=645"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}