0 Replies Latest reply on Dec 28, 2011 1:13 PM by chauffeurdevan

    NativeProcess and FFmpeg pipes

    chauffeurdevan Level 2

      Hi,

       

      I want to do a small interface with Air for FFMPEG using Native Process. Mainly, I want to compress an image sequence not starting at 0. To do that, I need to pipe (I think the filename) to ffmpeg. However the pipe doesn't seems to be sent as I get the following from stdout :

      video:0kB audio:0kB global headers:0kB muxing overhead -1.#IND00%

      Output file is empty, nothing was encoded (check -ss / -t / -frames parameters if used)

       

      Anybody did something similar, or maybe knows better than me about pipes and NativeProcess ?

       

      Here is my package

       

      package{
          import flash.desktop.NativeProcess;
          import flash.desktop.NativeProcessStartupInfo;
          import flash.filesystem.*;
          import flash.events.*;
          
          public class FFmpeg{        
              public function FFmpeg():void {
                  if(NativeProcess.isSupported) {
                      var appStorageUrl = File.documentsDirectory.url;
                      appStorageUrl = appStorageUrl.lastIndexOf("/") == appStorageUrl.length-1 ? appStorageUrl : appStorageUrl + "/";
                      var file:File = new File(appStorageUrl + "ffmpeg.exe");
                      var nativeProcessStartupInfo:NativeProcessStartupInfo = new NativeProcessStartupInfo();
                      nativeProcessStartupInfo.executable = file; 
                      var processArgs:Vector.<String> = new <String>["-y", "-r", "23.976", "-vcodec", "mjpeg", "-pix_fmt", "yuvj444p", "-s", "854x480", "-f", "image2", "-i", "-"];
                      processArgs.push("-vcodec");
                      processArgs.push("libx264");
                      processArgs.push("-f");
                      processArgs.push("h264");
                      processArgs.push("-strict");
                      processArgs.push("experimental");
                      processArgs.push(appStorageUrl + "test.mp4");
                      nativeProcessStartupInfo.arguments = processArgs;
                      _process = new NativeProcess(); 
                      _process.start(nativeProcessStartupInfo);
                      _process.addEventListener(ProgressEvent.STANDARD_OUTPUT_DATA, onOutputData);
                      _process.addEventListener(ProgressEvent.STANDARD_ERROR_DATA, onErrorData);
                      _process.addEventListener(NativeProcessExitEvent.EXIT, onExit);
                      _process.addEventListener(IOErrorEvent.STANDARD_OUTPUT_IO_ERROR, onIOError);
                      _process.addEventListener(IOErrorEvent.STANDARD_ERROR_IO_ERROR, onIOError);
                      _process.standardInput.writeUTFBytes(appStorageUrl + "test.png")
                      _process.closeInput();//seems to be needed
                  }
                  else {
                      trace("NativeProcess not supported.");
                  }
              }        
              
              private function onOutputData(event:ProgressEvent):void{
                  trace(event.type + event.target.standardOutput.readUTFBytes(event.target.standardOutput.bytesAvailable)); 
              }
              
              private function onErrorData(event:ProgressEvent):void{
                  trace(event.type + event.target.standardError.readUTFBytes(event.target.standardError.bytesAvailable)); 
              }
              
              private function onExit(event:NativeProcessExitEvent):void{
                  trace("Process exited with " + event.exitCode);
              }
              
              private function onIOError(event:IOErrorEvent):void{
                   trace("onIOError " + event.toString());
              }
          }
          
      }